emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 737d46e04d7 2/2: python--treesit-syntax-propertize: Fix edits in


From: Dmitry Gutov
Subject: master 737d46e04d7 2/2: python--treesit-syntax-propertize: Fix edits in the middle
Date: Thu, 25 Jan 2024 20:00:38 -0500 (EST)

branch: master
commit 737d46e04d73dbad84bf0225cebb1c936ff89365
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    python--treesit-syntax-propertize: Fix edits in the middle
    
    * lisp/progmodes/python.el (python--treesit-syntax-propertize):
    Process the beginning and the end of the triple-quoted string's
    delimiters separately.  Among other things, that still works when
    the beginning is outside of the propertized region (bug#68445).
---
 lisp/progmodes/python.el | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

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 @@ For NODE, OVERRIDE, START, END, and ARGS, see
   (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]