Subject: bug#79047: Add some multi-character pairs to some major modes.

From: Stefan Monnier <[email-masked]>
Date: Thu, 24 Jul 2025 13:02:13 -0400

> As a workaround, I bind post-self-insert-hook to nil around the call to
> self-insert-command, this being the only way I know to get predictable
> functionality from self-insert-command.

"predictable functionality" and `self-insert-command` don't get along
very well, I'm afraid (e.g. because of `auto-fill-chars` and abbrev
expansion).

Part of the problem is fundamental, I think: when several forms of
electricity want to affect the same key, there is inevitably some
delicate issues that require them to cooperate to some extent.
It's hard to make them work together peacefully *and* modularily at the
same time.

> The error here is that post-self-insert-hook is invoked from the middle
> of the command using self-insert-function, rather than after its end.
> One way of fixing this would be to put
> electric-pair-post-self-insert-function on post-command-hook instead.

That tends to move the problem: it would be your code which risks
breaking the others, rather than other way around.

I don't have a solution which I would call "good", but the best we have
so far is to get rid of the `c-electric-paren` command and turn it into
a hook added to `post-self-insert-hook` instead.  This will let you use
the DEPTH argument of `add-hook` to control when it is run w.r.t to the
other hooks.

That's what the other `electric-FOO-mode` do to cohabit.

        Stefan