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

    matlab-ts-mode: indent classdef continued properties
---
 matlab-ts-mode.el                                  | 31 ++++++++++++++++++++++
 .../indent_class_prop_continued2.m                 | 30 +++++++++++++++++++++
 .../indent_class_prop_continued2_expected.m        | 30 +++++++++++++++++++++
 .../indent_class_prop_continued2_expected_msgs.m   | 30 +++++++++++++++++++++
 4 files changed, 121 insertions(+)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index dcddd776cd..b33605e89d 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -2294,6 +2294,29 @@ Example:
                            (treesit-node-start assign-node))
                          matlab-ts-mode--indent-level)))))))
 
+(defvar matlab-ts--i-arg-namespace-fcn-prop-anchor-value nil)
+
+(defun matlab-ts--i-arg-namespace-fcn-prop-matcher (node parent _bol &rest _)
+  "Is NODE, PARENT a property default value?
+Example:
+        properties (Constant)
+            property1 = containers.Map(...
+    TAB>                    {"
+  (and (equal (treesit-node-type node) "arguments")
+       (string= (treesit-node-type parent) "function_call")
+       (let ((grand-parent (treesit-node-parent parent)))
+         (and (string= (treesit-node-type grand-parent) "field_expression")
+              (let ((great-grand-parent (treesit-node-parent grand-parent)))
+                (and (string= (treesit-node-type great-grand-parent) 
"default_value")
+                     (let ((great-great-grand-parent (treesit-node-parent 
great-grand-parent)))
+                       (and (string= (treesit-node-type 
great-great-grand-parent) "property")
+                            (setq 
matlab-ts--i-arg-namespace-fcn-prop-anchor-value
+                                  (treesit-node-start 
great-great-grand-parent))))))))))
+
+(defun matlab-ts--i-arg-namespace-fcn-prop-anchor (_node _parent _bol &rest _)
+  "Return anchor for `matlab-ts--i-arg-namespace-fcn-prop-matcher'."
+  matlab-ts--i-arg-namespace-fcn-prop-anchor-value)
+
 (defvar matlab-ts-mode--indent-rules
   `((matlab
 
@@ -2540,6 +2563,14 @@ Example:
      ;; <TAB>                    2, ...
      ((parent-is ,(rx bos "arguments" eos)) parent 0)
 
+     ;; I-Rule:      properties (Constant)
+     ;;                  property1 = containers.Map(...
+     ;;        TAB>          {
+     ;; See: 
tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2.m
+     (,#'matlab-ts--i-arg-namespace-fcn-prop-matcher
+      ,#'matlab-ts--i-arg-namespace-fcn-prop-anchor
+      ,matlab-ts-mode--indent-level)
+
      ;; I-Rule:      someNamespace1.subNamespace2.myFunction( ...
      ;;        TAB>      a, ... % comment for param1
      ;; See: 
tests/test-matlab-ts-mode-indent-files/indent_namespace_fcn_continued.m
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2.m 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2.m
new file mode 100644
index 0000000000..1a2c20b253
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2.m
@@ -0,0 +1,30 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - typing line by line doesn't 
work when there are no 'end' statements for classdef/properties
+
+classdef indent_class_prop_continued2
+
+    properties (Constant)
+        property1 = containers.Map(...
+            {
+              'one'
+              'two'
+            } ...
+            , ...
+            {
+              'foo'
+              'bar'
+            });
+
+        property2 = someFcn(...
+            {
+              'one'
+              'two'
+            } ...
+            , ...
+            {
+              'foo'
+              'bar'
+            });
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected.m
new file mode 100644
index 0000000000..1a2c20b253
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected.m
@@ -0,0 +1,30 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - typing line by line doesn't 
work when there are no 'end' statements for classdef/properties
+
+classdef indent_class_prop_continued2
+
+    properties (Constant)
+        property1 = containers.Map(...
+            {
+              'one'
+              'two'
+            } ...
+            , ...
+            {
+              'foo'
+              'bar'
+            });
+
+        property2 = someFcn(...
+            {
+              'one'
+              'two'
+            } ...
+            , ...
+            {
+              'foo'
+              'bar'
+            });
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected_msgs.m
new file mode 100644
index 0000000000..2817246f52
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued2_expected_msgs.m
@@ -0,0 +1,30 @@
+% -*- matlab-ts -*- %  <{Matched rule: ((lambda (node parent _bol &rest _) 
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal 
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _) 
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+% t-utils-test-indent: no-line-by-line-indent - typing line by line doesn't 
work when there are no 'end' statements for classdef/properties %  <{Matched 
rule: ((lambda (node parent _bol &rest _) (and node (not (string= 
(treesit-node-type node) "line_continuation")) (equal (treesit-node-type 
parent) "source_file"))) (lambda (_node _parent bol &rest _) (save-excursion 
(goto-char bol) (line-beginning-position))) 0)}>
+
+classdef indent_class_prop_continued2 %  <{Matched rule: ((lambda (node parent 
_bol &rest _) (and node (not (string= (treesit-node-type node) 
"line_continuation")) (equal (treesit-node-type parent) "source_file"))) 
(lambda (_node _parent bol &rest _) (save-excursion (goto-char bol) 
(line-beginning-position))) 0)}>
+
+    properties (Constant) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+        property1 = containers.Map(... %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            { %  <{Matched rule: (matlab-ts--i-arg-namespace-fcn-prop-matcher 
matlab-ts--i-arg-namespace-fcn-prop-anchor 4)}>
+              'one' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+              'two' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+            } ... %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+            , ... %  <{Matched rule: ((parent-is "\\`arguments\\'") parent 0)}>
+            { %  <{Matched rule: ((parent-is "\\`arguments\\'") parent 0)}>
+              'foo' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+              'bar' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+            }); %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+        property2 = someFcn(... %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            { %  <{Matched rule: ((n-p-gp 
"\\`\\(?:)\\|arguments\\|line_continuation\\)\\'" "\\`function_call\\'" 
"\\`default_value\\'") great-grand-parent 4)}>
+              'one' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+              'two' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+            } ... %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+            , ... %  <{Matched rule: ((parent-is "\\`arguments\\'") parent 0)}>
+            { %  <{Matched rule: ((parent-is "\\`arguments\\'") parent 0)}>
+              'foo' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+              'bar' %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent matlab-ts-mode--row-indent-level)}>
+            }); %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+    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)}>

Reply via email to