GNU bug report logs - #47936
AucTeX and electric-pair-mode

Previous Next

Package: auctex;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Wed, 21 Apr 2021 17:32:02 UTC

Severity: normal

Done: Tassilo Horn <tsdh <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47936 in the body.
You can then email your comments to 47936 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Wed, 21 Apr 2021 17:32:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Kaludercic <philipk <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Wed, 21 Apr 2021 17:32:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: bug-auctex <at> gnu.org
Subject: AucTeX and electric-pair-mode
Date: Wed, 21 Apr 2021 17:31:10 +0000
[Message part 1 (text/plain, inline)]
Hi,

an annoyance I have with auctex is it's interaction with
electric-pair-mode. If both LaTeX-electric-left-right-brace and
electric-pair-mode are enabled, typing '(' inserts "())", because both
AucTeX and the electric function insert a closing parentheses. I still
want to keep LaTeX-electric-left-right-brace enabled, because it handles
TeX-specific parentheses (\{, \left <something>, ...) better.

I'm not sure if there is a real fix for this, but I couldn't find
anything and my go-to solution of locally removing
electric-pair-post-self-insert-function from post-self-insert-hook is
also unstable.

The attached patch would propose a solution that respects
electric-pair-mode and doesn't insert an extra closing pair if
enabled. It seems to work on my system, and if there are no issues it
would be great if something along these lines could be done to avoid
this behaviour.

-- 
	Philip K.

[0001-Improve-handling-for-parentheses-with-electric-pair-.patch (text/x-diff, inline)]
From d47f68ddf8c7d1d9c90adbc2ea9ee09588010ce3 Mon Sep 17 00:00:00 2001
From: Philip K <philipk <at> posteo.net>
Date: Wed, 21 Apr 2021 19:25:16 +0200
Subject: [PATCH] Improve handling for parentheses with electric-pair-mode

---
 latex.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/latex.el b/latex.el
index 83d50caf..512639d5 100644
--- a/latex.el
+++ b/latex.el
@@ -2979,6 +2979,8 @@ is nil, consult user which brace should be used."
     (if rmacro
         (insert TeX-esc rmacro))
     (cond
+     ((and (string= (char-to-string last-command-event) lbrace)
+           electric-pair-mode))
      ((and TeX-arg-right-insert-p rbrace)
       (insert rbrace))
      (rmacro
-- 
2.30.2


Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Wed, 21 Apr 2021 20:10:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 47936-done <at> debbugs.gnu.org, bug-auctex <at> gnu.org
Subject: Re: bug#47936: AucTeX and electric-pair-mode
Date: Wed, 21 Apr 2021 21:54:57 +0200
Philip Kaludercic <philipk <at> posteo.net> writes:

Hi Philip,

> an annoyance I have with auctex is it's interaction with
> electric-pair-mode. If both LaTeX-electric-left-right-brace and
> electric-pair-mode are enabled, typing '(' inserts "())", because both
> AucTeX and the electric function insert a closing parentheses. I still
> want to keep LaTeX-electric-left-right-brace enabled, because it
> handles TeX-specific parentheses (\{, \left <something>, ...) better.

Ok, makes sense.

> The attached patch would propose a solution that respects
> electric-pair-mode and doesn't insert an extra closing pair if
> enabled.

> @@ -2979,6 +2979,8 @@ is nil, consult user which brace should be used."
>      (if rmacro
>          (insert TeX-esc rmacro))
>      (cond
> +     ((and (string= (char-to-string last-command-event) lbrace)
> +           electric-pair-mode))
>       ((and TeX-arg-right-insert-p rbrace)
>        (insert rbrace))
>       (rmacro

LGTM, I've applied it with slight modifications and a ChangeLog style
commit message following our/Emacs conventions.

Thanks a lot, Philip!

Bye,
Tassilo




Reply sent to Tassilo Horn <tsdh <at> gnu.org>:
You have taken responsibility. (Wed, 21 Apr 2021 20:10:02 GMT) Full text and rfc822 format available.

Notification sent to Philip Kaludercic <philipk <at> posteo.net>:
bug acknowledged by developer. (Wed, 21 Apr 2021 20:10:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 04:34:02 GMT) Full text and rfc822 format available.

Message #16 received at 47936 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 47936 <at> debbugs.gnu.org
Subject: Re: bug#47936: AucTeX and electric-pair-mode
Date: Thu, 22 Apr 2021 13:33:34 +0900
[Message part 1 (text/plain, inline)]
Hi Philip,

>>>>> Philip Kaludercic <philipk <at> posteo.net> writes:

> an annoyance I have with auctex is it's interaction with
> electric-pair-mode. If both LaTeX-electric-left-right-brace and
> electric-pair-mode are enabled, typing '(' inserts "())", because both
> AucTeX and the electric function insert a closing parentheses. I still
> want to keep LaTeX-electric-left-right-brace enabled, because it handles
> TeX-specific parentheses (\{, \left <something>, ...) better.

AUCTeX already has the following code in `LaTeX-common-initialization'
to turn off `electric-pair-mode' explicitly.  So I guess you customize
`LaTeX-mode-hook' to re-enable `electric-pair-mode'.

  ;; AUCTeX's brace pairing feature (`LaTeX-electric-left-right-brace') doesn't
  ;; play nice with `electric-pair-mode' which is a global minor mode as of
  ;; emacs 24.4.
  (when (and LaTeX-electric-left-right-brace
             (boundp 'electric-pair-mode))
    (set (make-local-variable 'electric-pair-mode) nil))

> The attached patch would propose a solution that respects
> electric-pair-mode and doesn't insert an extra closing pair if
> enabled. It seems to work on my system, and if there are no issues it
> would be great if something along these lines could be done to avoid
> this behaviour.

Thanks. Maybe the attached patch might be better so that
`LaTeX-insert-left-brace' can get rid of all unexpected interactions
with `self-insert-command'. Tassilo, what do you think about it?

Regards,
Ikumi Keita

[diff (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 05:04:02 GMT) Full text and rfc822 format available.

Message #19 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 47936 <at> debbugs.gnu.org, bug-auctex <at> gnu.org,
 Philip Kaludercic <philipk <at> posteo.net>
Subject: Re: bug#47936: AucTeX and electric-pair-mode
Date: Thu, 22 Apr 2021 06:56:06 +0200
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> AUCTeX already has the following code in `LaTeX-common-initialization'
> to turn off `electric-pair-mode' explicitly.  

Oh, I've already forgotten. :-)

> Thanks. Maybe the attached patch might be better so that
> `LaTeX-insert-left-brace' can get rid of all unexpected interactions
> with `self-insert-command'. Tassilo, what do you think about it?

Ah, yes, that's a a much better idea!  Feel free to install it and undo
Philip's change which shouldn't be needed anymore when not using
`self-insert-command'.

Thanks,
Tassilo




Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 05:04:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 05:48:02 GMT) Full text and rfc822 format available.

Message #25 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: 47936 <at> debbugs.gnu.org, bug-auctex <at> gnu.org,
 Philip Kaludercic <philipk <at> posteo.net>
Subject: Re: bug#47936: AucTeX and electric-pair-mode
Date: Thu, 22 Apr 2021 14:46:56 +0900
>>>>> Tassilo Horn <tsdh <at> gnu.org> writes:
> Ah, yes, that's a a much better idea!  Feel free to install it and undo
> Philip's change which shouldn't be needed anymore when not using
> `self-insert-command'.

Done!

Bye,
Ikumi Keita




Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 05:48:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 12:09:02 GMT) Full text and rfc822 format available.

Message #31 received at 47936 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: 47936 <at> debbugs.gnu.org, bug-auctex <at> gnu.org,
 Philip Kaludercic <philipk <at> posteo.net>
Subject: Re: bug#47936: AucTeX and electric-pair-mode
Date: Thu, 22 Apr 2021 21:08:41 +0900
>>>>> Tassilo Horn <tsdh <at> gnu.org> writes:
> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
>> AUCTeX already has the following code in `LaTeX-common-initialization'
>> to turn off `electric-pair-mode' explicitly.  

> Oh, I've already forgotten. :-)

>> Thanks. Maybe the attached patch might be better so that
>> `LaTeX-insert-left-brace' can get rid of all unexpected interactions
>> with `self-insert-command'. Tassilo, what do you think about it?

> Ah, yes, that's a a much better idea!  Feel free to install it and undo
> Philip's change which shouldn't be needed anymore when not using
> `self-insert-command'.

I reconsidered it and committed a modification so that
`LaTeX-insert-left-brace' suppresses such interaction only when it
inserts the right delimeter by itself. Now `electric-pair-mode' does its
job when e.g. prefix argument is given.

Regards,
Ikumi Keita




Information forwarded to bug-auctex <at> gnu.org:
bug#47936; Package auctex. (Thu, 22 Apr 2021 12:10:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 21 May 2021 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 89 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.