unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: 40865@debbugs.gnu.org
Subject: bug#40865: 26.3; Electric pair mode and syntax class $
Date: Tue, 12 May 2020 22:58:36 +0100	[thread overview]
Message-ID: <87imh0ak8j.fsf@gmail.com> (raw)
In-Reply-To: <993210aab0f5abcac7e2e84e4289468431c5b5f5.camel@gmail.com> (Augusto Stoffel's message of "Sun, 26 Apr 2020 12:18:32 +0200")

Augusto Stoffel <arstoffel@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.






      reply	other threads:[~2020-05-12 21:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-26 10:18 bug#40865: 26.3; Electric pair mode and syntax class $ Augusto Stoffel
2020-05-12 21:58 ` João Távora [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imh0ak8j.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=40865@debbugs.gnu.org \
    --cc=arstoffel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).