Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indent-heuristic that copies the leading whitespace from the previous line verbatim (instead of matching with tabs) #11951

Open
Spiffyk opened this issue Oct 27, 2024 · 2 comments
Labels
C-enhancement Category: Improvements

Comments

@Spiffyk
Copy link

Spiffyk commented Oct 27, 2024

There is a little gripe I have with indent-heuristic = simple while using the "tabs to indent, spaces to align" styling. For C functions, when parameters are long, I tend to do it like this:

static int my_func(int parameter1,
                   bool parameter2,
                   struct sth *parameter3)
/* ^^^^^^^^^^^^^^^
 * These are all spaces, to align the parameters with
 * the characters of the function header. */
{
        /* And the content is then indented with tabs. */
        /* snip */
}

With indent = { tab-width = 8, unit = "\t" }, when I add a new line to the parameters, Helix matches the previous indent by putting as many tabs as can fit, then padding the rest with spaces, like so (with . being spaces, <------> being tabs):

static int my_func(int parameter1,
...................bool parameter2,
<------><------>...bool new_parameter, /* added here with o */
...................struct mystruct *parameter3)
{
        /* snip */
}

It would be nice to have an indent-heuristic that simply copies the same exact whitespace onto the new line instead - where there are all tabs, copy tabs; where there are all spaces, copy spaces; if there is some weird mixture, just copy the mixture - i.e. to be even less clever about it.

If there is interest, I am willing to author a PR for this, be it by adding a new special heuristic, or changing the existing simple one.

@Spiffyk Spiffyk added the C-enhancement Category: Improvements label Oct 27, 2024
@daedroza
Copy link
Contributor

I am unsure if such a weird of way formatting the indent widths would actually work but if you like to disable, there is one PR here #11920.

I think improving the heuristics like copying the algo from the NMAC427/guess-indent.nvim is much better but for your usecase, it doesn't seem like it would work.

@Spiffyk
Copy link
Author

Spiffyk commented Oct 31, 2024

@daedroza To be clear, this issue is not so much about auto-detecting the indentation style.

Instead, it is about what happens when I create a new line. The indent-heuristic = simple is almost what I want - keeping the indent of the previous line - but instead of it trying to figure out the width, then padding that with its own mix of tabs and spaces, I want it to be basically even dumber and just copy verbatim whatever leading whitespace was on the previous line.

And as for the indent option in language.toml (or the auto-detected indent), I want that to only apply to me pressing Tab, <, or >.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

2 participants