From: "João Távora" <joaotavora@gmail.com>
To: Jim Porter <jporterbugs@gmail.com>
Cc: 49518@debbugs.gnu.org, Stephen Berman <stephen.berman@gmx.net>,
Daniel Fleischer <danflscr@gmail.com>
Subject: bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode
Date: Sun, 19 Sep 2021 01:20:30 +0100 [thread overview]
Message-ID: <87v92xbelt.fsf@gmail.com> (raw)
In-Reply-To: <87zgs9bgaz.fsf@gmail.com> ("João Távora"'s message of "Sun, 19 Sep 2021 00:43:48 +0100")
João Távora <joaotavora@gmail.com> writes:
> Jim Porter <jporterbugs@gmail.com> writes:
>
>> (CCing João since he wanted to hear about `electric-pair-mode' issues[1].)
>
> Thanks you Jim,
>
> I've read your original bug report. It is very clear in reproduction
> and also the analysis seems mostly correct. I'll see what I can do.
>
> The solution will probably go into python.el in terms of customization
> of electric-pair-mode's variables. The only question is whether it can
> be made to serve Stephen's and your requirements.
>
> In the meantime, if you're curious: this was one of the first things I
> worked in with autopair.el. See
> https://github.com/joaotavora/autopair/issues/6.
So after having a look at this, I came up with a patch. All tests
pass, and your original request is granted. Unfortunately, Stephen's
desired triple-pair behaviour is also lost. However, I think that
behaviour can be recovered via other more elegant, less accidental ways.
python.el has 'python-electric-pair-string-delimiter' for triple-pairing
that doesn't seem to be doing its thing.
Here is the patch. Give it a shot.
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index d8c377a2ef..b8b8a97651 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -198,7 +198,9 @@ electric-pair-syntax-info
inside a comment or string."
(let* ((pre-string-or-comment (or (bobp)
(nth 8 (save-excursion
- (syntax-ppss (1- (point)))))))
+ (skip-chars-backward
+ (make-string 1 command-event))
+ (syntax-ppss (point))))))
(post-string-or-comment (nth 8 (syntax-ppss (point))))
(string-or-comment (and post-string-or-comment
pre-string-or-comment))
The original idea of electric-pair-syntax-info is that
electric-pair-text-syntax-table is consulted if point is "well within" a
string or comment. That's why it backtracks a character to establish
pre-string-or-comment. But for strings started with multiple characters
it failed, as you well noticed.
So my patch makes it more likely that it understands if point is right
after the string start. Maybe better less brittle solutions can
probably be found within the syntax tables framework. If not, we can
make a variable. I'll think about it better later. Anyway, I'm not
entirely unhappy with this patch because all the tests pass, and they
are reasonably strict and sensitive to this stuff. So no breakage there
is a very good sign.
João
next prev parent reply other threads:[~2021-09-19 0:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=87v92xbelt.fsf@gmail.com \
--to=joaotavora@gmail.com \
--cc=49518@debbugs.gnu.org \
--cc=danflscr@gmail.com \
--cc=jporterbugs@gmail.com \
--cc=stephen.berman@gmx.net \
/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).