GNU bug report logs -
#77876
31.0.50; elec-pair --- `electric-pair-inhibit-predicate' ignored for `electric-pair-pairs'
Previous Next
To reply to this bug, email your comments to 77876 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Thu, 17 Apr 2025 20:23:06 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Fernando de Morais <fernandodemorais.jf <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 17 Apr 2025 20:23:06 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
*Notice:* I don't believe this is a bug, but I would like to bring up a
discussion about the issue.
To illustrate the matter, using `emacs -Q', please evaluate the
following snippet:
#+begin_src emacs-lisp
(progn
(elisp-enable-lexical-binding 'interactive)
(defun org-electric-pair-inhibit (char)
(let ((pairs '(?* ?/ ?_ ?= ?~ ?+)))
(or (when (member char pairs)
(not (region-active-p)))
(electric-pair-default-inhibit char))))
(autoload #'setq-mode-local "mode-local")
(setopt electric-pair-mode t)
(setq-mode-local org-mode
electric-pair-pairs (append
electric-pair-pairs
'((?* . ?*) (?/ . ?/)
(?_ . ?_) (?= . ?=)
(?~ . ?~) (?+ . ?+)))
electric-pair-inhibit-predicate #'org-electric-pair-inhibit)
(find-file "temp.org"))
#+end_src
Results in:
- The `org-electric-pair-inhibit' function is ignored, and the
characters that should only be inserted in pairs when the region is
active are inserted in pairs regardless.
After a bit of investigation, I found that characters listed in
`electric-pair-pairs' are always inserted in pairs unconditionally. The
function defined in `electric-pair-inhibit-predicate' is called only for
the pairs defined in the syntax table of the corresponding major mode.
Although I believe this was a design decision, in my view, the
`electric-pair-inhibit-predicate' function should also apply to
characters in the `electric-pair-pairs' list.
I'm not sure about the implications for other use cases, but a little
change made to the `electric-pair-post-self-insert-function' solves the
issue (diff attached).
Do you think a change like this could be considered? Thanks in advance.
--
Regards,
Fernando de Morais.
[elec-pair.patch (text/x-patch, inline)]
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index aa2577300fd..97aeca3f3b3 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -593,11 +593,10 @@ electric-pair-post-self-insert-function
;; Insert matching pair.
((and (memq syntax '(?\( ?\" ?\$))
(not overwrite-mode)
- (or unconditional
- (not (electric-pair--save-literal-point-excursion
- (goto-char pos)
- (funcall electric-pair-inhibit-predicate
- last-command-event)))))
+ (not (electric-pair--save-literal-point-excursion
+ (goto-char pos)
+ (funcall electric-pair-inhibit-predicate
+ last-command-event))))
(save-excursion (electric-pair--insert pair num))))))))
(defun electric-pair-open-newline-between-pairs-psif ()
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 26 Apr 2025 12:29:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 77876 <at> debbugs.gnu.org (full text, mbox):
> From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> Date: Thu, 17 Apr 2025 17:14:46 -0300
>
> *Notice:* I don't believe this is a bug, but I would like to bring up a
> discussion about the issue.
>
> To illustrate the matter, using `emacs -Q', please evaluate the
> following snippet:
>
> #+begin_src emacs-lisp
> (progn
> (elisp-enable-lexical-binding 'interactive)
>
> (defun org-electric-pair-inhibit (char)
> (let ((pairs '(?* ?/ ?_ ?= ?~ ?+)))
> (or (when (member char pairs)
> (not (region-active-p)))
> (electric-pair-default-inhibit char))))
>
> (autoload #'setq-mode-local "mode-local")
> (setopt electric-pair-mode t)
> (setq-mode-local org-mode
> electric-pair-pairs (append
> electric-pair-pairs
> '((?* . ?*) (?/ . ?/)
> (?_ . ?_) (?= . ?=)
> (?~ . ?~) (?+ . ?+)))
> electric-pair-inhibit-predicate #'org-electric-pair-inhibit)
> (find-file "temp.org"))
> #+end_src
>
> Results in:
>
> - The `org-electric-pair-inhibit' function is ignored, and the
> characters that should only be inserted in pairs when the region is
> active are inserted in pairs regardless.
>
> After a bit of investigation, I found that characters listed in
> `electric-pair-pairs' are always inserted in pairs unconditionally. The
> function defined in `electric-pair-inhibit-predicate' is called only for
> the pairs defined in the syntax table of the corresponding major mode.
>
> Although I believe this was a design decision, in my view, the
> `electric-pair-inhibit-predicate' function should also apply to
> characters in the `electric-pair-pairs' list.
>
> I'm not sure about the implications for other use cases, but a little
> change made to the `electric-pair-post-self-insert-function' solves the
> issue (diff attached).
>
> Do you think a change like this could be considered? Thanks in advance.
>
> --
> Regards,
> Fernando de Morais.
>
> diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
> index aa2577300fd..97aeca3f3b3 100644
> --- a/lisp/elec-pair.el
> +++ b/lisp/elec-pair.el
> @@ -593,11 +593,10 @@ electric-pair-post-self-insert-function
> ;; Insert matching pair.
> ((and (memq syntax '(?\( ?\" ?\$))
> (not overwrite-mode)
> - (or unconditional
> - (not (electric-pair--save-literal-point-excursion
> - (goto-char pos)
> - (funcall electric-pair-inhibit-predicate
> - last-command-event)))))
> + (not (electric-pair--save-literal-point-excursion
> + (goto-char pos)
> + (funcall electric-pair-inhibit-predicate
> + last-command-event))))
> (save-excursion (electric-pair--insert pair num))))))))
>
> (defun electric-pair-open-newline-between-pairs-psif ()
João, any comments or suggestions?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 26 Apr 2025 14:31:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 77876 <at> debbugs.gnu.org (full text, mbox):
On Sat, Apr 26, 2025 at 1:28 PM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > Date: Thu, 17 Apr 2025 17:14:46 -0300
> >
> > *Notice:* I don't believe this is a bug, but I would like to bring up a
> > discussion about the issue.
> >
> > To illustrate the matter, using `emacs -Q', please evaluate the
> > following snippet:
> >
> > #+begin_src emacs-lisp
> > (progn
> > (elisp-enable-lexical-binding 'interactive)
> >
> > (defun org-electric-pair-inhibit (char)
> > (let ((pairs '(?* ?/ ?_ ?= ?~ ?+)))
> > (or (when (member char pairs)
> > (not (region-active-p)))
> > (electric-pair-default-inhibit char))))
> >
> > (autoload #'setq-mode-local "mode-local")
> > (setopt electric-pair-mode t)
> > (setq-mode-local org-mode
> > electric-pair-pairs (append
> > electric-pair-pairs
> > '((?* . ?*) (?/ . ?/)
> > (?_ . ?_) (?= . ?=)
> > (?~ . ?~) (?+ . ?+)))
> > electric-pair-inhibit-predicate #'org-electric-pair-inhibit)
> > (find-file "temp.org"))
> > #+end_src
> >
> > Results in:
> >
> > - The `org-electric-pair-inhibit' function is ignored, and the
> > characters that should only be inserted in pairs when the region is
> > active are inserted in pairs regardless.
> >
> > After a bit of investigation, I found that characters listed in
> > `electric-pair-pairs' are always inserted in pairs unconditionally. The
> > function defined in `electric-pair-inhibit-predicate' is called only for
> > the pairs defined in the syntax table of the corresponding major mode.
> >
> > Although I believe this was a design decision, in my view, the
> > `electric-pair-inhibit-predicate' function should also apply to
> > characters in the `electric-pair-pairs' list.
> >
> > I'm not sure about the implications for other use cases, but a little
> > change made to the `electric-pair-post-self-insert-function' solves the
> > issue (diff attached).
> >
> > Do you think a change like this could be considered? Thanks in advance.
> >
> > --
> > Regards,
> > Fernando de Morais.
> >
> > diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
> > index aa2577300fd..97aeca3f3b3 100644
> > --- a/lisp/elec-pair.el
> > +++ b/lisp/elec-pair.el
> > @@ -593,11 +593,10 @@ electric-pair-post-self-insert-function
> > ;; Insert matching pair.
> > ((and (memq syntax '(?\( ?\" ?\$))
> > (not overwrite-mode)
> > - (or unconditional
> > - (not (electric-pair--save-literal-point-excursion
> > - (goto-char pos)
> > - (funcall electric-pair-inhibit-predicate
> > - last-command-event)))))
> > + (not (electric-pair--save-literal-point-excursion
> > + (goto-char pos)
> > + (funcall electric-pair-inhibit-predicate
> > + last-command-event))))
> > (save-excursion (electric-pair--insert pair num))))))))
> >
> > (defun electric-pair-open-newline-between-pairs-psif ()
>
> João, any comments or suggestions?
I don't know, much of this is out of my mental cache. But I would
start by checking
if it passes the unit tests for elec-pair.el (hoping that they haven't
been disabled
as as has happened in the past). The tests have a pretty important say on
what the library is supposed to do, as they were carefully crafted from a good
number of edge cases and bug reports.
João
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 10 May 2025 09:33:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 77876 <at> debbugs.gnu.org (full text, mbox):
Ping! Any progress with this issue?
> From: João Távora <joaotavora <at> gmail.com>
> Date: Sat, 26 Apr 2025 15:30:35 +0100
> Cc: Fernando de Morais <fernandodemorais.jf <at> gmail.com>, 77876 <at> debbugs.gnu.org
>
> On Sat, Apr 26, 2025 at 1:28 PM Eli Zaretskii <eliz <at> gnu.org> wrote:
> >
> > > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > > Date: Thu, 17 Apr 2025 17:14:46 -0300
> > >
> > > *Notice:* I don't believe this is a bug, but I would like to bring up a
> > > discussion about the issue.
> > >
> > > To illustrate the matter, using `emacs -Q', please evaluate the
> > > following snippet:
> > >
> > > #+begin_src emacs-lisp
> > > (progn
> > > (elisp-enable-lexical-binding 'interactive)
> > >
> > > (defun org-electric-pair-inhibit (char)
> > > (let ((pairs '(?* ?/ ?_ ?= ?~ ?+)))
> > > (or (when (member char pairs)
> > > (not (region-active-p)))
> > > (electric-pair-default-inhibit char))))
> > >
> > > (autoload #'setq-mode-local "mode-local")
> > > (setopt electric-pair-mode t)
> > > (setq-mode-local org-mode
> > > electric-pair-pairs (append
> > > electric-pair-pairs
> > > '((?* . ?*) (?/ . ?/)
> > > (?_ . ?_) (?= . ?=)
> > > (?~ . ?~) (?+ . ?+)))
> > > electric-pair-inhibit-predicate #'org-electric-pair-inhibit)
> > > (find-file "temp.org"))
> > > #+end_src
> > >
> > > Results in:
> > >
> > > - The `org-electric-pair-inhibit' function is ignored, and the
> > > characters that should only be inserted in pairs when the region is
> > > active are inserted in pairs regardless.
> > >
> > > After a bit of investigation, I found that characters listed in
> > > `electric-pair-pairs' are always inserted in pairs unconditionally. The
> > > function defined in `electric-pair-inhibit-predicate' is called only for
> > > the pairs defined in the syntax table of the corresponding major mode.
> > >
> > > Although I believe this was a design decision, in my view, the
> > > `electric-pair-inhibit-predicate' function should also apply to
> > > characters in the `electric-pair-pairs' list.
> > >
> > > I'm not sure about the implications for other use cases, but a little
> > > change made to the `electric-pair-post-self-insert-function' solves the
> > > issue (diff attached).
> > >
> > > Do you think a change like this could be considered? Thanks in advance.
> > >
> > > --
> > > Regards,
> > > Fernando de Morais.
> > >
> > > diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
> > > index aa2577300fd..97aeca3f3b3 100644
> > > --- a/lisp/elec-pair.el
> > > +++ b/lisp/elec-pair.el
> > > @@ -593,11 +593,10 @@ electric-pair-post-self-insert-function
> > > ;; Insert matching pair.
> > > ((and (memq syntax '(?\( ?\" ?\$))
> > > (not overwrite-mode)
> > > - (or unconditional
> > > - (not (electric-pair--save-literal-point-excursion
> > > - (goto-char pos)
> > > - (funcall electric-pair-inhibit-predicate
> > > - last-command-event)))))
> > > + (not (electric-pair--save-literal-point-excursion
> > > + (goto-char pos)
> > > + (funcall electric-pair-inhibit-predicate
> > > + last-command-event))))
> > > (save-excursion (electric-pair--insert pair num))))))))
> > >
> > > (defun electric-pair-open-newline-between-pairs-psif ()
> >
> > João, any comments or suggestions?
>
> I don't know, much of this is out of my mental cache. But I would
> start by checking
> if it passes the unit tests for elec-pair.el (hoping that they haven't
> been disabled
> as as has happened in the past). The tests have a pretty important say on
> what the library is supposed to do, as they were carefully crafted from a good
> number of edge cases and bug reports.
>
> João
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 10 May 2025 14:34:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 77876 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:
> Ping! Any progress with this issue?
Sorry for my late reply. I had trouble finding the tests and then
figuring out how to use them, but attached are the results: both for the
tests applied to the `elec-pair' without modifications, and with them.
Eight tests---the same ones---failed in both scenarios. The others were
successful. Additionally, I’ve been using `elec-pair' with the
modifications since my original email, and I haven’t encountered any
inconsistencies or errors in my daily use.
Thanks!
--
Regards,
Fernando de Morais.
[tests-with-changes (application/octet-stream, attachment)]
[tests-without-changes (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 17 May 2025 08:45:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 77876 <at> debbugs.gnu.org (full text, mbox):
> From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> Cc: João Távora <joaotavora <at> gmail.com>,
> 77876 <at> debbugs.gnu.org
> Date: Sat, 10 May 2025 11:31:45 -0300
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> > Ping! Any progress with this issue?
>
> Sorry for my late reply. I had trouble finding the tests and then
> figuring out how to use them, but attached are the results: both for the
> tests applied to the `elec-pair' without modifications, and with them.
>
> Eight tests---the same ones---failed in both scenarios. The others were
> successful. Additionally, I’ve been using `elec-pair' with the
> modifications since my original email, and I haven’t encountered any
> inconsistencies or errors in my daily use.
Thanks. My results are different: all tests pass both before and
after the change.
João, based on these results, I think we can install the change? Or
do you remember why the 'unconditional' condition was in the code?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 17 May 2025 10:33:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 77876 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I think unconditional is how that variable is supposed to work. The
syntax-aware stuff is what I did, and it uses other mechanisms. So this
change appears to be fusing two mechanisms. Ask Stefan Nonnier perhaps. he
introduced this library into Emacs and guided my work on it.
João
On Sat, May 17, 2025, 09:44 Eli Zaretskii <eliz <at> gnu.org> wrote:
> > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > Cc: João Távora <joaotavora <at> gmail.com>,
> > 77876 <at> debbugs.gnu.org
> > Date: Sat, 10 May 2025 11:31:45 -0300
> >
> > Eli Zaretskii <eliz <at> gnu.org> writes:
> >
> > > Ping! Any progress with this issue?
> >
> > Sorry for my late reply. I had trouble finding the tests and then
> > figuring out how to use them, but attached are the results: both for the
> > tests applied to the `elec-pair' without modifications, and with them.
> >
> > Eight tests---the same ones---failed in both scenarios. The others were
> > successful. Additionally, I’ve been using `elec-pair' with the
> > modifications since my original email, and I haven’t encountered any
> > inconsistencies or errors in my daily use.
>
> Thanks. My results are different: all tests pass both before and
> after the change.
>
> João, based on these results, I think we can install the change? Or
> do you remember why the 'unconditional' condition was in the code?
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sat, 24 May 2025 09:16:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 77876 <at> debbugs.gnu.org (full text, mbox):
Stefan, can you help us understand what is TRT in this case?
> From: João Távora <joaotavora <at> gmail.com>
> Date: Sat, 17 May 2025 11:32:19 +0100
> Cc: Fernando de Morais <fernandodemorais.jf <at> gmail.com>, 77876 <at> debbugs.gnu.org,
> Stefan Monnier <monnier <at> iro.umontreal.ca>
>
> I think unconditional is how that variable is supposed to work. The syntax-aware stuff is what I did, and it
> uses other mechanisms. So this change appears to be fusing two mechanisms. Ask Stefan Nonnier
> perhaps. he introduced this library into Emacs and guided my work on it.
>
> João
>
> On Sat, May 17, 2025, 09:44 Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
> > Cc: João Távora <joaotavora <at> gmail.com>,
> > 77876 <at> debbugs.gnu.org
> > Date: Sat, 10 May 2025 11:31:45 -0300
> >
> > Eli Zaretskii <eliz <at> gnu.org> writes:
> >
> > > Ping! Any progress with this issue?
> >
> > Sorry for my late reply. I had trouble finding the tests and then
> > figuring out how to use them, but attached are the results: both for the
> > tests applied to the `elec-pair' without modifications, and with them.
> >
> > Eight tests---the same ones---failed in both scenarios. The others were
> > successful. Additionally, I’ve been using `elec-pair' with the
> > modifications since my original email, and I haven’t encountered any
> > inconsistencies or errors in my daily use.
>
> Thanks. My results are different: all tests pass both before and
> after the change.
>
> João, based on these results, I think we can install the change? Or
> do you remember why the 'unconditional' condition was in the code?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77876
; Package
emacs
.
(Sun, 25 May 2025 14:10:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 77876 <at> debbugs.gnu.org (full text, mbox):
> Although I believe this was a design decision, in my view, the
> `electric-pair-inhibit-predicate' function should also apply to
> characters in the `electric-pair-pairs' list.
Currently, there the `electric-pair-inhibit-predicate` is called only
for pairs that come fro the syntax-table and not for those in
`electric-pair-pairs`, and this is by design, as you noted.
I can't remember how we ended up with this design, but if you look at
the code, the default `electric-pair-inhibit-if-helps-balance` presumes
that it's called for a char that has a specific meaning in the
syntax-table.
And the use of `unconditional` that you remove is the only use of that
value, which was computed for a reason.
Maybe a good way forward is to call `electric-pair-inhibit-predicate`
"unconditionally", but to pass it somehow the information whether the
pair comes from `electric-pair-pairs` or not, so
`electric-pair-inhibit-if-helps-balance` can skip trying to
preserve balance?
Ideally, the way this information is passed could be (re)used in
bug#78053. E.g. maybe pass it a string instead of a char?
This would be backward incompatible, so it's not ideal.
Another approach could be to replace the
(CHAR . CHAR)
syntax of `electric-pair-pairs` with a new syntax
(CHAR CHAR ...)
where the `...` could be used to hold information such as a predicate to
decide when this pair can be used, so you could use something like:
(setq-local electric-pair-pairs
'((?* ?* :predicate region-active-p)
(?/ ?/ :predicate region-active-p)
(?_ ?_ :predicate region-active-p)
(?= ?= :predicate region-active-p)
(?~ ?~ :predicate region-active-p)
(?+ ?+ :predicate region-active-p)))
- Stefan
This bug report was last modified 20 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.