Using tabs instead of spaces with Lazarus lazarus / 9-Editor ---------------------------------------------------------------------- Nadar · 2023-12-07 02:50 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 · 2023-12-07 11:01 Quote from: Nadar on December 07, 2023, 03:50:30 amIs 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. ---------------------------------------------------------------------- Thaddy · 2023-12-07 11:08 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. ---------------------------------------------------------------------- Joanna · 2023-12-07 11:33 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. ---------------------------------------------------------------------- Thaddy · 2023-12-07 11:37 That is what I suspected. ---------------------------------------------------------------------- 440bx · 2023-12-07 11:38 Quote from: Nadar on December 07, 2023, 03:50:30 amI'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. Quote from: Nadar on December 07, 2023, 03:50:30 amIs 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. ---------------------------------------------------------------------- Martin_fr · 2023-12-07 11:45 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 · 2023-12-08 04:17 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 · 2023-12-08 04:23 Quote from: TRon on December 07, 2023, 12:01:29 pmI 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. Quote from: TRon on December 07, 2023, 12:01:29 pmFor 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 · 2023-12-08 04:29 Quote from: Thaddy on December 07, 2023, 12:08:06 pmThe 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 · 2023-12-08 04:49 Quote from: 440bx on December 07, 2023, 12:38:12 pmAs @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 · 2023-12-08 05:01 Quote from: Martin_fr on December 07, 2023, 12:45:40 pm* 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). Quote from: Martin_fr on December 07, 2023, 12:45:40 pmCodetools > 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 · 2023-12-08 11:38 Quote from: Nadar on December 08, 2023, 06:01:15 amQuote from: Martin_fr on December 07, 2023, 12:45:40 pmCodetools > 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 · 2023-12-08 17:10 Quote from: Martin_fr on December 08, 2023, 12:38:52 pmIf 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). ---------------------------------------------------------------------- TRon · 2023-12-08 17:18 Quote from: Nadar on December 08, 2023, 05:23:59 amI 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. ---------------------------------------------------------------------- Nadar · 2023-12-08 19:21 I thought by now that I had explained the "problem" pretty well, but I guess I can try some more. Just to clarify - whitespace means all whitespace characters, that includes the tab character. The space character is just called space AFAIK. For those that don't see the point of using tab (although that's still beside the point), the point is that your eyes "get used to" the indent with, and reading code with a different indent width can be slower/feel "heavy". By using tab, and setting all your editors to use the tab width you're used to (I use 4 space width), makes all code have the same indentation width. Back when I used space I only used 2 spaces because I was too lazy to keep hitting space so many times (although tab-to-space could "solve" that). Back then, reading code with 4 width indent was "confusing" to me - but now 2 width feels very "dense" and a bit "hard to get an overview of". It's all down to habit and what you're used to, but by using the tab character everybody can get the indentation width that they are "used to" so it makes it easier for everybody. When using space, the indentation width is "fixed" in the code and will always be "wrong" for some people. I've used a lot of different editors/IDEs, and the first thing I do is usually finding the tab options and in the settings and changing them. I don't think I've seen a similar "problem" with any of the other IDEs, they all usually support using either tab or space for indentation. That's all I wanted to achieve here too - to end up with a code that had "one type" of indentation only - not a mix. Turning off codetools indentation seems to have solved it for me. Since I don't know exactly what the codetools indentation "magic" does, I don't know if that's a problem, but I suspect that I can live well without it. As to filing a bug report, I'm not sure that's the right thing here. First of all, I don't know if it's a "bug" as such - if nobody else has missed this and I have now found a way around it, is it really that much of a problem? Ideally I think Lazarus, as every other IDE I've tried, should handle both even with "all features enabled" - but it's not something that I deem important enough for me to "front" the issue or claim it as a bug. It's not a bug per se - I'd call it missing functionality that I would expect should be there. I expect that filing such a bug report would result in quite a lot more "explaining" of why it matters to have both options - and I honestly have better things to do with my time. On top of that I'm not sure I feel good calling it a bug ---------------------------------------------------------------------- Martin_fr · 2023-12-08 19:44 Yes, you have explained. In your reply to me, you pointed out that the codetools indent was the problem. Before you gave that answer, it was not clear (not to me). Codetools indent: If you haveCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if a= b then begin and press return, then the indent in the next line will increase by itself (you do not need to press tab (or space)) If you have code, and you paste other code (multiple lines) into it: The pasted code will be adjusted for indent. In general feedback like this helps. I do most of the work on the editor (but not on codetools). I look after the implementation of tab handling in the editor (again, except the codetool part). I myself use spaces not tabs. I still do the job, and I try to make it work for people who want to use tabs. But I don't always know, how people work with tabs. So without feedback, tabs will not be improved. (If I don't know what is wrong or missing, I can't fix it). As this is about codetools, I am not going to be able to improve it. I don't know if there is already a way for it to work. Or if it needs to be added. The information here on the forum will soon be forgotten. On the bug tracker, it will at least be remembered. If it will then be implemented or not, I do not know. ---------------------------------------------------------------------- Nadar · 2023-12-08 20:44 You're right that the automatic increase in indentation after "try", "begin" etc is not working now that I've turned off the codetools. But, it will still "automatically ident" to the level it was at at the previous line. So, instead of having the tab/space my way from the very beginning of the line, I just have to do one tab and I'm in the correct place. The following lines will already be in the correct position. Automatic indentation of pasted code is also missing, but I had already turned that off because it didn't always indent it like I wanted it anyway. It's not such a big deal for me to "block indent" whatever block I pasted. That way at least I know that things haven't "magically" reformatted itself without me noticing. I agree that it's very convenient to have "intelligent indentation" that automatically increase/decrease indentation by context - but I can live without it. It's much less job for me to handle this manually than it is to "clean up" the files for spaces in a another editor before committing. As I said I'm still not comfortable calling it a bug. It's something I'd wish was there, but if very few people use it, I guess it's kind of understandable if it hasn't been implemented. If there's a need for it to be "registered" in the bug tracker, somebody else could just as well do it as me. That said, I can't quite see how it would be that much work. All the logic of the codetools would be the same (when figuring out what indent level to use), it would just be for the part that formatted it to either use spaces or use let a tab character represent "one indentation level" instead. If I were to write the codetools code, I would think that I would use logic where I kept track of "indentation level" internally - not with a certain number of spaces. If that is the way it works, it should be very easy to "translate" each indentation level to one tab character. As to how people use tabs for indentation, I can't speak for everybody else, but I can explain how I (and the project I've been with for years) use it: One indentation level is exactly one tab character. No spaces whatsoever should exist before the first normal character/letter in "code section" of the source file. After the first letter, spaces are used exclusively - there are no more tabs on any given line. So, tabs are used exclusively to achieve indentation - nothing else. This makes indentation levels adjustable - which is the whole point. I don't use tabs in e.g commend sections/documentation, license headers etc - because you want them to stay formatted as they are. I only use it for code indentation.