[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 901f0eab20 3/5: Add an error fontification heuristic to c-ts-mode
From: |
Yuan Fu |
Subject: |
master 901f0eab20 3/5: Add an error fontification heuristic to c-ts-mode |
Date: |
Wed, 23 Nov 2022 22:50:56 -0500 (EST) |
branch: master
commit 901f0eab20de5c2b5dd81a92309b08af06623623
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Add an error fontification heuristic to c-ts-mode
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Use new
function.
(c-ts-fontify-error): New function.
---
lisp/progmodes/c-ts-mode.el | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 3555eb23d1..fc35d9aedd 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -314,7 +314,7 @@ MODE is either `c' or `cpp'."
:language mode
:feature 'error
- '((ERROR) @font-lock-warning-face)
+ '((ERROR) @c-ts-fontify-error)
:feature 'escape-sequence
:language mode
@@ -421,6 +421,26 @@ This function corrects the fontification on the colon in
(min end (treesit-node-end arg))
'default override))))))
+(defun c-ts-fontify-error (node override start end &rest _)
+ "Fontify the error nodes.
+For NODE, OVERRIDE, START, and END, see
+`treesit-font-lock-rules'."
+ (let ((parent (treesit-node-parent node))
+ (child (treesit-node-child node 0)))
+ (treesit-fontify-with-override
+ (max start (treesit-node-start node))
+ (min end (treesit-node-end node))
+ (cond
+ ;; This matches the case MACRO(struct a, b, c)
+ ;; where struct is seen as error.
+ ((and (equal (treesit-node-type child) "identifier")
+ (equal (treesit-node-type parent) "argument_list")
+ (member (treesit-node-text child)
+ '("struct" "long" "short" "enum" "union")))
+ 'font-lock-keyword-face)
+ (t 'font-lock-warning-face))
+ override)))
+
(defun c-ts-mode--imenu-1 (node)
"Helper for `c-ts-mode--imenu'.
Find string representation for NODE and set marker, then recurse