GNU bug report logs - #40865
26.3; Electric pair mode and syntax class $

Previous Next

Package: emacs;

Reported by: Augusto Stoffel <arstoffel <at> gmail.com>

Date: Sun, 26 Apr 2020 10:40:01 UTC

Severity: normal

Merged with 32076

Found in versions 24.5, 26.3

Full log


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

From: João Távora <joaotavora <at> gmail.com>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 40865 <at> debbugs.gnu.org
Subject: Re: bug#40865: 26.3; Electric pair mode and syntax class $
Date: Tue, 12 May 2020 22:58:36 +0100
Augusto Stoffel <arstoffel <at> gmail.com> writes:

Hi Augusto, thank you for the report.

> Electric pair mode does not treat string quote characters and paired
> delimiters (syntax class "$") in the same way, but it should probably
> do so.

Paired delimiters don't formally define any kind of syntactic region
between them, contrary to string delimiters.

Therefore, electric-pair-mode can't easily know if a decision to skip or
auto-pair would be benefitting the balance of the syntax buffer.
Therefore, it decides to be dumb and always autopair, never autoskip.

If I had chosen the alternative, having your point just before a '$foo$'
would make autoskip put it inside the group, instead of creating a new
'$$$foo$', which is probably what you wanted in that particular
situation.

Maybe, even though flawed, that is more defensible as a default
behaviour than the current one.  At least it doesn't seem to break any
tests.

The "correct" way to fix this is to make latex-mode treat paired
delimiters like it does string delimiteres.  But that probably has other
negative implications that I'm not aware of.

I have the vague recollection that this came up when I was developing
electric-pair-mode, particularly in latex-mode, some 6 years ago, but I
can't remember anymore.

Anyway, if you do prefer the alternative I gave earlier you can do this:

(add-hook 'latex-mode-hook
          (lambda ()
            (add-function :before-until
                          (local 'electric-pair-skip-self)
                          (lambda (char) (eq char ?$))
                          '((name . latex-skip-paired-delimiters)))))

João

PS: On a related note, note that AUCTex mode (a different mode to edit
TeX files) has a special binding for the dollar sign, TeX-insert-dollar,
which doesn't follow _any_ of electric-pair-mode.





This bug report was last modified 3 years and 359 days ago.

Previous Next


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