From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#68445: [PATCH] Problem with python--treesit-syntax-propertize Date: Mon, 22 Jan 2024 20:52:58 +0200 Message-ID: <707dc3b4-c7dd-45b5-9764-a9738a9142b6@gutov.dev> References: <5135ab69-3704-459f-b6c7-b8ea738e8d31@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39326"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Yuan Fu , 68445@debbugs.gnu.org To: kobarity Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 22 19:54: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 1rRzRD-000A07-0X for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Jan 2024 19:54:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRzQn-0004FO-OV; Mon, 22 Jan 2024 13:54: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 1rRzQk-0004FD-Lk for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2024 13:53:58 -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 1rRzQk-0000kE-DQ for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2024 13:53:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rRzQo-0004IS-IF for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2024 13:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Jan 2024 18:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68445 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68445-submit@debbugs.gnu.org id=B68445.170594959316457 (code B ref 68445); Mon, 22 Jan 2024 18:54:02 +0000 Original-Received: (at 68445) by debbugs.gnu.org; 22 Jan 2024 18:53:13 +0000 Original-Received: from localhost ([127.0.0.1]:41805 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRzQ0-0004HN-S0 for submit@debbugs.gnu.org; Mon, 22 Jan 2024 13:53:13 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48011) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRzPy-0004H9-Gd for 68445@debbugs.gnu.org; Mon, 22 Jan 2024 13:53:12 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id D92455C014E; Mon, 22 Jan 2024 13:53:00 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 22 Jan 2024 13:53:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1705949580; x=1706035980; bh=FSX9OAEp1e6FSHD19ZNzPBM+D6vXzzdeWp76F2w23VY=; b= mCBvLEaREPYKy5ORtIcQfdarT4iNAGlLOfQrHf0NLgQPS4ttRI90t7J6PYJpAVJu IbqJtpbxMv40lXpPsjEsOMEaJVNE+95b/OfIcznb9tx60OnIQ2S9U2r5/rTCDWSv TT9GrjaIFsiStcenMqTaAxF7RkQHa/h2lTsmWIBTuVtVvnVuZyDC9ANDZwDfF7Ff AFD7iQzAXSLXX15JK2LWHcHeBorvahRTj3xs4S1/FPLVtA1Gw89Byuk0N9ULJDzv Da3nPv0czayiH8k/4KJNT61OaL+ngfTudwF1uk1OwSJHyrPWW7Wx+PJZdVT3Mwft DjMaIGh6+hhxnWFn3XQZXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1705949580; x= 1706035980; bh=FSX9OAEp1e6FSHD19ZNzPBM+D6vXzzdeWp76F2w23VY=; b=G BNwfxInkdzohQv4u7pW9AaP2/2kJT3ebdK0blX1xCz3/70KnpA90YTMfzKZqXb8G p1EfGCINO41jnuTeWmWJK5R/Szn9UH7tHZlV8hk20ztGnFtoMsPfOzUv56B2k6CA wQI8rYFAnqtJbsXbHTuEU3/YAeurKTGgYu89J4u4CB38CS6XHI0LJdx4C+wH4yzq aqHpkVfUlWEMTS5+RBCtAPGWKaker053tpBVWJJUGDYRYuWU3ZGyXujGxxZATBZj oq1jZFvmB/m+uuI3j5PN/yoWe4QwNHrqR/i1RB/c/Xa4Mr9cI/ZZd0FS0d+I1hJ3 xv+JNDrjAA/0nh3SMCMkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekiedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvvehfhfgjtgfgse htjeertddtvdejnecuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhies ghhuthhovhdruggvvheqnecuggftrfgrthhtvghrnhepffeifedvleeukedtgfelieegud fgveekfeejveejffetffeuueeugefhveeiuddvnecuffhomhgrihhnpehgnhhurdhorhhg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepughmih htrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Jan 2024 13:52:59 -0500 (EST) Content-Language: en-US In-Reply-To: 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:278712 Archived-At: On 22/01/2024 17:44, kobarity wrote: > Hi, > > Dmitry Gutov wrote: >> On 21/01/2024 16:47, kobarity wrote: >>> I am resending my mail, as I made a mistake in X-Debbugs-CC. >> Was it supposed to appear in the bug's thread? I don't see it anywhere. > > My first mail was registered as Bug#68445, and my patch is there. > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68445 > > It says: > > Report forwarded to casouri gmail.com, dmitry@.gutov.dev, bug-gnu-emacs gnu.org: > > The extra period is my mistake and it may have caused the problem. > I'm sorry for the confusion. Yeah, but even so that's odd: I'm subscribed to the bug tracker, so the email should have at least arrived in my inbox, but it did not. >> I think there is also another approach--handle two different types of >> nodes separately, instead of just string_content, so we don't have to >> start from the beginning of the literal. Like this: >> >> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el >> index e2f614f52c2..4f8b0cb9473 100644 >> --- a/lisp/progmodes/python.el >> +++ b/lisp/progmodes/python.el >> @@ -1361,13 +1361,15 @@ python--treesit-syntax-propertize >> (while (re-search-forward (rx (or "\"\"\"" "'''")) end t) >> (let ((node (treesit-node-at (point)))) >> ;; The triple quotes surround a non-empty string. >> - (when (equal (treesit-node-type node) "string_content") >> - (let ((start (treesit-node-start node)) >> - (end (treesit-node-end node))) >> - (put-text-property (1- start) start >> - 'syntax-table (string-to-syntax "|")) >> - (put-text-property end (min (1+ end) (point-max)) >> - 'syntax-table (string-to-syntax "|")))))))) >> + (cond >> + ((equal (treesit-node-type node) "string_content") >> + (put-text-property (1- (treesit-node-start node)) >> + (treesit-node-start node) >> + 'syntax-table (string-to-syntax "|"))) >> + ((and (equal (treesit-node-type node) "string_end") >> + (= (treesit-node-start node) (- (point) 3))) >> + (put-text-property (- (point) 3) (- (point) 2) >> + 'syntax-table (string-to-syntax "|")))))))) >> >> >> ;;; Indentation >> > > This approach seems better than my patch, but it does not seem to > address the following special case. > > #+begin_src python > """a""""""b""" > #+end_src All right, try the patch below, please. It also covers the case of the empty literal. I've tried to find a case where it would behave poorly (e.g. by misdetecting three quotes from a combination of some other string literals), but couldn't. E.g., s = '''asdasd' is not a concatenation. It's always an error, at least according to the TS grammar. diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e2f614f52c2..41f612c8b1c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1359,15 +1359,15 @@ python--treesit-syntax-propertize (save-excursion (goto-char start) (while (re-search-forward (rx (or "\"\"\"" "'''")) end t) - (let ((node (treesit-node-at (point)))) - ;; The triple quotes surround a non-empty string. - (when (equal (treesit-node-type node) "string_content") - (let ((start (treesit-node-start node)) - (end (treesit-node-end node))) - (put-text-property (1- start) start - 'syntax-table (string-to-syntax "|")) - (put-text-property end (min (1+ end) (point-max)) - 'syntax-table (string-to-syntax "|")))))))) + (let ((node (treesit-node-at (- (point) 3)))) + ;; Handle triple-quoted strings. + (pcase (treesit-node-type node) + ("string_start" + (put-text-property (1- (point)) (point) + 'syntax-table (string-to-syntax "|"))) + ("string_end" + (put-text-property (- (point) 3) (- (point) 2) + 'syntax-table (string-to-syntax "|")))))))) ;;; Indentation