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: 27.1; python mode font-lock confused by string concatenation Date: Fri, 19 Jan 2024 17:01:48 +0100 Message-ID: References: <875z3ydqlz.fsf@tromey.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="33264"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.1 Cc: Tom Tromey To: 45897@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 19 17:02:28 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 1rQrK8-0008Mw-GZ for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Jan 2024 17:02:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQrJm-00048q-Gb; Fri, 19 Jan 2024 11:02:06 -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 1rQrJi-00048F-JD for bug-gnu-emacs@gnu.org; Fri, 19 Jan 2024 11:02:02 -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 1rQrJg-0002Xr-Po for bug-gnu-emacs@gnu.org; Fri, 19 Jan 2024 11:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rQrJi-0004bT-Ia for bug-gnu-emacs@gnu.org; Fri, 19 Jan 2024 11:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Jan 2024 16:02: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.170568012117670 (code B ref 45897); Fri, 19 Jan 2024 16:02:02 +0000 Original-Received: (at 45897) by debbugs.gnu.org; 19 Jan 2024 16:02:01 +0000 Original-Received: from localhost ([127.0.0.1]:59999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rQrJh-0004aa-0b for submit@debbugs.gnu.org; Fri, 19 Jan 2024 11:02:01 -0500 Original-Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:53308) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rQrJe-0004VO-UA for 45897@debbugs.gnu.org; Fri, 19 Jan 2024 11:01:59 -0500 Original-Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a2821884a09so68234766b.2 for <45897@debbugs.gnu.org>; Fri, 19 Jan 2024 08:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705680110; x=1706284910; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:cc:to :user-agent:references:in-reply-to:subject:from:from:to:cc:subject :date:message-id:reply-to; bh=ZIMV16RlXacrVlOY3Cef4iiiB4bRC5iqFPDGf1tKtPY=; b=BpVz2Ju1NSl700KxssKWLlEK4C0TvM/2Po0vYzfANQf9qTINxOPQEOGlLb+h/PCg5g NzBRGyabfO+UnHXLEX+tVFaNMy8pozXDiMu9DO4WEtRe6MepaCPo0e/am6gjw0Vhsrn0 475aCk0RuGjLzNqW7faJcoP1Qc0Ny3wFPJF9ePteIAjUnJDxNeFHtGkTNHOVzJXr0h13 gPWtuUzKI/LMcZruv8zWuROL3zGOmCDCwsTQ7pPrIU0S7HBeY/2WgM9SY5/WUTNfk7R/ +B0Cvwu9X2lhKNeMLsmhI2mciH/YohbCQNIiU16HE2QWgEj6kdEehH8X8xkLRocclZlh UJuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705680110; x=1706284910; h=content-transfer-encoding:mime-version:message-id:date:cc:to :user-agent:references:in-reply-to:subject:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZIMV16RlXacrVlOY3Cef4iiiB4bRC5iqFPDGf1tKtPY=; b=eNrOjIg8esmUh5OmzJEjp0t+CKGY2iWtYUQncafC7Hjw/xG/aja+ElOZfhMoUxdFY2 ABaA7UuruJYejI4gUQKAqnUv3mggaGbT9gbBTacCeCkSMhjNlDy8ElwuZ3q5quYZRnOi cKjGUsSmO1j8nZx/eO1JOXMS3Ud0faRi3CYD+7dymd5LL7fAIOZ0cuYCVadoRS8PMSZw 4vXz2kRfi5bLhhsxlOUwEEfLOLSAdWKfW9pCxg5q8R9YN1HyMRl5sC33rgjxbbkP+K4F TyIc15JVcrqwTO+F7fwrhn5At30HUMDc3Jw7RsiShuTRhF+FYio4gG7zfH8beTtdS32f BC/Q== X-Gm-Message-State: AOJu0Yy4me0Irkwb3F8qg+0v9ACDc9Qf9OVZRgf89mlaxUJRC/DAVCyX mfgTPUoIWGS0R6e1pzVZCDIQY7fCY/9KS7+zwg9fCVbJ3OW+xKw1 X-Google-Smtp-Source: AGHT+IERchoph9ElcaT/pRn6BlCvEFOx2y6oQbSPaLQkbRDdleBaw/XzGEJrbT9x5sFcxDBdmNBy4A== X-Received: by 2002:a17:906:40c8:b0:a28:b35d:f240 with SMTP id a8-20020a17090640c800b00a28b35df240mr6496ejk.10.1705680110090; Fri, 19 Jan 2024 08:01:50 -0800 (PST) Original-Received: from Jakubs-MacBook-Air.local ([185.249.114.4]) by smtp.gmail.com with ESMTPSA id i18-20020a170906091200b00a2c2b475a0esm10354896ejd.105.2024.01.19.08.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 08:01:49 -0800 (PST) In-Reply-To: <875z3ydqlz.fsf@tromey.com> (Tom Tromey's message of "Fri, 15 Jan 2021 11:03:52 -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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:278534 Archived-At: Tom Tromey writes: > Consider this 2-line Python file: > > x =3D "hello""" > y =3D "confused" > > If you put this into a .py file, Emacs will font-lock the second line > incorrectly. It appears that Emacs thinks the `"""' on the first line > is an opening triple quote. However, it is actually string > concatenation, with the second string being empty. > > I tripped over a case like this in some real code. Hi, thanks for the bug report and sorry for the late response! I confirm that this is an issue. I've prepared a patch which handles this special case: >From f34c84b8b4c629c51d547dd41d20222b32f838bb Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Jakub=3D20Je=3DC4=3D8Dm=3DC3=3DADnek?=3D Date: Fri, 19 Jan 2024 16:38:21 +0100 Subject: [PATCH] Fix syntax highlighting after string literal concatenation= in python-mode * lisp/progmodes/python.el (python-syntax-stringify): Fix incorrect font-lo= ck after string literal concatenation. --- lisp/progmodes/python.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e2f614f52c2..d6534a7ddae 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -908,7 +908,11 @@ is used to limit the scan." (defun python-syntax-stringify () "Put `syntax-table' property correctly on single/triple quotes." (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss))) + (line-ppss (save-excursion (backward-char 3) (parse-partial-sexp + (line-beginning-posi= tion) (point)))) (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss))) + (string-literal-concat (and (null string-start) + (and (not (null (nth 3 line-ppss))) (nth 8 line= -ppss)))) (quote-starting-pos (- (point) 3)) (quote-ending-pos (point))) (cond ((or (nth 4 ppss) ;Inside a comment @@ -921,6 +925,8 @@ is used to limit the scan." ((nth 5 ppss) ;; The first quote is escaped, so it's not part of a triple quo= te! (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) -- 2.39.3 (Apple Git-145) If the patch is good enough, I'll sign the paperwork (I've most likely crossed the line limit). Best, Jakub Je=C4=8Dm=C3=ADnek