From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode Date: Sun, 19 Sep 2021 11:44:47 +0100 Message-ID: <87o88oc09s.fsf@gmail.com> References: <877dhxp8wn.fsf@gmx.net> <58515d93-dbca-4cd1-e820-ad9d5bb6d462@gmail.com> <87zgs9bgaz.fsf@gmail.com> <87v92xbelt.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4168"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 49518@debbugs.gnu.org, Stephen Berman , Daniel Fleischer , monnier@iro.umontreal.ca To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 19 12:46:19 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mRuKw-0000qt-76 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 12:46:18 +0200 Original-Received: from localhost ([::1]:57284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRuKu-0000k4-OZ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 06:46:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRuKg-0000jt-4u for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 06:46:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54217) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRuKf-0006JU-TA for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 06:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mRuKf-0001Bq-OQ for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 06:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Sep 2021 10:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49518 X-GNU-PR-Package: emacs Original-Received: via spool by 49518-submit@debbugs.gnu.org id=B49518.16320483034493 (code B ref 49518); Sun, 19 Sep 2021 10:46:01 +0000 Original-Received: (at 49518) by debbugs.gnu.org; 19 Sep 2021 10:45:03 +0000 Original-Received: from localhost ([127.0.0.1]:37530 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRuJi-0001AF-Hr for submit@debbugs.gnu.org; Sun, 19 Sep 2021 06:45:03 -0400 Original-Received: from mail-wr1-f44.google.com ([209.85.221.44]:35771) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRuJe-00019Y-4P for 49518@debbugs.gnu.org; Sun, 19 Sep 2021 06:45:01 -0400 Original-Received: by mail-wr1-f44.google.com with SMTP id i23so23328148wrb.2 for <49518@debbugs.gnu.org>; Sun, 19 Sep 2021 03:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=dEX4z6w+900Kqdr2IN9yQZZeY2jHq2nckRdgZYAgE4k=; b=iKUg6aBsxz88hKjbV1DBYtqxfLwrE1wqNxQNLHGGOKPXc5K2r5qgnaP2sRdFVP3SI7 UikK5ZhLw5hl6dNc6jUW59QvLPYxigm+oBeP+YpkE9qfajS/BYvX/YliU87zBKpRpR+v 32WmrDC1Gf7EPvpPgEyFtBfNPbjxy0U0tojDpIiXYakj8tSBVRpugExAC95PFJWJjy/v +fcACMPy7mCpkyZZ7Pcy2jF/HLVWEZ5o4KQ8LlVvDgHeIbCU+dkQg8DDmthKCmN/dVRX Y/6kokEuP1cqIlRJ4JZsD5fmBzr/aOf3LUEfV4D4hgpJG/Idc0LIfA4rWdJjsLE6AJp7 zj2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=dEX4z6w+900Kqdr2IN9yQZZeY2jHq2nckRdgZYAgE4k=; b=4YzBwwdcI7L8dFwnxztCvsYGg+bXVTV++MnKIjk16GwPoy0W44KVX1mx0Toch2ofem yUDJgtGTc16KQz9WOxuHmql0zj9dVJ0f2HgeVmQKEZ9Z8Ob+Iw86IklXJNnA+JC0ecQn f5tjeF4pQikkc6fB7g/F/HB9xlllGnmqDHfJ2nU6tsWiv26Ws64uweS5ts52sWPc7ALI v6MxDhDx5qlFLvHK4r9AAcpzpDchLw9WmMImvYnIIr5OWJZk/E0CnNZCTTU1V5iQZ1c9 iwNyp5gpvw+N/5d7xcGTWfgF9XY3Mhi3hWp6rcpqbgeDDr7NlzuCfMlvlTzuU7L9cmOA 38FA== X-Gm-Message-State: AOAM530pNiS+07rEneXdt20L5bcHeQt5KQ6uOKOYK+zTSucibKyVwvfu plb3wSCLb2gFBMdI+NKAU6M= X-Google-Smtp-Source: ABdhPJxHl9aV73htzvWFRnALe7TVHFRjAf2q3Ap+WU8TGHZA91On+MLkdFEjbESI1EkJcGXxAiMg/A== X-Received: by 2002:adf:e44c:: with SMTP id t12mr23133739wrm.49.1632048292131; Sun, 19 Sep 2021 03:44:52 -0700 (PDT) Original-Received: from krug (a83-132-177-247.cpe.netcabo.pt. [83.132.177.247]) by smtp.gmail.com with ESMTPSA id 23sm9013988wme.27.2021.09.19.03.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 03:44:51 -0700 (PDT) In-Reply-To: (Jim Porter's message of "Sat, 18 Sep 2021 18:55:06 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:214700 Archived-At: [Stefan, I'm CC-ing you to assist with a python.el syntax propertization bug and a patch for it at the end of this mail] Jim Porter writes: > On 9/18/2021 5:20 PM, Jo=C3=A3o T=C3=A1vora wrote: >> 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 >> + (string 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)) >>=20 > > Thanks, this patch works for me.=20 >> Maybe better less brittle solutions can probably be found within the >> syntax tables framework. > I agree that something less brittle would be nice, but that might be > tricky. I had tried a few options when I filed this bug, but nothing > worked quite right. The point of 'electric-pair-syntax-info's STRING-OR-COMMENT-START return value is to tell if both the current and the pre-insertion point are and were inside a string or a comment. It seems reasonable (i.e. not crazy) to skip the same syntax _and_ char backwards to discover that. Ideally this would be remembered from before the insertion, it's true. But again, the fact that the patch passes all demanding tests is a good sign: they are quite strict. Notice, for example, that if the patch were the seemingly also reasonable: (let* ((pre-string-or-comment (or (bobp) (nth 8 (save-excursion - (skip-chars-backward - (string command-event)) + (skip-syntax-backward + (string (char-syntax com= mand-event))) (syntax-ppss (point)))))) (post-string-or-comment (nth 8 (syntax-ppss (point)))) (string-or-comment (and post-string-or-comment There would be one single test failure in a ruby-mode "mixed quote" situation. > As for Stephen's desired behavior, the code snippet I posted above[1] > mostly fixes it (just the `python-electric-pair-string-delimiter' part > is necessary after your patch). However, that code doesn't work right > if `electric-pair-skip-self' is set to nil, so I'd need to be a bit > smarter with the implementation if I wanted to merge it into > Emacs. Perhaps there's an even cleaner solution though. I think the cleaner solution is to fix a bug in python.el. Here's the reproduction for that bug (no electric pair mode involved) emacs -Q something.py type two single quotes M-: (nth 3 (syntax-ppss)) notice how the return value says you're outside a string, correctly type another quote M-: (nth 3 (syntax-ppss)) notice how the return value says you're inside a string, correctly backspace the quote just entered M-: (nth 3 (syntax-ppss)) notice how the return value says you're inside a string, incorrectly When this bug is fixed, I'm confident that Stephen's case will start working. In fact, it's possible that if this python.el bug were fixed, we wouldn't need the above patch at all, becasue backtracking one char into just before the third quote of a triple quote should _also_ yield a nil (nth 3 (syntax-ppss)). In fact, I have tried a patch for python.el that could fix _all_ of this (but would need some heavy testing probably): =20 (defvar python-mode-syntax-tablediff --git a/lisp/progmodes/python.el = b/lisp/progmodes/python.el index 19b79b6919..da7b92ae42 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -775,12 +775,14 @@ python-syntax-stringify ;; The first quote is escaped, so it's not part of a triple= quote! (goto-char (1+ quote-starting-pos))) ((null string-start) - ;; This set of quotes delimit the start of a string. - (put-text-property quote-starting-pos (1+ quote-starting-po= s) + ;; This set of quotes delimit the start of a string. Put + ;; the delimiter syntax in the last of the three quotes. + (put-text-property (1- quote-ending-pos) quote-ending-pos 'syntax-table (string-to-syntax "|"))) (t - ;; This set of quotes delimit the end of a string. - (put-text-property (1- quote-ending-pos) quote-ending-pos + ;; This set of quotes delimit the end of a string. Put the + ;; delimiter syntax in the first of the three quotess. + (put-text-property quote-starting-pos (1+ quote-starting-po= s) 'syntax-table (string-to-syntax "|")))))) =20=20=20=20=20 (defvar python-mode-syntax-table Jo=C3=A3o