unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Daniel Fleischer <danflscr@gmail.com>
Cc: 49518@debbugs.gnu.org, "Stephen Berman" <stephen.berman@gmx.net>,
	"João Távora" <joaotavora@gmail.com>
Subject: bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode
Date: Sat, 18 Sep 2021 09:56:17 -0700	[thread overview]
Message-ID: <58515d93-dbca-4cd1-e820-ad9d5bb6d462@gmail.com> (raw)
In-Reply-To: <m2lf3uniuw.fsf@gmail.com>

(CCing João since he wanted to hear about `electric-pair-mode' issues[1].)

On 9/18/2021 5:55 AM, Daniel Fleischer wrote:
> Jim Porter [2021-07-11 Sun 10:34] wrote:
> 
>> That's true, and I've been working on a patch to make that behavior
>> more robust. The code for that is in
>> `python-electric-pair-string-delimiter', but I think an improved
>> implementation of that would depend on how this bug is fixed. I have a
>> local patch that works for me, but it depends on the other
>> electric-pair settings I use, so it couldn't merge as-is.
> 
> As I'm also bothered by this, is there some resolution?
> 
> BTW, my solution is hooking this code in 'inferior-python-mode':
> 
> (setq-local electric-pair-pairs
>              (append electric-pair-pairs '((?' . ?'))))

This isn't the right fix in general, but maybe it will help you. It 
works for me because I turn off `electric-pair-mode' inside comments and 
strings, but with the default configuration, it will pair single-quotes 
inside double-quoted strings (i.e. you won't be able to type an 
apostrophe). There's probably a more robust solution, but I haven't had 
time to investigate further...

----------------------------------------

   (defun user--python-electric-pair-string-delimiter ()
     (when (and electric-pair-mode
                (memq last-command-event '(?\" ?'))
                (let ((count 0))
                  (while (eq (char-before (- (point) count)) 
last-command-event)
                    (cl-incf count))
                  (= count 3)))
       (save-excursion (insert (make-string 3 last-command-event)))))

   (defun user--electric-pair-python-hook ()
     (setq-local electric-pair-text-syntax-table python-mode-syntax-table))

   (advice-add #'python-electric-pair-string-delimiter
               :override #'user--python-electric-pair-string-delimiter)
   (add-hook 'python-mode-hook #'user--electric-pair-python-hook)

----------------------------------------

[1] https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg01313.html





  reply	other threads:[~2021-09-18 16:56 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 [this message]
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

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=58515d93-dbca-4cd1-e820-ad9d5bb6d462@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=49518@debbugs.gnu.org \
    --cc=danflscr@gmail.com \
    --cc=joaotavora@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).