[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master cb60342c01 3/7: Tweak c-ts-mode fontification
From: |
Yuan Fu |
Subject: |
master cb60342c01 3/7: Tweak c-ts-mode fontification |
Date: |
Tue, 22 Nov 2022 04:07:11 -0500 (EST) |
branch: master
commit cb60342c0184fa8ef9462c9926e93dceff959f49
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Tweak c-ts-mode fontification
New features: function and variable, which consistently fontify all
occurrences of functions and variables, respectively.
Remove expression feature, as its purpose is fulfilled by function,
variable, and property combined.
Fix declaration feature, remove unnecessary rule from label
feature.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): See
above description.
(c-ts-mode--fontify-variable): New function.
(c-ts-mode--base-mode): Add & remove features.
---
lisp/progmodes/c-ts-mode.el | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 6eaf200182..3555eb23d1 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -269,7 +269,7 @@ MODE is either `c' or `cpp'."
:feature 'definition
;; Highlights identifiers in declarations.
`((declaration
- declarator: (_) @font-lock-variable-name-face)
+ declarator: (_) @c-ts-mode--fontify-declarator)
(field_declaration
declarator: (_) @c-ts-mode--fontify-declarator)
@@ -295,21 +295,21 @@ MODE is either `c' or `cpp'."
(identifier) @font-lock-variable-name-face))
(assignment_expression
left: (subscript_expression
- (identifier) @font-lock-variable-name-face)))
+ (identifier) @font-lock-variable-name-face))
+ (init_declarator declarator: (_) @c-ts-mode--fontify-declarator))
:language mode
- :feature 'expression
+ :feature 'function
'((call_expression
- function: (identifier) @font-lock-function-name-face)
- (field_expression
- argument: (identifier) @font-lock-variable-name-face)
- (pointer_expression
- (identifier) @font-lock-variable-name-face))
+ function: (identifier) @font-lock-function-name-face))
+
+ :language mode
+ :feature 'variable
+ '((identifier) @c-ts-mode--fontify-variable)
:language mode
:feature 'label
- '((expression_statement (identifier) @font-lock-variable-name-face)
- (labeled_statement
+ '((labeled_statement
label: (statement_identifier) @font-lock-constant-face))
:language mode
@@ -367,6 +367,19 @@ For NODE, OVERRIDE, START, END, and ARGS, see
(_ 'font-lock-variable-name-face))
override))))
+(defun c-ts-mode--fontify-variable (node override start end &rest _)
+ "Fontify an identifier node.
+Fontify it if NODE is not a function identifier. For NODE,
+OVERRIDE, START, END, and ARGS, see `treesit-font-lock-rules'."
+ (when (not (equal (treesit-node-type
+ (treesit-node-parent node))
+ "call_expression"))
+ (treesit-fontify-with-override
+ (max (treesit-node-start node) start)
+ (min (treesit-node-end node) end)
+ 'font-lock-variable-name-face
+ override)))
+
(defun c-ts-mode--fontify-defun (node override start end &rest _)
"Correctly fontify the DEFUN macro.
For NODE, OVERRIDE, START, and END, see
@@ -497,8 +510,8 @@ the subtrees."
(setq-local treesit-font-lock-feature-list
'(( comment constant keyword literal preprocessor string)
( assignment definition label property type)
- ( bracket delimiter error escape-sequence expression
- operator))))
+ ( delimiter error escape-sequence function
+ operator variable bracket))))
;;;###autoload
(define-derived-mode c-ts-mode c-ts-mode--base-mode "C"
- master updated (b32f50c6d8 -> 1161c96cc9), Yuan Fu, 2022/11/22
- master 74892eefc8 1/7: * lisp/treesit.el (treesit-max-buffer-size): Enlarge value., Yuan Fu, 2022/11/22
- master d6d4adf3bd 5/7: Tweak faces in Java and TypeScript, Yuan Fu, 2022/11/22
- master c7202e7f4a 2/7: ; Fix docstrings in treesit.el, Yuan Fu, 2022/11/22
- master cb60342c01 3/7: Tweak c-ts-mode fontification,
Yuan Fu <=
- master 6e07838051 4/7: treesit-font-lock-recompute-features now has two modes of operation, Yuan Fu, 2022/11/22
- master e494ca4f4d 6/7: Fix treesit_record_change in casify_region, Yuan Fu, 2022/11/22
- master 1161c96cc9 7/7: Separate tree-sitter and non-tree-sitter variant of sh-mode, Yuan Fu, 2022/11/22