branch: externals/matlab-mode commit a06ed0f93745c940808fb07d242812f8a13ff3f8 Author: John Ciolfi <john.ciolfi...@gmail.com> Commit: John Ciolfi <john.ciolfi...@gmail.com>
matlab-ts-mode: improve font for keywords used in non-keyword context --- matlab-ts-mode.el | 50 ++++++++++++++-------- .../font_lock_events_non_keyword_expected.txt | 4 +- .../font_lock_keywords_as_others_expected.txt | 50 +++++++++++----------- .../font_lock_struct_function_issue71_expected.txt | 2 +- 4 files changed, 59 insertions(+), 47 deletions(-) diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el index 87b4ce43b9..ea0536d3f1 100644 --- a/matlab-ts-mode.el +++ b/matlab-ts-mode.el @@ -649,10 +649,14 @@ than the FILED-EXPRESSION-NODE start-point and end-point." (defun matlab-ts-mode--is-variable-overriding-builtin (variable-node) "Is VARIABLE-NODE overriding a builtin? -Example, disp variable is overriding the disp builtin functin: +Example, disp variable is overriding the disp builtin function: disp = 1:10;" (let ((variable (treesit-node-text variable-node))) - (gethash variable matlab-ts-mode--builtins-ht))) + (or (gethash variable matlab-ts-mode--builtins-ht) + ;; Initially arguments, etc. capabilities didn't exist in MATLAB. When they were added, + ;; compatibility was kept when these were used as variables. So, they are "semi-keywords". + (string-match-p (rx bos (or "arguments" "enumeration" "events" "methods" "properties") eos) + (treesit-node-text variable-node))))) (defvar matlab-ts-mode--font-lock-settings (treesit-font-lock-rules @@ -696,7 +700,7 @@ Example, disp variable is overriding the disp builtin functin: ;; We could use this for items like true, false, pi, etc. See some of these numbers in: ;; https://www.mathworks.com/content/dam/mathworks/fact-sheet/matlab-basic-functions-reference.pdf ;; however, they do show up as builtins, which to me seems more accurate. - ;; This rule needs to come before the "F-Rule: keyworks: if, else, end, etc." because + ;; This rule needs to come before the "F-Rule: keywords: if, else, end, etc." because ;; we want the end_keyword when used as a number index into a cell/matrix to be a number font. ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_numbers.m :language 'matlab @@ -704,14 +708,6 @@ Example, disp variable is overriding the disp builtin functin: '(((number) @matlab-ts-mode-number-face) ((end_keyword) @matlab-ts-mode-end-number-face)) - ;; F-Rule: keywords: if, else, end, etc. - ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords.m - ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_class_methods.m - ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_keyword_spmd.m - :language 'matlab - :feature 'keyword - `([,@matlab-ts-mode--keywords] @font-lock-keyword-face) - ;; F-Rule: variable ;; Could add font-lock-variable-name-face to variable uses. Consider ;; i1 = [1, 2]; @@ -760,7 +756,18 @@ Example, disp variable is overriding the disp builtin functin: (enum (identifier) @matlab-ts-mode-property-face) ;; Events block in classdef ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_class_events.m - (events (identifier) @matlab-ts-mode-property-face)) + (events (identifier) @matlab-ts-mode-property-face) + ;; Namespaces, structs, classdef methods/property access. Note any keyword is allowed, + ;; e.g. foo.methods.function = 1; + (field_expression (identifier) @default)) + + ;; F-Rule: keywords: if, else, end, etc. + ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords.m + ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_class_methods.m + ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_keyword_spmd.m + :language 'matlab + :feature 'keyword + `([,@matlab-ts-mode--keywords] @font-lock-keyword-face) ;; F-Rule: Types, e.g. int32() :language 'matlab @@ -774,7 +781,6 @@ Example, disp variable is overriding the disp builtin functin: @font-lock-type-face)) (property name: (identifier) (identifier) @font-lock-type-face :?) (property name: (property_name (identifier)) (identifier) @font-lock-type-face :?)) - ;; F-Rule: factory items that come with MATLAB, Simulink, or add-on products ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_builtins.m @@ -813,10 +819,6 @@ Example, disp variable is overriding the disp builtin functin: ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_class_MultiplePropBlocks.m ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_class_prop_access.m (property (validation_functions (identifier) @font-lock-function-call-face)) - (property (validation_functions (field_expression (identifier) @font-lock-function-call-face))) - (property (validation_functions ((field_expression - (function_call name: (identifier) - @font-lock-function-call-face))))) (property name: (identifier) @matlab-ts-mode-property-face) (property name: (property_name (identifier) @matlab-ts-mode-property-face)) ;; Attributes of properties, methods @@ -824,6 +826,16 @@ Example, disp variable is overriding the disp builtin functin: (attribute (identifier) @font-lock-type-face "=" (identifier) @font-lock-builtin-face) (attribute (identifier) @font-lock-type-face)) + ;; F-Rule: validation functions from namespace + ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_fcn_arguments2_issue57.m + :language 'matlab + :feature 'definition + :override t + '((property (validation_functions (field_expression (identifier) @font-lock-function-call-face))) + (property (validation_functions ((field_expression + (function_call name: (identifier) + @font-lock-function-call-face)))))) + ;; F-Rule: Function Name = Value arguments ;; See: tests/test-matlab-ts-mode-font-lock-files/font_lock_fcn_name_value_properties.m :language 'matlab @@ -1595,7 +1607,7 @@ Sets `matlab-ts-mode--i-next-line-pair' to (ANCHOR-NODE . OFFSET)" (if (or last-child-of-error-node ;; Continuation: arguments ;; firstArgument ... - ;; TAB> doube + ;; TAB> double (let ((prev-sibling (treesit-node-prev-sibling node))) (and prev-sibling (string= (treesit-node-type prev-sibling) "line_continuation")))) @@ -3511,4 +3523,4 @@ so configuration variables of that mode, do not affect this mode. ;; LocalWords: NPS BUF myfcn pcase xr repeat:nil docstring numberp imenu alist nondirectory mapc ;; LocalWords: funcall mfile elec foo'bar mapcar lsp noerror alnum featurep grep'ing mapconcat wie ;; LocalWords: Keymap keymap netshell gud ebstop mlgud ebclear ebstatus mlg mlgud's subjob reindent -;; LocalWords: DWIM dwim parens caar cdar utils fooenum mcode CRLF +;; LocalWords: DWIM dwim parens caar cdar utils fooenum mcode CRLF cmddual lang diff --git a/tests/test-matlab-ts-mode-font-lock-files/font_lock_events_non_keyword_expected.txt b/tests/test-matlab-ts-mode-font-lock-files/font_lock_events_non_keyword_expected.txt index 4d6b1ca8c5..478aa72451 100644 --- a/tests/test-matlab-ts-mode-font-lock-files/font_lock_events_non_keyword_expected.txt +++ b/tests/test-matlab-ts-mode-font-lock-files/font_lock_events_non_keyword_expected.txt @@ -2,6 +2,6 @@ c ccc ccccccccc ccc c cccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc -kkkkkk o n -dDkkkkkk o n +VVVVVV o n +dDdddddd o n dddddddDddddddDd diff --git a/tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords_as_others_expected.txt b/tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords_as_others_expected.txt index 1cc3b0c00d..8627c7a6a0 100644 --- a/tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords_as_others_expected.txt +++ b/tests/test-matlab-ts-mode-font-lock-files/font_lock_keywords_as_others_expected.txt @@ -2,7 +2,7 @@ c ccc ccccccccc ccc c ccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc -kkkkkkkkk o n +VVVVVVVVV o n c ccccc c c c cccc c c c ccccc c c @@ -11,13 +11,13 @@ c cccccccc c c c cccc c c c cccccc c c c ccc c c -kkkkkkkkkkk o n -kkkkkk o n +VVVVVVVVVVV o n +VVVVVV o n c ccc c c c cccccccc c c c cccccc c c c cc c c -kkkkkkk o n +VVVVVVV o n c ccccccccc c c c cccccc c c c cccccccccc c c @@ -37,30 +37,30 @@ c ccc c ccccc c c c cccccccccccccccccccccc -dDkkkkkkkkk o n +dDddddddddd o n dDddddd o n -dDkkkk o n -dDkkkkk o n -dDkkkkkkkk o n +dDdddd o n +dDddddd o n +dDdddddddd o n +dDdddddddd o n +dDdddd o n +dDdddddd o n +dDddd o n +dDddddddddddd o n +dDdddddd o n +dDddd o n dDdddddddd o n -dDkkkk o n -dDkkkkkk o n -dDkkk o n -dDkkkkkkkkkkk o n -dDkkkkkk o n -dDkkk o n -dDkkkkkkkk o n -dDkkkkkk o n -dDkk o n -dDkkkkkkk o n -dDkkkkkkkkk o n -dDkkkkkk o n -dDkkkkkkkkkk o n +dDdddddd o n +dDdd o n +dDddddddd o n +dDddddddddd o n +dDdddddd o n +dDdddddddddd o n dDdddddddddd o n dDdddddd o n -dDkkkk o n -dDkkkkkk o n -dDkkk o n -dDkkkkk o n +dDdddd o n +dDdddddd o n +dDddd o n +dDddddd o n diff --git a/tests/test-matlab-ts-mode-font-lock-files/font_lock_struct_function_issue71_expected.txt b/tests/test-matlab-ts-mode-font-lock-files/font_lock_struct_function_issue71_expected.txt index 02f439a0b2..acea5e0693 100644 --- a/tests/test-matlab-ts-mode-font-lock-files/font_lock_struct_function_issue71_expected.txt +++ b/tests/test-matlab-ts-mode-font-lock-files/font_lock_struct_function_issue71_expected.txt @@ -5,5 +5,5 @@ c cccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc v o nD vv o obdbdoonodD v o BBBBBBBBBbddb -dDkkkkkkkk +dDdddddddd