[feature requrest] only auto indent when leaving the current line
Hello,
it would be good to have a flag to enable such a feature. I do often have the problem, that aggressive-indent-mode starts indenting stuff while I'm writing code in a line which is not finished yet.
For example:
if(
The mode now indents everything after this. However, when I'm done the line looks like this:
if($blah){return}
So, no re-indent would have been required.
If the mode would only try to re-indent after I leave the line (ie. pressing RET) it would be best (for me, at least).
Thanks, Tom
You can avoid indenting in that situation with the dont-indent-if variable. Try the following:
(let ((line (thing-at-point 'line)))
(and (stringp line)
(string-match "\\bif *([^)]*$" line)))
I tried:
(add-to-list 'aggressive-indent-dont-indent-if
(let ((line (thing-at-point 'line)))
(and (stringp line)
(string-match "\\bif *([^)]*$" line))))
but this doesn't work. Indenting still starts whenever I enter anything on a line. In the case of an if-statement, it starts after I entered "i". The same applies for while (starts at "w") or for (starts at "f") etc.
So I came up with this:
(setq my-last-line-num 0)
(add-to-list 'aggressive-indent-dont-indent-if
(lambda ()
(let ((line (line-number-at-pos)))
(if (eq line my-last-line-num)
(progn
t)
(progn
(setq my-last-line-num line)
nil )))))
I added a couple of debug-prints, but nothing gets printed, so it seems it doesn't get executed at all.
This should do what you're trying to achieve.
(add-to-list 'aggressive-indent-dont-indent-if
'(let ((line (line-number-at-pos)))
(if (eq line my-last-line-num)
t
(progn
(setq my-last-line-num line)
nil)))))
Unfortunately it doesn't. With this in place, no indenting at all happens any more (which was the same with my version), unless if I hit