unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31361: 25.3; Issue when advising `indent-line-function'
@ 2018-05-03 21:15 Nicolas Goaziou
  2018-05-05 14:26 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Goaziou @ 2018-05-03 21:15 UTC (permalink / raw)
  To: 31361; +Cc: Stefan Monnier

Hello,

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.

You can reproduce the issue with the following recipe:

  - Open a new buffer in Fundamental mode (so `indent-line-function' is
    `indent-relative')

  - Insert : "-- Test"

  - From there, <RET> returns to column 0.  However, upon evaluating the
    following:

      M-: (add-function :before-until (local 'indent-line-function) #'ignore)

    <RET> now moves point at the same column as the "T" from "Test", in
    the new line.


Regards,

-- 
Nicolas Goaziou                                                0x80A93738





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#31361: 25.3; Issue when advising `indent-line-function'
  2018-05-03 21:15 bug#31361: 25.3; Issue when advising `indent-line-function' Nicolas Goaziou
@ 2018-05-05 14:26 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2018-05-05 14:26 UTC (permalink / raw)
  To: 31361; +Cc: Stefan Monnier

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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-05 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 21:15 bug#31361: 25.3; Issue when advising `indent-line-function' Nicolas Goaziou
2018-05-05 14:26 ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).