Subject: bug#66162: [PATCH] Various fixes to lua-ts-mode font-locking

From: john muhl <[email-masked]>
Date: Fri, 22 Sep 2023 18:43:43 -0500

Tags: patch

Here are some fixes around font-locking mostly to do with functions and
assignments; e.g.

  f1 = function() end

now correctly marks f1 as a function name.

>From df023cab8834477c63adf7fdc88afa1871c0fc96 Mon Sep 17 00:00:00 2001
From: john muhl <[email-masked]>
Date: Fri, 22 Sep 2023 18:36:18 -0500
Subject: [PATCH] Various fixes to lua-ts-mode font-locking

* lisp/progmodes/lua-ts-mode.el (lua-ts--font-lock-settings):
Identify functions and assignments in more places. Use constant
face for goto/labels.
---
 lisp/progmodes/lua-ts-mode.el | 56 +++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el
index 071953d3d2f..030a3585158 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -121,7 +121,9 @@ lua-ts--font-lock-settings
    :feature 'constant
    '((variable_list
       attribute: (attribute (["<" ">"] (identifier))))
-     @font-lock-constant-face)
+     @font-lock-constant-face
+     (goto_statement (identifier) @font-lock-constant-face)
+     (label_statement) @font-lock-constant-face)
 
    :language 'lua
    :feature 'operator
@@ -131,12 +133,6 @@ lua-ts--font-lock-settings
      @font-lock-operator-face
      (vararg_expression) @font-lock-operator-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 'builtin
    `(((identifier) @font-lock-builtin-face
@@ -150,8 +146,7 @@ lua-ts--font-lock-settings
       name: (method_index_expression
              method: (identifier) @font-lock-function-call-face))
      (function_call
-      name: (dot_index_expression
-             table: (identifier) @font-lock-function-call-face)))
+      name: (dot_index_expression (identifier) @font-lock-function-call-face)))
 
    :language 'lua
    :feature 'punctuation
@@ -164,12 +159,7 @@ lua-ts--font-lock-settings
       @font-lock-variable-use-face)
      (function_call
       name: (method_index_expression
-             table: (identifier) @font-lock-variable-use-face))
-     (goto_statement (identifier) @font-lock-variable-use-face))
-
-   :language 'lua
-   :feature 'assignment
-   '((variable_list (identifier) @font-lock-variable-name-face))
+             table: (identifier) @font-lock-variable-use-face)))
 
    :language 'lua
    :feature 'number
@@ -199,9 +189,43 @@ lua-ts--font-lock-settings
    :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))
+     (function_declaration
+      name: (method_index_expression (identifier) @font-lock-function-name-face))
+     (function_declaration
+      (method_index_expression
+       (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)
-     (label_statement) @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
-- 
2.41.0