branch: externals/matlab-mode
commit ed8009e156572d4f3555a3731e1079aa13f13e6f
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: fix validation_function indent
---
 matlab-ts-mode.el                                  | 25 ++++++++++--
 ...ic_indent_arguments_constraints_expected_msgs.m |  2 +-
 .../indent_cont_properties_expected_msgs.m         |  4 +-
 .../electric_indent_arguments_constraints.m        | 16 ++++++++
 ...ctric_indent_arguments_constraints_expected.txt | 44 ++++++++++++++++++++++
 5 files changed, 85 insertions(+), 6 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 053526d115..57ae3ccd49 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -2563,9 +2563,28 @@ Example:
   (car matlab-ts-mode--i-ret-pair))
 
 (defun matlab-ts-mode--i-ret-offset (&rest _)
-  "Return anchor for `matlab-ts-mode--i-ret-matcher'."
+  "Return offset for `matlab-ts-mode--i-ret-matcher'."
   (cdr matlab-ts-mode--i-ret-pair))
 
+(defvar matlab-ts-mode--i-validation-functions-offset-value)
+
+(defun matlab-ts-mode--i-validation-functions-offset (&rest _)
+  "Return offset for `matlab-ts-mode--validation-functions-matcher'."
+  matlab-ts-mode--i-validation-functions-offset-value)
+
+(defun matlab-ts-mode--i-validation-functions-matcher (_node parent _bol &rest 
_)
+  "Is PARENT a validation function?"
+  (when (string= (treesit-node-type parent) "validation_functions")
+    (save-excursion
+      (goto-char (treesit-node-start parent)) ;; goto opening "{" of the 
validation functions cell
+      (forward-char)
+      (if (and (re-search-forward "[^ \t]" (pos-eol) t)  ;; no validation fcn 
on the "{" line?
+               (progn (backward-char)
+                      (not (looking-at "\\.\\.\\."))))
+          (setq matlab-ts-mode--i-validation-functions-offset-value 1)
+        (setq matlab-ts-mode--i-validation-functions-offset-value 2)))
+    t))
+
 (defvar matlab-ts-mode--indent-rules
   `((matlab
 
@@ -2660,9 +2679,9 @@ Example:
      ;;                 { ...
      ;;                   mustBeReal ...
      ;;                   ^                     <== TAB/RET to here
-     ((parent-is ,(rx bos "validation_functions" eos))
+     (,#'matlab-ts-mode--i-validation-functions-matcher
       parent
-      ,(if matlab-ts-mode--electric-indent 1 2))
+      ,#'matlab-ts-mode--i-validation-functions-offset)
 
      ;; I-Rule: property after a property
      ;;         properties
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected_msgs.m
index 48e02c32ac..f3e2e5ef3a 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected_msgs.m
@@ -11,6 +11,6 @@ function electric_indent_arguments_constraints(input1, 
params) %  <{Matched rule
         params.fooBarZoo  = 'auto' %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
         params.otherThing ... %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
             {mustBeNumeric, mustBeReal, mustBeFinite, mustBeNonnegative, ... % 
 <{Matched rule: (matlab-ts-mode--i-cont-matcher parent 
matlab-ts-mode--i-cont-offset)}>
-             mustBeNonsparse, mustBeLessThanOrEqual(params.otherThing, 1)} = 1 
%  <{Matched rule: ((parent-is "\\`validation_functions\\'") parent 1)}>
+             mustBeNonsparse, mustBeLessThanOrEqual(params.otherThing, 1)} = 1 
%  <{Matched rule: (matlab-ts-mode--i-validation-functions-matcher parent 
matlab-ts-mode--i-validation-functions-offset)}>
     end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
 end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_cont_properties_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_cont_properties_expected_msgs.m
index fac0de2490..e97d1e3720 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_cont_properties_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_cont_properties_expected_msgs.m
@@ -15,7 +15,7 @@ classdef indent_cont_properties %  <{Matched rule: 
(matlab-ts-mode--i-top-level
                 obj    %#ok<INUSA> %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
                 a ... %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
                     { ... %  <{Matched rule: (matlab-ts-mode--i-cont-matcher 
parent matlab-ts-mode--i-cont-offset)}>
-                      mustBeReal ... %  <{Matched rule: ((parent-is 
"\\`validation_functions\\'") parent 2)}>
+                      mustBeReal ... %  <{Matched rule: 
(matlab-ts-mode--i-validation-functions-matcher parent 
matlab-ts-mode--i-validation-functions-offset)}>
                     } %  <{Matched rule: ((n-p-gp "\\`}\\'" 
"\\`validation_functions\\'" nil) parent 0)}>
             end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
             disp(a) %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
@@ -25,7 +25,7 @@ classdef indent_cont_properties %  <{Matched rule: 
(matlab-ts-mode--i-top-level
             arguments %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
                 p1 string {mustBeScalarOrEmpty} %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
                 p2 double {... %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
-                            mustBeReal ... %  <{Matched rule: ((parent-is 
"\\`validation_functions\\'") parent 2)}>
+                            mustBeReal ... %  <{Matched rule: 
(matlab-ts-mode--i-validation-functions-matcher parent 
matlab-ts-mode--i-validation-functions-offset)}>
                           } = 0 %  <{Matched rule: ((n-p-gp "\\`}\\'" 
"\\`validation_functions\\'" nil) parent 0)}>
             end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
             disp(p1) %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints.m
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints.m
new file mode 100644
index 0000000000..99ae5608f5
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints.m
@@ -0,0 +1,16 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+function electric_indent_arguments_constraints(input1, params)
+    arguments
+        input11    (:,:)
+
+        params.foo1       = lines(1)
+        params.foobar     = 'auto'
+        params.fooBarZoo  = 'auto'
+        params.otherThing ...
+            {mustBeNumeric, mustBeReal, mustBeFinite, mustBeNonnegative, ...
+             mustBeNonsparse, mustBeLessThanOrEqual(params.otherThing, 1)} = 1
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected.txt
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected.txt
new file mode 100644
index 0000000000..3b051afdaf
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_constraints_expected.txt
@@ -0,0 +1,44 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,522> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,112]@{% 
t-utils-test-indent: no-line-by-line-indent - li...}@) \n[112,114]
+ (function_definition<114,521> function[114,122] name: 
(identifier[123,160]@{electric_indent_arguments_constraints}@)
+  (function_arguments<160,176> ([160,161] arguments: 
(identifier[161,167]@{input1}@) ,[167,168] (identifier[169,175]@{params}@) 
)[175,176])
+  \n[176,177]
+  (arguments_statement<181,518> arguments[181,190] \n[190,191]
+   (property<199,215> name: (identifier[199,206]@{input11}@)
+    (dimensions<210,215> ([210,211]
+     (spread_operator<211,212> :[211,212])
+     ,[212,213]
+     (spread_operator<213,214> :[213,214])
+     )[214,215]))
+   \n[215,217]
+   (property<225,253>
+    name: (property_name<225,236> (identifier[225,231]@{params}@) .[231,232] 
(identifier[232,236]@{foo1}@))
+    (default_value<243,253> =[243,244]
+     (function_call<245,253> name: (identifier[245,250]@{lines}@) ([250,251]
+      (arguments<251,252> argument: (number[251,252]@{1}@))
+      )[252,253])))
+   \n[253,254]
+   (property<262,288>
+    name: (property_name<262,275> (identifier[262,268]@{params}@) .[268,269] 
(identifier[269,275]@{foobar}@))
+    (default_value<280,288> =[280,281]
+     (string<282,288> '[282,283] (string_content[283,287]@{auto}@) 
'[287,288])))
+   \n[288,289]
+   (property<297,323>
+    name: (property_name<297,313> (identifier[297,303]@{params}@) .[303,304] 
(identifier[304,313]@{fooBarZoo}@))
+    (default_value<315,323> =[315,316]
+     (string<317,323> '[317,318] (string_content[318,322]@{auto}@) 
'[322,323])))
+   \n[323,324]
+   (property<332,509>
+    name: (property_name<332,349> (identifier[332,338]@{params}@) .[338,339] 
(identifier[339,349]@{otherThing}@))
+    (line_continuation[350,354]@{...\n}@)
+    (validation_functions<366,505> {[366,367] 
(identifier[367,380]@{mustBeNumeric}@) ,[380,381] 
(identifier[382,392]@{mustBeReal}@) ,[392,393] 
(identifier[394,406]@{mustBeFinite}@) ,[406,407] 
(identifier[408,425]@{mustBeNonnegative}@) ,[425,426] 
(line_continuation[427,431]@{...\n}@) (identifier[444,459]@{mustBeNonsparse}@) 
,[459,460]
+     (function_call<461,504> name: 
(identifier[461,482]@{mustBeLessThanOrEqual}@) ([482,483]
+      (arguments<483,503>
+       argument: (field_expression<483,500> object: 
(identifier[483,489]@{params}@) .[489,490] field: 
(identifier[490,500]@{otherThing}@))
+       ,[500,501] (number[502,503]@{1}@))
+      )[503,504])
+     }[504,505])
+    (default_value<506,509> =[506,507] (number[508,509]@{1}@)))
+   \n[509,510] end[514,517] \n[517,518])
+  end[518,521])
+ \n[521,522])

Reply via email to