all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
@ 2024-10-08  3:10 Marc Soda
  2024-10-12 12:21 ` Eli Zaretskii
  2024-10-17 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 20+ messages in thread
From: Marc Soda @ 2024-10-08  3:10 UTC (permalink / raw)
  To: 73688


[-- Attachment #1.1: Type: text/plain, Size: 1407 bytes --]

When using electric-pair-mode, electric-pair-conservative-inhibit
doesn't respect electric-pair-preserve-balance. For example, type out a
string, go to the beginning of the line, type ", go to the end of the
line, and type ". You are left with "foo"". (Exact keys from the start
of a line are fooC-a"C-e", if that's more clear.) I would expect to be
left with "foo" instead.

This is easy to resolve in your init file (after some digging), but I
think the current behavior is non-intuitive.

Please consider the attached patch.

In GNU Emacs 29.4 (build 2, x86_64-apple-darwin23.6.0, NS appkit-2487.70
Version 14.6.1 (Build 23G93)) of 2024-10-03 built on gemini.local
Windowing system distributor 'Apple', version 10.3.2566
System Description: macOS 15.0.1

Configured using:
'configure --disable-dependency-tracking --disable-silent-rules
--enable-locallisppath=/usr/local/share/emacs/site-lisp
--infodir=/usr/local/Cellar/emacs-plus@29/29.4/share/info/emacs
--prefix=/usr/local/Cellar/emacs-plus@29/29.4 --with-xml2 --with-gnutls
--with-native-compilation --without-compress-install --without-dbus
--without-imagemagick --with-modules --with-rsvg --with-ns
--disable-ns-self-contained 'CFLAGS=-O2 -DFD_SETSIZE=10000
-DDARWIN_UNLIMITED_SELECT -I/usr/local/opt/gcc/include
-I/usr/local/opt/libgccjit/include' 'LDFLAGS=-L/usr/local/lib/gcc/14
-I/usr/local/opt/gcc/include -I/usr/local/opt/libgccjit/include''

[-- Attachment #1.2: Type: text/html, Size: 2548 bytes --]

[-- Attachment #2: 0001-preserve-balance-in-conservative-mode.patch --]
[-- Type: application/octet-stream, Size: 1012 bytes --]

From 7b75b4d1447157fac733c6a1bf23b5e4b7362a65 Mon Sep 17 00:00:00 2001
From: Marc Soda <marc@soda.fm>
Date: Mon, 7 Oct 2024 22:54:33 -0400
Subject: [PATCH] preserve balance in conservative mode

---
 lisp/elec-pair.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index c9627763d8d..382307503e8 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -200,7 +200,11 @@ be considered.")
    (and (eq char (char-before))
 	(eq char (char-before (1- (point)))))
    ;; I also find it often preferable not to pair next to a word.
-   (eq (char-syntax (following-char)) ?w)))
+   (eq (char-syntax (following-char)) ?w)
+   (eq (char-syntax (following-char)) ?w)
+   ;; Also consider preserving balance
+   (and electric-pair-preserve-balance
+        (electric-pair-inhibit-if-helps-balance char))))
 
 (defmacro electric-pair--with-syntax (string-or-comment &rest body)
   "Run BODY with appropriate syntax table active.
-- 
2.39.5 (Apple Git-154)


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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-08  3:10 bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode Marc Soda
@ 2024-10-12 12:21 ` Eli Zaretskii
  2024-10-12 19:47   ` Marc Soda
  2024-10-12 20:36   ` João Távora
  2024-10-17 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-10-12 12:21 UTC (permalink / raw)
  To: Marc Soda, João Távora; +Cc: 73688

> Date: Tue, 08 Oct 2024 03:10:54 +0000
> From: Marc Soda <marc@soda.fm>
> 
> When using electric-pair-mode, electric-pair-conservative-inhibit
> doesn't respect electric-pair-preserve-balance. For example, type out a
> string, go to the beginning of the line, type ", go to the end of the
> line, and type ". You are left with "foo"". (Exact keys from the start
> of a line are fooC-a"C-e", if that's more clear.) I would expect to be
> left with "foo" instead.
> 
> This is easy to resolve in your init file (after some digging), but I
> think the current behavior is non-intuitive.
> 
> Please consider the attached patch.

João, do you have any comments?

> diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
> index c9627763d8d..382307503e8 100644
> --- a/lisp/elec-pair.el
> +++ b/lisp/elec-pair.el
> @@ -200,7 +200,11 @@ be considered.")
>     (and (eq char (char-before))
>  	(eq char (char-before (1- (point)))))
>     ;; I also find it often preferable not to pair next to a word.
> -   (eq (char-syntax (following-char)) ?w)))
> +   (eq (char-syntax (following-char)) ?w)  <<<<<<<<<<<<<<<<<<
> +   (eq (char-syntax (following-char)) ?w)  <<<<<<<<<<<<<<<<<<
> +   ;; Also consider preserving balance
> +   (and electric-pair-preserve-balance
> +        (electric-pair-inhibit-if-helps-balance char))))

Why duplicate lines there?





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-12 12:21 ` Eli Zaretskii
@ 2024-10-12 19:47   ` Marc Soda
  2024-10-12 20:36   ` João Távora
  1 sibling, 0 replies; 20+ messages in thread
From: Marc Soda @ 2024-10-12 19:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73688, João Távora

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

That was a silly typo on my part from when I created the patch. Thanks for catching. I attached a clean version.

Marc

On Saturday, October 12th, 2024 at 8:21 AM, Eli Zaretskii <eliz@gnu.org> wrote:

> 
> 
> > Date: Tue, 08 Oct 2024 03:10:54 +0000
> 
> > From: Marc Soda marc@soda.fm
> > 
> > When using electric-pair-mode, electric-pair-conservative-inhibit
> > doesn't respect electric-pair-preserve-balance. For example, type out a
> > string, go to the beginning of the line, type ", go to the end of the
> > line, and type ". You are left with "foo"". (Exact keys from the start
> > of a line are fooC-a"C-e", if that's more clear.) I would expect to be
> > left with "foo" instead.
> > 
> > This is easy to resolve in your init file (after some digging), but I
> > think the current behavior is non-intuitive.
> > 
> > Please consider the attached patch.
> 
> 
> João, do you have any comments?
> 
> > diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
> > index c9627763d8d..382307503e8 100644
> > --- a/lisp/elec-pair.el
> > +++ b/lisp/elec-pair.el
> > @@ -200,7 +200,11 @@ be considered.")
> > (and (eq char (char-before))
> > (eq char (char-before (1- (point)))))
> > ;; I also find it often preferable not to pair next to a word.
> > - (eq (char-syntax (following-char)) ?w)))
> > + (eq (char-syntax (following-char)) ?w) <<<<<<<<<<<<<<<<<<
> > + (eq (char-syntax (following-char)) ?w) <<<<<<<<<<<<<<<<<<
> > + ;; Also consider preserving balance
> > + (and electric-pair-preserve-balance
> > + (electric-pair-inhibit-if-helps-balance char))))
> 
> 
> Why duplicate lines there?

[-- Attachment #2: 0001-preserve-balance-in-conservative-mode.patch --]
[-- Type: application/octet-stream, Size: 969 bytes --]

From 5883b8f22dac78be1f06e1c2760da2fb6fc8c327 Mon Sep 17 00:00:00 2001
From: Marc Soda <marc@soda.fm>
Date: Sat, 12 Oct 2024 15:44:28 -0400
Subject: [PATCH] preserve balance in conservative mode

---
 lisp/elec-pair.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index c9627763d8d..71bc33ead26 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -200,7 +200,10 @@ be considered.")
    (and (eq char (char-before))
 	(eq char (char-before (1- (point)))))
    ;; I also find it often preferable not to pair next to a word.
-   (eq (char-syntax (following-char)) ?w)))
+   (eq (char-syntax (following-char)) ?w)
+   ;; Also consider preserving balance
+   (and electric-pair-preserve-balance
+        (electric-pair-inhibit-if-helps-balance char))))
 
 (defmacro electric-pair--with-syntax (string-or-comment &rest body)
   "Run BODY with appropriate syntax table active.
-- 
2.39.5 (Apple Git-154)


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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-12 12:21 ` Eli Zaretskii
  2024-10-12 19:47   ` Marc Soda
@ 2024-10-12 20:36   ` João Távora
  2024-10-12 20:43     ` Marc Soda
  1 sibling, 1 reply; 20+ messages in thread
From: João Távora @ 2024-10-12 20:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Marc Soda, 73688

On Sat, Oct 12, 2024 at 1:21 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Tue, 08 Oct 2024 03:10:54 +0000
> > From: Marc Soda <marc@soda.fm>
> >
> > When using electric-pair-mode, electric-pair-conservative-inhibit
> > doesn't respect electric-pair-preserve-balance. For example, type out a
> > string, go to the beginning of the line, type ", go to the end of the
> > line, and type ". You are left with "foo"". (Exact keys from the start
> > of a line are fooC-a"C-e", if that's more clear.) I would expect to be
> > left with "foo" instead.
> >
> > This is easy to resolve in your init file (after some digging), but I
> > think the current behavior is non-intuitive.
> >
> > Please consider the attached patch.
>
> João, do you have any comments?

This is not reproducible here, but then again this isn't an
Emacs -Q recipe. What major-mode? In my *scratch* buffer, if
I type

   f o o C-a " C-e "

, as Marc seems to suggest, I am left with

  ""foo""

as the contents, which is a balanced situation.  I do not expect
to have:

  "foo"

To get that, I would need to have typed " with the region active.

João





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-12 20:36   ` João Távora
@ 2024-10-12 20:43     ` Marc Soda
  2024-10-12 23:36       ` João Távora
  0 siblings, 1 reply; 20+ messages in thread
From: Marc Soda @ 2024-10-12 20:43 UTC (permalink / raw)
  To: João Távora; +Cc: Eli Zaretskii, 73688

Sorry, this is my first emacs bug report, I should have been more clear.

From emacs -Q:

(electric-pair-mode t)
(setq electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)

Evaluate those two lines and then type:

f o o C-a " C-e "

and you will be left with "foo""

Marc

On Saturday, October 12th, 2024 at 4:35 PM, João Távora <joaotavora@gmail.com> wrote:

> 
> 
> On Sat, Oct 12, 2024 at 1:21 PM Eli Zaretskii eliz@gnu.org wrote:
> 
> > > Date: Tue, 08 Oct 2024 03:10:54 +0000
> > > From: Marc Soda marc@soda.fm
> > > 
> > > When using electric-pair-mode, electric-pair-conservative-inhibit
> > > doesn't respect electric-pair-preserve-balance. For example, type out a
> > > string, go to the beginning of the line, type ", go to the end of the
> > > line, and type ". You are left with "foo"". (Exact keys from the start
> > > of a line are fooC-a"C-e", if that's more clear.) I would expect to be
> > > left with "foo" instead.
> > > 
> > > This is easy to resolve in your init file (after some digging), but I
> > > think the current behavior is non-intuitive.
> > > 
> > > Please consider the attached patch.
> > 
> > João, do you have any comments?
> 
> 
> This is not reproducible here, but then again this isn't an
> Emacs -Q recipe. What major-mode? In my scratch buffer, if
> I type
> 
> f o o C-a " C-e "
> 
> , as Marc seems to suggest, I am left with
> 
> ""foo""
> 
> as the contents, which is a balanced situation. I do not expect
> to have:
> 
> "foo"
> 
> To get that, I would need to have typed " with the region active.
> 
> João





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-12 20:43     ` Marc Soda
@ 2024-10-12 23:36       ` João Távora
  0 siblings, 0 replies; 20+ messages in thread
From: João Távora @ 2024-10-12 23:36 UTC (permalink / raw)
  To: Marc Soda, Stefan Monnier; +Cc: Eli Zaretskii, 73688

On Sat, Oct 12, 2024 at 9:43 PM Marc Soda <marc@soda.fm> wrote:
>
> Sorry, this is my first emacs bug report, I should have been more clear.
>
> From emacs -Q:
>
> (electric-pair-mode t)
> (setq electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)

Ah, so this is the (quite) old implementation from Stefan, I think.
I didn't write or know it.  I don't think it's compatible with
balance preservation.

João





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-08  3:10 bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode Marc Soda
  2024-10-12 12:21 ` Eli Zaretskii
@ 2024-10-17 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-26 17:48   ` Marc Soda
  1 sibling, 1 reply; 20+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-17 16:48 UTC (permalink / raw)
  To: Marc Soda; +Cc: 73688

> When using electric-pair-mode, electric-pair-conservative-inhibit
> doesn't respect electric-pair-preserve-balance.

That's a feature.
At least that was for me the main reason to have
`electric-pair-conservative-inhibit`, i.e. so the behavior does not
depend on the global paren balance of the whole buffer (both because it
can be costly to compute and because it can be difficult to predict for
the user).

IOW, why do you use `electric-pair-conservative-inhibit` if you care
about preserving global balance?


        Stefan






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-17 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-26 17:48   ` Marc Soda
  2024-10-26 18:47     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 20+ messages in thread
From: Marc Soda @ 2024-10-26 17:48 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 73688

> That's a feature.
>
> IOW, why do you use `electric-pair-conservative-inhibit` if you care
> about preserving global balance?

Fair enough. To answer your question, I want the other things you have listed in `electric-pair-conservative-inhibit`. In particular, the line commented "I also find it often preferable not to pair next to a word." is very valuable to me. However, I can solve my issue pretty easily by add something like the following to my init.el:

(setq electric-pair-inhibit-predicate
      ;; Also inhibit if the pair would balanced
      (lambda (char)
        (or (electric-pair-conservative-inhibit char)
            (electric-pair-inhibit-if-helps-balance char))))

The reason I submitted the patch is because is took me several years to get irritated enough to dig in and fix it for myself! :) Also, like I said above, it seemed non-intuitive. Thanks for considering, but feel free to disregard.

Are there any improvements you want made here? Only asking because I currently have the context.

Thanks,
Marc

On Thursday, October 17th, 2024 at 12:48 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> 
> 
> > When using electric-pair-mode, electric-pair-conservative-inhibit
> 
> > doesn't respect electric-pair-preserve-balance.
> 
> 
> That's a feature.
> At least that was for me the main reason to have
> `electric-pair-conservative-inhibit`, i.e. so the behavior does not
> depend on the global paren balance of the whole buffer (both because it
> can be costly to compute and because it can be difficult to predict for
> the user).
> 
> IOW, why do you use `electric-pair-conservative-inhibit` if you care
> about preserving global balance?
> 
> 
> Stefan





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-26 17:48   ` Marc Soda
@ 2024-10-26 18:47     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-09  9:22       ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-26 18:47 UTC (permalink / raw)
  To: Marc Soda; +Cc: 73688

>> IOW, why do you use `electric-pair-conservative-inhibit` if you care
>> about preserving global balance?
>
> Fair enough. To answer your question, I want the other things you have
> listed in `electric-pair-conservative-inhibit`.  In particular, the
> line commented "I also find it often preferable not to pair next to
> a word." is very valuable to me.  However, I can solve my issue pretty
> easily by adding something like the following to my init.el:
>
> (setq electric-pair-inhibit-predicate
>       ;; Also inhibit if the pair would balanced
>       (lambda (char)
>         (or (electric-pair-conservative-inhibit char)
>             (electric-pair-inhibit-if-helps-balance char))))

I see, I think you can get the same result with

    (add-function :before-until electric-pair-inhibit-predicate
                  #'electric-pair-conservative-inhibit)

But maybe it would make sense to add a third value to
`electric-pair-preserve-balance` to get the behavior you describe.

> The reason I submitted the patch is because is took me several years
> to get irritated enough to dig in and fix it for myself! :) Also, like
> I said above, it seemed non-intuitive.  Thanks for considering, but
> feel free to disregard.

Do you have an idea of how/where we could change some of the
documentation to avoid that kind of problem in the future?


        Stefan






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-10-26 18:47     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-09  9:22       ` Eli Zaretskii
  2024-11-09 10:30         ` Nikolay Kudryavtsev
  2024-11-23 17:29         ` Marc Soda
  0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-11-09  9:22 UTC (permalink / raw)
  To: Marc Soda, Stefan Monnier; +Cc: 73688

Ping! Marc, can you please answer Stefan's questions?

> Cc: 73688@debbugs.gnu.org
> Date: Sat, 26 Oct 2024 14:47:02 -0400
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> >> IOW, why do you use `electric-pair-conservative-inhibit` if you care
> >> about preserving global balance?
> >
> > Fair enough. To answer your question, I want the other things you have
> > listed in `electric-pair-conservative-inhibit`.  In particular, the
> > line commented "I also find it often preferable not to pair next to
> > a word." is very valuable to me.  However, I can solve my issue pretty
> > easily by adding something like the following to my init.el:
> >
> > (setq electric-pair-inhibit-predicate
> >       ;; Also inhibit if the pair would balanced
> >       (lambda (char)
> >         (or (electric-pair-conservative-inhibit char)
> >             (electric-pair-inhibit-if-helps-balance char))))
> 
> I see, I think you can get the same result with
> 
>     (add-function :before-until electric-pair-inhibit-predicate
>                   #'electric-pair-conservative-inhibit)
> 
> But maybe it would make sense to add a third value to
> `electric-pair-preserve-balance` to get the behavior you describe.
> 
> > The reason I submitted the patch is because is took me several years
> > to get irritated enough to dig in and fix it for myself! :) Also, like
> > I said above, it seemed non-intuitive.  Thanks for considering, but
> > feel free to disregard.
> 
> Do you have an idea of how/where we could change some of the
> documentation to avoid that kind of problem in the future?
> 
> 
>         Stefan
> 
> 
> 
> 
> 





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-09  9:22       ` Eli Zaretskii
@ 2024-11-09 10:30         ` Nikolay Kudryavtsev
  2024-11-09 15:55           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-23 17:29         ` Marc Soda
  1 sibling, 1 reply; 20+ messages in thread
From: Nikolay Kudryavtsev @ 2024-11-09 10:30 UTC (permalink / raw)
  To: Eli Zaretskii, Marc Soda, Stefan Monnier; +Cc: 73688

I'm another person interested in exactly this feature. Had a similar 
rough hack in my init, though I didn't notice that 
electric-pair-conservative-inhibit mostly works...

Not 100% sure about this, but I'm probably not the first person to think 
that a single predicate design just does not work here in a satisfying 
manner and it should be electric-pair-inhibit-predicates and then the 
end user can tweak them as needed.







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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-09 10:30         ` Nikolay Kudryavtsev
@ 2024-11-09 15:55           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-10 14:28             ` Nikolay Kudryavtsev
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-11-09 15:55 UTC (permalink / raw)
  To: Nikolay Kudryavtsev; +Cc: Eli Zaretskii, Marc Soda, 73688

> Not 100% sure about this, but I'm probably not the first person to think
> that a single predicate design just does not work here in a satisfying
> manner and it should be electric-pair-inhibit-predicates and then the end
> user can tweak them as needed.

But then we'd have to hard-code whether the predicates are AND'ed or
OR'ed together.  In contrast the current design lets you choosing between
`(add-function :before-until ...)` and `(add-function :before-while ...)`.


        Stefan






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-09 15:55           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-10 14:28             ` Nikolay Kudryavtsev
  2024-11-23 12:22               ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Nikolay Kudryavtsev @ 2024-11-10 14:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, Marc Soda, 73688

OR seems like the natural solution for multiple predicates in this case. 
And if you need AND for a subset of predicates, you can easily roll out 
your own predicate implementing that.

Obviously there's nothing really wrong with add-function hacks in 
practice, but, in my opinion, if we're relying on them in places for 
which a proper customization ability was already designed and 
implemented, it's a telling sign that it is inadequate.






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-10 14:28             ` Nikolay Kudryavtsev
@ 2024-11-23 12:22               ` Eli Zaretskii
  2024-11-23 17:37                 ` Nikolay Kudryavtsev
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2024-11-23 12:22 UTC (permalink / raw)
  To: Nikolay Kudryavtsev; +Cc: 73688, marc, monnier

> From: Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>
> Date: Sun, 10 Nov 2024 17:28:44 +0300
> Cc: Eli Zaretskii <eliz@gnu.org>, Marc Soda <marc@soda.fm>,
>  73688@debbugs.gnu.org
> 
> OR seems like the natural solution for multiple predicates in this case. 
> And if you need AND for a subset of predicates, you can easily roll out 
> your own predicate implementing that.
> 
> Obviously there's nothing really wrong with add-function hacks in 
> practice, but, in my opinion, if we're relying on them in places for 
> which a proper customization ability was already designed and 
> implemented, it's a telling sign that it is inadequate.

Is there anything else to do in this bug, or should we now close it?





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-09  9:22       ` Eli Zaretskii
  2024-11-09 10:30         ` Nikolay Kudryavtsev
@ 2024-11-23 17:29         ` Marc Soda
  1 sibling, 0 replies; 20+ messages in thread
From: Marc Soda @ 2024-11-23 17:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73688, Stefan Monnier

> Do you have an idea of how/where we could change some of the
> documentation to avoid that kind of problem in the future?

Sorry for the silence here, I've been unusually busy for the few weeks.

Multiple OR'd predicates predicates makes sense to me. I'd be willing to work on that if there's interest.

As for documentation, I'm not really sure. I couldn't find anything referencing electric-pair-inhibit-predicate in the manual. Should probably added to https://www.gnu.org/software/emacs/manual/html_node/emacs/Matching.html.





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-23 12:22               ` Eli Zaretskii
@ 2024-11-23 17:37                 ` Nikolay Kudryavtsev
  2024-11-30 10:21                   ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Nikolay Kudryavtsev @ 2024-11-23 17:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73688, marc, monnier, João Távora

Yes, I think before closing, we need João, or someone else on the dev 
team to judge on the merit of the multiple ORd 
electric-pair-inhibit-predicates idea.

Implementing it would lead to deprecating 
electric-pair-inhibit-predicate(should be still working though for X 
major versions), and beyond this use-case there doesn't seem to be that 
many other use cases for inhibit-predicates anyway. But this would give 
us a lot more flexibility for whenever they appear, since this seems to 
be the proper solution here.






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-23 17:37                 ` Nikolay Kudryavtsev
@ 2024-11-30 10:21                   ` Eli Zaretskii
  2024-11-30 12:30                     ` João Távora
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2024-11-30 10:21 UTC (permalink / raw)
  To: Nikolay Kudryavtsev, monnier, joaotavora; +Cc: marc, 73688

> Date: Sat, 23 Nov 2024 17:29:24 +0000
> From: Marc Soda <marc@soda.fm>
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 73688@debbugs.gnu.org
> 
> > Do you have an idea of how/where we could change some of the
> > documentation to avoid that kind of problem in the future?
> 
> Sorry for the silence here, I've been unusually busy for the few weeks.
> 
> Multiple OR'd predicates predicates makes sense to me. I'd be willing to work on that if there's interest.
> 
> As for documentation, I'm not really sure. I couldn't find anything referencing electric-pair-inhibit-predicate in the manual. Should probably added to https://www.gnu.org/software/emacs/manual/html_node/emacs/Matching.html.
> 

> From: Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>
> Date: Sat, 23 Nov 2024 20:37:23 +0300
> Cc: monnier@iro.umontreal.ca, marc@soda.fm, 73688@debbugs.gnu.org,
>  João Távora <joaotavora@gmail.com>
> 
> Yes, I think before closing, we need João, or someone else on the dev 
> team to judge on the merit of the multiple ORd 
> electric-pair-inhibit-predicates idea.
> 
> Implementing it would lead to deprecating 
> electric-pair-inhibit-predicate(should be still working though for X 
> major versions), and beyond this use-case there doesn't seem to be that 
> many other use cases for inhibit-predicates anyway. But this would give 
> us a lot more flexibility for whenever they appear, since this seems to 
> be the proper solution here.

Stefan and João, any comments or suggestions?





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-30 10:21                   ` Eli Zaretskii
@ 2024-11-30 12:30                     ` João Távora
  2024-12-01 10:25                       ` Nikolay Kudryavtsev
  0 siblings, 1 reply; 20+ messages in thread
From: João Távora @ 2024-11-30 12:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73688, marc, Nikolay Kudryavtsev, monnier

On Sat, Nov 30, 2024 at 10:22 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > Implementing it would lead to deprecating
> > electric-pair-inhibit-predicate(should be still working though for X
> > major versions), and beyond this use-case there doesn't seem to be that
> > many other use cases for inhibit-predicates anyway. But this would give
> > us a lot more flexibility for whenever they appear, since this seems to
> > be the proper solution here.
>
> Stefan and João, any comments or suggestions?

I see some talk of multiple ORd predicates, and deprecating electric-pair-i-p
saying it's not flexible, and I don't think that's true.

I don't think it's a good idea to hardcode in some intermediate level of
just-what-I-want customization when there are already two levels:

- a relatively blunt customization-based one that fits a majority of users,
- a finer-grained powerful based on Elisp add-function one that fits
very specific
needs.

To me that's a good example of Alan Kay's “Simple things should
be simple; complex things should be possible.".

So I think it's a better idea to add snippet examples to the documentation
that describe how to achieve these complex things.

João





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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-11-30 12:30                     ` João Távora
@ 2024-12-01 10:25                       ` Nikolay Kudryavtsev
  2024-12-01 12:27                         ` João Távora
  0 siblings, 1 reply; 20+ messages in thread
From: Nikolay Kudryavtsev @ 2024-12-01 10:25 UTC (permalink / raw)
  To: João Távora, Eli Zaretskii; +Cc: 73688, marc, monnier

Well, that's your call here.

But let me try and restate why I think there's a real problem. If we go 
at it from the perspective of a user who has no knowledge of 
electric-pair-mode internals, but now has the idea that the he wants a 
before-word predicate. A quick look through variables would allow him to 
discover the existence of electric-pair-inhibit-predicate. And just by 
the name alone it sounds like exactly the right thing. But unfortunately 
if the user looks into electric-pair-default-inhibit he'd notice that it 
wraps around either electric-pair-inhibit-if-helps-balance or 
electric-pair-conservative-inhibit. So, now the user needs to know what 
those functions actually do and whether anything would break if he 
removes them and replaces them with his own. Or a more careless 
user(like me) would roll out his own predicate and only then notice that 
it broke some advanced behavior. In the end, a reasonable user who just 
wants to add a simple thing is now burdened by all the cognitive load of 
learning numerous functions and use cases.

Thus electric-pair-inhibit-predicate in it's current state is not 
something really user-customizable, but more of an Emacs internal.

As for the add-function option, I think relying on those as the first 
option goes against the Emacs philosophy of providing real 
customizability wherever possible and avoiding littering the manuals(and 
user inits) with dirty hacks like this as a much as possible. Also, just 
from the user standpoint, in the above case the same user would probably 
go for add-function only after he already noticed that the 
electric-pair-inhibit-predicate is inadequate for his purposes.






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

* bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode
  2024-12-01 10:25                       ` Nikolay Kudryavtsev
@ 2024-12-01 12:27                         ` João Távora
  0 siblings, 0 replies; 20+ messages in thread
From: João Távora @ 2024-12-01 12:27 UTC (permalink / raw)
  To: Nikolay Kudryavtsev; +Cc: 73688, Eli Zaretskii, marc, monnier

On Sun, Dec 1, 2024 at 10:25 AM Nikolay Kudryavtsev
<nikolay.kudryavtsev@gmail.com> wrote:
>
> Well, that's your call here.

No, it's not. It's just my opinion :-)





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

end of thread, other threads:[~2024-12-01 12:27 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08  3:10 bug#73688: [PATCH] electric-pair-mode - preserve balance in conservative mode Marc Soda
2024-10-12 12:21 ` Eli Zaretskii
2024-10-12 19:47   ` Marc Soda
2024-10-12 20:36   ` João Távora
2024-10-12 20:43     ` Marc Soda
2024-10-12 23:36       ` João Távora
2024-10-17 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 17:48   ` Marc Soda
2024-10-26 18:47     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-09  9:22       ` Eli Zaretskii
2024-11-09 10:30         ` Nikolay Kudryavtsev
2024-11-09 15:55           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-10 14:28             ` Nikolay Kudryavtsev
2024-11-23 12:22               ` Eli Zaretskii
2024-11-23 17:37                 ` Nikolay Kudryavtsev
2024-11-30 10:21                   ` Eli Zaretskii
2024-11-30 12:30                     ` João Távora
2024-12-01 10:25                       ` Nikolay Kudryavtsev
2024-12-01 12:27                         ` João Távora
2024-11-23 17:29         ` Marc Soda

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.