[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 2f03053e56: Utilize new font-lock faces for C/C++ an
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 2f03053e56: Utilize new font-lock faces for C/C++ and Python tree-sitter use |
Date: |
Thu, 17 Nov 2022 15:08:12 -0500 (EST) |
branch: feature/tree-sitter
commit 2f03053e568f38a1dce5ffe02ad1359069ef84c8
Author: Randy Taylor <dev@rjt.dev>
Commit: Yuan Fu <casouri@gmail.com>
Utilize new font-lock faces for C/C++ and Python tree-sitter use
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Use new
escape, number, property, operator, bracket, and delimiter font-lock
faces.
(c-ts-mode--base-mode): Add them to the feature list.
(c-ts-mode): Fix typo.
* lisp/progmodes/python.el (python--treesit-settings): Use new number,
property, operator, bracket, and delimiter font-lock faces.
(python-mode): Add them to the feature list.
---
lisp/progmodes/c-ts-mode.el | 48 +++++++++++++++++++++++++++++----------------
lisp/progmodes/python.el | 41 ++++++++++++++++++++++++++++++++------
2 files changed, 66 insertions(+), 23 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b951031d81..f8e809bb43 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -230,19 +230,17 @@ MODE is either `c' or `cpp'."
:language mode
:feature 'operator
- :override t
`([,@c-ts-mode--operators] @font-lock-operator-face
"!" @font-lock-negation-char-face)
:language mode
:feature 'string
`((string_literal) @font-lock-string-face
- (system_lib_string) @font-lock-string-face
- (escape_sequence) @font-lock-escape-face)
+ (system_lib_string) @font-lock-string-face)
:language mode
:feature 'literal
- `((number_literal) @font-lock-constant-face
+ `((number_literal) @font-lock-number-face
(char_literal) @font-lock-constant-face)
:language mode
@@ -268,14 +266,11 @@ MODE is either `c' or `cpp'."
declarator: (_) @c-ts-mode--fontify-struct-declarator)
(function_definition
- declarator: (_) @c-ts-mode--fontify-struct-declarator)
+ declarator: (_) @c-ts-mode--fontify-struct-declarator))
- ;; Should we highlight identifiers in the parameter list?
- ;; (parameter_declaration
- ;; declarator: (_) @c-ts-mode--fontify-struct-declarator)
-
- (enumerator
- name: (identifier) @font-lock-variable-name-face))
+ ;; Should we highlight identifiers in the parameter list?
+ ;; (parameter_declaration
+ ;; declarator: (_) @c-ts-mode--fontify-struct-declarator))
:language mode
:feature 'assignment
@@ -298,8 +293,7 @@ MODE is either `c' or `cpp'."
'((call_expression
function: (identifier) @font-lock-function-name-face)
(field_expression
- argument: (identifier) @font-lock-variable-name-face
- field: (field_identifier) @font-lock-property-face)
+ argument: (identifier) @font-lock-variable-name-face)
(pointer_expression
(identifier) @font-lock-variable-name-face))
@@ -313,6 +307,25 @@ MODE is either `c' or `cpp'."
:feature 'error
'((ERROR) @font-lock-warning-face)
+ :feature 'escape-sequence
+ :language mode
+ :override t
+ '((escape_sequence) @font-lock-escape-face)
+
+ :language mode
+ :feature 'property
+ '((field_identifier) @font-lock-property-face
+ (enumerator
+ name: (identifier) @font-lock-property-face))
+
+ :language mode
+ :feature 'bracket
+ '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+
+ :language mode
+ :feature 'delimiter
+ '((["," ":" ";"]) @font-lock-delimiter-face)
+
:language mode
:feature 'emacs-devel
'(((call_expression function: (identifier) @fn)
@@ -471,9 +484,10 @@ the subtrees."
(setq-local which-func-functions nil)
(setq-local treesit-font-lock-feature-list
- '((comment preprocessor constant string literal keyword)
- (type definition label assignment)
- (expression error operator))))
+ '(( comment constant keyword literal preprocessor string)
+ ( assignment definition label property type)
+ ( bracket delimiter error escape-sequence expression
+ operator))))
;;;###autoload
(define-derived-mode c-ts-mode c-ts-mode--base-mode "C"
@@ -500,7 +514,7 @@ the subtrees."
;;;###autoload
(define-derived-mode c++-ts-mode c-ts-mode--base-mode "C++"
- "Major mode for editing C, powered by tree-sitter."
+ "Major mode for editing C++, powered by tree-sitter."
:group 'c++
(unless (treesit-ready-p nil 'cpp)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index ad4665eb19..22485a025e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -975,11 +975,8 @@ It makes underscores and dots word constituent chars.")
"copyright" "credits" "exit" "license" "quit"))
(defvar python--treesit-operators
- ;; This is not used. And and, or, not, is, in are fontified as
- ;; keywords.
'("-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "%" "%="
- "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~"
- "and" "in" "is" "not" "or"))
+ "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~"))
(defvar python--treesit-special-attributes
'("__annotations__" "__closure__" "__code__"
@@ -1117,7 +1114,38 @@ be fontified."
:feature 'escape-sequence
:language 'python
:override t
- '((escape_sequence) @font-lock-escape-face))
+ '((escape_sequence) @font-lock-escape-face)
+
+ :feature 'number
+ :language 'python
+ :override t
+ '([(integer) (float)] @font-lock-number-face)
+
+ :feature 'property
+ :language 'python
+ :override t
+ '((attribute
+ attribute: (identifier) @font-lock-property-face)
+ (class_definition
+ body: (block
+ (expression_statement
+ (assignment left:
+ (identifier) @font-lock-property-face)))))
+
+ :feature 'operator
+ :language 'python
+ :override t
+ `([,@python--treesit-operators] @font-lock-operator-face)
+
+ :feature 'bracket
+ :language 'python
+ :override t
+ '(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)
+
+ :feature 'delimiter
+ :language 'python
+ :override t
+ '(["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face))
"Tree-sitter font-lock settings.")
@@ -6553,7 +6581,8 @@ Add import for undefined name `%s' (empty to skip): "
'(( comment string function-name class-name)
( keyword builtin constant type)
( assignment decorator escape-sequence
- string-interpolation)))
+ string-interpolation number property
+ operator bracket delimiter)))
(setq-local treesit-font-lock-settings python--treesit-settings)
(setq-local imenu-create-index-function
#'python-imenu-treesit-create-index)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/tree-sitter 2f03053e56: Utilize new font-lock faces for C/C++ and Python tree-sitter use,
Yuan Fu <=