From: ej32u--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 42654@debbugs.gnu.org
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 [thread overview]
Message-ID: <fb43e861-b009-86d6-94ab-e55f22f5fb74@protonmail.com> (raw)
In-Reply-To: <87h74xstem.fsf@gnus.org>
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.
next prev parent reply other threads:[~2022-06-07 2:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-01 17:31 bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-06 15:28 ` Lars Ingebrigtsen
2022-06-07 2:08 ` ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-06-07 9:53 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fb43e861-b009-86d6-94ab-e55f22f5fb74@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=42654@debbugs.gnu.org \
--cc=ej32u@protonmail.com \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.