Subject: bug#38406: 27.0.50; post-self-insert-hook does not hold its contract in cc-mode derived modes

From: yyoncho <[email-masked]>
Date: Sun, 1 Dec 2019 17:27:33 +0200

Hi Alan

> Again, how does this binding of post-self-insert-hook to nil in CC Mode
> affect you?  What is it you're trying to do that this binding makes
> difficult?

ATM this change breaks at least 2 packages - lsp-mode and smartparents. I
am the maintainer of lsp-mode and it uses the hook for 2 things:

1. There are keys that are triggering displaying function signature.
2. There are keys that are triggering onTypeFormatting which happens
asynchronously.

I am not aware of how exactly smartparens uses post-insert-hook.

Thanks,
Ivan

On Sun, Dec 1, 2019 at 5:07 PM Alan Mackenzie <[email-masked]> wrote:

> Hello, Ivan.
>
> On Sun, Dec 01, 2019 at 12:02:56 +0200, yyoncho wrote:
> > Hi Alan,
>
> > > There are other possible "fixes", for example modifying these functions
> > > so that they don't use self-insert-command at all, but somehow I don't
> > > think that's what you want.
>
> > I don't think that the code that is implemented against the contract
> listed
> > in the hook documentation should be rewritten. If electric stuff is so
> > that important and there is no way to disable it by default then at
> > least a function to unbind the electric functionality the
> > documentation of post-self-insert-hook should state: "Don't rely on
> > this hook in cc derived modes because of {implementation details}. If
> > you still want to use post-self-insert-hook disable use
> > {implementation details} to turn electric off."
>
> The problem you have stumbled over is more of a political problem than a
> technical one.
>
> post-self-insert-hook was introduced relatively recently as a quick and
> dirty method of doing certain things.  Its implications weren't thought
> through beforehand.  In particular, it breaks major modes which use
> self-insert-command as part of their processing, including CC Mode.
>
> If functions put onto post-self-insert-hook didn't violate the
> definition of self-insert-command (inserting exactly one copy of the key
> typed), there wouldn't be a problem.  An example of such a function is
> blink-paren-post-self-insert-function (see lisp/simple.el L7801).
>
> However, there are several functions put onto this hook that make
> extensive buffer changes.  An example is
> electric-pair-post-self-insert-function (in lisp/elec-pair.el).  These
> mess up self-insert-command, and violate the principle that major modes
> should be in charge of what text goes where in a window.
>
> People like using post-self-insert-hook without worrying about the
> problems it causes.  Binding post-self-insert-hook to nil in CC Mode,
> while not good, was a pragmatic workaround from around a year ago.  This
> allowed electric-pair-mode to function in CC Mode.  As I said, this
> problem is primarily a political problem.  Forgive me not wanting to
> draw too much attention to it at the moment.
>
> Again, how does this binding of post-self-insert-hook to nil in CC Mode
> affect you?  What is it you're trying to do that this binding makes
> difficult?
>
> > Thanks,
> > Ivan
>
> --
> Alan Mackenzie (Nuremberg, Germany).
>