GNU bug report logs - #42654
Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs

Previous Next

Package: emacs;

Reported by: ej32u <at> protonmail.com

Date: Sat, 1 Aug 2020 18:26:01 UTC

Severity: normal

To reply to this bug, email your comments to 42654 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#42654; Package emacs. (Sat, 01 Aug 2020 18:26:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to ej32u <at> protonmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 01 Aug 2020 18:26:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: ej32u <at> protonmail.com
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: Using electric-pair-inihibit-predicate won't work for all members of
 electric-pair-pairs
Date: Sat, 01 Aug 2020 17:31:55 +0000
[Message part 1 (text/plain, inline)]
Hello,

This is what I understood from testing (Emacs 28.0.50) and the code of electric-pair-mode.

- More pairs can be defined by adding to electric-pair-pairs.
- To use electric-pair-inhibit-predicate, the syntax of the character must be one of '(?\( ?\" ?\$).

- In Org mode, it is convenient to have pairs for "~", "+", "_", and "/". These characters are not in the syntax classes required to run the inhibition function.
- The syntax class of the characters can be modified, such as with (modify-syntax-entry ?* "$").

- Once the syntax class is modified, the characters are automatically paired by electric-pair-mode. This means that the characters then do no need to be added to electric-pair-pairs.

I think it is a bug that electric-pair-inhibit-predicate won't be run when checking members of electric-pair-pairs. Yes, the syntax can be modified, but that makes the adding of the pair to electric-pair-pairs redundant, no?

Am I misunderstanding the purpose of these variables?

Thank you.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42654; Package emacs. (Mon, 06 Jun 2022 15:29:01 GMT) Full text and rfc822 format available.

Message #8 received at 42654 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: ej32u <at> protonmail.com
Cc: 42654 <at> debbugs.gnu.org
Subject: Re: bug#42654: Using electric-pair-inihibit-predicate won't work
 for all members of electric-pair-pairs
Date: Mon, 06 Jun 2022 17:28:33 +0200
ej32u <at> protonmail.com writes:

> * More pairs can be defined by adding to electric-pair-pairs.
> * To use electric-pair-inhibit-predicate, the syntax of the character must be one of '
>  (?\( ?\" ?\$).
> * In Org mode, it is convenient to have pairs for "~", "+", "_", and "/". These
>  characters are not in the syntax classes required to run the inhibition function.
> * The syntax class of the characters can be modified, such as with
>  (modify-syntax-entry ?* "$").
> * Once the syntax class is modified, the characters are automatically paired by
>  electric-pair-mode. This means that the characters then do no need to be added to
>  electric-pair-pairs.
>
> I think it is a bug that electric-pair-inhibit-predicate won't be run when checking
> members of electric-pair-pairs. Yes, the syntax can be modified, but that makes the
> adding of the pair to electric-pair-pairs redundant, no?

(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




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 06 Jun 2022 15:29:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42654; Package emacs. (Tue, 07 Jun 2022 02:09:02 GMT) Full text and rfc822 format available.

Message #13 received at 42654 <at> debbugs.gnu.org (full text, mbox):

From: ej32u <at> protonmail.com
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 42654 <at> debbugs.gnu.org
Subject: Re: 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
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.






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42654; Package emacs. (Tue, 07 Jun 2022 09:54:01 GMT) Full text and rfc822 format available.

Message #16 received at 42654 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: ej32u <at> protonmail.com
Cc: 42654 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#42654: Using electric-pair-inihibit-predicate won't work
 for all members of electric-pair-pairs
Date: Tue, 07 Jun 2022 11:53:17 +0200
ej32u <at> protonmail.com writes:

> 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 '(?\( ?\" ?\$))~.

Ah, right.  Here's the complete recipe to reproduce the problem:

(progn
  (require 'elec-pair)

  (setq-local electric-pair-pairs (cons '(?* . ?*) electric-pair-pairs))
  (electric-pair-mode 1)

  (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))

`my-inhibit-for-org-heading' is never run when typing * in this
scenario, because it doesn't have parentheses/quote syntax, so
`electric-pair-syntax-info' returns UNCONDITIONAL true.

I'm not sure what the logic is behind this -- perhaps João has some
comments; added to the CCs.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Removed tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 05 Jul 2022 11:38:03 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 37 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.