aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorStefan Kangas2023-01-10 09:51:57 +0100
committerStefan Kangas2023-01-10 09:51:57 +0100
commit60240f54e5fed16a0522fb766ffef073db596f1f (patch)
treea8677abd38758e66c56900632756a39a0ebccb7b /lisp/progmodes/python.el
parent4d1d43e41fafaa5beecba57686f5d5f4146746c8 (diff)
parent55aabfea4accd04aed9424b5cdbe304d12be6224 (diff)
downloademacs-60240f54e5fed16a0522fb766ffef073db596f1f.tar.gz
emacs-60240f54e5fed16a0522fb766ffef073db596f1f.zip
Merge from origin/emacs-29
55aabfea4ac Fix c-ts-mode comment indent 8377ed5298f Highlight identifier in import statements in js-ts-mode aa9df1260c3 Don't print named tree-sitter nodes with parenthesizes (b... e385c099b8c Improve fontification for import-statements in typescript... 28dd6021384 Fix c-ts-mode indentation for 2nd line in block comment (... 8a36a0f44aa ; xref.el: Bump version f16cc7c49c7 ; project.el: Bump version ebc5263667b ; * src/callint.c (Finteractive): Doc string clarification. c1401d1c6c8 * lisp/vc/diff-mode.el (diff-font-lock-keywords): Check f... 1f8ad353d9f Minor improvement for tree-sitter explorer ef87c755660 Make sure NODE is not the root node in tree-sitter indent... 1238fa8e49b Fix label indent of GNU and Linux style in c-ts-mode (bug... dc911e4ba5c Improve go-ts-mode Imenu, navigation and electric pair (b... 20f36c8f6f9 ; ruby.rb: Fix pattern matching syntax and extend the exa... d46f7f4edcc Revert "Add c-or-c++-ts-mode (bug#59613)" 1469aac20d8 ; * src/pgtkfns.c (parse_resource_key): Use recursive sch... da96a1fd741 Add back renamed function 'font-lock-fontify-syntacticall... b1aa720671e ; * lisp/progmodes/ruby-ts-mode.el: Fix compilation warni... 5cb01ac5d78 ; * src/callint.c (Finteractive): Fix the doc string (bug... 53e64cfb852 Improve options and docs of M-x command completion fef4f18cc33 ; Fix NEWS e04b3d41bb4 Update to Org 9.6-90-ga6523f e3d806b4172 Fix string fontification on python-ts-mode (bug#60599) 800e15e3be0 Fix string-interpolation feature of python-ts-mode (bug#6... 38b63f4c3ce Add indentation rule for concatenated_string (bug#60572) 2cdd75a18ff Fix highlighting of variable-declarations in typescript-t... 73168793c01 Fix label indentation for Linux style in c-ts-mode (bug#6... 8575043f56b Remove duplicate entries in c-ts-mode's Imenu ef7f3c6388b Fix use of treesit-ready-p in c/c++-ts-mode cc1de953d4f ; * lisp/progmodes/gud.el (gud-tooltip-modes): Add ts- mo... 16f1e47ca8b ; * lisp/align.el (align-c++-modes): Add c/c++-ts-mode. 508389ad2bb Add documentation for c/c++-ts-mode (bug#60443) ee3e8d3f927 (ruby-ts--font-lock-settings): Improve highlighting in pa... 614f8c431d3 Optionally include the namespace in c-ts-mode--declarator... 7c356934fbb Support namespaces in c++-ts-mode (bug#60397) 757c2c25922 Fix c-ts-mode--looking-at-star 1df2826639c Add c-or-c++-ts-mode (bug#59613) 0cb686ffb6b Document the 'definition-name' property. 7f855b5297b ; Fix description of etc/DOC e9341119fe4 ; Fix documentation of etc/DOC 86a3462e3d2 (treesit-simple-indent-presets): Do that for 'or' as well. e0fef510b00 ; Minor rewording of tree-sitter terminology f58452e3ae7 Fix 'python-shell-buffer-substring' when START is in midd... 7f9588685a0 ; Fix last change e8b85f225d9 Rearrange the "Saving Emacs Sessions" section of the user... # Conflicts: # etc/NEWS # lisp/progmodes/c-ts-mode.el
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