unofficial mirror of bug-gnu-emacs@gnu.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
  0 siblings, 1 reply; 6+ 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] 6+ 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
  0 siblings, 2 replies; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread

end of thread, other threads:[~2024-10-12 23:36 UTC | newest]

Thread overview: 6+ 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

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).