From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= Newsgroups: gmane.emacs.bugs Subject: bug#45897: [PATCH] 27.1; python mode font-lock confused by string concatenation Date: Sun, 21 Jan 2024 00:33:55 +0100 Message-ID: References: <875z3ydqlz.fsf@tromey.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29133"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.1 Cc: 45897@debbugs.gnu.org, Eli Zaretskii To: kobarity Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 21 00:35:21 2024 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 1rRKrw-0007PG-Ow for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Jan 2024 00:35:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRKrd-00088R-4o; Sat, 20 Jan 2024 18:35:01 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRKrb-00088A-JY for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 18:34:59 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rRKrb-0006zh-BB for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 18:34:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rRKre-0006Qu-DP for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 18:35:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <875z3ydqlz.fsf@tromey.com> Resent-From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Jan 2024 23:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45897 X-GNU-PR-Package: emacs Original-Received: via spool by 45897-submit@debbugs.gnu.org id=B45897.170579364924646 (code B ref 45897); Sat, 20 Jan 2024 23:35:02 +0000 Original-Received: (at 45897) by debbugs.gnu.org; 20 Jan 2024 23:34:09 +0000 Original-Received: from localhost ([127.0.0.1]:36145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRKqn-0006PR-2A for submit@debbugs.gnu.org; Sat, 20 Jan 2024 18:34:09 -0500 Original-Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:43117) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRKqj-0006Ou-Ik for 45897@debbugs.gnu.org; Sat, 20 Jan 2024 18:34:07 -0500 Original-Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-559cef15db5so5595385a12.0 for <45897@debbugs.gnu.org>; Sat, 20 Jan 2024 15:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705793636; x=1706398436; darn=debbugs.gnu.org; h=mime-version:message-id:date:cc:user-agent:subject:to:from:from:to :cc:subject:date:message-id:reply-to; bh=E3lFVCXwUL5xHZ8cGtUSrW90+TPU6qfu2VOyZVPYPuw=; b=Qgxx6w1pIWnWPIiuuMQWfEdmr9sWN+yP5NN2Y39DTZQe8worg8CUBYbofBSAOIhH+m XIXLgH44usgqCpy/yZeir/qYtrpe+cTe1ee8eqtEt//VKgEFPWV72DC+pMoEqQaSzfen JZNpXd8R8pl4i3FFQpzycQiOhq6AEfJhnca5bJkBwehkDR4Xd8uZbubavN1rOWQvOR2+ gv6N40meb0d5CzxgjIWjN2qiKUrFZHA0EBgG/S5k3QjMWAgrJYAWnDDHFQPQK4LVxE1S LrEYjkbod/uuXXd04NNQxmHWJnS6n4OKM4sD/75UpnwhdCz/fSNYuV1v/pY0FgiOaw4A QTiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705793636; x=1706398436; h=mime-version:message-id:date:cc:user-agent:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E3lFVCXwUL5xHZ8cGtUSrW90+TPU6qfu2VOyZVPYPuw=; b=sstyEX6cffcHKJVhyZ0bXD25PCahxHN/7eMfjMoXwUNuFdhTDrbR4UqzM0o8wlmg+U mQhuUxqbwz5ftWHBdxynluUjB2S95E5Pzk9cHTup4xL5mauL2iw44Rnb963Qc+0PuZhN 2TI0Jst9T+i2+9Tgthz0fWIENFd17I8LPY2I4SUHbMImvJMbZgfVfhyj9kH1sLB5j3dn 5j3qKrkLrOaSUR5UBhdn5fAaLc9dDuDiZyIRSmjIffXnqKuokOK2uO9I/SOE14EaxWph 2LT+RmsAAboo8+SVdqaQ9mDlchh4cJ1kZ3bH/Jnvo86N67q4Hk9dle7gpO5kA1KyvGqF di9g== X-Gm-Message-State: AOJu0YzuRrdM4/IG3N4+0XkGi0Wrc+Xj2djlkyVlKuaYEtzLb0wz8lly RwMHeN6mh/+V540AUnN9MfeneYLzrAMEQqWX5aqfYUnqLWQcC87/ X-Google-Smtp-Source: AGHT+IGhTGvM/OST9ZIE6OSBnck7DBZNDsNDnOLu0ifj9AXUUCiLU6PjvMGJGiXN23+LsQ51Eh5CdA== X-Received: by 2002:aa7:d7c9:0:b0:55b:fda0:4ee9 with SMTP id e9-20020aa7d7c9000000b0055bfda04ee9mr1025233eds.2.1705793636254; Sat, 20 Jan 2024 15:33:56 -0800 (PST) Original-Received: from Jakubs-MacBook-Air.local (ip-217-030-066-058.aim-net.cz. [217.30.66.58]) by smtp.gmail.com with ESMTPSA id e9-20020a056402104900b0055c15c5919csm275438edu.86.2024.01.20.15.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 15:33:55 -0800 (PST) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:278632 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable kobarity writes: > Thank you for the patch. I tried it and confirmed that the example > shown by Tom Tromey is fixed. > > I think ppss and line-ppss would be the same in this example. Can you > give an example of a case where ppss and line-ppss are different? Well, it would be different in case like this: #+BEGIN_SRC python " # <- forgotten quote a =3D "abc""" #+END_SRC `ppss' would in the context of `python-syntax-stringify' evaluate to '(0 nil 8 nil nil nil 0 nil nil nil nil), while `line-ppss' to '(0 nil 5 34 nil nil 0 nil 7 nil nil). Note the 3rd and 8th element. Here's the snippet to test it: #+BEGIN_SRC emacs-lisp (with-temp-buffer (insert "\" a =3D \"abc\"\"\"") (backward-char 3) (syntax-ppss) (parse-partial-sexp (line-beginning-position) (point))) #+END_SRC I was thinking that we want to consider only cases where the quote is on the same line but I guess I wanted to solve a problem we don't have. I've revised the patch to be more simple, please see attached. > I noticed an error in the commit-msg hook when applying the patch. > CONTRIBUTE states the following: > > - Lines in ChangeLog entries should preferably be not longer than 63 > characters, and must not exceed 78 characters, unless they consist > of a single word of at most 140 characters; this 78/140 limit is > enforced by a commit hook. Thanks, fixed. > Also, the indentation still looks wrong to me. It might be better to > attach the patch instead of pasting it into the body of the mail. Please see attached. > Attached is a patch to add an ERT that identifies this issue. Please > add it to your patch if you like. Thanks, I've added it to my patch and added 'Co-authored-by:' to commit description. Best, Jakub Je=C4=8Dm=C3=ADnek --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=0001-Fix-syntax-highlighting-after-string-literal-concat-.patch Content-Description: 0001-Fix-syntax-highlighting-after-string-literal-concat >From af1f029bde36456b359e9768a8e525fdac6db3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C4=8Dm=C3=ADnek?= Date: Fri, 19 Jan 2024 16:38:21 +0100 Subject: [PATCH] Fix syntax highlighting after string literal concat in python-mode * lisp/progmodes/python.el (python-syntax-stringify): Fix incorrect font-lock after string literal concatenation. (Bug#45897) * test/lisp/progmodes/python-tests.el (python-font-lock-string-literal-concatenation): New test. Co-authored-by: kobarity --- lisp/progmodes/python.el | 3 +++ test/lisp/progmodes/python-tests.el | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e2f614f52c2..bee9c1d8cda 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -909,6 +909,7 @@ is used to limit the scan." "Put `syntax-table' property correctly on single/triple quotes." (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss))) (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss))) + (string-literal-concat (numberp (nth 3 ppss))) (quote-starting-pos (- (point) 3)) (quote-ending-pos (point))) (cond ((or (nth 4 ppss) ;Inside a comment @@ -921,6 +922,8 @@ is used to limit the scan." ((nth 5 ppss) ;; The first quote is escaped, so it's not part of a triple quote! (goto-char (1+ quote-starting-pos))) + ;; Handle string literal concatenation (bug#45897) + (string-literal-concat nil) ((null string-start) ;; This set of quotes delimit the start of a string. Put ;; string fence syntax on last quote. (bug#49518) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 97ffd5fe20f..59957ff0712 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -660,6 +660,18 @@ r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" (3 . font-lock-string-face) (14) (16 . font-lock-string-face)))) +(ert-deftest python-font-lock-string-literal-concatenation () + "Test for bug#45897." + (python-tests-assert-faces + "x = \"hello\"\"\" +y = \"confused\"" + '((1 . font-lock-variable-name-face) (2) + (3 . font-lock-operator-face) (4) + (5 . font-lock-string-face) (14) + (15 . font-lock-variable-name-face) (16) + (17 . font-lock-operator-face) (18) + (19 . font-lock-string-face)))) + ;;; Indentation -- 2.39.3 (Apple Git-145) --=-=-=--