bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#42654: Using electric-pair-inihibit-predicate won't work for all mem


From: ej32u
Subject: bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs
Date: Tue, 07 Jun 2022 02:08:01 +0000

On 6/6/22 11:28, Lars Ingebrigtsen wrote:
 > (I'm going through old bug reports that unfortunately weren't resolved
 > at the time.)
 >
 > Looking at the code, I'm not quite sure I understand your point here.
 > Perhaps it would be easier if you had a simple test case, and you could
 > explain what you see happening, and what you want to have happen?
 >
 > --
 > (domestic pets only, the antidote for overdose, milk.)
 >    bloggy blog: http://lars.ingebrigtsen.no

Hello,

This was a while ago, but here is how I remember it.  I wanted to add
the character "*" to ~electric-pair-pairs~ for Org mode.  However, I did
not want it to pair when inserting at the beginning of a line, since the
character is also used to begin headings.

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 '(?\( ?\" ?\$))~.

I think that the running of the inhibition function should also occur
for pairs in ~electric-pair-pairs~ and that it should not depend on the
syntax of the inserted character for pairs in ~electric-pair-pairs~.

Nowadays, I am using Smartparens (https://github.com/Fuco1/smartparens),
which already has the behavior I sought.

Below is an example:

1. Add the character "*" to ~electric-pair-pairs~ so that it is
automatically
    paired:

    #+begin_src emacs-lisp
      (setq-local electric-pair-pairs (cons '(?* . ?*) electric-pair-pairs))
    #+end_src

2. Add a predicate to not pair "*" when it is at the beginning of a
    line.  NOTE: This does not work. The character "*" does not have
    the required syntax to run in
    ~electric-pair-post-self-insert-function~ (one of ?\), ?\", or ?\$).

    #+begin_src emacs-lisp
      (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)
    #+end_src

3. Test inserting "*" at the beginning of the line.  See that it is
    paired.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]