unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode
@ 2021-07-11  1:32 Jim Porter
  2021-07-11  8:11 ` Stephen Berman
  0 siblings, 1 reply; 12+ messages in thread
From: Jim Porter @ 2021-07-11  1:32 UTC (permalink / raw)
  To: 49518

To reproduce this issue:

  1.  emacs -Q --eval '(electric-pair-mode)' foo.py
  2a. Type " (double-quote); result should be "|", where | is the point
  2b. Type " (double-quote); result should be ""|
      (Note: This is the correct behavior, as I understand it.)
  3.  Delete everything (optional)
  4a. Type ' (single-quote); result should be '|'
  4b. Type ' (single-quote); result is ''|', but (I think) it should be ''|

Having looked through the source of both `electric-pair-mode' and
`python-mode', I believe I understand the problem.

First, some background: in `electric-pair-syntax-info', it checks
whether the point is inside a string or comment. If so, it uses
`electric-pair-text-syntax-table' (defaulting to
`prog-mode-syntax-table'); if not, it uses `python-mode-syntax-table'.
Normally, this means if you have a snippet like ''|', the point is
*not* inside string; it's after the end of one string and before the
start of the next.

However, Python has multiline strings, which causes an issue here.
When python-mode sees 3 quotation marks in a row, it doesn't see that
as an empty string followed by the start of a separate string; it sees
the start of a multiline string. Thus, when we have our snippet ''|',
the point is considered to be in a string. That means
`electric-pair-syntax-info' uses `electric-pair-text-syntax-table'.
Since the default prog-mode syntax table doesn't consider single-quote
to be a quote character, `electric-pair-syntax-info' ends up returning
nil.

Notably, this *isn't* an issue for double-quote. While we
(temporarily) have the state ""|", double-quote is a quote character
according to `electric-pair-text-syntax-table', and so skip-self
proceeds as expected.

(You might think the fix here would be to do like `emacs-lisp-mode'
and locally set `electric-pair-text-pairs' to include single-quote.
This wouldn't work though, since it would make it hard to type an
apostrophe in a word; `electric-pair-mode' would double it up.)

One possible fix would be for `python-mode' to locally set
`electric-pair-text-syntax-table' to `python-mode-syntax-table'. This
seems to work for me after some basic testing, but I'm not confident
it's the right thing to do here; I don't see any examples of other
modes that do this, and I haven't thought over all the possible
problems with it.





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

end of thread, other threads:[~2021-09-22 20:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11  1:32 bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode Jim Porter
2021-07-11  8:11 ` Stephen Berman
2021-07-11 17:34   ` Jim Porter
2021-09-18 12:55     ` Daniel Fleischer
2021-09-18 16:56       ` Jim Porter
2021-09-18 23:43         ` João Távora
2021-09-19  0:20           ` João Távora
2021-09-19  1:55             ` Jim Porter
2021-09-19 10:44               ` João Távora
2021-09-19 16:35                 ` João Távora
2021-09-21  9:59                   ` João Távora
2021-09-22 20:04                     ` Jim Porter

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