Recent

Author Topic: Code formatting changing when file saved/loaded  (Read 6629 times)

MoonWolf

  • New Member
  • *
  • Posts: 10
Code formatting changing when file saved/loaded
« on: October 13, 2015, 07:28:56 pm »
Hi,
I am using Lazarus 1.4.2 for Windows with FPC  2.6.4. I am having a problem with code formatting. For example:
Code: Pascal  [Select][+][-]
  1. function caaCalcMass(WeightInGrains : extended): extended;
  2. begin
  3.   result := (WeightInGrains / GrainsPerPound) / GravityConstant;
  4. end;
  5.  
The above code can change to.
Code: Pascal  [Select][+][-]
  1. function caaCalcMass(WeightInGrains : extended): extended;
  2. begin
  3.         result := (WeightInGrains / GrainsPerPound) / GravityConstant;
  4. end;
  5.  
I can live with this, but it is annoying. I have used Lazarus for several years and this is the first time I have seen this behavior. Has anyone else got this problem?

Thanks.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Code formatting changing when file saved/loaded
« Reply #1 on: October 13, 2015, 08:28:47 pm »
What are your settings under:
Tools > Options > Editor > General > Tab and Indent

Do you have it set like attached image?

(It seems like you have a tab in front of "Result :=".)

MoonWolf

  • New Member
  • *
  • Posts: 10
Re: Code formatting changing when file saved/loaded
« Reply #2 on: October 14, 2015, 12:55:23 am »
What are your settings under:
Tools > Options > Editor > General > Tab and Indent

Do you have it set like attached image?

(It seems like you have a tab in front of "Result :=".)

My settings are identical to the settings in the attached image.

I think the tab in front of "Result :=" is the case.

I have had problems in the past with auto indent. So when I set up 1.4.2 I don't think I made any changes to the default settings.

« Last Edit: October 14, 2015, 01:00:54 am by MoonWolf »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Code formatting changing when file saved/loaded
« Reply #3 on: October 14, 2015, 10:59:22 am »
You could try renaming your editoroptions.xml to editoroptions-old.xml in your config-directory and starting Lazarus. A new editoroptions.xml will be made and your back to the default options for the editor-settings.

If that doesn't work you could do the same with codetoolsoptions.xml.


(I would also be really annoyed if tabs kept appearing where I didn't want them.)

MoonWolf

  • New Member
  • *
  • Posts: 10
Re: Code formatting changing when file saved/loaded
« Reply #4 on: October 14, 2015, 04:35:46 pm »
Thank you for your suggestions. :)
I will give them a try.

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: Code formatting changing when file saved/loaded
« Reply #5 on: October 14, 2015, 08:10:30 pm »
maybe you should change the tab to spaces width to only 2 instead of 8.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Code formatting changing when file saved/loaded
« Reply #6 on: October 14, 2015, 08:20:39 pm »
maybe you should change the tab to spaces width to only 2 instead of 8.
You could do that but it would only mask this annoyance.
I know from experience that if you mix tab and spaces it can be very confusing and annoying. Even when the tab is set at 2 spaces when you put one space in front of it it will not jump. Putting another space it will jump 2 spaces. Very very annoying. It's better to find out why this is happening. (This is why I hate tabs in source-code but that was another discussion from a while ago)

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: Code formatting changing when file saved/loaded
« Reply #7 on: October 14, 2015, 10:45:18 pm »
I know from experience that if you mix tab and spaces it can be very confusing and annoying.
I totally agree with you, but I thought when `Tab to spaces` is checked the editor automatically replaces tabs by the required spaces (or am I wrong?).

maybe I didn't understand `MoonWolf` question?    :-\

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Code formatting changing when file saved/loaded
« Reply #8 on: October 14, 2015, 10:49:01 pm »
but I thought when `Tab to spaces` is checked the editor automatically replaces tabs by the required spaces (or am I wrong?).
Yes, but that setting was already set correctly. Apparently the spaces are there on saving the file but when loading it again they turn into tabs. And that may never happen.

MoonWolf

  • New Member
  • *
  • Posts: 10
Re: Code formatting changing when file saved/loaded
« Reply #9 on: October 15, 2015, 12:17:53 am »
You could try renaming your editoroptions.xml to editoroptions-old.xml in your config-directory and starting Lazarus. A new editoroptions.xml will be made and your back to the default options for the editor-settings.

If that doesn't work you could do the same with codetoolsoptions.xml.


(I would also be really annoyed if tabs kept appearing where I didn't want them.)
This is odd.  The only copy of editoroptions.xml is located in "D:\lazarus\tools\install\linux" and it is dated 2007. I can't find the other file at all.

MoonWolf

  • New Member
  • *
  • Posts: 10
Re: Code formatting changing when file saved/loaded
« Reply #10 on: October 15, 2015, 12:22:00 am »
rvk - As a temporary expedient I'm going to avoid using the tab key and stick with spaces.

shobits1 - I've tried that on previous versions of Lazarus and got some peculiar results from auto-indent.

Thanks for the replies.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Code formatting changing when file saved/loaded
« Reply #11 on: October 15, 2015, 10:54:29 am »
As a temporary expedient I'm going to avoid using the tab key and stick with spaces.
Mmm, that shouldn't matter if, when loading, Lazarus makes them Tabs again. But if it does, then you didn't explain the problem correctly. I thought you saw spaces before saving and a tab after loading.

Could you do the following?
Under Tools > Options > Editor > Misc: Set the "Show special characters".

Now you can see, if you use the tab, if there is really a tab set (it shows » character as tab) or the tab is converted to spaces (· characters). What do you see?
(It's important to know if it has a tab before saving.)

If it has tabs, your "Tabs to spaces"-setting doesn't work.

If it does have spaces, save the file and look with a bin/hex-editor if the spaces are $20 of $09. Which are they?

Now load the file again and see if the spaces are converted to tabs.

MoonWolf

  • New Member
  • *
  • Posts: 10
Re: Code formatting changing when file saved/loaded
« Reply #12 on: October 15, 2015, 06:39:40 pm »
Mmm, that shouldn't matter if, when loading, Lazarus makes them Tabs again. But if it does, then you didn't explain the problem correctly. I thought you saw spaces before saving and a tab after loading.
It appeared to me that Lazarus was making them tabs again. I spent several hours trying to figure this out before posting here. I should have spent more time. Now the problem appears to be user error on my part.   

Could you do the following?
Under Tools > Options > Editor > Misc: Set the "Show special characters".

Now you can see, if you use the tab, if there is really a tab set (it shows » character as tab) or the tab is converted to spaces (· characters). What do you see?
(It's important to know if it has a tab before saving.)
All the tabs I entered were converted to spaces  (· characters). No tab characters ( » ) are present.

If it has tabs, your "Tabs to spaces"-setting doesn't work.

If it does have spaces, save the file and look with a bin/hex-editor if the spaces are $20 of $09. Which are they?

$20.

Now load the file again and see if the spaces are converted to tabs.
The spaces are remaining spaces. Thanks for the tip on showing special characters.

I can only conclude that I was saving tabs when I thought I was saving spaces.  :-[

I would like to thank those who responded and I apologize for wasting their time.  :'(

 

TinyPortal © 2005-2018