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

From: Eli Zaretskii <[email-masked]>
Date: Fri, 25 Jul 2025 15:02:12 +0300

> Date: Fri, 25 Jul 2025 11:42:37 +0000
> Cc: [email-masked], [email-masked], [email-masked],
>   [email-masked], [email-masked]
> From: Alan Mackenzie <[email-masked]>
> 
> > > self-insert-command, called from Lisp, is broken.  There is no usable
> > > definition of its functionality.
> 
> > What's wrong with its doc string as that definition?
> 
> It's inaccurate and misleading.
> 
> We have:
> 
>     Insert the character you type.
>     Whichever character C you type to run this command is inserted.
>     [Plus all the bits about the numeric prefix, abbreviations, etc.]
> 
> More accurate would be:
> 
>     Maybe insert the character you type (depending on
>     post-self-insert-hook).
>     Insert or delete further characters as specified by
>     post-self-insert-hook.
>     Leave point at the position determined by post-self-insert-hook or
>     after the inserted character.

Of course, if you truncate the doc string at some arbitrary point, you
can claim anything about its low quality.  The full doc string is
this:

  Insert the character you type.
  Whichever character C you type to run this command is inserted.
  The numeric prefix argument N says how many times to repeat the insertion.
  Before insertion, ‘expand-abbrev’ is executed if the inserted character does
  not have word syntax and the previous character in the buffer does.
  After insertion, ‘internal-auto-fill’ is called if
  ‘auto-fill-function’ is non-nil and if the ‘auto-fill-chars’ table has
  a non-nil value for the inserted character.  At the end, it runs
  ‘post-self-insert-hook’.

Which does mention post-self-insert-hook.  (And the ELisp manual
expands on the possible uses of that hook.)

What kind of argument is it when you elide arbitrary parts of the
documentation, just to make your point?  In what book does that
qualify as a serious discussion?

> ..  This makes it unusable in a Lisp program.

That's debatable, and is not the issue when the doc string and the
definition of functionality are being discussed.

> For example, in
> c-electric-paren, which handles the user entering "(" or ")", the code
> needs to determine whether the "(" was entered at the end of a line.
> The current self-insert-command, which inserts arbitrary further
> characters, makes this difficult.

So we have two electric behaviors that could conflict.  That's not
anything new, and we have ways of handling these situations, as Stefan
pointed out, and as you can see in the source code.  What does this
have to do with the issue at hand?

> I am suggesting that self-insert-command should be made usable from Lisp
> again, as it once was, and have suggested a means for achieving this.

Your request is noted.  I find it hard to believe that we will take
that direction, since post-self-insert-hook is used in so many useful
features nowadays.