[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 2701da0eee5: Fix python-ts-mode triple quote syntax (bug#67262)
From: |
Yuan Fu |
Subject: |
emacs-29 2701da0eee5: Fix python-ts-mode triple quote syntax (bug#67262) |
Date: |
Sat, 23 Dec 2023 22:09:38 -0500 (EST) |
branch: emacs-29
commit 2701da0eee54d85f79104c7a91610bf591159a51
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix python-ts-mode triple quote syntax (bug#67262)
* lisp/progmodes/python.el (python--treesit-syntax-propertize): New
function.
(python-ts-mode): Activate python--treesit-syntax-propertize.
---
lisp/progmodes/python.el | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 7c5c20608bd..d7250148fad 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1228,6 +1228,21 @@ For NODE, OVERRIDE, START, END, and ARGS, see
(treesit-node-start node) (treesit-node-end node)
'font-lock-variable-use-face override start end)))
+(defun python--treesit-syntax-propertize (start end)
+ "Propertize triple-quote strings between START and END."
+ (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 "|"))))))))
+
;;; Indentation
@@ -6729,6 +6744,8 @@ implementations: `python-mode' and `python-ts-mode'."
#'python--treesit-defun-name)
(treesit-major-mode-setup)
+ (setq-local syntax-propertize-function #'python--treesit-syntax-propertize)
+
(python-skeleton-add-menu-items)
(when python-indent-guess-indent-offset
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-29 2701da0eee5: Fix python-ts-mode triple quote syntax (bug#67262),
Yuan Fu <=