[...]
What do you mean here with "the indent" versus a delta? If the new indent's value is not count in "current indent + something * indent size" (where here "current indent" is previous line's indent) I don't see how this would possibly fit with configured indent sizes, nor what's the advantage?
Sorry the aside about delta vs indent relates to problems I had with Jiri's patch and probably doesn't make sense without knowing the whole of the previous thread, so ignore it. [Or see very last comment]
[...]
I agree that re-indenting the whole file would just be pointless, but not really with the other points.
OK, it may broke a manually tuned indentation, but that'd only be on that very line and hopefully the regex would be somewhat OK.
A not-that easy (very) small improvement would be not to change the indentation if:
- the line has greater indent that the previous line and we would also
add indent (e.g. if either there's nothing to do or we'd do the same thing another way), or 2) the line has smaller indent than the previous line and we also would remove indent (just the opposite)
So then, we'd no break manual indent if it only change the width of the indent to add/remove. Maybe it's overcompliacted for the very small gain.
Several common cases of manual indentation will still break even with this change so I agree it wouldn't add much.
Option 4 is rejected because auto new line indent is really the minimum required to be called "auto" indentation
Agreed.
So that leaves option 3. The upside is that new lines get a sensible indentation automatically, the downside is that lines that should be unindented won't be until enter or user command. I have used another editor that worked this way and after a while I became used to it. Note that editing an existing line won't destroy manual indentation unless you tell it to or create a new line after.
I don't understand why we would change the N-1 line's indent?
It doesn't change line N-1 but when you create a new line (ie type enter) the line you are on (line N) is checked for things like } or fi and the indent set for it. Delaying checking till enter/user command avoids your fi/file problem.
The settings are two ("indent this line", "indent next line") lists of pairs of a regex and a signed count.
Because pairs are not supported by g_key_file I suggest instead of a count that only one step is allowed (step size is another parameter) and we fall back to just having four regexes per language (as per Jiri's solution) "indent this line one step", "undent this line one step" "indent next line one step", undent next line one step".
These settings are per language so they should come from the filetype files.
A final thought, as there is now an "apply auto indent" command, if there is a selection the auto indent should ripple through the whole selection.
Well. This does seem to look quite OK at first glance, but what's the real difference with Jiří's (and my) solution, but using the previous line's indent as the reference?
Well thats the main difference, (idea stolen from Emacs) and the point that indentation is only triggered on return or an explicit user command "adjust indentation" (which you should rarely need).
-- which seems quite cool since it'd
fix most of the problems I see, basically re-unindenting already unindented lines.
Well, that is actually what I was meaning by "calculating a stable indent value" vs "calculating a delta, which we then have to prevent from being re-applied to an already adjusted line"
Cheers Lex