aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorPo Lu2023-01-11 16:07:32 +0800
committerPo Lu2023-01-11 16:07:32 +0800
commit2fa5583d96fe78ff66d6fd41f18e54e4e20ea7d6 (patch)
treed3cf4a755e2da9b11c284763ed20041033b5dc3b /lisp/progmodes/python.el
parent494bedde3235f9034746c977260bbbc2c1e51d8c (diff)
parent033f2cc6140d03e78403f37689b9f54b64bded01 (diff)
downloademacs-2fa5583d96fe78ff66d6fd41f18e54e4e20ea7d6.tar.gz
emacs-2fa5583d96fe78ff66d6fd41f18e54e4e20ea7d6.zip
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el36
1 files changed, 28 insertions, 8 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 59164d7d50c..21d16db287c 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1067,11 +1067,28 @@ fontified."
1067 "expression_statement")) 1067 "expression_statement"))
1068 'font-lock-doc-face 1068 'font-lock-doc-face
1069 'font-lock-string-face))) 1069 'font-lock-string-face)))
1070 (when (eq (char-after string-beg) ?f) 1070 ;; Don't highlight string prefixes like f/r/b.
1071 (cl-incf string-beg)) 1071 (save-excursion
1072 (goto-char string-beg)
1073 (when (search-forward "\"" string-end t)
1074 (setq string-beg (match-beginning 0))))
1072 (treesit-fontify-with-override 1075 (treesit-fontify-with-override
1073 string-beg string-end face override start end))) 1076 string-beg string-end face override start end)))
1074 1077
1078(defun python--treesit-fontify-string-interpolation
1079 (node _ start end &rest _)
1080 "Fontify string interpolation.
1081NODE is the string node. Do not fontify the initial f for
1082f-strings. START and END mark the region to be
1083fontified."
1084 ;; This is kind of a hack, it basically removes the face applied by
1085 ;; the string feature, so that following features can apply their
1086 ;; face.
1087 (let ((n-start (treesit-node-start node))
1088 (n-end (treesit-node-end node)))
1089 (remove-text-properties
1090 (max start n-start) (min end n-end) '(face))))
1091
1075(defvar python--treesit-settings 1092(defvar python--treesit-settings
1076 (treesit-font-lock-rules 1093 (treesit-font-lock-rules
1077 :feature 'comment 1094 :feature 'comment
@@ -1082,10 +1099,12 @@ fontified."
1082 :language 'python 1099 :language 'python
1083 '((string) @python--treesit-fontify-string) 1100 '((string) @python--treesit-fontify-string)
1084 1101
1102 ;; HACK: This feature must come after the string feature and before
1103 ;; other features. Maybe we should make string-interpolation an
1104 ;; option rather than a feature.
1085 :feature 'string-interpolation 1105 :feature 'string-interpolation
1086 :language 'python 1106 :language 'python
1087 :override t 1107 '((interpolation) @python--treesit-fontify-string-interpolation)
1088 '((interpolation (identifier) @font-lock-variable-name-face))
1089 1108
1090 :feature 'definition 1109 :feature 'definition
1091 :language 'python 1110 :language 'python
@@ -3766,15 +3785,16 @@ the python shell:
3766 (line-beginning-position) 3785 (line-beginning-position)
3767 start)))) 3786 start))))
3768 (substring (buffer-substring-no-properties start end)) 3787 (substring (buffer-substring-no-properties start end))
3769 (starts-at-point-min-p (save-restriction 3788 (starts-at-first-line-p (save-restriction
3770 (widen) 3789 (widen)
3771 (= (point-min) start))) 3790 (goto-char start)
3791 (= (line-number-at-pos) 1)))
3772 (encoding (python-info-encoding)) 3792 (encoding (python-info-encoding))
3773 (toplevel-p (zerop (save-excursion 3793 (toplevel-p (zerop (save-excursion
3774 (goto-char start) 3794 (goto-char start)
3775 (python-util-forward-comment 1) 3795 (python-util-forward-comment 1)
3776 (current-indentation)))) 3796 (current-indentation))))
3777 (fillstr (cond (starts-at-point-min-p 3797 (fillstr (cond (starts-at-first-line-p
3778 nil) 3798 nil)
3779 ((not no-cookie) 3799 ((not no-cookie)
3780 (concat 3800 (concat