branch: externals/matlab-mode
commit 33e942a17730a4b0fa931b601e186fd3f82aa164
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode--ei: fix insertion of commas in arrays
---
matlab-ts-mode--ei.el | 30 ++++++++-----------
.../electric_indent_m_matrix_strings_comma.m | 12 ++++++++
...ectric_indent_m_matrix_strings_comma_expected.m | 12 ++++++++
...c_indent_m_matrix_strings_comma_expected_msgs.m | 12 ++++++++
.../electric_indent_matrix_cols_expected.m | 2 +-
.../electric_indent_matrix_cols_expected_msgs.m | 2 +-
.../electric_indent_matrix_comma_add_expected.m | 4 +--
...lectric_indent_matrix_comma_add_expected_msgs.m | 4 +--
.../electric_indent_matrix_expected.m | 12 ++++----
.../electric_indent_matrix_expected_msgs.m | 12 ++++----
.../electric_indent_m_matrix_strings_comma.m | 12 ++++++++
...tric_indent_m_matrix_strings_comma_expected.txt | 35 ++++++++++++++++++++++
12 files changed, 113 insertions(+), 36 deletions(-)
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index fcdf4d45b8..c103910bc1 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -285,27 +285,21 @@ is used in `matlab-ts-mode--ei-spacing'"
(let ((node (treesit-node-at (point))))
- ;; If next node is a matrix comma node return that
- ;; Example:
+ ;; If next node is a array comma node return that. Examples:
;; x1 = [(3*(2+1)) 2]
- ;; ^ <== point here
- ;; Next node is the invisible comma node having same start and end
point.
- ;; Example:
+ ;; ^ <== point here (next node is invisible comma
node w/start=end pt)
;; x2 = [1, 2]
- ;; ^ <== point here
- ;; Next node is the comma node.
-
+ ;; ^ <== point here (next node is comma node)
(when (looking-at "[ \t]" (point))
- (let ((candidate node))
- (while (and (= (treesit-node-end candidate) (point))
- (let* ((next-node (treesit-node-next-sibling candidate))
- (next-type (treesit-node-type next-node)))
- ;; At comma node of a row in a MATLAB array (a matrix
or cell)?
- (when (and (equal next-type ",")
- (string= (treesit-node-type
(treesit-node-parent next-node))
- "row"))
- (cl-return-from
matlab-ts-mode--ei-move-to-and-get-node
- (cons next-node next-type)))))
+ (let ((candidate node)) ;; candidate will be the array element
+ (while (= (treesit-node-end candidate) (point)) ;; lookup to find
our array element
+ (let* ((next-node (treesit-node-next-sibling candidate))
+ (next-type (treesit-node-type next-node)))
+ ;; At comma node of a row in an array (a matrix or cell)?
+ (when (and (equal next-type ",")
+ (string= (treesit-node-type (treesit-node-parent
next-node)) "row"))
+ (cl-return-from matlab-ts-mode--ei-move-to-and-get-node
+ (cons next-node next-type))))
(setq candidate (treesit-node-parent candidate)))))
;; Move to next non-whitespace character to get next node
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
new file mode 100644
index 0000000000..4937416ea5
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+s1 = ['ab' 'cd'];
+
+s2 = ["ab" "cd"];
+
+abc = 'foo';
+
+s3 = [' ' abc ' with properties:' 10 10 ...
+ ' type: {' 10];
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.m
new file mode 100644
index 0000000000..2061768048
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+s1 = ['ab', 'cd'];
+
+s2 = ["ab", "cd"];
+
+abc = 'foo';
+
+s3 = [' ', abc, ' with properties:', 10, 10 ...
+ ' type: {', 10];
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected_msgs.m
new file mode 100644
index 0000000000..d20ea0112a
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected_msgs.m
@@ -0,0 +1,12 @@
+% -*- 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)}>
+
+s1 = ['ab', 'cd']; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+s2 = ["ab", "cd"]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+abc = 'foo'; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+s3 = [' ', abc, ' with properties:', 10, 10 ... % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+ ' type: {', 10]; % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected.m
index 241dbe15d9..bbc506ccb7 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected.m
@@ -49,7 +49,7 @@ m4a = [a * b + c, d + a;
m4b = [a * b + c, d + a;
b, c];
-m5a = [a * b + c d + a; ...
+m5a = [a * b + c, d + a; ...
...
...
b, c];
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
index 620c04f91d..6ee38a7393 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
@@ -49,7 +49,7 @@ m4a = [a * b + c, d + a; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-
m4b = [a * b + c, d + a; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
b, c]; % <{Matched rule: (matlab-ts-mode--i-row-matcher
matlab-ts-mode--i-row-matcher-anchor matlab-ts-mode--i-row-matcher-offset)}>
-m5a = [a * b + c d + a; ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+m5a = [a * b + c, d + a; ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
... % <{Matched rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'")
parent 2)}>
... % <{Matched rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'")
parent 2)}>
b, c]; % <{Matched rule: (matlab-ts-mode--i-row-matcher
matlab-ts-mode--i-row-matcher-anchor matlab-ts-mode--i-row-matcher-offset)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected.m
index a1389ea004..99fc7e8e87 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected.m
@@ -1,7 +1,7 @@
% -*- matlab-ts -*-
-x1 = [(3 * (2 + 1)) 2];
+x1 = [(3 * (2 + 1)), 2];
x2 = [1, 2];
-m1 = [1, 2, 3000; 3, (4 + 6 * 2) +6];
+m1 = [1, 2, 3000; 3, (4 + 6 * 2), +6];
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected_msgs.m
index cf87a2cf88..f05478e91c 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_comma_add_expected_msgs.m
@@ -1,7 +1,7 @@
% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-x1 = [(3 * (2 + 1)) 2]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+x1 = [(3 * (2 + 1)), 2]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
x2 = [1, 2]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-m1 = [1, 2, 3000; 3, (4 + 6 * 2) +6]; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+m1 = [1, 2, 3000; 3, (4 + 6 * 2), +6]; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected.m
index dfd8bb46c0..617d18ed3e 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected.m
@@ -19,18 +19,18 @@ e = 0
e + e
-[-e +e]
+[-e, +e]
-f = [e + e -e +e]
+f = [e + e, -e, +e]
g = -e
h = [1, 2; ...
3, 4];
-c2 = {['freq' '%'] num2str(2)};
+c2 = {['freq', '%'], num2str(2)};
-c3 = {a, b, [c, '%'] f(1)};
+c3 = {a, b, [c, '%'], f(1)};
x = [
1, 2;
@@ -51,9 +51,9 @@ d2 = dictionary([nativeProperties(:, 1);
propertyStateArray(:, 1)], ...
m3 = uint8([ones(20, 1); 2 * ones(8, 1); ones(8, 1); 2 * ones(8, 1); ones(7,
1)]);
-foo123(t0, :) = tan(th(t0) / 2) .* [sx(t0)' sy(t0)' sz(t0)'];
+foo123(t0, :) = tan(th(t0) / 2) .* [sx(t0)', sy(t0)', sz(t0)'];
-c3 = {{[17.50, 0] [17.50, 0]} {[120, 0] [120, 20]}};
+c3 = {{[17.50, 0], [17.50, 0]}, {[120, 0], [120, 20]}};
c4{1} = [1, 2; 3, 4];
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
index d1deceeb76..0df493d38f 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
@@ -19,18 +19,18 @@ e = 0 % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0
e + e % <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0
0)}>
-[-e +e] % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+[-e, +e] % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-f = [e + e -e +e] % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+f = [e + e, -e, +e] % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
g = -e % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
h = [1, 2; ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
3, 4]; % <{Matched rule: (matlab-ts-mode--i-row-matcher
matlab-ts-mode--i-row-matcher-anchor matlab-ts-mode--i-row-matcher-offset)}>
-c2 = {['freq' '%'] num2str(2)}; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+c2 = {['freq', '%'], num2str(2)}; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-c3 = {a, b, [c, '%'] f(1)}; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+c3 = {a, b, [c, '%'], f(1)}; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
x = [ % <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0
0)}>
1, 2; % <{Matched rule: (matlab-ts-mode--i-row-matcher
matlab-ts-mode--i-row-matcher-anchor matlab-ts-mode--i-row-matcher-offset)}>
@@ -51,9 +51,9 @@ d2 = dictionary([nativeProperties(:, 1);
propertyStateArray(:, 1)], ... % <{Mat
m3 = uint8([ones(20, 1); 2 * ones(8, 1); ones(8, 1); 2 * ones(8, 1); ones(7,
1)]); % <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0
0)}>
-foo123(t0, :) = tan(th(t0) / 2) .* [sx(t0)' sy(t0)' sz(t0)']; % <{Matched
rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+foo123(t0, :) = tan(th(t0) / 2) .* [sx(t0)', sy(t0)', sz(t0)']; % <{Matched
rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-c3 = {{[17.50, 0] [17.50, 0]} {[120, 0] [120, 20]}}; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+c3 = {{[17.50, 0], [17.50, 0]}, {[120, 0], [120, 20]}}; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
c4{1} = [1, 2; 3, 4]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
new file mode 100644
index 0000000000..4937416ea5
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+s1 = ['ab' 'cd'];
+
+s2 = ["ab" "cd"];
+
+abc = 'foo';
+
+s3 = [' ' abc ' with properties:' 10 10 ...
+ ' type: {' 10];
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.txt
new file mode 100644
index 0000000000..1771e06a2c
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_strings_comma_expected.txt
@@ -0,0 +1,35 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,269> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,112]@{%
t-utils-test-indent: no-line-by-line-indent - li...}@)
+ (assignment<114,134> left: (identifier[114,116]@{s1}@) =[117,118]
+ right:
+ (matrix<119,134> [[119,120]
+ (row<120,133>
+ (string<120,124> '[120,121] (string_content[121,123]@{ab}@) '[123,124])
+ ,[129,129]
+ (string<129,133> '[129,130] (string_content[130,132]@{cd}@) '[132,133]))
+ ][133,134]))
+ ;[134,135]
+ (assignment<137,157> left: (identifier[137,139]@{s2}@) =[140,141]
+ right:
+ (matrix<142,157> [[142,143]
+ (row<143,156>
+ (string<143,147> "[143,144] (string_content[144,146]@{ab}@) "[146,147])
+ ,[152,152]
+ (string<152,156> "[152,153] (string_content[153,155]@{cd}@) "[155,156]))
+ ][156,157]))
+ ;[157,158]
+ (assignment<160,171> left: (identifier[160,163]@{abc}@) =[164,165]
+ right: (string<166,171> '[166,167] (string_content[167,170]@{foo}@)
'[170,171]))
+ ;[171,172]
+ (assignment<174,267> left: (identifier[174,176]@{s3}@) =[177,178]
+ right:
+ (matrix<179,267> [[179,180]
+ (row<180,266>
+ (string<180,184> '[180,181] (string_content[181,183]@{ }@) '[183,184])
+ ,[185,185] (identifier[185,188]@{abc}@) ,[189,189]
+ (string<189,208> '[189,190] (string_content[190,207]@{ with
properties:}@) '[207,208])
+ ,[209,209] (number[209,211]@{10}@) ,[212,212] (number[212,214]@{10}@)
(line_continuation[215,231]@{...\n }@) ,[231,231]
+ (string<231,263> '[231,232] (string_content[232,262]@{
type: \{}@) '[262,263])
+ ,[264,264] (number[264,266]@{10}@))
+ ][266,267]))
+ ;[267,268] \n[268,269])