From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Fixing post-self-insert-hook. Date: Fri, 17 Sep 2021 19:37:27 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32522"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 17 21:38:23 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mRJgl-0008KF-BN for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 21:38:23 +0200 Original-Received: from localhost ([::1]:36286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRJgj-0000Aj-OZ for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 15:38:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRJg6-0007vV-UP for emacs-devel@gnu.org; Fri, 17 Sep 2021 15:37:42 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:59437 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mRJg4-0004oy-U4 for emacs-devel@gnu.org; Fri, 17 Sep 2021 15:37:42 -0400 Original-Received: (qmail 29111 invoked by uid 3782); 17 Sep 2021 19:37:28 -0000 Original-Received: from acm.muc.de (p4fe159e7.dip0.t-ipconnect.de [79.225.89.231]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 17 Sep 2021 21:37:28 +0200 Original-Received: (qmail 8390 invoked by uid 1000); 17 Sep 2021 19:37:27 -0000 Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:274929 Archived-At: 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).