SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Features and/or Improvements => Topic started by: rowbearto on December 26, 2018, 05:38:57 PM

Title: Indent with tabs and align with spaces
Post by: rowbearto on December 26, 2018, 05:38:57 PM
I'd like to see SlickEdit implement an option for "Indent with tabs and align with spaces" as discussed here:

https://dmitryfrank.com/articles/indent_with_tabs_align_with_spaces
http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_spaces#Smart_tabs

clang-format supports this with UseTab==UT_ForIndentation, see: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
I think SlickEdit only supports the clang-format option of UseTab==UT_Always

This was discussed previously in a topic on this forum:

https://community.slickedit.com/index.php?topic=15730.0
Title: Re: Indent with tabs and align with spaces
Post by: jporkkahtc on January 09, 2019, 07:04:16 PM
I agree with the intent here - tabs are fine, but should only be used at the start of a line, but basically, it is hopeless :-(
All lines should match this regex: ^[\t]*[^\t\r\n]*$

If the editor can do this reliably, then tabs aren't really needed.
(Really, if *all* editors that are used on a given code base can do this).
To get it right, the editor needs to know exactly how many tabs are needed at the start of the line -- so it must know the indent level.

If it knows this much, then no leading tabs are needed at all - the editor can just display the text indented correctly (virtual beautify).

If the intention of actually putting in the correct number of leading tabs is to allow for editors that aren't aware of this convention, then OK - but now you are back to the same old problems with mixing tabs and spaces, relying on people to get it right and not doing it a little different to suit their whim.
See the comment by Alan Kilborn in the first link.
Alan doesn't get it, but that is basically the problem.

Title: Re: Indent with tabs and align with spaces
Post by: rowbearto on January 09, 2019, 08:39:17 PM
I'm not sure I understand your post.

The developers (or a beautifier) are responsible for properly indenting with the correct number of tabs (with some help from the IDE). Proper display of the source relies on the tabs/spaces being there.

So each time developer wants to indent, they use a tab char instead of a space. IDE can help them when they press <ENTER> on a multiline statement and press <TAB> key, IDE can be smart enough to insert tabs/spaces depending on where cursor is.

Now I want to tell the IDE/editor how many spaces each tab corresponds to (for display purposes only, not to insert spaces instead of tabs). SlickEdit and almost every editor supports this. Slickedit "tabs" command allows to tell IDE how much to indent for each tab.

I also want the editor to realize that when I enter in a multi-line statement, that the non-first columns should use tab only for the initial indent, and then spaces to align after.

I mainly want this for small projects that are almost completely under my control. Sometimes I myself would rather see more or less indenting and I can control this by using SlickEdit "tabs" command.

For larger projects with many many developers, I agree that it would be practically impossible to rely on all people to do this properly and follow the rules. However it is possible to use formatting tools that will beautify the code putting in the correct numbers of tabs and spaces and have it done with each commit. clang-format beautifier can do this. Unfortunately, the SE beautifier can't (and that is why I request this feature).

In large projects that don't force beautifier running on commit (probably most), then I follow the project's convention (usually spaces for initial indent) while I would prefer using tabs and having everyone follow these rules (I realize it would be impossible to get everyone to follow the rules). But it would help to get more developers to be able to follow the rules if each IDE supported it, so asking SE to support it is a step in that direction. I would not be surprised if this is already supported by VIM and Emacs.

But for the small projects/tools that are totally under my control, I do follow these rules and would like SE to help me do that by supporting it with the beautifier and by intelligently inserting tab/space characters upon pressing <ENTER> or <tab>.
Title: Re: Indent with tabs and align with spaces
Post by: rowbearto on March 08, 2019, 03:19:42 PM
Note that "indent with tabs, align with spaces" is the official format of Google Go language as output by gofmt:

https://golang.org/cmd/gofmt/

Quote
Gofmt formats Go programs. It uses tabs for indentation and blanks for alignment.

You can also find on YouTube where Ken Thompson, a co-inventor of Unix, along with Rob Pike talk about their preference for tabs and whey they made this the Go default:

https://www.youtube.com/watch?v=sln-gJaURzk#t=1735
Title: Re: Indent with tabs and align with spaces
Post by: JeppeOland on November 12, 2019, 06:40:07 PM
Does SE support loading a clang-format file?
(That would be cool since I am contributing to projects that use that as the style ruleset)
Title: Re: Indent with tabs and align with spaces
Post by: patrick on November 12, 2019, 08:50:58 PM
No, we don't support loading or importing clang-format files.  It would be nice to have.
Title: Re: Indent with tabs and align with spaces
Post by: Chris Nisbet on April 20, 2023, 10:31:36 PM
I appreciate that this is an old thread, but I'd like to add my vote for this feature as well.
Title: Re: Indent with tabs and align with spaces
Post by: Speed8ump on May 25, 2023, 03:15:04 PM
As a holder and daily user of a named license for SE 2014, this is one of the features which would compel me to upgrade. I get *so*tired* of fixing my hanging indent alignments on function calls:
Code: [Select]
>--->---updatePowerStatus(.online,
>--->---...................upsMode,
>--->---...................mainsMode.);
or complex conditionals:
Code: [Select]
>--->---else.if (..SoftResetTimer.>=.FiveSeconds
>--->---........||.(..CanNtrf::GetPWBDev()
>--->---...........&&.CanNtrf::GetPWBDev()->GetBrakeOutputCondition().==.PWB_OUT_POWER_OFF_DETECTED
>--->---...........&&.CanNtrf::GetPWBDev()->GetDoorOutputCondition().==.PWB_OUT_POWER_OFF_DETECTED
>--->---...........&&.CanNtrf::GetPWBDev()->GetCarLightOutputCondition().==.PWB_OUT_POWER_OFF_DETECTED
>--->---...........)
>--->---........)