From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: yyoncho 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: Sun, 1 Dec 2019 12:02:56 +0200 Message-ID: References: <20191130143638.GA6716@ACM> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000daa3840598a191af" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="160914"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 38406@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Dec 01 11:04:31 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 1ibM5f-000fiI-BV for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Dec 2019 11:04:31 +0100 Original-Received: from localhost ([::1]:49214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibM5d-00012r-If for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Dec 2019 05:04:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57955) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibM5E-00011R-1x for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2019 05:04:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibM5C-0006xl-4A for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2019 05:04:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57750) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ibM5B-0006wx-SO for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2019 05:04:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ibM5B-0001CJ-Lj for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2019 05:04:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: yyoncho Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Dec 2019 10:04: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.15751945974539 (code B ref 38406); Sun, 01 Dec 2019 10:04:01 +0000 Original-Received: (at 38406) by debbugs.gnu.org; 1 Dec 2019 10:03:17 +0000 Original-Received: from localhost ([127.0.0.1]:35490 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ibM4S-0001B9-RY for submit@debbugs.gnu.org; Sun, 01 Dec 2019 05:03:17 -0500 Original-Received: from mail-lj1-f182.google.com ([209.85.208.182]:34889) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ibM4P-0001Au-VU for 38406@debbugs.gnu.org; Sun, 01 Dec 2019 05:03:15 -0500 Original-Received: by mail-lj1-f182.google.com with SMTP id j6so27469545lja.2 for <38406@debbugs.gnu.org>; Sun, 01 Dec 2019 02:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=maZFkN/Z5cMsDDpqK5peUCiAP1Mu0ulFOBOKw14i9PE=; b=aGN6nijrXZaUxMWtydf8muM5ACWG3v/eBvE2g3mWy+SexaFPmCLwBQr02+/vmJVNkV rdC1kndTjADoqymTdVay6HNewFJIQ9OoWb1i9TjZuAymD7V2Mah1NTMIT5qqTB4UZL/6 x2OviFqruY/disyH8KaR+a67qyULIP9Y/7TMXh1RPUOUz3+2disuNJO3+pKuXDFXgvKv 9za439U7Z1HMYZcNMFdiE/1wENL6fprBAIK0F2Apqo4aV91Co0KbqV42IbpSzdbUPA4l UtMJCtwdn8QC0oC7BDRk0Q5BuxZ6qqgvEsAgonI0j8eSieXm+79kISmpUW3e3orjyEJP 3QEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=maZFkN/Z5cMsDDpqK5peUCiAP1Mu0ulFOBOKw14i9PE=; b=XtCH1DECKaw5wBKff5NTdEEn/xESk0E4w1RFobIZGEsuLxRRpHQt3QqlcKci9C/GX9 BIfunhrSE9Uz1MIn7CamHXezVrhtwTR+vBwA5FQ2ajkCRB46ZlqcjeYq67dG+Itxvvek incGJEHPda9DsgutEb3vD/9G+OE7mYkkZeXKX/bGplY2g6V4O8ji5QexXsEnR7ely0B/ g3meBZcFye4Bt6arswI8RNRWUljuZrzDlz+itYo5sLJST9gjBsOMTM6EUi9Pvl+cPrLg aLEBXE/ql0sWb8UvUk4HtCKyIPzKci6R8lNfTK/w+pg+feQHTFQlvqTo7AI14Y6+yjLy YpPQ== X-Gm-Message-State: APjAAAUt1Qu4CGmY5awOe5XH0PgT2LEz6We/v9xxnc8RZKcEtnalEl/d 88UMIBqJRhhJPYp0bAaMGFlkVNKwjP7zthQ9LfQ= X-Google-Smtp-Source: APXvYqwgcPTAJ0gFKwE5/h/hjpCE5Xv8lwYoJMnj0/JNCtXZxUBwnOdByCcf6awCi078seyaZb4SXqkcmKQMNNFtp0A= X-Received: by 2002:a2e:808a:: with SMTP id i10mr27028889ljg.151.1575194587733; Sun, 01 Dec 2019 02:03:07 -0800 (PST) In-Reply-To: <20191130143638.GA6716@ACM> 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:172703 Archived-At: --000000000000daa3840598a191af Content-Type: text/plain; charset="UTF-8" Hi Alan, > 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. I don't think that the code that is implemented against the contract listed in the hook documentation should be rewritten. If electric stuff is so that important and there is no way to disable it by default then at least a function to unbind the electric functionality the documentation of post-self-insert-hook should state: "Don't rely on this hook in cc derived modes because of {implementation details}. If you still want to use post-self-insert-hook disable use {implementation details} to turn electric off." Thanks, Ivan On Sat, Nov 30, 2019 at 4:36 PM Alan Mackenzie wrote: > 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). > --000000000000daa3840598a191af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Alan,

> 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
&= gt; think that's what you want.

I don't thin= k that the code that is implemented against the contract listed in
the h= ook documentation should be rewritten. If electric=C2=A0stuff is so thatimportant and there is no way to disable it by default then at least a fun= ction
to unbind the electric functionality the documentation of post-sel= f-insert-hook
should state: "Don't rely on this hook in cc deri= ved modes because of
{implementation details}. If you still want to use = post-self-insert-hook disable
use {implementation details} to turn elect= ric off."=C2=A0

Thanks,
Iva= n


On Sat, Nov 30, 2019 at = 4:36 PM Alan Mackenzie <= acm@muc.de> wrote:
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.=C2=A0 This is a problematic hook, since it is capable of disrupting th= e
correct functionality of any Lisp program which uses
self-insert-command.=C2=A0 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 b= y
> default functions:

> > (define-key c-mode-base-map "#"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-pound)
> > (define-key c-mode-base-map "{"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-brace)
> > (define-key c-mode-base-map "}"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-brace)
> > (define-key c-mode-base-map "/"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-slash)
> > (define-key c-mode-base-map "*"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-star)
> > (define-key c-mode-base-map ";"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-semi&comma)
> > (define-key c-mode-base-map ","=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-semi&comma)
> > (define-key c-mode-base-map ":"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-colon)
> > (define-key c-mode-base-map "("=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-paren)
> > (define-key c-mode-base-map ")"=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'c-electric-paren)

> All of these functions (or at least majority) contain the following li= nes:

> > (let (post-self-insert-hook) ; Disable random functionality.
> >=C2=A0 =C2=A0 =C2=A0 (self-insert-command (prefix-numeric-value ar= g)))

Yes.=C2=A0 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?=C2=A0 What do you want to do that t= he
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.=C2=A0 If there were an easy way to do this, I would have=
done it.=C2=A0 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.=C2=A0 The major mode has no way to control what it does, th= us
is unable to guarantee the major mode will work.

There are other possible "fixes", for example modifying these fun= ctions
so that they don't use self-insert-command at all, but somehow I don= 9;t
think that's what you want.

Another fix would be to specify restrictions on what one is allowed to
do in this hook.=C2=A0 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.=C2=A0 Maybe you can't= .=C2=A0 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)
>=C2=A0 of 2019-11-23 built on kyoncho-H87-D3H
> Repository revision: 8934762bb37273e6606097de92dcc2556456acd2
> Repository branch: master
> Windowing system distributor 'The X.Org Foundation', version 1= 1.0.12001000
> System Description: Linux Mint 19.1

[ .... ]

--
Alan Mackenzie (Nuremberg, Germany).
--000000000000daa3840598a191af--