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: Re: Fixing post-self-insert-hook. Date: Fri, 17 Sep 2021 20:53:42 +0000 Message-ID: References: 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="32760"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 17 22:54:24 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 1mRKsJ-0008LM-IB for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 22:54:23 +0200 Original-Received: from localhost ([::1]:41416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRKsH-0000aM-Pf for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 16:54:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRKrj-0008K1-4M for emacs-devel@gnu.org; Fri, 17 Sep 2021 16:53:47 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:61475 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mRKrh-00035y-3r for emacs-devel@gnu.org; Fri, 17 Sep 2021 16:53:46 -0400 Original-Received: (qmail 78040 invoked by uid 3782); 17 Sep 2021 20:53:42 -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 22:53:42 +0200 Original-Received: (qmail 8892 invoked by uid 1000); 17 Sep 2021 20:53:42 -0000 Content-Disposition: inline In-Reply-To: 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:274940 Archived-At: Hello, Stefan. On Fri, Sep 17, 2021 at 16:04:58 -0400, Stefan Monnier wrote: > > What is sometimes done with it is to effect buffer changes additional > > to the prime change caused by self-insert-function. > FWIW, I think the above "sometimes" really means "always" or "almost > always" ;-) > [ That was the primary motivation for the addition of this hook. ] > > 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. Actually, it was just 111, not 293. Sorry. > The question here is why those effects are undesirable while the other > effects (like auto-fill or abbrev expansion) aren't. It's because it's like making a buffer change in an after-change function (that is an insertion or a deletion, not just a text-property change). There's no way for the calling function to keep track of what's done. This was the cause of bug #33794 in January 2019. > I suspect that those 293 uses fall into roughly 3 different camps: > - Those that really do want the full `self-insert-command` effects. > - Those that call `self-insert-command` mostly because the author didn't > know better and they should really call `insert` instead. > - The rest that wants more than `insert` but less than > `self-insert-command`. > The last group might indeed deserve a new function. That may be so, but the point is, an indeterminate part of these 111 calls is currently undefined. The effect of self-insert-function called from Lisp is wholly dependent on what happens to be in post-s-i-h. You might get no characters inserted, you might get 1 or 2, you might get many. You just can't know at programming time. However, if the call to post-self-insert-hook were to be postponed to the end of the function, all the 111 Lisp calls would be defined again, and they would do the same as they did before post-s-i-h came along. > Stefan > PS: I do have one regret regarding `post-self-insert-hook`: I should > have defined a `self-insert-function` variable instead. This is > because some of the `post-self-insert-hook` functions would be > cleaner if they could be turned into (add-function :around > self-insert-function ...). > Sadly, `add-function` didn't exist back then :-( I actually disagree with this (or I'm lacking some knowledge). With M-: post-self-insert-function you can see what's in the hook, and with a little bit of delq, and so on, can change it for testing purposes. I don't think you can do any of that with an add-function type structure. Please tell me if I'm wrong, here. Thanks! -- Alan Mackenzie (Nuremberg, Germany).