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

    matlab-ts-mode--ei: handle m-matrix in properties
---
 matlab-ts-mode--ei.el                              | 29 ++++++++++++++++------
 .../electric_indent_m_matrix_in_prop.m             | 19 ++++++++++++++
 .../electric_indent_m_matrix_in_prop_expected.m    | 19 ++++++++++++++
 ...lectric_indent_m_matrix_in_prop_expected_msgs.m | 19 ++++++++++++++
 .../electric_indent_m_matrix_in_prop.m             | 19 ++++++++++++++
 .../electric_indent_m_matrix_in_prop_expected.txt  | 22 ++++++++++++++++
 6 files changed, 119 insertions(+), 8 deletions(-)

diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index b996c226a7..68722caeb0 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -734,8 +734,11 @@ when on the 2nd continuation only line, nil is returned."
 Point is left at beginning of line containing the ASSIGN-NODE text.
 Returns the line number after the ASSIGN-NODE in the tmp-buf."
   (let (assign-str
+        assign-end-linenum
         n-levels
-        end-linenum)
+        (n-extra-levels 0)
+        (is-prop (treesit-parent-until assign-node (rx bos (or "properties" 
"arguments") eos))))
+
     (with-current-buffer (treesit-node-buffer assign-node)
       (let* ((assign-start-pos (save-excursion (goto-char (treesit-node-start 
assign-node))
                                                (pos-bol)))
@@ -748,13 +751,18 @@ Returns the line number after the ASSIGN-NODE in the 
tmp-buf."
                          ;; else: not at a standard level so no need to add 
conditionals as the
                          ;; indent level will be corrected later.
                          0))))
+    (when is-prop
+      (setq n-extra-levels (max (- n-levels 2) 0)
+            n-levels 2))
 
-    (cl-loop for level from 1 to n-levels do
-             (insert "if 1\n"))
+    (if is-prop
+        (insert "classdef foo\n" "properties\n")
+      (cl-loop for level from 1 to n-levels do
+               (insert "if 1\n")))
 
     (insert assign-str "\n")
 
-    (setq end-linenum (line-number-at-pos))
+    (setq assign-end-linenum (line-number-at-pos))
 
     (cl-loop for level from 1 to n-levels do
              (insert "end\n"))
@@ -768,11 +776,16 @@ Returns the line number after the ASSIGN-NODE in the 
tmp-buf."
           (treesit--indent-verbose nil))
       (indent-region (point-min) (point-max)))
 
-
     (goto-char (point-min))
-    (when (> n-levels 0)
-      (forward-line n-levels))
-    end-linenum))
+    (forward-line n-levels) ;; Leave point at assignment start
+    (when (> n-extra-levels 0) ;; Add additional whitespace on left?
+      (save-excursion
+        (let ((start-point (point))
+              (end-point (progn
+                           (goto-char (point-min))
+                           (forward-line assign-end-linenum))))
+          (string-rectangle start-point end-point (make-string (* 
n-extra-levels 4) ? )))))
+    assign-end-linenum))
 
 ;; TODO - investigate performance improvements for m-matrix line alignment.
 ;; 1. Should we improve performance by leveraging prior line when TABing lines?
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
new file mode 100644
index 0000000000..b94d0c0ce7
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
@@ -0,0 +1,19 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_m_matrix_in_prop
+ properties
+     pStrings string = [    ... Default value
+                % comment1
+                "string one"; ...
+        
+                % comment2
+                "string2"; ...
+        
+                % comment for following two strings
+                "string3"; ...
+                           "string four that is long"; ...
+            ];
+end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.m
new file mode 100644
index 0000000000..5ad43bd73a
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.m
@@ -0,0 +1,19 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_m_matrix_in_prop
+    properties
+        pStrings string = [ ... Default value
+                            % comment1
+                           "string one"               ; ...
+
+                            % comment2
+                           "string2"                  ; ...
+
+                            % comment for following two strings
+                           "string3"                  ; ...
+                           "string four that is long" ; ...
+                          ];
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected_msgs.m
new file mode 100644
index 0000000000..6fe62c26d6
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected_msgs.m
@@ -0,0 +1,19 @@
+% -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+classdef electric_indent_m_matrix_in_prop %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+    properties %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+        pStrings string = [ ... Default value %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+                            % comment1 %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+                           "string one"               ; ... %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
+
+                            % comment2 %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+                           "string2"                  ; ... %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
+
+                            % comment for following two strings %  <{Matched 
rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+                           "string3"                  ; ... %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
+                           "string four that is long" ; ... %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
+                          ]; %  <{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)}>
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
new file mode 100644
index 0000000000..b94d0c0ce7
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop.m
@@ -0,0 +1,19 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_m_matrix_in_prop
+ properties
+     pStrings string = [    ... Default value
+                % comment1
+                "string one"; ...
+        
+                % comment2
+                "string2"; ...
+        
+                % comment for following two strings
+                "string3"; ...
+                           "string four that is long"; ...
+            ];
+end
+end
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.txt
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.txt
new file mode 100644
index 0000000000..77f4d14c38
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_in_prop_expected.txt
@@ -0,0 +1,22 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,516> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,112]@{% 
t-utils-test-indent: no-line-by-line-indent - li...}@) \n[112,114]
+ (class_definition<114,515> classdef[114,122] name: 
(identifier[123,155]@{electric_indent_m_matrix_in_prop}@) \n[155,156]
+  (properties<157,511> properties[157,167] \n[167,168]
+   (property<173,506> name: (identifier[173,181]@{pStrings}@) 
(identifier[182,188]@{string}@)
+    (default_value<189,506> =[189,190]
+     (matrix<191,506> [[191,192] (line_continuation[196,214]@{... Default 
value\n}@) (comment[230,240]@{% comment1}@)
+      (row<257,269>
+       (string<257,269> "[257,258] (string_content[258,268]@{string one}@) 
"[268,269]))
+      (line_continuation[271,275]@{...\n}@) (comment[300,310]@{% comment2}@)
+      (row<327,336>
+       (string<327,336> "[327,328] (string_content[328,335]@{string2}@) 
"[335,336]))
+      (line_continuation[338,342]@{...\n}@) (comment[367,402]@{% comment for 
following two strings}@)
+      (row<419,428>
+       (string<419,428> "[419,420] (string_content[420,427]@{string3}@) 
"[427,428]))
+      (line_continuation[430,434]@{...\n}@)
+      (row<461,487>
+       (string<461,487> "[461,462] (string_content[462,486]@{string four that 
is long}@) "[486,487]))
+      (line_continuation[489,493]@{...\n}@) ][505,506])))
+   ;[506,507] \n[507,508] end[508,511])
+  \n[511,512] end[512,515])
+ \n[515,516])

Reply via email to