GNU bug report logs -
#67554
[PATCH] Improve font-lock in lua-ts-mode
Previous Next
Reported by: john muhl <jm <at> pub.pink>
Date: Fri, 1 Dec 2023 00:07:01 UTC
Severity: normal
Tags: patch
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 67554 in the body.
You can then email your comments to 67554 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67554
; Package
emacs
.
(Fri, 01 Dec 2023 00:07:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
john muhl <jm <at> pub.pink>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Fri, 01 Dec 2023 00:07:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Tags: patch
While testing out ert-font-lock I found some inconsistencies and
missing highlights. This also moves properties to level 4
font-lock and adds font-lock-comment-delimiter-face.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67554
; Package
emacs
.
(Fri, 01 Dec 2023 00:37:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 67554 <at> debbugs.gnu.org (full text, mbox):
[0001-Improve-font-locking-in-lua-ts-mode-bug-67554.patch (text/x-patch, attachment)]
From 5a87b7b231a384c7035e75105bc173fc05f38336 Mon Sep 17 00:00:00 2001
From: john muhl <jm <at> pub.pink>
Date: Tue, 14 Nov 2023 16:25:43 -0600
Subject: [PATCH] Improve font-locking in lua-ts-mode (bug#67554)
* lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Move property
highlighting to level 4.
(lua-ts--keywords): Remove `true', `false' and `nil' from
keywords.
(lua-ts--font-lock-settings): Highlight assignments, functions
and labels in more places. Distinguish comment delimiters.
(lua-ts--comment-font-lock): New function.
---
lisp/progmodes/lua-ts-mode.el | 151 ++++++++++++++++++----------------
1 file changed, 79 insertions(+), 72 deletions(-)
diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el
index a910d759c83..7dd05b2757f 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -133,135 +133,141 @@ lua-ts--builtins
"Lua built-in functions for tree-sitter font-locking.")
(defvar lua-ts--keywords
- '("and" "do" "else" "elseif" "end" "for" "function"
- "goto" "if" "in" "local" "not" "or" "repeat"
- "return" "then" "until" "while")
+ '("and" "do" "else" "elseif" "end" "for" "function" "goto" "if"
+ "in" "local" "not" "or" "repeat" "return" "then" "until" "while")
"Lua keywords for tree-sitter font-locking and navigation.")
+(defun lua-ts--comment-font-lock (node override start end &rest _)
+ "Apply font lock to comment NODE within START and END.
+Applies `font-lock-comment-delimiter-face' and
+`font-lock-comment-face' See `treesit-fontify-with-override' for
+values of OVERRIDE."
+ (let* ((node-start (treesit-node-start node))
+ (node-end (treesit-node-end node))
+ (node-text (treesit-node-text node t))
+ (delimiter-end (+ 2 node-start)))
+ (when (and (>= node-start start)
+ (<= delimiter-end end)
+ (string-match "\\`--" node-text))
+ (treesit-fontify-with-override node-start
+ delimiter-end
+ font-lock-comment-delimiter-face
+ override))
+ (treesit-fontify-with-override (max delimiter-end start)
+ (min node-end end)
+ font-lock-comment-face
+ override)))
+
(defvar lua-ts--font-lock-settings
(treesit-font-lock-rules
- :language 'lua
+ :default-language 'lua
:feature 'bracket
'(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)
- :language 'lua
:feature 'delimiter
'(["," ";"] @font-lock-delimiter-face)
- :language 'lua
:feature 'constant
- '((variable_list
- attribute: (attribute (["<" ">"] (identifier))))
- @font-lock-constant-face
- (goto_statement (identifier) @font-lock-constant-face)
- (label_statement) @font-lock-constant-face)
+ '([(variable_list
+ attribute: (attribute (["<" ">"] (identifier))))
+ (label_statement)
+ (true) (false) (nil)]
+ @font-lock-constant-face)
- :language 'lua
:feature 'operator
- '(["and" "not" "or" "+" "-" "*" "/" "%" "^"
- "#" "==" "~=" "<=" ">=" "<" ">" "=" "&"
- "~" "|" "<<" ">>" "//" ".."]
- @font-lock-operator-face
- (vararg_expression) @font-lock-operator-face)
+ '(["+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">="
+ "<" ">" "=" "&" "~" "|" "<<" ">>" "//" ".."
+ (vararg_expression)]
+ @font-lock-operator-face)
- :language 'lua
:feature 'builtin
`(((identifier) @font-lock-builtin-face
(:match ,(regexp-opt lua-ts--builtins 'symbols)
@font-lock-builtin-face)))
- :language 'lua
:feature 'function
'((function_call name: (identifier) @font-lock-function-call-face)
(function_call
- name: (method_index_expression
- method: (identifier) @font-lock-function-call-face))
+ (method_index_expression
+ method: (identifier) @font-lock-function-call-face))
(function_call
- name: (dot_index_expression (identifier) @font-lock-function-call-face)))
+ (dot_index_expression
+ field: (identifier) @font-lock-function-call-face)))
- :language 'lua
:feature 'punctuation
'(["." ":"] @font-lock-punctuation-face)
- :language 'lua
:feature 'variable
'((function_call
- arguments: (arguments (identifier))
- @font-lock-variable-use-face)
+ (arguments (identifier) @font-lock-variable-use-face))
(function_call
- name: (method_index_expression
- table: (identifier) @font-lock-variable-use-face)))
+ (arguments
+ (binary_expression (identifier) @font-lock-variable-use-face)))
+ (function_call
+ (arguments
+ (bracket_index_expression (identifier) @font-lock-variable-use-face)))
+ (function_declaration
+ (parameters name: (identifier) @font-lock-variable-name-face)))
- :language 'lua
:feature 'number
'((number) @font-lock-number-face)
- :language 'lua
:feature 'keyword
- `((break_statement) @font-lock-keyword-face
- (true) @font-lock-constant-face
- (false) @font-lock-constant-face
- (nil) @font-lock-constant-face
- ,(vconcat lua-ts--keywords)
- @font-lock-keyword-face)
-
- :language 'lua
+ `([(break_statement)
+ ,(vconcat lua-ts--keywords)]
+ @font-lock-keyword-face
+ (goto_statement ((identifier) @font-lock-constant-face)))
+
:feature 'string
'((string) @font-lock-string-face)
- :language 'lua
:feature 'escape
:override t
'((escape_sequence) @font-lock-escape-face)
- :language 'lua
:feature 'comment
- '((comment) @font-lock-comment-face
+ '((comment) @lua-ts--comment-font-lock
(hash_bang_line) @font-lock-comment-face)
- :language 'lua
:feature 'definition
'((function_declaration
- name: (identifier) @font-lock-function-name-face)
- (assignment_statement
- (variable_list name: [(identifier)]) @font-lock-function-name-face
- (expression_list value: (function_definition)))
- (table_constructor
- (field
- name: (identifier) @font-lock-function-name-face
- value: (function_definition)))
- (function_declaration
- name: (dot_index_expression (identifier) @font-lock-function-name-face))
+ (identifier) @font-lock-function-name-face)
(function_declaration
- name: (method_index_expression (identifier) @font-lock-function-name-face))
+ (dot_index_expression
+ field: (identifier) @font-lock-function-name-face))
(function_declaration
(method_index_expression
+ method: (identifier) @font-lock-function-name-face))
+ (assignment_statement
+ (variable_list
+ (identifier) @font-lock-function-name-face)
+ (expression_list value: (function_definition)))
+ (field
+ name: (identifier) @font-lock-function-name-face
+ value: (function_definition))
+ (assignment_statement
+ (variable_list
(dot_index_expression
- table: (identifier) @font-lock-function-name-face
- field: (identifier) @font-lock-property-name-face
- )))
- (parameters
- name: (identifier) @font-lock-variable-name-face)
+ field: (identifier) @font-lock-function-name-face))
+ (expression_list
+ value:
+ (function_definition))))
+
+ :feature 'assignment
+ '((variable_list (identifier) @font-lock-variable-name-face)
+ (variable_list
+ (bracket_index_expression
+ field: (identifier) @font-lock-variable-name-face))
+ (variable_list
+ (dot_index_expression
+ field: (identifier) @font-lock-variable-name-face))
(for_numeric_clause name: (identifier) @font-lock-variable-name-face))
- :language 'lua
:feature 'property
'((field name: (identifier) @font-lock-property-name-face)
(dot_index_expression
field: (identifier) @font-lock-property-use-face))
- :language 'lua
- :feature 'assignment
- '((variable_list
- [(identifier)
- (bracket_index_expression)]
- @font-lock-variable-name-face)
- (variable_list
- (dot_index_expression
- table: (identifier))
- @font-lock-variable-name-face))
-
- :language 'lua
:feature 'error
:override t
'((ERROR) @font-lock-warning-face))
@@ -665,13 +671,14 @@ lua-ts-mode
(setq-local treesit-font-lock-settings lua-ts--font-lock-settings)
(setq-local treesit-font-lock-feature-list
'((comment definition)
- (keyword property string)
+ (keyword string)
(assignment builtin constant number)
(bracket
delimiter
escape
function
operator
+ property
punctuation
variable)))
--
2.41.0
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 02 Dec 2023 13:52:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
john muhl <jm <at> pub.pink>
:
bug acknowledged by developer.
(Sat, 02 Dec 2023 13:52:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 67554-done <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 30 Nov 2023 18:34:59 -0600
> From: john muhl via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
>
> >From 5a87b7b231a384c7035e75105bc173fc05f38336 Mon Sep 17 00:00:00 2001
> From: john muhl <jm <at> pub.pink>
> Date: Tue, 14 Nov 2023 16:25:43 -0600
> Subject: [PATCH] Improve font-locking in lua-ts-mode (bug#67554)
>
> * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Move property
> highlighting to level 4.
> (lua-ts--keywords): Remove `true', `false' and `nil' from
> keywords.
> (lua-ts--font-lock-settings): Highlight assignments, functions
> and labels in more places. Distinguish comment delimiters.
> (lua-ts--comment-font-lock): New function.
Thanks, pushed to the master branch (with a couple of minor
adjustments), and closing the bug.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67554
; Package
emacs
.
(Sat, 02 Dec 2023 14:14:01 GMT)
Full text and
rfc822 format available.
Message #16 received at 67554 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> Date: Thu, 30 Nov 2023 18:34:59 -0600
>> From: john muhl via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>>
>> >From 5a87b7b231a384c7035e75105bc173fc05f38336 Mon Sep 17 00:00:00 2001
>> From: john muhl <jm <at> pub.pink>
>> Date: Tue, 14 Nov 2023 16:25:43 -0600
>> Subject: [PATCH] Improve font-locking in lua-ts-mode (bug#67554)
>>
>> * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Move property
>> highlighting to level 4.
>> (lua-ts--keywords): Remove `true', `false' and `nil' from
>> keywords.
>> (lua-ts--font-lock-settings): Highlight assignments, functions
>> and labels in more places. Distinguish comment delimiters.
>> (lua-ts--comment-font-lock): New function.
>
> Thanks, pushed to the master branch (with a couple of minor
> adjustments), and closing the bug.
Thanks for the help. The missing period in the doc string was
inherited from ruby-ts-mode if you wanted to fix the same thing
there (line 200). Or I could send a patch if that is somehow
less work for you.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#67554
; Package
emacs
.
(Sat, 02 Dec 2023 14:52:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 67554 <at> debbugs.gnu.org (full text, mbox):
> From: john muhl <jm <at> pub.pink>
> Cc: 67554 <at> debbugs.gnu.org
> Date: Sat, 02 Dec 2023 08:08:16 -0600
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> > Thanks, pushed to the master branch (with a couple of minor
> > adjustments), and closing the bug.
>
> Thanks for the help. The missing period in the doc string was
> inherited from ruby-ts-mode if you wanted to fix the same thing
> there (line 200). Or I could send a patch if that is somehow
> less work for you.
Fixed, thanks.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 31 Dec 2023 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 132 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.