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


  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #15 on: December 08, 2023, 08:21:31 pm »
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  ;)


  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Using tabs instead of spaces with Lazarus
« Reply #16 on: December 08, 2023, 08:44:00 pm »
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 have
Code: Pascal  [Select][+][-]
  1.   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.


  • New Member
  • *
  • Posts: 17
Re: Using tabs instead of spaces with Lazarus
« Reply #17 on: December 08, 2023, 09:44:03 pm »
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.
« Last Edit: December 08, 2023, 10:04:17 pm by Nadar »


TinyPortal © 2005-2018