GNU bug report logs - #77876
31.0.50; elec-pair --- `electric-pair-inhibit-predicate' ignored for `electric-pair-pairs'

Previous Next

Package: emacs;

Reported by: Fernando de Morais <fernandodemorais.jf <at> gmail.com>

Date: Thu, 17 Apr 2025 20:23:05 UTC

Severity: normal

Found in version 31.0.50

To reply to this bug, email your comments to 77876 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#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):

From: Fernando de Morais <fernandodemorais.jf <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; elec-pair --- `electric-pair-inhibit-predicate' ignored
 for `electric-pair-pairs'
Date: Thu, 17 Apr 2025 17:14:46 -0300
[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 ()

This bug report was last modified 6 days ago.

Previous Next


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