Malabarba / aggressive-indent-mode

Emacs minor mode that keeps your code always indented. More reliable than electric-indent-mode.
850 stars 36 forks source link

[Feature request] Aggressively indent function at point #92

Closed Wasabichicken closed 7 years ago

Wasabichicken commented 8 years ago

This feature request is prompted by the legacy code base I'm working on, where people throughout the years have mixed indenting styles quite frivolously. Though aggressive-indent shapes it all up in no time, for me, that's unfortunately unacceptable as any changeset I do would be littered with indentation fixes, creating huge commits.

If at all possible, I'd like an option to only aggressively indent stuff I'm fixing, for example things within the local function. If I were to edit multiple functions, then I could live with a couple dozen lines of indentation fixes in the immediate scope, but not hundreds of small fixes spread all over a several thousand lines long source file.

I looked at aggressive-indent-dont-indent-if, but it appears to be an all-or-nothing solution, it either indents everything or nothing at all.

Thank you.

Malabarba commented 8 years ago

Aggressive indent should already behave like that. The problem is that "the local function" is actually quite hard to determine in some cases. For instance, if you just type an opening paren (, the entire rest of the file will "look like" it's part of the current function.

I could write an optional feature where it assumes you never have unbalanced sexps, and tries to be as polite as possible in that situation, but I don't know when I'll get the time. =/

Wasabichicken commented 8 years ago

A piece of infrastructure I think could be nice would be a aggressive-indent-line-if function that gets called with ever increasing and decreasing line numbers as its sole argument, returning t if the line should be indented or not. Users could then implement their own "decider" function, possibly based on stuff like thing-at-point, which I've found got a good ideas of where functions starts and ends.

If I get around to building it, I guess I'll send a pull request.

Malabarba commented 7 years ago

Ok, I've added a variable aggressive-indent-stop-here-hook that should do what you asked for.