From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Fixing post-self-insert-hook. Date: Sat, 18 Sep 2021 23:55:10 +0100 Message-ID: <874kahcx4h.fsf_-_@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24474"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Stefan Monnier , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 19 00:56:12 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 1mRjFk-0006FL-5u for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Sep 2021 00:56:12 +0200 Original-Received: from localhost ([::1]:33600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRjFi-0002Ti-AK for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Sep 2021 18:56:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRjEp-0001jx-Im for emacs-devel@gnu.org; Sat, 18 Sep 2021 18:55:15 -0400 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:35596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRjEn-0000TX-Sa for emacs-devel@gnu.org; Sat, 18 Sep 2021 18:55:15 -0400 Original-Received: by mail-wr1-x42e.google.com with SMTP id i23so21518576wrb.2 for ; Sat, 18 Sep 2021 15:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-transfer-encoding; bh=DgJik10Jp0wfqtJGV7eGoV7o6NYC/MfUejcpELQsk+0=; b=AV1MwOuC/j890ioaAAS8hVk8bOOpznvedNz2jRCDYeQsR2iajpe3trGULTgT+awD+3 2Vd3E8/AddC5urlwEMy1w3j3qG06q4QB4ePuSQ3EXj12vQGXPiFkOAxpCHM22RTwz1W0 QivraSTerK9esQNxQ9N1kRdZZaXWBPqbEVwMtCm39+9vT9MD/3uVotDvtdsJ6y7pcHSX obZXQTFDMQDeN5cr1PZqTI1zG0g35cx9/BNj7HBY6P+2l+1QTLG3Taot6tjGSQcaPSIQ DEY7QEFqAepbo3YQB9iIh8QB1W/BI+H8u5p+oAdq3FQdCOS1okiEk9zB2SwAAJnjBmYY j77g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-transfer-encoding; bh=DgJik10Jp0wfqtJGV7eGoV7o6NYC/MfUejcpELQsk+0=; b=oi8jL4FcjO+wamJ2sRX7OND1cMO5iK9AIV4O+Bemmh7u6UwliKPA5puuPxbUEz1PPD lRFp8nq4XV7OQCP5Bh7PQ8PQ7Tr4eI164o/O0SnNjdhLxlvucVZvFLHN9xq8Rj5uDLz8 cJp+NBO9DGQiGhsFzT3loiTJD38Afk39HwyPnOzzWsm9IQXcRPbeWXwNSMNblwuZc9UF h9VioDsIF3AlAele/Mu5QYWFMrCfbupUiS+ACqAp5f6e12UHr8pHO7GxMzqzuk7xyxX6 s9y4shp1zukTF8gwqBbXZdObQ5OK4sVbfseLJcqxmuNTbvYQgysuXRGD95zXXKu2JXb5 NcJQ== X-Gm-Message-State: AOAM530nL92STWfHOhXJHToBEuPtlkR2/kNkm5WFSCYXUZHO4ZuAlCsI jD59SOSm67GysYAf2lDYw6g= X-Google-Smtp-Source: ABdhPJy7GfAQ0deQ4FHbA9OkpYwip6QjUyyYzgyWd9QMX8j1+GN/489X0aawnMuhaXHq9c4BTM5GdQ== X-Received: by 2002:adf:d084:: with SMTP id y4mr19898120wrh.249.1632005711854; Sat, 18 Sep 2021 15:55:11 -0700 (PDT) Original-Received: from krug (a83-132-177-247.cpe.netcabo.pt. [83.132.177.247]) by smtp.gmail.com with ESMTPSA id j98sm11512788wrj.88.2021.09.18.15.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Sep 2021 15:55:11 -0700 (PDT) In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora=22's?= message of "Sat, 18 Sep 2021 22:59:13 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=joaotavora@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:275034 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > it's just done. I've asked Jo=C3=A3o about such an interface over the la= st > few years, now and then, but such has not yet been forthcoming. I've made my opinion clear now and then, over the years. But here I go again: 'electric-pair-post-self-insert-function' (aka e-p-p-s-i-f) existed before I have laid my programmer eyes on it. It's not an internal function, it has a defined protocol and exists to be a member of 'post-self-insert-hook'. Its purpose is -- and has always been -- to insert aditional delimiters related to the one just typed or, alternatively, to delete the character just inserted when it happens to skip a closing delimiter. In Emacs, as you know, a delimiter is a well defined thing, thanks to syntax tables. e-p-m's functionality, known sometimes as auto-pairing, is implemented in numerous editors. I first saw it in TextMate around 2008. In Emacs, apart from e-p-m, extensions such as autopair, smartparens, paredit (and probably others) do the same. The only significant thing I did in e-p-m -- besides a boring code refactor coordinated with then-maintainer Stefan -- was add the ability to choose which action to take based on the information conveyed by syntax-ppss, so that a degree of delimiter balance is maintained. As you known, syntax-ppss, relies again on that fundamental Emacs abstraction -- the syntax-table -- that buffers have. This works very well in practice and is a testament to how useful simple syntax tables are. Nevertheless, if you want to extract things from e-p-p-s-i-f and use them in your function, you can refactor its innards. As long as you don't break anything (fortunately there are good tests) or convolute elec-pair.el's code beyond recognition. Don't expect me to spend my time any time in this effort: I won't. I think it would be a very gross waste of time. _My_ time, at least. You may convince someone else of that idea. My alternative suggestion, which I've offered now and then, over the years, is for you to study how cc-mode behaves when you bind the delimiter keys simply to 'self-insert-command' and refrain from re-inventing 'electric-pair-mode' inside cc-mode. I do this in my .emacs, and I see that other users have settled on the same practice. If you were to try that, you could theoretically arrive at the conclusion that it is possible to do everything cc-mode does today w.r.t. electricity via the existing interfaces of 'electric-pair-mode', 'electric-layout-mode' and 'electric-indent-mode'. I must be honest. I don't really expect you arrive at that conclusion or even try that experiment. That's OK, I can't force anyone to reason the way I do. My personal hopes for C/C++/Java editing in Emacs are a completely new major mode where syntax is handled by TreeSitter and all the keys are bound to 'self-insert-command'. I'd bet good money that 'electric-pair-mode' is going to work there fine and with 0 configuration, like it does in all other major modes. With best regards, Jo=C3=A3o