GNU bug report logs - #53661
29.0.50; electric-pair-mode not respecting electric-pair-inhibit-predicate.

Previous Next

Package: emacs;

Reported by: Ergus <spacibba <at> aol.com>

Date: Mon, 31 Jan 2022 15:08:01 UTC

Severity: normal

Found in version 29.0.50

To reply to this bug, email your comments to 53661 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#53661; Package emacs. (Mon, 31 Jan 2022 15:08:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ergus <spacibba <at> aol.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 31 Jan 2022 15:08:01 GMT) Full text and rfc822 format available.

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

From: Ergus <spacibba <at> aol.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; electric-pair-mode not respecting
 electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 16:06:39 +0100
Hi:

When adding new pairs to `electric-pair-pairs' the
`electric-pair-inhibit-predicate' variable is not respected.

Looking at the elect-pair file it seems to be related with:
`electric-pair-post-self-insert-function' that hard-coded the condition
to call `electric-pair-inhibit-predicate' with:

(memq syntax '(?\( ?\" ?\$))

So, for other pairs, the function electric-pair-inhibit-predicate is
never called.

The fix only for this seems trivial, but there are hard-coded conditions
like this in many places, so maybe a more "complete" fix may be
desirable.

Best


I faced this issue trying to implement a workaround to add some pairs
that are only electrically inserted when `use-region-p' (Ex: <> or '').


In GNU Emacs 29.0.50 (build 50, x86_64-pc-linux-gnu, GTK+ Version 3.24.31, cairo version 1.17.4)
 of 2022-01-31 built on Ergus
Repository revision: 9a56b4e6864c4e0815bb67805cfa67910ab3eeb5
Repository branch: master
System Description: Arch Linux

Configured using:
 'configure --prefix=/home/ergo/.local/ --with-mailutils --with-json
 --with-x-toolkit=gtk3 --with-xft --with-wide-int --with-modules
 --with-cairo --with-harfbuzz --with-native-compilation --with-pgtk'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER
PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
WEBP XIM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/d

Minor modes in effect:
  windmove-mode: t
  global-auto-revert-mode: t
  xclip-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  flyspell-mode: t
  company-mode: t
  flycheck-mode: t
  diff-hl-margin-local-mode: t
  diff-hl-margin-mode: t
  diff-hl-mode: t
  counsel-mode: t
  ivy-mode: t
  composable-mark-mode: t
  composable-mode: t
  repeat-mode: t
  xterm-mouse-mode: t
  minibuffer-depth-indicate-mode: t
  winner-mode: t
  show-smartparens-global-mode: t
  show-smartparens-mode: t
  smartparens-strict-mode: t
  smartparens-mode: t
  save-place-mode: t
  which-key-mode: t
  override-global-mode: t
  delete-selection-mode: t
  savehist-mode: t
  global-display-fill-column-indicator-mode: t
  display-fill-column-indicator-mode: t
  global-display-line-numbers-mode: t
  display-line-numbers-mode: t
  eldoc-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
~/gits/emacs_clones/composable/composable-mark hides /home/ergo/.config/emacs/elpa/composable-20201024.1458/composable-mark
~/gits/emacs_clones/composable/composable hides /home/ergo/.config/emacs/elpa/composable-20201024.1458/composable
/home/ergo/.config/emacs/elpa/transient-20220130.1941/transient hides /home/ergo/.local/share/emacs/29.0.50/lisp/transient
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-jump hides /usr/share/emacs/site-lisp/notmuch-jump
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-hello hides /usr/share/emacs/site-lisp/notmuch-hello
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-query hides /usr/share/emacs/site-lisp/notmuch-query
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-show hides /usr/share/emacs/site-lisp/notmuch-show
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-parser hides /usr/share/emacs/site-lisp/notmuch-parser
/home/ergo/.config/emacs/elpa/cmake-mode-20210104.1831/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-wash hides /usr/share/emacs/site-lisp/notmuch-wash
/home/ergo/.config/emacs/elpa/protobuf-mode-20211013.1726/protobuf-mode hides /usr/share/emacs/site-lisp/protobuf-mode
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-crypto hides /usr/share/emacs/site-lisp/notmuch-crypto
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-tree hides /usr/share/emacs/site-lisp/notmuch-tree
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/coolj hides /usr/share/emacs/site-lisp/coolj
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-lib hides /usr/share/emacs/site-lisp/notmuch-lib
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-compat hides /usr/share/emacs/site-lisp/notmuch-compat
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-company hides /usr/share/emacs/site-lisp/notmuch-company
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-draft hides /usr/share/emacs/site-lisp/notmuch-draft
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-tag hides /usr/share/emacs/site-lisp/notmuch-tag
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-message hides /usr/share/emacs/site-lisp/notmuch-message
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-mua hides /usr/share/emacs/site-lisp/notmuch-mua
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-address hides /usr/share/emacs/site-lisp/notmuch-address
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-print hides /usr/share/emacs/site-lisp/notmuch-print
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch hides /usr/share/emacs/site-lisp/notmuch
/home/ergo/.config/emacs/elpa/notmuch-20220126.1122/notmuch-maildir-fcc hides /usr/share/emacs/site-lisp/notmuch-maildir-fcc

Features:
(shadow sort mail-extr emacsbug message yank-media rmc puny rfc822 mml
mml-sec epa derived epg rfc6068 epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils windmove
time-date amx s autorevert filenotify xclip yasnippet-snippets yasnippet
help-fns radix-tree cl-print debug backtrace flyspell-correct-ivy
flyspell-correct flyspell ispell company-semantic company-template
company-capf company-elisp company flycheck find-func pcase
diff-hl-margin diff-hl-dired diff-hl log-view pcvs-util vc-dir ewoc vc
cape counsel xdg xref project dired dired-loaddefs compile
text-property-search comint ansi-color swiper ivy-avy avy ivy flx
ivy-faces ivy-overlay colir vc-git diff-mode vc-dispatcher term/tmux
term/xterm xterm init composable composable-mark powerline comp
comp-cstr warnings powerline-separators color powerline-themes repeat
xt-mouse edmacro kmacro mb-depth simple-16-theme winner ring elec-pair
smartparens-config smartparens-text smartparens advice thingatpt dash
saveplace diminish which-key cl-extra help-mode use-package
use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key use-package-core disp-table delsel
savehist easy-mmode display-fill-column-indicator display-line-numbers
ede/auto eieio-base tex-site slime-autoloads rx info package browse-url
url url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs eieio-loaddefs password-cache json map url-vars
seq gv subr-x byte-opt bytecomp byte-compile cconv early-init profiler
cl-loaddefs cl-lib iso-transl tooltip eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/pgtk-win
pgtk-win term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit pgtk lcms2 multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 410033 140294)
 (symbols 48 23414 1)
 (strings 32 87030 22121)
 (string-bytes 1 3013452)
 (vectors 16 59969)
 (vector-slots 8 1599695 599854)
 (floats 8 212 1163)
 (intervals 56 7255 3355)
 (buffers 992 17))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53661; Package emacs. (Mon, 31 Jan 2022 16:43:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ergus <spacibba <at> aol.com>
Cc: 53661 <at> debbugs.gnu.org
Subject: Re: bug#53661: 29.0.50;
 electric-pair-mode not respecting electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 18:41:59 +0200
> Date: Mon, 31 Jan 2022 16:06:39 +0100
> From:  Ergus via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> When adding new pairs to `electric-pair-pairs' the
> `electric-pair-inhibit-predicate' variable is not respected.
> 
> Looking at the elect-pair file it seems to be related with:
> `electric-pair-post-self-insert-function' that hard-coded the condition
> to call `electric-pair-inhibit-predicate' with:
> 
> (memq syntax '(?\( ?\" ?\$))
> 
> So, for other pairs, the function electric-pair-inhibit-predicate is
> never called.

The above condition looks at the _syntax_ of a character, not at the
character itself.  So what do you find "hard-coded" there,and what
kind of pairs of characters did you want to add that don't have one of
those syntaxes?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53661; Package emacs. (Mon, 31 Jan 2022 17:31:02 GMT) Full text and rfc822 format available.

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

From: Ergus <spacibba <at> aol.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 53661 <at> debbugs.gnu.org
Subject: Re: bug#53661: 29.0.50; electric-pair-mode not respecting
 electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 18:29:31 +0100
On Mon, Jan 31, 2022 at 06:41:59PM +0200, Eli Zaretskii wrote:
>> Date: Mon, 31 Jan 2022 16:06:39 +0100
>> From:  Ergus via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> When adding new pairs to `electric-pair-pairs' the
>> `electric-pair-inhibit-predicate' variable is not respected.
>>
>> Looking at the elect-pair file it seems to be related with:
>> `electric-pair-post-self-insert-function' that hard-coded the condition
>> to call `electric-pair-inhibit-predicate' with:
>>
>> (memq syntax '(?\( ?\" ?\$))
>>
>> So, for other pairs, the function electric-pair-inhibit-predicate is
>> never called.
>
>The above condition looks at the _syntax_ of a character, not at the
>character itself.  So what do you find "hard-coded" there,and what
>kind of pairs of characters did you want to add that don't have one of
>those syntaxes?

Hi Eli:

I wanted to add "<>" so I added to my init:

(add-to-list 'electric-pair-pairs '(?< . ?>))

But I wanted to restrict the electric-insertion only to when the region
was active; else using `<` to compare may be wrong; so I thought that
implementing my own `electric-pair-inhibit-predicate' in a simple way
like more or less:

(if (and (eq char ?<) (not (use-region-p)))
    t
    (electric-pair-default-inhibit))

could make the trick, but this doesn't work as I thought. I don't know
if there is a better way to go around this. 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53661; Package emacs. (Mon, 31 Jan 2022 18:05:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ergus <spacibba <at> aol.com>
Cc: 53661 <at> debbugs.gnu.org
Subject: Re: bug#53661: 29.0.50; electric-pair-mode not respecting
 electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 20:04:02 +0200
> Date: Mon, 31 Jan 2022 18:29:31 +0100
> From: Ergus <spacibba <at> aol.com>
> Cc: 53661 <at> debbugs.gnu.org
> 
> >> (memq syntax '(?\( ?\" ?\$))
> >>
> >> So, for other pairs, the function electric-pair-inhibit-predicate is
> >> never called.
> >
> >The above condition looks at the _syntax_ of a character, not at the
> >character itself.  So what do you find "hard-coded" there,and what
> >kind of pairs of characters did you want to add that don't have one of
> >those syntaxes?
> 
> Hi Eli:
> 
> I wanted to add "<>" so I added to my init:
> 
> (add-to-list 'electric-pair-pairs '(?< . ?>))

And it didn't work because of the hard-coded syntaxes?

What is the syntax of ?< in the mode where you wanted to add that?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53661; Package emacs. (Mon, 31 Jan 2022 19:21:02 GMT) Full text and rfc822 format available.

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

From: Ergus <spacibba <at> aol.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 53661 <at> debbugs.gnu.org
Subject: Re: bug#53661: 29.0.50; electric-pair-mode not respecting
 electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 20:20:01 +0100
On Mon, Jan 31, 2022 at 08:04:02PM +0200, Eli Zaretskii wrote:
>> Date: Mon, 31 Jan 2022 18:29:31 +0100
>> From: Ergus <spacibba <at> aol.com>
>> Cc: 53661 <at> debbugs.gnu.org
>>
>> >> (memq syntax '(?\( ?\" ?\$))
>> >>
>> >> So, for other pairs, the function electric-pair-inhibit-predicate is
>> >> never called.
>> >
>> >The above condition looks at the _syntax_ of a character, not at the
>> >character itself.  So what do you find "hard-coded" there,and what
>> >kind of pairs of characters did you want to add that don't have one of
>> >those syntaxes?
>>
>> Hi Eli:
>>
>> I wanted to add "<>" so I added to my init:
>>
>> (add-to-list 'electric-pair-pairs '(?< . ?>))
>
>And it didn't work because of the hard-coded syntaxes?
>
Adding to the list worked correctly, What didn't work was to use the
electric-pair-inhibit-predicate that was never called, so a < always
inserted a >.

>What is the syntax of ?< in the mode where you wanted to add that?

It is just c++-mode.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53661; Package emacs. (Mon, 31 Jan 2022 19:30:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ergus <spacibba <at> aol.com>
Cc: 53661 <at> debbugs.gnu.org
Subject: Re: bug#53661: 29.0.50; electric-pair-mode not respecting
 electric-pair-inhibit-predicate.
Date: Mon, 31 Jan 2022 21:28:54 +0200
> Date: Mon, 31 Jan 2022 20:20:01 +0100
> From: Ergus <spacibba <at> aol.com>
> Cc: 53661 <at> debbugs.gnu.org
> 
> >> I wanted to add "<>" so I added to my init:
> >>
> >> (add-to-list 'electric-pair-pairs '(?< . ?>))
> >
> >And it didn't work because of the hard-coded syntaxes?
> >
> Adding to the list worked correctly, What didn't work was to use the
> electric-pair-inhibit-predicate that was never called, so a < always
> inserted a >.
> 
> >What is the syntax of ?< in the mode where you wanted to add that?
> 
> It is just c++-mode.

And that is your problem, I believe: <> in C++ aren't treated as
parentheses or string delimiters, so their syntax doesn't fit what
electric-pair-mode assumes.

IOW, you need a different, C++ specific feature.  (I'd be surprised if
none already existed, btw.)




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

Previous Next


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