[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#31361: 25.3; Issue when advising `indent-line-function'
From: |
Nicolas Goaziou |
Subject: |
bug#31361: 25.3; Issue when advising `indent-line-function' |
Date: |
Sat, 05 May 2018 16:26:27 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) |
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> When `indent-line-function' is advised, using `add-function', and the
> variable contains `indent-relative', `indent-according-to-mode' has an
> erratic behavior.
>
> In the following code, from `indent-according-to-mode',
>
> (if (memq indent-line-function
> '(indent-relative indent-relative-maybe))
> ...
> ;; The normal case.
> (funcall indent-line-function))
>
> the if branch is no longer executed because `indent-line-function' is no
> longer `indent-relative' but a closure around it.
Thinking more about the problem, I think I can describe it differently.
When `indent-line-function' is set to `indent-relative' -- or
`indent-relative-maybe' -- the function `indent-relative' is not meant
to be actually called to handle the indentation. Instead, some ad-hoc
indentation is hard-coded into `indent-according-to-mode', which see.
However, when `indent-line-function' is advised, according to my
previous report, `indent-relative' is actually called for indentation,
which is not the intent, per above.
So basically, any call to `indent-according-to-mode', e.g., with
`reindent-then-newline-and-indent' or through Electric Indent mode, is
broken whenever `indent-relative' is advised.
One idea, suggested by Stefan, would be to write
`indent-according-to-mode' like the following:
(if (memq (advice--cd*r indent-line-function)
'(indent-relative indent-relative-maybe))
...
;; The normal case.
(funcall indent-line-function))
i.e., strip advices so that the ad-hoc code is executed, as intended,
instead of ultimately calling `indent-relative'. Unfortunately, this is
insufficient because the advices are not applied, which is also wrong.
If this stripping is done, it should also ensure that advices are
applied on the ad-hoc indentation code there.
FWIW, my gut feeling is that `indent-relative' -- and
`indent-relative-maybe' -- ought to be normalized to behave like
a normal indentation function, i.e., a function actually called from
`indent-according-to-mode'. This was the case before commit
a17b712b4d812d28086ae9af02f9043b36cf3e19 (Oct 30 2001).
Currently, `indent-relative' is two-sided. Therefore, the previous
suggestion might entail to split `indent-relative' into two parts, one
meant to be used as a value for `indent-line-function' -- maybe named
`indent-relative-function' -- and the other one to be used like current
`indent-relative', i.e., jumping from one indent point to the other.