From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: ej32u--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs Date: Tue, 07 Jun 2022 02:08:01 +0000 Message-ID: References: <1TK38SyOLkqabqkCrOYwMFSlY5dxH2-9LZVgtl-xgLwFmdAta5cLCMcWRLXya124ex_cHppAJJOM0nyVVS16JUlTv7zWNdB2oy68gM1cNYw=@protonmail.com> <87h74xstem.fsf@gnus.org> Reply-To: ej32u@protonmail.com 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="38497"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 42654@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 07 04:09:31 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nyOew-0009lP-71 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Jun 2022 04:09:30 +0200 Original-Received: from localhost ([::1]:41060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyOeu-00051t-RZ for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 06 Jun 2022 22:09:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyOeU-00051i-Qo for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2022 22:09:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyOeU-0002nb-IM for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2022 22:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nyOeU-0005ZT-99 for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2022 22:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: ej32u@protonmail.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Jun 2022 02:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42654 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 42654-submit@debbugs.gnu.org id=B42654.165456769421355 (code B ref 42654); Tue, 07 Jun 2022 02:09:02 +0000 Original-Received: (at 42654) by debbugs.gnu.org; 7 Jun 2022 02:08:14 +0000 Original-Received: from localhost ([127.0.0.1]:37199 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyOdi-0005YN-BN for submit@debbugs.gnu.org; Mon, 06 Jun 2022 22:08:14 -0400 Original-Received: from mail-4322.protonmail.ch ([185.70.43.22]:58007) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyOde-0005Y3-5Y for 42654@debbugs.gnu.org; Mon, 06 Jun 2022 22:08:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1654567684; x=1654826884; bh=eEBV2UVcmr0TBnQ3BiCKn9sV35l6b2PspbXEMhegopY=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=U/gz/lN0wVBKhcXExlVv889AHlwEqT4Y6VtKqj9cQKR4PcUak0UEavLQc4WXxEieI dF0ipag6DI2hOp1wJKMhZU8AWMk4m+ZKKODcVicLQAOWas49UXdwBD1pSahaj/JglA cQPiLvkW9jlp3ZKOI7By293OshAdvP+gcc84t6YvShDIgCpXTlfL1YwyrHDolFpzj6 qq4Q4XR2Ak4Y8BjvE8kDXfTFi4+ZZT0yeaOc/OasR0/b5ttP3dDa6EfgP6YriPt/PT /6AvUwb4323CDkeNdGPwaPJ3VebracmcpOtHOe+RzXaRqpMqd506aygM7gD31TpkAZ /76oH+M3CcaFQ== In-Reply-To: <87h74xstem.fsf@gnus.org> Feedback-ID: 1525109:user:proton X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" X-ACL-Warn: , ej32u@protonmail.com Xref: news.gmane.io gmane.emacs.bugs:233830 Archived-At: On 6/6/22 11:28, Lars Ingebrigtsen wrote: > (I'm going through old bug reports that unfortunately weren't resolved > at the time.) > > Looking at the code, I'm not quite sure I understand your point here. > Perhaps it would be easier if you had a simple test case, and you could > explain what you see happening, and what you want to have happen? > > -- > (domestic pets only, the antidote for overdose, milk.) > bloggy blog: http://lars.ingebrigtsen.no Hello, This was a while ago, but here is how I remember it. I wanted to add the character "*" to ~electric-pair-pairs~ for Org mode. However, I did not want it to pair when inserting at the beginning of a line, since the character is also used to begin headings. I tried setting ~electric-pair-inhibit-predicate~, but found that it isn't used unless the inserted character has the right syntax. That function is run by ~electric-pair-post-self-insert-function~, which seems to only run the predicate function if the inserted character is ~(memq syntax '(?\( ?\" ?\$))~. I think that the running of the inhibition function should also occur for pairs in ~electric-pair-pairs~ and that it should not depend on the syntax of the inserted character for pairs in ~electric-pair-pairs~. Nowadays, I am using Smartparens (https://github.com/Fuco1/smartparens), which already has the behavior I sought. Below is an example: 1. Add the character "*" to ~electric-pair-pairs~ so that it is automatically paired: #+begin_src emacs-lisp (setq-local electric-pair-pairs (cons '(?* . ?*) electric-pair-pairs)= ) #+end_src 2. Add a predicate to not pair "*" when it is at the beginning of a line. NOTE: This does not work. The character "*" does not have the required syntax to run in ~electric-pair-post-self-insert-function~ (one of ?\), ?\", or ?\$). #+begin_src emacs-lisp (defun my-inhibit-for-org-heading (inserted-char) (or (and (eq inserted-char ?*) ;; If point was the beginning of the line, don't pair. (eq (1- (point)) (line-beginning-position))) (funcall (default-toplevel-value 'electric-pair-inhibit-predicate) inserted-char))) (setq-local electric-pair-inhibit-predicate #'my-inhibit-for-org-heading) #+end_src 3. Test inserting "*" at the beginning of the line. See that it is paired.