Subject: Re: bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 07 Jun 2022 11:53:17 +0200

[email-masked] 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