unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs
@ 2020-08-01 17:31 ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-06-06 15:28 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2020-08-01 17:31 UTC (permalink / raw)
  To: 42654

[-- Attachment #1: Type: text/plain, Size: 999 bytes --]

Hello,

This is what I understood from testing (Emacs 28.0.50) and the code of electric-pair-mode.

- More pairs can be defined by adding to electric-pair-pairs.
- To use electric-pair-inhibit-predicate, the syntax of the character must be one of '(?\( ?\" ?\$).

- In Org mode, it is convenient to have pairs for "~", "+", "_", and "/". These characters are not in the syntax classes required to run the inhibition function.
- The syntax class of the characters can be modified, such as with (modify-syntax-entry ?* "$").

- Once the syntax class is modified, the characters are automatically paired by electric-pair-mode. This means that the characters then do no need to be added to electric-pair-pairs.

I think it is a bug that electric-pair-inhibit-predicate won't be run when checking members of electric-pair-pairs. Yes, the syntax can be modified, but that makes the adding of the pair to electric-pair-pairs redundant, no?

Am I misunderstanding the purpose of these variables?

Thank you.

[-- Attachment #2: Type: text/html, Size: 3199 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-06 15:28 UTC (permalink / raw)
  To: ej32u; +Cc: 42654

ej32u@protonmail.com writes:

> * More pairs can be defined by adding to electric-pair-pairs.
> * To use electric-pair-inhibit-predicate, the syntax of the character must be one of '
>  (?\( ?\" ?\$).
> * In Org mode, it is convenient to have pairs for "~", "+", "_", and "/". These
>  characters are not in the syntax classes required to run the inhibition function.
> * The syntax class of the characters can be modified, such as with
>  (modify-syntax-entry ?* "$").
> * Once the syntax class is modified, the characters are automatically paired by
>  electric-pair-mode. This means that the characters then do no need to be added to
>  electric-pair-pairs.
>
> I think it is a bug that electric-pair-inhibit-predicate won't be run when checking
> members of electric-pair-pairs. Yes, the syntax can be modified, but that makes the
> adding of the pair to electric-pair-pairs redundant, no?

(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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs
  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
  2022-06-07  9:53     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-06-07  2:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 42654

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.







^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#42654: Using electric-pair-inihibit-predicate won't work for all members of electric-pair-pairs
  2022-06-07  2:08   ` ej32u--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-06-07  9:53     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-07  9:53 UTC (permalink / raw)
  To: ej32u; +Cc: 42654, João Távora

ej32u@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-07  9:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-06-07  9:53     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).