Recent

Author Topic: Using tabs instead of spaces with Lazarus  (Read 3214 times)

Nadar

  • New Member
  • *
  • Posts: 17
Using tabs instead of spaces with Lazarus
« on: December 07, 2023, 03:50:30 am »
Disclaimer: I know that there are many, in part strong, opinions regarding if tabs or spaces are the "best" form of indentation. I have discovered that it doesn't make much of a difference, it all depends on what you're used to (I used to be a space-indenter and have since converted after working a lot with code that is tab indented). What does matter though is that it is consistent, or formatting the code becomes somewhat "random".

I'm using Lazarus to write some code that is to be used in a project which uses tab as indentation. I've tried to configure it for using tabs to the best of my abilities, but it is inconsistent. My actual code ends up being a mix. It looks to me like the codetools (or something related) doesn't respect that tab is indentation.

As it is now, I have to manually "clean" the files before making git commits. It's a bit of a pain. I haven't found a way to actually show whitespace characters either, and the search/replace function is somewhat "hard to work with" (especially since it keeps closing every time you use it and you have to make sure the cursor isn't on something when opening it again, or it will replace whatever search phrase you were working on). So, I'm opening and formatting everything in another editor before committing. After that I have to make sure that the files are reloaded in Lazarus, so that the changes are kept. In, short, it's a hassle.

Is there a way to make Lazarus work properly with tabs, or do I have to keep doing this for every commit?

TRon

  • Hero Member
  • *****
  • Posts: 3626
Re: Using tabs instead of spaces with Lazarus
« Reply #1 on: December 07, 2023, 12:01:29 pm »
Is there a way to make Lazarus work properly with tabs, or do I have to keep doing this for every commit?
As you wrote yourself each and everyone has its own opinion on tabs vs spaces but also choosing between either side each side seem to have its own preferences.

Though you ventilated your frustration on inconsistency you failed to mention what is inconsistent and what you already configured to try and make things work the way you want them to. I assume you are familiar with the menu Tools, options (IDE options), editor, general, items Tabs and indent & Miscellaneous ?

For example, at the misc item you can at least set the option "show special characters" that allows you to distinguish between tabs and characters.

Not saying that all these setting work in the way you want them to but in case you believe there is something that is not behaving as it should then you could always try and report it as a bug and/or feature request.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Thaddy

  • Hero Member
  • *****
  • Posts: 16183
  • Censorship about opinions does not belong here.
Re: Using tabs instead of spaces with Lazarus
« Reply #2 on: December 07, 2023, 12:08:06 pm »
The inconsistency is that tabs can not be relied upon.
I think that Lazarus has an option to treat tabs a a defined number of spaces. But I never used that since I am one of those guys that HATE tabs since I often need to reformat other people´ s code to make it readable..
I want consistent behavior along any editor I choose. Tabs do not fit that bill, although it should! it gives you more headaches than warranted.
« Last Edit: December 07, 2023, 12:21:22 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1216
Re: Using tabs instead of spaces with Lazarus
« Reply #3 on: December 07, 2023, 12:33:48 pm »
Lazarus has an option to convert tabs to spaces as well as “ tab indents blocks” which I believe make the tab align with the previous line of code.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 16183
  • Censorship about opinions does not belong here.
Re: Using tabs instead of spaces with Lazarus
« Reply #4 on: December 07, 2023, 12:37:41 pm »
That is what I suspected.
If I smell bad code it usually is bad code and that includes my own code.

440bx

  • Hero Member
  • *****
  • Posts: 4735
Re: Using tabs instead of spaces with Lazarus
« Reply #5 on: December 07, 2023, 12:38:12 pm »
I've tried to configure it for using tabs to the best of my abilities, but it is inconsistent. My actual code ends up being a mix. It looks to me like the codetools (or something related) doesn't respect that tab is indentation.
As @Tron mentioned, without the specifics of the problem no help can be given.  What inconsistencies are you referring to ?... an example of the inconsistencies would be very useful... provide a little snippet of code where the inconsistencies occur...

Maybe what you refer to as "inconsistency" may be a bug but, without specifics no determination can be made.

Is there a way to make Lazarus work properly with tabs, or do I have to keep doing this for every commit?
If you don't provide useful specifics, you'll probably be stuck having to do whatever you're doing for every commit.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Using tabs instead of spaces with Lazarus
« Reply #6 on: December 07, 2023, 12:45:40 pm »
All settings in Menu: Tools > Options  (On Mac Preferences)

* Tabs:
Editor > Genearl > Tabs and Indent
  "Tabs to spaces" off
  "smart tabs" off  (probably...)
  Drop down "Auto indent" => tabs

Codetools > General
  Turn OFF all indention options.

   That means if you press return after a "begin" there will be NO indent added.
   If you want that, and want it tabs....
   Never tried, but you probably need to write a new "example file"... no idea


* Show Special Char:
  Editor > General > Misc "Show special chars"

* Find dialog
    Editor > General > Misc "Find text at cursor"
   Or use cursor down inside the find dialog to get the previous search term

Nadar

  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #7 on: December 08, 2023, 05:17:35 am »
It seems that many of you misunderstood what I mean with "inconsistent". That wasn't critique of Lazarus or those that prefer spaces or anything else, I was merely saying that whatever choice you make, it should be consistent (in the same source file). With my current settings I end up with a mix of spaces and tabs, which isn't good in my view. It ruins the main point of using tabs in that people can use different tab with to make code "readable to them", and it makes future commits very likely to introduce whitespace changes, which tends to ruin diffs.

I want code to use either space or tab for indentation, not a mix. The way my code is formatted now, some lines are all tab - some are all space - and some have both tabs and spaces in the "indentation part of the line".

I'll get back to the other points after having checked my settings closer - I just feel that there's a need to clarify this.

Nadar

  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #8 on: December 08, 2023, 05:23:59 am »
I assume you are familiar with the menu Tools, options (IDE options), editor, general, items Tabs and indent & Miscellaneous ?

I don't know if I qualify as "familiar with", but I feel that I tried to tweak the things I deem relevant without managing to get rid of spaces in some of the indentations, so I guess the answer is yes.

For example, at the misc item you can at least set the option "show special characters" that allows you to distinguish between tabs and characters.
Ah - there it was  ;) Don't ask me how I could have missed it, but I assume that I've been "scanning for" the word "whitespace" and simply missed "special" (characters). Thanks anyway, this makes it a lot easier to see what is actually happening when (as opposed to having to open the file in another editor after having saved it before I can see what ended up as spaces and what ended up as tabs).

Nadar

  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #9 on: December 08, 2023, 05:29:36 am »
The inconsistency is that tabs can not be relied upon.
I think that Lazarus has an option to treat tabs a a defined number of spaces. But I never used that since I am one of those guys that HATE tabs since I often need to reformat other people´ s code to make it readable..
I want consistent behavior along any editor I choose. Tabs do not fit that bill, although it should! it gives you more headaches than warranted.

I'm not too eager to start that discussion, although I must just state that I don't find tabs unreliable or "difficult" in any way. Even though I used to be a "space guy", I now find them easier to deal with - except for one thing: The fact that GitHub think it's appropriate to show a tab as 8 spaces without letting you choose. It makes the code hard to read at their site.

Nadar

  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #10 on: December 08, 2023, 05:49:31 am »
As @Tron mentioned, without the specifics of the problem no help can be given.  What inconsistencies are you referring to ?... an example of the inconsistencies would be very useful... provide a little snippet of code where the inconsistencies occur...

Maybe what you refer to as "inconsistency" may be a bug but, without specifics no determination can be made.

If you don't provide useful specifics, you'll probably be stuck having to do whatever you're doing for every commit.

I'm sorry that my initial post was so unclear. All I want is for the code to end up with no leading spaces when I don't type leading spaces. I exclusively use the tab key to make indents, and wants the resulting text file to reflect that.

Now that I know how to get Lazarus to show whitespace characters, it was quite easy to figure out what was causing it. As soon as I turn of everything under Codetools -> General -> Indentation for Pascal sources, the spaces are gone. It seems to me like as long as e.g "On break line" is enabled, the "default indentation functionality" is disabled (turning it on or off makes no difference). As soon as I disable the "Codetools indentation"; the "default indentation" is activated and it actually DOES manage to insert tabs.

Nadar

  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #11 on: December 08, 2023, 06:01:15 am »
* Tabs:
Editor > Genearl > Tabs and Indent
  "Tabs to spaces" off
  "smart tabs" off  (probably...)
  Drop down "Auto indent" => tabs
I had those settings, except that I had the dropdown to "Tabs, then spaces" (not that either choice made a difference to this issue).

Codetools > General
  Turn OFF all indention options.

   That means if you press return after a "begin" there will be NO indent added.
   If you want that, and want it tabs....
   Never tried, but you probably need to write a new "example file"... no idea
That was it as stated above. I do still get indentation to the seemingly correct level when I press enter - but it might be that it's "less smart" than it used to be (I just discovered this so I haven't tested it much yet). I tried to give the codetools an example file with only tabs in it earlier, and it didn't seem to make any difference.

It seems to me like this "issue" is that the codetools have no setting for using tabs. It doesn't seem to use the settings from other parts of the options, and it doesn't have one itself. Thus, it's "space only".

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Using tabs instead of spaces with Lazarus
« Reply #12 on: December 08, 2023, 12:38:52 pm »
Codetools > General
  Turn OFF all indention options.

   That means if you press return after a "begin" there will be NO indent added.
   If you want that, and want it tabs....
   Never tried, but you probably need to write a new "example file"... no idea
That was it as stated above. I do still get indentation to the seemingly correct level when I press enter - but it might be that it's "less smart" than it used to be (I just discovered this so I haven't tested it much yet). I tried to give the codetools an example file with only tabs in it earlier, and it didn't seem to make any difference.

It seems to me like this "issue" is that the codetools have no setting for using tabs. It doesn't seem to use the settings from other parts of the options, and it doesn't have one itself. Thus, it's "space only".

The documentation https://wiki.freepascal.org/IDE_Window:_Codetools_Options#Indentation and https://wiki.freepascal.org/Fully_automatic_indentation doesn't seem to say anything on the topic.
I don't know, if it will use tabs, if the sample file is completely made to use tabs.

If it can't be controlled via the sample file, then maybe make an issue report / feature request on the bug tracker?

TRon

  • Hero Member
  • *****
  • Posts: 3626
Re: Using tabs instead of spaces with Lazarus
« Reply #13 on: December 08, 2023, 06:10:20 pm »
If it can't be controlled via the sample file, then maybe make an issue report / feature request on the bug tracker?
I am not familiar with using tab vs space but if I configure the IDE editor to use tabs and start a new project then the cradle code is actually using tabs. Changing back to using whitespace does not change the existing cradle code (only newly added code but that can work confusing depending on other settings like for example use same indent as previous block).

I personally dislike using tabs as indent so have not experimented further but I can imagine TS being right about inconsistent behaviour as some things did not make sense to me as well for these bits that I did manage to test/check. On the other hand anything that does not make sense to me does not necessarily mean it is wrongly implemented or a bug. There are many features in the IDE that imho goes against logic (I know what they are and do not complain (anymore) as most of these things are usually based on a design decision).
« Last Edit: December 08, 2023, 06:25:32 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

TRon

  • Hero Member
  • *****
  • Posts: 3626
Re: Using tabs instead of spaces with Lazarus
« Reply #14 on: December 08, 2023, 06:18:19 pm »
I don't know if I qualify as "familiar with", but I feel that I tried to tweak the things I deem relevant without managing to get rid of spaces in some of the indentations, so I guess the answer is yes.
The "problem" is that what is logic for you might not be for the ones who implement these features/options.

That is why it is more then OK to complain but in that case please try to be specific as you can't defy logic used by someone else and one that doesn't seem to match yours :)

I have tried to play with the options and some things do not make sense to me and some of the options seem to contradict (precedence of one option over another). For me that is a pure personal 'feeling' but on the same time I dislike using tabs as indentation in code as in practice it is terribly inconsistent between applications (that is something I learned the hard way back when I started programming). But my opinion on the use of tabs is besides the point as the IDE editor should behave consistent for those that do choose to use tabs for indentation.

This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

 

TinyPortal © 2005-2018