unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: 31361@debbugs.gnu.org
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>
Subject: bug#31361: 25.3; Issue when advising `indent-line-function'
Date: Sat, 05 May 2018 16:26:27 +0200	[thread overview]
Message-ID: <87o9huci6b.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87sh78phj1.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Thu, 03 May 2018 23:15:46 +0200")

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.





      reply	other threads:[~2018-05-05 14:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 21:15 bug#31361: 25.3; Issue when advising `indent-line-function' Nicolas Goaziou
2018-05-05 14:26 ` Nicolas Goaziou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9huci6b.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=31361@debbugs.gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).