unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Fixing post-self-insert-hook.
@ 2021-09-17 19:37 Alan Mackenzie
  2021-09-17 20:04 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Alan Mackenzie @ 2021-09-17 19:37 UTC (permalink / raw)
  To: emacs-devel; +Cc: João Távora

Hello, Emacs.

For some while, there's been a problem with post-self-insert-hook.  Not
the hook itself, but what is sometimes done with it.

What is sometimes done with it is to effect buffer changes additional to
the prime change caused by self-insert-function.  This is the case, for
example, with electric-pair-post-self-insert-function.  Usually, when
self-insert-function is called from a key binding, this is harmless.  The
key gets inserted, then the auxiliary buffer changes take place.  Fine.

What isn't fine is when self-insert-function is called from Lisp, as it
is 293 times from our sources, including from cc-cmds.el.  The calling
Lisp function expects (usually) exactly one copy of the pressed key to be
inserted into the buffer.  With the pertinent post-self-insert-hook
functions in place, this certainty is lost.  There could be none, one,
two, or even many characters inserted.  This can wreck the functionality
of the Lisp function.

This is precisely what happened in quite a few c-electric-* functions,
and the uneasy workaround was to bind post-self-insert-hook to nil around
calls to self-insert-function, giving certainty back to the processing,
and try to compensate for this elsewhere.

This is clearly unsatisfactory.

#########################################################################

Given that it is now (at least politically) impossible to ban buffer
changing post-self-insert-hook functions, I propose to change the time at
which the hook gets called.

Instead of getting called straight after the self-insert-command, it
should be called at the end of the command which called
self-insert-command.  Just before post-command-hook, perhaps.  Yes there
are details to be worked out.

This will make no difference to the usual self-insert-command call.  It
will, however, restore the certainty of processing to Lisp code such as
c-electric-brace without having to resort to ugly workarounds.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-09-19 20:20 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-17 19:37 Fixing post-self-insert-hook Alan Mackenzie
2021-09-17 20:04 ` Stefan Monnier
2021-09-17 20:53   ` Alan Mackenzie
2021-09-17 21:45     ` João Távora
2021-09-18  6:08       ` tomas
2021-09-18  8:44         ` João Távora
2021-09-18 14:15     ` Stefan Monnier
2021-09-18 15:56       ` Alan Mackenzie
2021-09-18 18:03         ` Stefan Monnier
     [not found]         ` <CALDnm52z_8HyqdC92nrMgzOMOOq48h2MQ4pjbROBOsdm5N_cJg@mail.gmail.com>
2021-09-18 22:55           ` João Távora
2021-09-19 12:14             ` Alan Mackenzie
2021-09-19 12:36               ` João Távora
2021-09-19 12:59               ` Stefan Monnier
2021-09-19 14:57                 ` Alan Mackenzie
2021-09-19 20:20                   ` Stefan Monnier
2021-09-17 20:15 ` João Távora
2021-09-17 20:35   ` Alan Mackenzie
2021-09-17 20:48     ` João Távora
2021-09-18  5:59     ` Eli Zaretskii
2021-09-18  9:41       ` Alan Mackenzie
2021-09-18  5:50 ` Eli Zaretskii
2021-09-18  9:57   ` Alan Mackenzie
2021-09-18 11:04     ` Eli Zaretskii

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).