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

From: Alan Mackenzie <[email-masked]>
Date: Fri, 25 Jul 2025 10:32:15 +0000

Hello, Eli.

On Fri, Jul 25, 2025 at 09:53:03 +0300, Eli Zaretskii wrote:
> > Date: Thu, 24 Jul 2025 18:47:24 +0000
> > Cc: Eli Zaretskii <[email-masked]>, [email-masked], [email-masked],
> >   [email-masked], [email-masked]
> > From: Alan Mackenzie <[email-masked]>

> > > > But electric pair mode's implementation violates an (unwritten) Emacs
> > > > convention about hooks, i.e. that a hook function doesn't mess with
> > > > the functionality that invoked it.  For example, a function in
> > > > window-scroll-functions may not change the scrolling state of a
> > > > window, and an after-change-functions function never changes the text
> > > > of a buffer.

> > > > By contrast, electric-pair-post-self-insert-function does mess with
> > > > the invoking functionality, namely self-insert-command; it inserts
> > > > further characters.  From the point of view of a Lisp program, this
> > > > makes self-insert-function an undefined function - what it does
> > > > varies from time to time and from buffer to buffer.

> > As you're aware, when faced with a problem, I tend to analyse the cause
> > at the appropriately abstract level, and then fix that cause, rather than
> > just paper over the problem with some unsatisfactory workaround.

> > The fundamental cause of this problem with electric pair mode is, I
> > believe, in my two quoted paragraphs above.  I ask you to answer the
> > points made in these two paragraphs.

> And as I already mention, you perceive a convention where there is
> none.

OK, then, Emacs hackers have abided by this non-convention nevertheless,
out of instinctive good sense and good taste.  Up until
post-self-insert-hook.

> Thus electric-pair-mode doesn't violate any conventions.

self-insert-command, called from Lisp, is broken.  There is no usable
definition of its functionality.  So far, there is no competing analysis
to mine as to how it's broken.  Stefan's "solution" is not to use
self-insert-command.  This is impractical for c-electric-paren and
friends.  Incidentally there are around 122 uses of self-insert-command
in Emacs.

So it's looking like the ugly workarounds in c-electric-paren to use
self-insert-command will have to remain.  I'm disappointed about this.

-- 
Alan Mackenzie (Nuremberg, Germany).