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

Full log


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




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

Previous Next


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