aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorYuan Fu2022-11-02 17:03:03 -0700
committerYuan Fu2022-11-02 17:03:03 -0700
commit69ab588bb54178df0d3be6b4c04dabb49f5a2ac9 (patch)
treea308a378f3efb1f742fec67cd807bc394689bd0b /lisp/progmodes/python.el
parentf331be1f074d68e7e5cdbac324419e07c186492a (diff)
downloademacs-69ab588bb54178df0d3be6b4c04dabb49f5a2ac9.tar.gz
emacs-69ab588bb54178df0d3be6b4c04dabb49f5a2ac9.zip
Pass region start and end to tree-sitter fontification functions
* doc/lispref/modes.texi (Parser-based Font Lock): Update manual. * lisp/progmodes/js.el (js--fontify-template-string) * lisp/progmodes/python.el (python--treesit-fontify-string): Update function to only fontify within the region. * lisp/treesit.el (treesit-font-lock-rules): Update docstring. (treesit-font-lock-fontify-region): Pass START and END to fontification functions.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el12
1 files changed, 7 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 603cdb14e15..8db96b117f3 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1015,11 +1015,12 @@ It makes underscores and dots word constituent chars.")
1015 "VMSError" "WindowsError" 1015 "VMSError" "WindowsError"
1016 )) 1016 ))
1017 1017
1018(defun python--treesit-fontify-string (node override &rest _) 1018(defun python--treesit-fontify-string (node override start end &rest _)
1019 "Fontify string. 1019 "Fontify string.
1020NODE is the leading quote in the string. Do not fontify the initial 1020NODE is the leading quote in the string. Do not fontify the
1021f for f-strings. OVERRIDE is the override flag described in 1021initial f for f-strings. OVERRIDE is the override flag described
1022`treesit-font-lock-rules'." 1022in `treesit-font-lock-rules'. START and END marks the region to
1023be fontified."
1023 (let* ((string (treesit-node-parent node)) 1024 (let* ((string (treesit-node-parent node))
1024 (string-beg (treesit-node-start string)) 1025 (string-beg (treesit-node-start string))
1025 (string-end (treesit-node-end string)) 1026 (string-end (treesit-node-end string))
@@ -1033,7 +1034,8 @@ f for f-strings. OVERRIDE is the override flag described in
1033 'font-lock-string-face))) 1034 'font-lock-string-face)))
1034 (when (eq (char-after string-beg) ?f) 1035 (when (eq (char-after string-beg) ?f)
1035 (cl-incf string-beg)) 1036 (cl-incf string-beg))
1036 (treesit-fontify-with-override string-beg string-end face override))) 1037 (treesit-fontify-with-override
1038 (max start string-beg) (min end string-end) face override)))
1037 1039
1038(defvar python--treesit-settings 1040(defvar python--treesit-settings
1039 (treesit-font-lock-rules 1041 (treesit-font-lock-rules