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

    matlab-ts-mode--ei: handle case of closing ')' for struct alignment
---
 matlab-ts-mode--ei.el                              |  5 ++++-
 .../electric_indent_struct_in_prop2.m              | 17 ++++++++++++++
 .../electric_indent_struct_in_prop2_expected.m     | 17 ++++++++++++++
 ...electric_indent_struct_in_prop2_expected_msgs.m | 17 ++++++++++++++
 .../electric_indent_struct_in_prop2.m              | 17 ++++++++++++++
 .../electric_indent_struct_in_prop2_expected.txt   | 26 ++++++++++++++++++++++
 6 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 43c2f19251..5ea2acb034 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -1030,7 +1030,10 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO."
       (when (string-match-p (rx bos (0+ (or " " "\t")) "...") ei-line) ;; skip 
continuations
         (cl-return-from matlab-ts-mode--ei-align-line-in-m-struct ei-info))
       (setq comma-offset (string-match-p "," ei-line)
-            new-comma-offset (+ (string-match-p "[^ \t]" ei-line) 
max-field-width)))
+            new-comma-offset (+ (string-match-p "[^ \t]" ei-line) 
max-field-width))
+      (when (not comma-offset) ;; Ending ");" by itself on a line
+        ;; TopTester: electric_indent_struct_in_prop2.m
+        (cl-return-from matlab-ts-mode--ei-align-line-in-m-struct ei-info)))
 
     (let ((n-spaces-to-add (- new-comma-offset comma-offset)))
       (when (not (= n-spaces-to-add 0))
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2.m
new file mode 100644
index 0000000000..07b0a23e6e
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_struct_in_prop2
+    properties
+        s(1,1)struct{mustBeNonempty}=struct( ...
+                   'field1'                      , 1, ...
+'otherField2', 2 ...
+            );
+        m = [
+100000, 2
+               3, 4000000
+];
+    end
+
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.m
new file mode 100644
index 0000000000..40b9fab954
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_struct_in_prop2
+    properties
+        s (1,1) struct {mustBeNonempty} = struct( ...
+            'field1'     , 1, ...
+            'otherField2', 2 ...
+            );
+        m = [
+              100000,       2
+                   3, 4000000
+            ];
+    end
+
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected_msgs.m
new file mode 100644
index 0000000000..c55b3105e2
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected_msgs.m
@@ -0,0 +1,17 @@
+% -*- 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_struct_in_prop2 %  <{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)}>
+        s (1,1) struct {mustBeNonempty} = struct( ... %  <{Matched rule: 
((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            'field1'     , 1, ... %  <{Matched rule: ((n-p-gp 
"\\`\\(?:)\\|arguments\\|line_continuation\\)\\'" "\\`function_call\\'" 
"\\`default_value\\'") great-grand-parent 4)}>
+            'otherField2', 2 ... %  <{Matched rule: ((parent-is 
"\\`arguments\\'") parent 0)}>
+            ); %  <{Matched rule: ((n-p-gp 
"\\`\\(?:)\\|arguments\\|line_continuation\\)\\'" "\\`function_call\\'" 
"\\`default_value\\'") great-grand-parent 4)}>
+        m = [ %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+              100000,       2 %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
+                   3, 4000000 %  <{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_struct_in_prop2.m
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2.m
new file mode 100644
index 0000000000..07b0a23e6e
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in 
error nodes
+
+classdef electric_indent_struct_in_prop2
+    properties
+        s(1,1)struct{mustBeNonempty}=struct( ...
+                   'field1'                      , 1, ...
+'otherField2', 2 ...
+            );
+        m = [
+100000, 2
+               3, 4000000
+];
+    end
+
+end
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.txt
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.txt
new file mode 100644
index 0000000000..08f2766200
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_struct_in_prop2_expected.txt
@@ -0,0 +1,26 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,379> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,112]@{% 
t-utils-test-indent: no-line-by-line-indent - li...}@) \n[112,114]
+ (class_definition<114,378> classdef[114,122] name: 
(identifier[123,154]@{electric_indent_struct_in_prop2}@) \n[154,155]
+  (properties<159,373> properties[159,169] \n[169,170]
+   (property<178,311> name: (identifier[178,179]@{s}@)
+    (dimensions<179,184> ([179,180] (number[180,181]@{1}@) ,[181,182] 
(number[182,183]@{1}@) )[183,184])
+    (identifier[184,190]@{struct}@)
+    (validation_functions<190,206> {[190,191] 
(identifier[191,205]@{mustBeNonempty}@) }[205,206])
+    (default_value<206,311> =[206,207]
+     (function_call<207,311> name: (identifier[207,213]@{struct}@) ([213,214] 
(line_continuation[215,219]@{...\n}@)
+      (arguments<238,293>
+       argument: (string<238,246> '[238,239] 
(string_content[239,245]@{field1}@) '[245,246])
+       ,[268,269] (number[270,271]@{1}@) ,[271,272] 
(line_continuation[273,277]@{...\n}@)
+       (string<277,290> '[277,278] (string_content[278,289]@{otherField2}@) 
'[289,290])
+       ,[290,291] (number[292,293]@{2}@))
+      (line_continuation[294,298]@{...\n}@) )[310,311])))
+   ;[311,312] \n[312,313]
+   (property<321,364> name: (identifier[321,322]@{m}@)
+    (default_value<323,364> =[323,324]
+     (matrix<325,364> [[325,326]
+      (row<327,336> (number[327,333]@{100000}@) ,[333,334] 
(number[335,336]@{2}@))
+      (row<352,362> (number[352,353]@{3}@) ,[353,354] 
(number[355,362]@{4000000}@))
+      ][363,364])))
+   ;[364,365] \n[365,366] end[370,373])
+  \n[373,375] end[375,378])
+ \n[378,379])

Reply via email to