From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#38406: 27.0.50; post-self-insert-hook does not hold its contract in cc-mode derived modes Date: Sat, 30 Nov 2019 14:36:38 +0000 Message-ID: <20191130143638.GA6716@ACM> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="152814"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 38406@debbugs.gnu.org To: yyoncho Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 30 15:37:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ib3ry-000dWs-CQ for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Nov 2019 15:37:11 +0100 Original-Received: from localhost ([::1]:40772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ib3rx-0007x5-90 for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Nov 2019 09:37:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45504) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ib3rr-0007wy-2S for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2019 09:37:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ib3rp-0001RZ-TX for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2019 09:37:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56119) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ib3rp-0001RU-Pu for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2019 09:37:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ib3rp-0002Bk-O1 for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2019 09:37:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Nov 2019 14:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38406 X-GNU-PR-Package: emacs Original-Received: via spool by 38406-submit@debbugs.gnu.org id=B38406.15751246058374 (code B ref 38406); Sat, 30 Nov 2019 14:37:01 +0000 Original-Received: (at 38406) by debbugs.gnu.org; 30 Nov 2019 14:36:45 +0000 Original-Received: from localhost ([127.0.0.1]:33859 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ib3rY-0002Az-Sb for submit@debbugs.gnu.org; Sat, 30 Nov 2019 09:36:45 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:35146 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1ib3rW-0002Aq-EN for 38406@debbugs.gnu.org; Sat, 30 Nov 2019 09:36:44 -0500 Original-Received: (qmail 5590 invoked by uid 3782); 30 Nov 2019 14:36:40 -0000 Original-Received: from acm.muc.de (p2E5D5014.dip0.t-ipconnect.de [46.93.80.20]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 30 Nov 2019 15:36:38 +0100 Original-Received: (qmail 6867 invoked by uid 1000); 30 Nov 2019 14:36:38 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:172683 Archived-At: Hello, Yyoncho. On Wed, Nov 27, 2019 at 22:00:26 +0200, yyoncho wrote: > As per post-self-insert-hook documentation. > > Hook run at the end of `self-insert-command'. > > This is run after inserting the character. Yes. This is a problematic hook, since it is capable of disrupting the correct functionality of any Lisp program which uses self-insert-command. This transpired in CC Mode, so to make c-electric-brace and friends work, the action of the hook was nullified. > This does not hold by default in cc-mode due to the following mapped by > default functions: > > (define-key c-mode-base-map "#" 'c-electric-pound) > > (define-key c-mode-base-map "{" 'c-electric-brace) > > (define-key c-mode-base-map "}" 'c-electric-brace) > > (define-key c-mode-base-map "/" 'c-electric-slash) > > (define-key c-mode-base-map "*" 'c-electric-star) > > (define-key c-mode-base-map ";" 'c-electric-semi&comma) > > (define-key c-mode-base-map "," 'c-electric-semi&comma) > > (define-key c-mode-base-map ":" 'c-electric-colon) > > (define-key c-mode-base-map "(" 'c-electric-paren) > > (define-key c-mode-base-map ")" 'c-electric-paren) > All of these functions (or at least majority) contain the following lines: > > (let (post-self-insert-hook) ; Disable random functionality. > > (self-insert-command (prefix-numeric-value arg))) Yes. This was one way to get self-insert-function to perform its correct functionality, namely inserting exactly one copy of a typed key (or alternatively N copies when there's a prefix key). > Possible fixes: First question, what's the problem? What do you want to do that the above mechanism hinders? > 1. Do not bind the functions by default. They are essential to the correct functioning of CC Mode. > 2. Rewrite them so they do not inhibit post-self-insert-hook functions. This is difficult. If there were an easy way to do this, I would have done it. Note that, from the point of view of a major mode, post-self-insert-hook is totally random functionality - it is a bit like a trojan horse. The major mode has no way to control what it does, thus is unable to guarantee the major mode will work. There are other possible "fixes", for example modifying these functions so that they don't use self-insert-command at all, but somehow I don't think that's what you want. Another fix would be to specify restrictions on what one is allowed to do in this hook. I would prefer this, but other people would object strongly. I would advise against using post-self-insert-hook, if you possibly can. after-change-functions may be a good alternative. Maybe you can't. So, again, what is it you're trying to do? > In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.1) > of 2019-11-23 built on kyoncho-H87-D3H > Repository revision: 8934762bb37273e6606097de92dcc2556456acd2 > Repository branch: master > Windowing system distributor 'The X.Org Foundation', version 11.0.12001000 > System Description: Linux Mint 19.1 [ .... ] -- Alan Mackenzie (Nuremberg, Germany).