branch: externals/matlab-mode
commit 7436f6414cfc94360448f2f7ebb4b1e63ad58451
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: indent - alignment assignments
Running M-x indent-region on:
length= 5;
width = 10;
area= length* width;
will produce:
length = 5;
width = 10;
area = length * width;
---
NEWS.org | 44 +--
matlab-ts-mode.el | 306 +++++++++++++--------
.../electric_indent_align_assignments.m | 26 +-
.../electric_indent_align_assignments_expected.m | 32 ++-
...ectric_indent_align_assignments_expected_msgs.m | 32 ++-
.../electric_indent_example.m | 2 +
.../electric_indent_example_expected.m | 6 +-
.../electric_indent_example_expected_msgs.m | 6 +-
.../electric_indent_matrix_expected.m | 2 +-
.../electric_indent_matrix_expected_msgs.m | 2 +-
.../electric_indent_operators.m | 4 +
.../electric_indent_operators_expected.m | 4 +
.../electric_indent_operators_expected_msgs.m | 4 +
.../electric_indent_align_assignments.m | 26 +-
.../electric_indent_align_assignments_expected.txt | 104 +++++--
.../electric_indent_example.m | 2 +
.../electric_indent_example_expected.txt | 184 ++++++-------
.../electric_indent_operators.m | 4 +
.../electric_indent_operators_expected.txt | 172 ++++++------
19 files changed, 600 insertions(+), 362 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 6806548383..f49bb30b4c 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -44,28 +44,28 @@ Running
will produce:
#+begin_src matlab
- % Calculate the Golden Ratio (phi)
- phi = (1 + sqrt(5)) / 2;
- disp(['Golden Ratio (phi): ', num2str(phi)]); % Display the value
-
- % Plot the exponential function with a Taylor Series Approximation
- x = -2 : 0.1 : 2;
- y_exp = exp(x);
- y_taylor = 1 + x + x.^2 / 2 + x.^3 / 6; % First few terms
-
- % Plot the approximation
- figure; % Create a new figure
- plot(x, y_exp, 'b-', 'LineWidth', 2); % Plot the actual exponential
- hold on; % Keep the current plot
- plot(x, y_taylor, ...
- 'r--', ...
- 'LineWidth', 1.5);
- title('Exponential Function & Taylor Approximation');
- xlabel('x');
- ylabel('y');
- legend('exp(x)', 'Taylor Series');
- grid on;
- hold off;
+% Calculate the Golden Ratio (phi)
+phi = (1 + sqrt(5)) / 2;
+disp(['Golden Ratio (phi): ', num2str(phi)]); % Display the value
+
+% Plot the exponential function with a Taylor Series Approximation
+x = -2 : 0.1 : 2;
+y_exp = exp(x);
+y_taylor = 1 + x + x.^2 / 2 + x.^3 / 6; % First few terms
+
+% Plot the approximation
+figure; % Create a new figure
+plot(x, y_exp, 'b-', 'LineWidth', 2); % Plot the actual exponential
+hold on; % Keep the current plot
+plot(x, y_taylor, ...
+ 'r--', ...
+ 'LineWidth', 1.5);
+title('Exponential Function & Taylor Approximation');
+xlabel('x');
+ylabel('y');
+legend('exp(x)', 'Taylor Series');
+grid on;
+hold off;
#+end_src
* Release 7.4.1 Nov 26, 2025
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index c219137ffe..0ec96027d5 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -3160,120 +3160,207 @@ Assumes that current point is at
`back-to-indentation'."
line-node-types
(concat line-node-types (when line-node-types " ") node-type)))
+(cl-defun matlab-ts-mode--ei-get-new-line (&optional start-node start-offset)
+ "Get new line content with element spacing adjusted.
+Optional START-NODE and START-OFFSET are used to compute new line-offset
+to restore point after updating line. Note, new line content may be same
+as current line. Also computes line-node-types which is a string containing
+the line node types.
+Returns electric indent info, ei-info,
+ (list NEW-LINE-CONTENT LINE-OFFSET LINE-NODE-TYPES FIRST-NODE-IN-LINE)
+or nil."
+ (save-excursion
+ (back-to-indentation)
+ (when (matlab-ts-mode--no-elements-to-indent)
+ (cl-return-from matlab-ts-mode--ei-get-new-line))
+
+ ;; Compute ei-line, the electric indented line content
+ (let* (line-offset ;; used in restoring point
+ (ei-line (buffer-substring (line-beginning-position) (point)))
+ (pair (matlab-ts-mode--move-to-and-get-node))
+ (node (or (car pair)
+ (cl-return-from matlab-ts-mode--ei-get-new-line)))
+ (node-type (cdr pair))
+ (first-node node)
+ line-node-types
+ next2-pair ;; used when we have: (NODE-RE (NEXT-NODE-RE
NEXT2-NODE-RE) N-SPACES-BETWEEN)
+ next2-n-spaces-between)
+
+ (cl-loop
+ while (and (< (point) (line-end-position))
+ (< (treesit-node-end node) (line-end-position)))
+ do
+ (let* ((next-pair (progn
+ (goto-char (treesit-node-end node))
+ (or next2-pair
+ (matlab-ts-mode--move-to-and-get-node))))
+ (next-node (let ((candidate-node (car next-pair)))
+ (when (not candidate-node)
+ (cl-return))
+ (when (= (treesit-node-start candidate-node)
+ (treesit-node-end candidate-node))
+ ;; Syntax errors can result in empty nodes, so
skip this line
+ ;; TopTester: electric_indent_empty_node_error.m
+ (cl-return-from matlab-ts-mode--ei-get-new-line))
+ candidate-node))
+ (next-node-type (cdr next-pair))
+ (n-spaces-between next2-n-spaces-between))
+
+ (setq next2-pair nil
+ next2-n-spaces-between nil)
+
+ (when matlab-ts-mode--electric-indent-assert
+ (setq line-node-types (matlab-ts-mode--update-line-node-types
line-node-types
+ node
node-type)))
+
+ (when (not n-spaces-between)
+ (cl-loop for tuple in matlab-ts-mode--electric-indent-spacing do
+ (let* ((node-re (nth 0 tuple))
+ (next-spec (nth 1 tuple))
+ (next-node-re (if (listp next-spec) (car next-spec)
next-spec))
+ (next2-node-re (when (listp next-spec) (cdr
next-spec))))
+
+ (when (and (string-match-p node-re node-type)
+ (string-match-p next-node-re next-node-type)
+ (or (not next2-node-re)
+ (save-excursion
+ (goto-char (treesit-node-end next-node))
+ (let* ((pair
(matlab-ts-mode--move-to-and-get-node))
+ (next2-node-type
+ (or (cdr pair)
+ (cl-return-from
+
matlab-ts-mode--ei-get-new-line))))
+
+ (when (string-match-p next2-node-re
next2-node-type)
+ (setq next2-pair pair)
+ (setq next2-n-spaces-between (nth 2
tuple))
+ t)))))
+
+ (setq n-spaces-between (nth 2 tuple))
+ (when matlab-ts-mode--electric-indent-verbose
+ (message "-->ei-matched: %S for node=<\"%s\" %S>
next-node=<\"%s\" %S>"
+ tuple node-type node next-node-type
next-node))
+ (cl-return)))))
+
+ (when (not n-spaces-between)
+ (error "Internal error, unhandled node <\"%s\" %S> and next-node
<\"%s\" %S>"
+ node-type node next-node-type next-node))
+
+ (let* ((node-end (treesit-node-end node))
+ (next-node-start (treesit-node-start next-node))
+ (extra-chars (matlab-ts-mode--node-extra-chars node-end
next-node-start)))
+ ;; Update ei-line
+ (when (equal start-node node)
+ (setq line-offset (+ (length ei-line) start-offset)))
+
+ (setq ei-line (matlab-ts-mode--concat-ei-line ei-line node
extra-chars n-spaces-between))
+
+ (setq node next-node
+ node-type next-node-type)
+ )))
+
+ (when node
+ (when matlab-ts-mode--electric-indent-assert
+ (setq line-node-types (matlab-ts-mode--update-line-node-types
line-node-types
+ node
node-type)))
+ (let ((extra-chars (matlab-ts-mode--node-extra-chars
+ (min (treesit-node-end node) (line-end-position))
+ (line-end-position))))
+ (setq ei-line (matlab-ts-mode--concat-ei-line ei-line node
extra-chars 0))))
+
+ (list ei-line line-offset line-node-types first-node))))
+
+(defun matlab-ts-mode--ei-is-assign (node)
+ "Is NODE the first node of a single-line assignmnet?"
+ (let ((parent (treesit-node-parent node)))
+ (while (and parent
+ (not (string= (treesit-node-type parent) "assignment")))
+ (setq parent (treesit-node-parent parent)))
+ (and parent
+ (let ((first-child (treesit-node-child parent 0)))
+ (eq (treesit-node-start node) (treesit-node-start first-child)))
+ (<= (treesit-node-end parent) (line-end-position))
+ (save-excursion
+ (beginning-of-line)
+ (when (re-search-forward "=" (line-end-position) t)
+ (backward-char)
+ (let ((eq-node (treesit-node-at (point))))
+ (and (equal (treesit-node-type eq-node) "=")
+ (equal (treesit-node-type (treesit-node-parent eq-node))
"assignment"))))))))
+
+(defun matlab-ts-mode--ei-assign-offset (ei-line)
+ "Get the assignment offset from the indent-level in EI-LINE."
+ (let* ((first-char-offset (or (string-match-p "[^ \t]" ei-line) (error
"Assert: no first char")))
+ (offset (- (or (string-match-p "=" ei-line) (error "Assert: no ="))
+ first-char-offset)))
+ offset))
+
+(defun matlab-ts-mode--ei-align-assignments (ei-info)
+ "Update EI-INfO to align assignments.
+See `matlab-ts-mode--ei-get-new-line' for EI-INFO."
+ (let ((first-node-in-line (nth 3 ei-info)))
+ (when (matlab-ts-mode--ei-is-assign first-node-in-line)
+ (let* ((ei-line (nth 0 ei-info))
+ (line-assign-offset (matlab-ts-mode--ei-assign-offset ei-line))
+ (assign-offset line-assign-offset)
+ line-start-pt)
+ (save-excursion
+ (beginning-of-line)
+ (setq line-start-pt (point))
+
+ ;; Look backwards and then forwards for single-line assignments
+ (cl-loop
+ for direction in '(-1 1) do
+ (goto-char line-start-pt)
+ (cl-loop
+ while (not (if (= direction -1) (bobp) (eobp))) do
+ (forward-line direction)
+ (let* ((l-info (matlab-ts-mode--ei-get-new-line))
+ (l-first-node (nth 3 l-info)))
+ (if (and l-first-node
+ (matlab-ts-mode--ei-is-assign l-first-node))
+ (let ((l-offset (matlab-ts-mode--ei-assign-offset (nth 0
l-info))))
+ (when (> l-offset assign-offset)
+ (setq assign-offset l-offset)))
+ (cl-return))))))
+ (let ((diff (- assign-offset line-assign-offset)))
+ (when (> diff 0)
+ (let* ((loc (1- (string-match "=" ei-line)))
+ (new-line-offset (let ((line-offset (nth 1 ei-info)))
+ (when line-offset
+ (if (<= loc line-offset)
+ (+ line-offset diff)
+ line-offset)))))
+ (setq ei-line (concat (substring ei-line 0 loc)
+ (make-string diff ? )
+ (substring ei-line loc)))
+ (setq ei-info (list ei-line new-line-offset (nth 2 ei-info) (nth
3 ei-info)))))))))
+ ei-info)
+
(cl-defun matlab-ts-mode--indent-elements-in-line (&optional start-node
start-offset)
- "Indent current line by adjust spacing around elements.
+ "Indent current line by adjust spacing around elements.
Optional START-NODE and START-OFFSET are used to restore the point when
line is updated. Returns t if line was updated."
- (back-to-indentation)
- (when (matlab-ts-mode--no-elements-to-indent)
- (cl-return-from matlab-ts-mode--indent-elements-in-line))
-
- ;; Compute ei-line, the electric indented line content
- (let* (line-offset ;; used in restoring point
- (ei-line (buffer-substring (line-beginning-position) (point)))
- (pair (matlab-ts-mode--move-to-and-get-node))
- (node (or (car pair)
- (cl-return-from matlab-ts-mode--indent-elements-in-line)))
- (node-type (cdr pair))
- line-node-types
- next2-pair ;; used when we have: (NODE-RE (NEXT-NODE-RE
NEXT2-NODE-RE) N-SPACES-BETWEEN)
- next2-n-spaces-between)
-
- (cl-loop
- while (and (< (point) (line-end-position))
- (< (treesit-node-end node) (line-end-position)))
- do
- (let* ((next-pair (progn
- (goto-char (treesit-node-end node))
- (or next2-pair
- (matlab-ts-mode--move-to-and-get-node))))
- (next-node (let ((candidate-node (car next-pair)))
- (when (not candidate-node)
- (cl-return))
- (when (= (treesit-node-start candidate-node)
- (treesit-node-end candidate-node))
- ;; Syntax errors can result in empty nodes, so skip
this line
- ;; TopTester: electric_indent_empty_node_error.m
- (cl-return-from
matlab-ts-mode--indent-elements-in-line))
- candidate-node))
- (next-node-type (cdr next-pair))
- (n-spaces-between next2-n-spaces-between))
-
- (setq next2-pair nil
- next2-n-spaces-between nil)
-
- (when matlab-ts-mode--electric-indent-assert
- (setq line-node-types (matlab-ts-mode--update-line-node-types
line-node-types
- node
node-type)))
-
- (when (not n-spaces-between)
- (cl-loop for tuple in matlab-ts-mode--electric-indent-spacing do
- (let* ((node-re (nth 0 tuple))
- (next-spec (nth 1 tuple))
- (next-node-re (if (listp next-spec) (car next-spec)
next-spec))
- (next2-node-re (when (listp next-spec) (cdr
next-spec))))
-
- (when (and (string-match-p node-re node-type)
- (string-match-p next-node-re next-node-type)
- (or (not next2-node-re)
- (save-excursion
- (goto-char (treesit-node-end next-node))
- (let* ((pair
(matlab-ts-mode--move-to-and-get-node))
- (next2-node-type
- (or (cdr pair)
- (cl-return-from
-
matlab-ts-mode--indent-elements-in-line))))
-
- (when (string-match-p next2-node-re
next2-node-type)
- (setq next2-pair pair)
- (setq next2-n-spaces-between (nth 2
tuple))
- t)))))
-
- (setq n-spaces-between (nth 2 tuple))
- (when matlab-ts-mode--electric-indent-verbose
- (message "-->ei-matched: %S for node=<\"%s\" %S>
next-node=<\"%s\" %S>"
- tuple node-type node next-node-type
next-node))
- (cl-return)))))
-
- (when (not n-spaces-between)
- (error "Internal error, unhandled node <\"%s\" %S> and next-node
<\"%s\" %S>"
- node-type node next-node-type next-node))
-
- (let* ((node-end (treesit-node-end node))
- (next-node-start (treesit-node-start next-node))
- (extra-chars (matlab-ts-mode--node-extra-chars node-end
next-node-start)))
- ;; Update ei-line
- (when (equal start-node node)
- (setq line-offset (+ (length ei-line) start-offset)))
-
- (setq ei-line (matlab-ts-mode--concat-ei-line ei-line node
extra-chars n-spaces-between))
-
- (setq node next-node
- node-type next-node-type)
- )))
-
- (when node
- (when matlab-ts-mode--electric-indent-assert
- (setq line-node-types (matlab-ts-mode--update-line-node-types
line-node-types
- node
node-type)))
- (let ((extra-chars (matlab-ts-mode--node-extra-chars
- (min (treesit-node-end node) (line-end-position))
- (line-end-position))))
- (setq ei-line (matlab-ts-mode--concat-ei-line ei-line node extra-chars
0))))
-
;; If line was indented (ei-line is not same as current line), then update
the buffer
- (let* ((curr-line (buffer-substring (line-beginning-position)
(line-end-position)))
- (updated (not (string= curr-line ei-line))))
- (when updated
- (delete-region (line-beginning-position) (line-end-position))
- (insert ei-line)
- (when matlab-ts-mode--electric-indent-assert
- (matlab-ts-mode--electric-indent-assert-match line-node-types))
- (when line-offset
- (goto-char (+ (line-beginning-position) line-offset))))
- ;; result
- updated)))
+ (let ((ei-info (matlab-ts-mode--ei-get-new-line start-node start-offset)))
+ (when ei-info
+ (setq ei-info (matlab-ts-mode--ei-align-assignments ei-info))
+ (let* ((ei-line (nth 0 ei-info))
+ (line-offset (nth 1 ei-info))
+ (line-node-types (nth 2 ei-info))
+ (curr-line (buffer-substring (line-beginning-position)
(line-end-position)))
+ (updated (not (string= curr-line ei-line))))
+
+ (when updated
+ (delete-region (line-beginning-position) (line-end-position))
+ (insert ei-line)
+ (when matlab-ts-mode--electric-indent-assert
+ (matlab-ts-mode--electric-indent-assert-match line-node-types))
+ (when line-offset
+ (goto-char (+ (line-beginning-position) line-offset))))
+ ;; result
+ updated))))
(defun matlab-ts-mode--treesit-indent ()
"Call `treesit-indent', then do electric indent."
@@ -3318,6 +3405,7 @@ line is updated. Returns t if line was updated."
(curr-line start-line)
(end-line (line-number-at-pos end)))
+ ;; TODO optimize assignment alignment to compute once
(when matlab-ts-mode-electric-indent
(save-excursion
(goto-char beg)
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
index 8f140973bb..0093d1a725 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
@@ -2,12 +2,32 @@
% Consecuitvie assignment alignment
+% t-utils-test-indent: no-line-by-line-indent - when we type line-by-line, we
don't see later
+% assignment values, thus to fully indent, need to
re-indent the file after
+% typing line-by-line.
+
a = 10;
-bLongVariable = [1, 2, 3];
+ bLongVariable = [1, 2, 3];
c = 5;
-dShort = [1, 2];
-x = a + bLongVariable + c + dShort;
+ dShort = [1, 2];
+x = a + bLongVariable + c + dShort;
+disp(x);
length = 5;
width = 10;
area=length*width;
+
+% other
+
+a = 1.234;
+ abc = [1, 2 , 5 ];
+abcdefg = [1, 2; 3, 44 ];
+x = 1;
+ f( a(x),1) = 10;
+g = foo(1,2,3);
+
+% some more
+
+x = 2;
+ y = 3;
+ z = x * y;
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.m
index a45355b6d8..3ec2af61bc 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.m
@@ -2,12 +2,32 @@
% Consecuitvie assignment alignment
-a = 10;
+% t-utils-test-indent: no-line-by-line-indent - when we type line-by-line, we
don't see later
+% assignment values, thus to fully indent, need to
re-indent the file after
+% typing line-by-line.
+
+a = 10;
bLongVariable = [1, 2, 3];
-c = 5;
-dShort = [1, 2];
-x = a + bLongVariable + c + dShort;
+c = 5;
+dShort = [1, 2];
+x = a + bLongVariable + c + dShort;
+disp(x);
length = 5;
-width = 10;
-area = length * width;
+width = 10;
+area = length * width;
+
+% other
+
+a = 1.234;
+abc = [1, 2, 5];
+abcdefg = [1, 2; 3, 44];
+x = 1;
+f(a(x), 1) = 10;
+g = foo(1, 2, 3);
+
+% some more
+
+x = 2;
+y = 3;
+z = x * y;
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
index 1bf7218b89..fded9249f0 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
@@ -2,12 +2,32 @@
% Consecuitvie assignment alignment % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-a = 10; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% t-utils-test-indent: no-line-by-line-indent - when we type line-by-line, we
don't see later % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% assignment values, thus to fully indent, need to
re-indent the file after % <{Matched rule:
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% typing line-by-line. % <{Matched rule:
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+
+a = 10; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
bLongVariable = [1, 2, 3]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-c = 5; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-dShort = [1, 2]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-x = a + bLongVariable + c + dShort; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+c = 5; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+dShort = [1, 2]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+x = a + bLongVariable + c + dShort; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+disp(x); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
length = 5; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-width = 10; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-area = length * width; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+width = 10; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+area = length * width; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+% other % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+a = 1.234; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+abc = [1, 2, 5]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+abcdefg = [1, 2; 3, 44]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+x = 1; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+f(a(x), 1) = 10; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+g = foo(1, 2, 3); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+% some more % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+x = 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+y = 3; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+z = x * y; % <{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_example.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
index fdb3b0bade..55204cec9c 100644
--- a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
+++ b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
@@ -1,5 +1,7 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - alignment of assignments not
possible with line-by-line indent
+
% Calculate the Golden Ratio (phi)
phi= ( 1+ sqrt( 5))/ 2 ;
disp( [ 'Golden Ratio (phi): ', num2str( phi ) ] ); %
Display the value
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.m
index 3910a44e07..8b9d93fff8 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.m
@@ -1,12 +1,14 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - alignment of assignments not
possible with line-by-line indent
+
% Calculate the Golden Ratio (phi)
phi = (1 + sqrt(5)) / 2;
disp(['Golden Ratio (phi): ', num2str(phi)]); % Display the value
% Plot the exponential function with a Taylor Series Approximation
-x = -2 : 0.1 : 2;
-y_exp = exp(x);
+x = -2 : 0.1 : 2;
+y_exp = exp(x);
y_taylor = 1 + x + x.^2 / 2 + x.^3 / 6; % First few terms
% Plot the approximation
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected_msgs.m
index ade0b3da11..0bcf351b1b 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected_msgs.m
@@ -1,12 +1,14 @@
% -*- 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 - alignment of assignments not
possible with line-by-line indent % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+
% Calculate the Golden Ratio (phi) % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
phi = (1 + sqrt(5)) / 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
disp(['Golden Ratio (phi): ', num2str(phi)]); % Display the value % <{Matched
rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
% Plot the exponential function with a Taylor Series Approximation %
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-x = -2 : 0.1 : 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-y_exp = exp(x); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+x = -2 : 0.1 : 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+y_exp = exp(x); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
y_taylor = 1 + x + x.^2 / 2 + x.^3 / 6; % First few terms % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
% Plot the approximation % <{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 5c5879d073..01fdf189cf 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
@@ -54,4 +54,4 @@ c3 = {{[17.50 0] [17.50 0]} {[120 0] [120 20]}};
c4{1} = [1 2; 3 4];
-v4 = [c4{1}(1, 1), c4{1}(1, 1)];
+v4 = [c4{1}(1, 1), c4{1}(1, 1)];
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 358e236990..6c3daf82ac 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
@@ -54,4 +54,4 @@ c3 = {{[17.50 0] [17.50 0]} {[120 0] [120 20]}}; % <{Matched
rule: (matlab-ts-m
c4{1} = [1 2; 3 4]; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-v4 = [c4{1}(1, 1), c4{1}(1, 1)]; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+v4 = [c4{1}(1, 1), c4{1}(1, 1)]; % <{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_operators.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
index 1b3e006642..47ea4db9d2 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
@@ -20,9 +20,13 @@ a2 = (1 + 2) ^ (3 + 4);
a3 = (1 + 2) .^ (3 + 4);
+% comment
+
a = 2;
b = 3;
+% comment
+
m1 = 2^3 * 4;
m2 = a ^ 4 * 4;
m3 = a ^ b * 4;
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.m
index e1091f32dc..e715409a38 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.m
@@ -20,9 +20,13 @@ a2 = (1 + 2) ^ (3 + 4);
a3 = (1 + 2) .^ (3 + 4);
+% comment
+
a = 2;
b = 3;
+% comment
+
m1 = 2^3 * 4;
m2 = a^4 * 4;
m3 = a^b * 4;
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected_msgs.m
index 9eac175931..e3756491a9 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected_msgs.m
@@ -20,9 +20,13 @@ a2 = (1 + 2) ^ (3 + 4); % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-t
a3 = (1 + 2) .^ (3 + 4); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
a = 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
b = 3; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
m1 = 2^3 * 4; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
m2 = a^4 * 4; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
m3 = a^b * 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_align_assignments.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
index 8f140973bb..0093d1a725 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments.m
@@ -2,12 +2,32 @@
% Consecuitvie assignment alignment
+% t-utils-test-indent: no-line-by-line-indent - when we type line-by-line, we
don't see later
+% assignment values, thus to fully indent, need to
re-indent the file after
+% typing line-by-line.
+
a = 10;
-bLongVariable = [1, 2, 3];
+ bLongVariable = [1, 2, 3];
c = 5;
-dShort = [1, 2];
-x = a + bLongVariable + c + dShort;
+ dShort = [1, 2];
+x = a + bLongVariable + c + dShort;
+disp(x);
length = 5;
width = 10;
area=length*width;
+
+% other
+
+a = 1.234;
+ abc = [1, 2 , 5 ];
+abcdefg = [1, 2; 3, 44 ];
+x = 1;
+ f( a(x),1) = 10;
+g = foo(1,2,3);
+
+% some more
+
+x = 2;
+ y = 3;
+ z = x * y;
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.txt
index 99e6a35d11..11e41ad641 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.txt
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected.txt
@@ -1,34 +1,80 @@
# -*- t-utils-ts-parse-tree -*-
-(source_file<1,198> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,57]@{%
Consecuitvie assignment alignment}@)
- (assignment<59,65> left: (identifier[59,60]@{a}@) =[61,62] right:
(number[63,65]@{10}@))
- ;[65,66]
- (assignment<67,92> left: (identifier[67,80]@{bLongVariable}@) =[81,82]
+(source_file<1,657> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,57]@{%
Consecuitvie assignment alignment}@) (comment[59,294]@{% t-utils-test-indent:
no-line-by-line-indent - wh...}@)
+ (assignment<296,302> left: (identifier[296,297]@{a}@) =[298,299] right:
(number[300,302]@{10}@))
+ ;[302,303]
+ (assignment<308,333> left: (identifier[308,321]@{bLongVariable}@) =[322,323]
right:
- (matrix<83,92> [[83,84]
- (row<84,91> (number[84,85]@{1}@) ,[85,86] (number[87,88]@{2}@) ,[88,89]
(number[90,91]@{3}@))
- ][91,92]))
- ;[92,93]
- (assignment<94,99> left: (identifier[94,95]@{c}@) =[96,97] right:
(number[98,99]@{5}@))
- ;[99,100]
- (assignment<101,116> left: (identifier[101,107]@{dShort}@) =[108,109]
+ (matrix<324,333> [[324,325]
+ (row<325,332> (number[325,326]@{1}@) ,[326,327] (number[328,329]@{2}@)
,[329,330] (number[331,332]@{3}@))
+ ][332,333]))
+ ;[333,334]
+ (assignment<335,340> left: (identifier[335,336]@{c}@) =[337,338] right:
(number[339,340]@{5}@))
+ ;[340,341]
+ (assignment<349,364> left: (identifier[349,355]@{dShort}@) =[356,357]
right:
- (matrix<110,116> [[110,111]
- (row<111,115> (number[111,112]@{1}@) ,[112,113] (number[114,115]@{2}@))
- ][115,116]))
- ;[116,117]
- (assignment<118,152> left: (identifier[118,119]@{x}@) =[120,121]
+ (matrix<358,364> [[358,359]
+ (row<359,363> (number[359,360]@{1}@) ,[360,361] (number[362,363]@{2}@))
+ ][363,364]))
+ ;[364,365]
+ (assignment<366,412> left: (identifier[366,367]@{x}@) =[380,381]
right:
- (binary_operator<122,152>
+ (binary_operator<382,412>
left:
- (binary_operator<122,143>
- left: (binary_operator<122,139> left: (identifier[122,123]@{a}@)
+[124,125] right: (identifier[126,139]@{bLongVariable}@))
- +[140,141] right: (identifier[142,143]@{c}@))
- +[144,145] right: (identifier[146,152]@{dShort}@)))
- ;[152,153]
- (assignment<155,165> left: (identifier[155,161]@{length}@) =[162,163] right:
(number[164,165]@{5}@))
- ;[165,166]
- (assignment<167,177> left: (identifier[167,172]@{width}@) =[173,174] right:
(number[175,177]@{10}@))
- ;[177,178]
- (assignment<179,196> left: (identifier[179,183]@{area}@) =[183,184]
- right: (binary_operator<184,196> left: (identifier[184,190]@{length}@)
*[190,191] right: (identifier[191,196]@{width}@)))
- ;[196,197] \n[197,198])
+ (binary_operator<382,403>
+ left: (binary_operator<382,399> left: (identifier[382,383]@{a}@)
+[384,385] right: (identifier[386,399]@{bLongVariable}@))
+ +[400,401] right: (identifier[402,403]@{c}@))
+ +[404,405] right: (identifier[406,412]@{dShort}@)))
+ ;[412,413]
+ (function_call<414,421> name: (identifier[414,418]@{disp}@) ([418,419]
+ (arguments<419,420> argument: (identifier[419,420]@{x}@))
+ )[420,421])
+ ;[421,422]
+ (assignment<424,434> left: (identifier[424,430]@{length}@) =[431,432] right:
(number[433,434]@{5}@))
+ ;[434,435]
+ (assignment<436,446> left: (identifier[436,441]@{width}@) =[442,443] right:
(number[444,446]@{10}@))
+ ;[446,447]
+ (assignment<448,465> left: (identifier[448,452]@{area}@) =[452,453]
+ right: (binary_operator<453,465> left: (identifier[453,459]@{length}@)
*[459,460] right: (identifier[460,465]@{width}@)))
+ ;[465,466] (comment[468,475]@{% other}@)
+ (assignment<477,486> left: (identifier[477,478]@{a}@) =[479,480] right:
(number[481,486]@{1.234}@))
+ ;[486,487]
+ (assignment<500,521> left: (identifier[500,503]@{abc}@) =[504,505]
+ right:
+ (matrix<506,521> [[506,507]
+ (row<507,518> (number[507,508]@{1}@) ,[508,509] (number[510,511]@{2}@)
,[514,515] (number[517,518]@{5}@))
+ ][520,521]))
+ ;[521,522]
+ (assignment<523,547> left: (identifier[523,530]@{abcdefg}@) =[531,532]
+ right:
+ (matrix<533,547> [[533,534]
+ (row<534,538> (number[534,535]@{1}@) ,[535,536] (number[537,538]@{2}@))
+ (row<540,545> (number[540,541]@{3}@) ,[541,542] (number[543,545]@{44}@))
+ ][546,547]))
+ ;[547,548]
+ (assignment<549,554> left: (identifier[549,550]@{x}@) =[551,552] right:
(number[553,554]@{1}@))
+ ;[554,555]
+ (assignment<574,595>
+ left:
+ (function_call<574,590> name: (identifier[574,575]@{f}@) ([575,576]
+ (arguments<583,589>
+ argument:
+ (function_call<583,587> name: (identifier[583,584]@{a}@) ([584,585]
+ (arguments<585,586> argument: (identifier[585,586]@{x}@))
+ )[586,587])
+ ,[587,588] (number[588,589]@{1}@))
+ )[589,590])
+ =[591,592] right: (number[593,595]@{10}@))
+ ;[595,596]
+ (assignment<597,611> left: (identifier[597,598]@{g}@) =[599,600]
+ right:
+ (function_call<601,611> name: (identifier[601,604]@{foo}@) ([604,605]
+ (arguments<605,610> argument: (number[605,606]@{1}@) ,[606,607]
(number[607,608]@{2}@) ,[608,609] (number[609,610]@{3}@))
+ )[610,611]))
+ ;[611,612] (comment[614,625]@{% some more}@)
+ (assignment<627,632> left: (identifier[627,628]@{x}@) =[629,630] right:
(number[631,632]@{2}@))
+ ;[632,633]
+ (assignment<636,641> left: (identifier[636,637]@{y}@) =[638,639] right:
(number[640,641]@{3}@))
+ ;[641,642]
+ (assignment<646,655> left: (identifier[646,647]@{z}@) =[648,649]
+ right: (binary_operator<650,655> left: (identifier[650,651]@{x}@) *[652,653]
right: (identifier[654,655]@{y}@)))
+ ;[655,656] \n[656,657])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
index fdb3b0bade..55204cec9c 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
@@ -1,5 +1,7 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - alignment of assignments not
possible with line-by-line indent
+
% Calculate the Golden Ratio (phi)
phi= ( 1+ sqrt( 5))/ 2 ;
disp( [ 'Golden Ratio (phi): ', num2str( phi ) ] ); %
Display the value
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.txt
index 08edaae805..271dae11bc 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.txt
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example_expected.txt
@@ -1,103 +1,103 @@
# -*- t-utils-ts-parse-tree -*-
-(source_file<1,857> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,56]@{%
Calculate the Golden Ratio (phi)}@)
- (assignment<72,104> left: (identifier[72,75]@{phi}@) =[75,76]
+(source_file<1,969> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,132]@{%
t-utils-test-indent: no-line-by-line-indent - al...}@) (comment[134,168]@{%
Calculate the Golden Ratio (phi)}@)
+ (assignment<184,216> left: (identifier[184,187]@{phi}@) =[187,188]
right:
- (binary_operator<78,104>
+ (binary_operator<190,216>
left:
- (parenthesis<78,99> ([78,79]
- (binary_operator<84,98> left: (number[84,85]@{1}@) +[85,86]
+ (parenthesis<190,211> ([190,191]
+ (binary_operator<196,210> left: (number[196,197]@{1}@) +[197,198]
right:
- (function_call<87,98> name: (identifier[87,91]@{sqrt}@) ([91,92]
- (arguments<96,97> argument: (number[96,97]@{5}@))
- )[97,98]))
- )[98,99])
- /[99,100] right: (number[103,104]@{2}@)))
- ;[106,107]
- (function_call<113,177> name: (identifier[113,117]@{disp}@) ([117,118]
- (arguments<121,174>
+ (function_call<199,210> name: (identifier[199,203]@{sqrt}@) ([203,204]
+ (arguments<208,209> argument: (number[208,209]@{5}@))
+ )[209,210]))
+ )[210,211])
+ /[211,212] right: (number[215,216]@{2}@)))
+ ;[218,219]
+ (function_call<225,289> name: (identifier[225,229]@{disp}@) ([229,230]
+ (arguments<233,286>
argument:
- (matrix<121,174> [[121,122]
- (row<126,171>
- (string<126,148> '[126,127] (string_content[127,147]@{Golden Ratio
(phi): }@) '[147,148])
- ,[148,149]
- (function_call<157,171> name: (identifier[157,164]@{num2str}@) ([164,165]
- (arguments<166,169> argument: (identifier[166,169]@{phi}@))
- )[170,171]))
- ][173,174]))
- )[176,177])
- ;[177,178] (comment[185,204]@{% Display the value}@) (comment[209,275]@{%
Plot the exponential function with a Taylor Seri...}@)
- (assignment<279,310> left: (identifier[279,280]@{x}@) =[281,282]
+ (matrix<233,286> [[233,234]
+ (row<238,283>
+ (string<238,260> '[238,239] (string_content[239,259]@{Golden Ratio
(phi): }@) '[259,260])
+ ,[260,261]
+ (function_call<269,283> name: (identifier[269,276]@{num2str}@) ([276,277]
+ (arguments<278,281> argument: (identifier[278,281]@{phi}@))
+ )[282,283]))
+ ][285,286]))
+ )[288,289])
+ ;[289,290] (comment[297,316]@{% Display the value}@) (comment[321,387]@{%
Plot the exponential function with a Taylor Seri...}@)
+ (assignment<391,422> left: (identifier[391,392]@{x}@) =[393,394]
right:
- (range<284,310>
- (unary_operator<284,286> -[284,285] operand: (number[285,286]@{2}@))
- :[292,293] (number[296,299]@{0.1}@) :[302,303] (number[309,310]@{2}@)))
- ;[310,311]
- (assignment<314,332> left: (identifier[314,319]@{y_exp}@) =[319,320]
+ (range<396,422>
+ (unary_operator<396,398> -[396,397] operand: (number[397,398]@{2}@))
+ :[404,405] (number[408,411]@{0.1}@) :[414,415] (number[421,422]@{2}@)))
+ ;[422,423]
+ (assignment<426,444> left: (identifier[426,431]@{y_exp}@) =[431,432]
right:
- (function_call<320,332> name: (identifier[320,323]@{exp}@) ([323,324]
- (arguments<328,329> argument: (identifier[328,329]@{x}@))
- )[331,332]))
- ;[334,335]
- (assignment<342,388> left: (identifier[342,350]@{y_taylor}@) =[351,352]
+ (function_call<432,444> name: (identifier[432,435]@{exp}@) ([435,436]
+ (arguments<440,441> argument: (identifier[440,441]@{x}@))
+ )[443,444]))
+ ;[446,447]
+ (assignment<454,500> left: (identifier[454,462]@{y_taylor}@) =[463,464]
right:
- (binary_operator<353,388>
+ (binary_operator<465,500>
left:
- (binary_operator<353,376>
- left: (binary_operator<353,356> left: (number[353,354]@{1}@) +[354,355]
right: (identifier[355,356]@{x}@))
- +[360,361]
+ (binary_operator<465,488>
+ left: (binary_operator<465,468> left: (number[465,466]@{1}@) +[466,467]
right: (identifier[467,468]@{x}@))
+ +[472,473]
right:
- (binary_operator<363,376>
- left: (binary_operator<363,370> left: (identifier[363,364]@{x}@)
.^[364,366] right: (number[369,370]@{2}@))
- /[372,373] right: (number[375,376]@{2}@)))
- +[376,377]
+ (binary_operator<475,488>
+ left: (binary_operator<475,482> left: (identifier[475,476]@{x}@)
.^[476,478] right: (number[481,482]@{2}@))
+ /[484,485] right: (number[487,488]@{2}@)))
+ +[488,489]
right:
- (binary_operator<377,388>
- left: (binary_operator<377,381> left: (identifier[377,378]@{x}@)
.^[378,380] right: (number[380,381]@{3}@))
- /[386,387] right: (number[387,388]@{6}@))))
- ;[388,389] (comment[393,410]@{% First few terms}@) (comment[435,459]@{% Plot
the approximation}@)
- (command<463,476> (command_name[463,469]@{figure}@)
(command_argument[476,476]@{}@))
- ;[476,477] (comment[477,498]@{% Create a new figure}@)
- (function_call<502,549> name: (identifier[502,506]@{plot}@) ([506,507]
- (arguments<511,548> argument: (identifier[511,512]@{x}@) ,[512,513]
(identifier[513,518]@{y_exp}@) ,[518,519]
- (string<530,534> '[530,531] (string_content[531,533]@{b-}@) '[533,534])
- ,[534,535]
- (string<535,546> '[535,536] (string_content[536,545]@{LineWidth}@)
'[545,546])
- ,[546,547] (number[547,548]@{2}@))
- )[548,549])
- ;[549,550] (comment[557,586]@{% Plot the actual exponential}@)
- (command<591,598> (command_name[591,595]@{hold}@)
(command_argument[596,598]@{on}@))
- ;[601,602] (comment[602,625]@{% Keep the current plot}@)
- (function_call<628,698> name: (identifier[628,632]@{plot}@) ([632,633]
- (arguments<633,697> argument: (identifier[633,634]@{x}@) ,[634,635]
(identifier[636,644]@{y_taylor}@) ,[644,645]
(line_continuation[660,664]@{...\n}@)
- (string<671,676> '[671,672] (string_content[672,675]@{r--}@) '[675,676])
- ,[676,677] (line_continuation[677,681]@{...\n}@)
- (string<681,692> '[681,682] (string_content[682,691]@{LineWidth}@)
'[691,692])
- ,[692,693] (number[694,697]@{1.5}@))
- )[697,698])
- ;[698,699]
- (function_call<701,753> name: (identifier[701,706]@{title}@) ([706,707]
- (arguments<707,752>
- argument: (string<707,752> '[707,708] (string_content[708,751]@{Exponential
Function & Taylor Approximation}@) '[751,752]))
- )[752,753])
- ;[753,754]
- (function_call<759,773> name: (identifier[759,765]@{xlabel}@) ([765,766]
- (arguments<769,772>
- argument: (string<769,772> '[769,770] (string_content[770,771]@{x}@)
'[771,772]))
- )[772,773])
- ;[773,774]
- (function_call<775,786> name: (identifier[775,781]@{ylabel}@) ([781,782]
- (arguments<782,785>
- argument: (string<782,785> '[782,783] (string_content[783,784]@{y}@)
'[784,785]))
- )[785,786])
- ;[786,787]
- (function_call<791,829> name: (identifier[791,797]@{legend}@) ([797,798]
- (arguments<801,826>
- argument: (string<801,809> '[801,802] (string_content[802,808]@{exp(x)}@)
'[808,809])
- ,[809,810]
- (string<811,826> '[811,812] (string_content[812,825]@{Taylor Series}@)
'[825,826]))
- )[828,829])
- ;[829,830]
- (command<833,840> (command_name[833,837]@{grid}@)
(command_argument[838,840]@{on}@))
- ;[842,843]
- (command<845,853> (command_name[845,849]@{hold}@)
(command_argument[850,853]@{off}@))
- ;[855,856] \n[856,857])
+ (binary_operator<489,500>
+ left: (binary_operator<489,493> left: (identifier[489,490]@{x}@)
.^[490,492] right: (number[492,493]@{3}@))
+ /[498,499] right: (number[499,500]@{6}@))))
+ ;[500,501] (comment[505,522]@{% First few terms}@) (comment[547,571]@{% Plot
the approximation}@)
+ (command<575,588> (command_name[575,581]@{figure}@)
(command_argument[588,588]@{}@))
+ ;[588,589] (comment[589,610]@{% Create a new figure}@)
+ (function_call<614,661> name: (identifier[614,618]@{plot}@) ([618,619]
+ (arguments<623,660> argument: (identifier[623,624]@{x}@) ,[624,625]
(identifier[625,630]@{y_exp}@) ,[630,631]
+ (string<642,646> '[642,643] (string_content[643,645]@{b-}@) '[645,646])
+ ,[646,647]
+ (string<647,658> '[647,648] (string_content[648,657]@{LineWidth}@)
'[657,658])
+ ,[658,659] (number[659,660]@{2}@))
+ )[660,661])
+ ;[661,662] (comment[669,698]@{% Plot the actual exponential}@)
+ (command<703,710> (command_name[703,707]@{hold}@)
(command_argument[708,710]@{on}@))
+ ;[713,714] (comment[714,737]@{% Keep the current plot}@)
+ (function_call<740,810> name: (identifier[740,744]@{plot}@) ([744,745]
+ (arguments<745,809> argument: (identifier[745,746]@{x}@) ,[746,747]
(identifier[748,756]@{y_taylor}@) ,[756,757]
(line_continuation[772,776]@{...\n}@)
+ (string<783,788> '[783,784] (string_content[784,787]@{r--}@) '[787,788])
+ ,[788,789] (line_continuation[789,793]@{...\n}@)
+ (string<793,804> '[793,794] (string_content[794,803]@{LineWidth}@)
'[803,804])
+ ,[804,805] (number[806,809]@{1.5}@))
+ )[809,810])
+ ;[810,811]
+ (function_call<813,865> name: (identifier[813,818]@{title}@) ([818,819]
+ (arguments<819,864>
+ argument: (string<819,864> '[819,820] (string_content[820,863]@{Exponential
Function & Taylor Approximation}@) '[863,864]))
+ )[864,865])
+ ;[865,866]
+ (function_call<871,885> name: (identifier[871,877]@{xlabel}@) ([877,878]
+ (arguments<881,884>
+ argument: (string<881,884> '[881,882] (string_content[882,883]@{x}@)
'[883,884]))
+ )[884,885])
+ ;[885,886]
+ (function_call<887,898> name: (identifier[887,893]@{ylabel}@) ([893,894]
+ (arguments<894,897>
+ argument: (string<894,897> '[894,895] (string_content[895,896]@{y}@)
'[896,897]))
+ )[897,898])
+ ;[898,899]
+ (function_call<903,941> name: (identifier[903,909]@{legend}@) ([909,910]
+ (arguments<913,938>
+ argument: (string<913,921> '[913,914] (string_content[914,920]@{exp(x)}@)
'[920,921])
+ ,[921,922]
+ (string<923,938> '[923,924] (string_content[924,937]@{Taylor Series}@)
'[937,938]))
+ )[940,941])
+ ;[941,942]
+ (command<945,952> (command_name[945,949]@{grid}@)
(command_argument[950,952]@{on}@))
+ ;[954,955]
+ (command<957,965> (command_name[957,961]@{hold}@)
(command_argument[962,965]@{off}@))
+ ;[967,968] \n[968,969])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
index 1b3e006642..47ea4db9d2 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators.m
@@ -20,9 +20,13 @@ a2 = (1 + 2) ^ (3 + 4);
a3 = (1 + 2) .^ (3 + 4);
+% comment
+
a = 2;
b = 3;
+% comment
+
m1 = 2^3 * 4;
m2 = a ^ 4 * 4;
m3 = a ^ b * 4;
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.txt
index e39993a1af..2a1fc1a228 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.txt
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_operators_expected.txt
@@ -1,5 +1,5 @@
# -*- t-utils-ts-parse-tree -*-
-(source_file<1,734> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
+(source_file<1,756> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
(if_statement<22,96> if[22,24]
condition:
(boolean_operator<25,75>
@@ -131,99 +131,99 @@
(parenthesis<340,347> ([340,341]
(binary_operator<341,346> left: (number[341,342]@{3}@) +[343,344] right:
(number[345,346]@{4}@))
)[346,347])))
- ;[347,348]
- (assignment<350,355> left: (identifier[350,351]@{a}@) =[352,353] right:
(number[354,355]@{2}@))
- ;[355,356]
- (assignment<357,362> left: (identifier[357,358]@{b}@) =[359,360] right:
(number[361,362]@{3}@))
- ;[362,363]
- (assignment<365,377> left: (identifier[365,367]@{m1}@) =[368,369]
+ ;[347,348] (comment[350,359]@{% comment}@)
+ (assignment<361,366> left: (identifier[361,362]@{a}@) =[363,364] right:
(number[365,366]@{2}@))
+ ;[366,367]
+ (assignment<368,373> left: (identifier[368,369]@{b}@) =[370,371] right:
(number[372,373]@{3}@))
+ ;[373,374] (comment[376,385]@{% comment}@)
+ (assignment<387,399> left: (identifier[387,389]@{m1}@) =[390,391]
right:
- (binary_operator<370,377>
- left: (binary_operator<370,373> left: (number[370,371]@{2}@) ^[371,372]
right: (number[372,373]@{3}@))
- *[374,375] right: (number[376,377]@{4}@)))
- ;[377,378]
- (assignment<379,394> left: (identifier[379,381]@{m2}@) =[382,383]
+ (binary_operator<392,399>
+ left: (binary_operator<392,395> left: (number[392,393]@{2}@) ^[393,394]
right: (number[394,395]@{3}@))
+ *[396,397] right: (number[398,399]@{4}@)))
+ ;[399,400]
+ (assignment<401,416> left: (identifier[401,403]@{m2}@) =[404,405]
right:
- (binary_operator<384,394>
- left: (binary_operator<384,390> left: (identifier[384,385]@{a}@)
^[386,387] right: (number[389,390]@{4}@))
- *[391,392] right: (number[393,394]@{4}@)))
- ;[394,395]
- (assignment<396,411> left: (identifier[396,398]@{m3}@) =[399,400]
+ (binary_operator<406,416>
+ left: (binary_operator<406,412> left: (identifier[406,407]@{a}@)
^[408,409] right: (number[411,412]@{4}@))
+ *[413,414] right: (number[415,416]@{4}@)))
+ ;[416,417]
+ (assignment<418,433> left: (identifier[418,420]@{m3}@) =[421,422]
right:
- (binary_operator<401,411>
- left: (binary_operator<401,407> left: (identifier[401,402]@{a}@)
^[403,404] right: (identifier[406,407]@{b}@))
- *[408,409] right: (number[410,411]@{4}@)))
- ;[411,412]
- (assignment<413,429> left: (identifier[413,415]@{m4}@) =[416,417]
+ (binary_operator<423,433>
+ left: (binary_operator<423,429> left: (identifier[423,424]@{a}@)
^[425,426] right: (identifier[428,429]@{b}@))
+ *[430,431] right: (number[432,433]@{4}@)))
+ ;[433,434]
+ (assignment<435,451> left: (identifier[435,437]@{m4}@) =[438,439]
right:
- (binary_operator<418,429> left: (number[418,419]@{2}@) ^[420,421]
+ (binary_operator<440,451> left: (number[440,441]@{2}@) ^[442,443]
right:
- (parenthesis<422,429> ([422,423]
- (binary_operator<423,428> left: (number[423,424]@{3}@) *[425,426] right:
(number[427,428]@{4}@))
- )[428,429])))
- ;[429,430]
- (assignment<432,445> left: (identifier[432,434]@{m5}@) =[435,436]
+ (parenthesis<444,451> ([444,445]
+ (binary_operator<445,450> left: (number[445,446]@{3}@) *[447,448] right:
(number[449,450]@{4}@))
+ )[450,451])))
+ ;[451,452]
+ (assignment<454,467> left: (identifier[454,456]@{m5}@) =[457,458]
right:
- (binary_operator<437,445>
- left: (binary_operator<437,441> left: (number[437,439]@{2.}@) ^[439,440]
right: (number[440,441]@{3}@))
- *[442,443] right: (number[444,445]@{4}@)))
- ;[445,446]
- (assignment<447,463> left: (identifier[447,449]@{m6}@) =[450,451]
+ (binary_operator<459,467>
+ left: (binary_operator<459,463> left: (number[459,461]@{2.}@) ^[461,462]
right: (number[462,463]@{3}@))
+ *[464,465] right: (number[466,467]@{4}@)))
+ ;[467,468]
+ (assignment<469,485> left: (identifier[469,471]@{m6}@) =[472,473]
right:
- (binary_operator<452,463>
- left: (binary_operator<452,459> left: (identifier[452,453]@{a}@)
.^[454,456] right: (number[458,459]@{4}@))
- *[460,461] right: (number[462,463]@{4}@)))
- ;[463,464]
- (assignment<465,481> left: (identifier[465,467]@{m7}@) =[468,469]
+ (binary_operator<474,485>
+ left: (binary_operator<474,481> left: (identifier[474,475]@{a}@)
.^[476,478] right: (number[480,481]@{4}@))
+ *[482,483] right: (number[484,485]@{4}@)))
+ ;[485,486]
+ (assignment<487,503> left: (identifier[487,489]@{m7}@) =[490,491]
right:
- (binary_operator<470,481>
- left: (binary_operator<470,477> left: (identifier[470,471]@{a}@)
.^[472,474] right: (identifier[476,477]@{b}@))
- *[478,479] right: (number[480,481]@{4}@)))
- ;[481,482]
- (assignment<483,500> left: (identifier[483,485]@{m8}@) =[486,487]
+ (binary_operator<492,503>
+ left: (binary_operator<492,499> left: (identifier[492,493]@{a}@)
.^[494,496] right: (identifier[498,499]@{b}@))
+ *[500,501] right: (number[502,503]@{4}@)))
+ ;[503,504]
+ (assignment<505,522> left: (identifier[505,507]@{m8}@) =[508,509]
right:
- (binary_operator<488,500> left: (number[488,489]@{2}@) .^[490,492]
+ (binary_operator<510,522> left: (number[510,511]@{2}@) .^[512,514]
right:
- (parenthesis<493,500> ([493,494]
- (binary_operator<494,499> left: (number[494,495]@{3}@) *[496,497] right:
(number[498,499]@{4}@))
- )[499,500])))
- ;[500,501] \n[501,503]
- (function_definition<503,733> function[503,511] name:
(identifier[512,517]@{myBar}@)
- (function_arguments<517,531> ([517,518] arguments:
(identifier[518,519]@{x}@) ,[519,520] (identifier[520,521]@{y}@) ,[521,522]
(identifier[522,530]@{propArgs}@) )[530,531])
- \n[531,532]
- (arguments_statement<536,655> arguments[536,545] \n[545,546]
- (property<554,568> name: (identifier[554,555]@{x}@)
- (dimensions<556,561> ([556,557]
- (spread_operator<557,558> :[557,558])
- ,[558,559]
- (spread_operator<559,560> :[559,560])
- )[560,561])
- (identifier[562,568]@{double}@))
- \n[568,569]
- (property<577,591> name: (identifier[577,578]@{y}@)
- (dimensions<579,584> ([579,580]
- (spread_operator<580,581> :[580,581])
- ,[581,582]
- (spread_operator<582,583> :[582,583])
- )[583,584])
- (identifier[585,591]@{double}@))
- \n[591,592]
- (class_property<600,647> (identifier[600,608]@{propArgs}@) .?[609,611]
(identifier[612,618]@{matlab}@) .[618,619] (identifier[619,627]@{graphics}@)
.[627,628] (identifier[628,633]@{chart}@) .[633,634]
(identifier[634,643]@{primitive}@) .[643,644] (identifier[644,647]@{Bar}@))
- \n[647,648] end[652,655])
- (block<660,730>
- (assignment<660,699> left: (identifier[660,672]@{propertyCell}@) =[673,674]
+ (parenthesis<515,522> ([515,516]
+ (binary_operator<516,521> left: (number[516,517]@{3}@) *[518,519] right:
(number[520,521]@{4}@))
+ )[521,522])))
+ ;[522,523] \n[523,525]
+ (function_definition<525,755> function[525,533] name:
(identifier[534,539]@{myBar}@)
+ (function_arguments<539,553> ([539,540] arguments:
(identifier[540,541]@{x}@) ,[541,542] (identifier[542,543]@{y}@) ,[543,544]
(identifier[544,552]@{propArgs}@) )[552,553])
+ \n[553,554]
+ (arguments_statement<558,677> arguments[558,567] \n[567,568]
+ (property<576,590> name: (identifier[576,577]@{x}@)
+ (dimensions<578,583> ([578,579]
+ (spread_operator<579,580> :[579,580])
+ ,[580,581]
+ (spread_operator<581,582> :[581,582])
+ )[582,583])
+ (identifier[584,590]@{double}@))
+ \n[590,591]
+ (property<599,613> name: (identifier[599,600]@{y}@)
+ (dimensions<601,606> ([601,602]
+ (spread_operator<602,603> :[602,603])
+ ,[603,604]
+ (spread_operator<604,605> :[604,605])
+ )[605,606])
+ (identifier[607,613]@{double}@))
+ \n[613,614]
+ (class_property<622,669> (identifier[622,630]@{propArgs}@) .?[631,633]
(identifier[634,640]@{matlab}@) .[640,641] (identifier[641,649]@{graphics}@)
.[649,650] (identifier[650,655]@{chart}@) .[655,656]
(identifier[656,665]@{primitive}@) .[665,666] (identifier[666,669]@{Bar}@))
+ \n[669,670] end[674,677])
+ (block<682,752>
+ (assignment<682,721> left: (identifier[682,694]@{propertyCell}@) =[695,696]
right:
- (function_call<675,699> name: (identifier[675,689]@{namedargs2cell}@)
([689,690]
- (arguments<690,698> argument: (identifier[690,698]@{propArgs}@))
- )[698,699]))
- ;[699,700]
- (function_call<705,729> name: (identifier[705,708]@{bar}@) ([708,709]
- (arguments<709,728> argument: (identifier[709,710]@{x}@) ,[710,711]
(identifier[711,712]@{y}@) ,[712,713]
- (function_call<713,728> name: (identifier[713,725]@{propertyCell}@)
{[725,726]
- (arguments<726,727>
- argument: (spread_operator<726,727> :[726,727]))
- }[727,728]))
- )[728,729])
- \n[729,730])
- end[730,733])
- \n[733,734])
+ (function_call<697,721> name: (identifier[697,711]@{namedargs2cell}@)
([711,712]
+ (arguments<712,720> argument: (identifier[712,720]@{propArgs}@))
+ )[720,721]))
+ ;[721,722]
+ (function_call<727,751> name: (identifier[727,730]@{bar}@) ([730,731]
+ (arguments<731,750> argument: (identifier[731,732]@{x}@) ,[732,733]
(identifier[733,734]@{y}@) ,[734,735]
+ (function_call<735,750> name: (identifier[735,747]@{propertyCell}@)
{[747,748]
+ (arguments<748,749>
+ argument: (spread_operator<748,749> :[748,749]))
+ }[749,750]))
+ )[750,751])
+ \n[751,752])
+ end[752,755])
+ \n[755,756])