branch: externals/matlab-mode
commit 1a977380c22cb38b9c41ef263b31488d83d6e832
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: align of trailing comments
For example, running M-x indent-region on:
x = 1; % comment
foo = [1,2, 3, 4]; % comment
b = 3; % comment
now results in:
x = 1; % comment
foo = [1, 2, 3, 4]; % comment
b = 3; % comment
---
NEWS.org | 52 ++++-----
matlab-ts-mode.el | 129 ++++++++++++++++----
.../electric_indent_example.m | 8 +-
.../electric_indent_example_expected.m | 14 +--
.../electric_indent_example_expected_msgs.m | 14 +--
.../electric_indent_trailing_comments.m | 12 ++
.../electric_indent_trailing_comments_expected.m | 12 ++
...ectric_indent_trailing_comments_expected_msgs.m | 12 ++
.../electric_indent_example.m | 8 +-
.../electric_indent_example_expected.txt | 130 ++++++++++-----------
.../electric_indent_trailing_comments.m | 12 ++
.../electric_indent_trailing_comments_expected.txt | 30 +++++
12 files changed, 298 insertions(+), 135 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index f49bb30b4c..f0c8722887 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -18,14 +18,14 @@ For example, given:
% 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
+ yExp=exp( x ) ;
+ yTaylor = 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
+ plot( x,yExp, 'b-','LineWidth',2); % Plot the actual
exponential
hold on ;% Keep the current plot
- plot(x, y_taylor, ...
+ plot(x, yTaylor, ...
'r--',...
'LineWidth', 1.5);
title('Exponential Function & Taylor Approximation');
@@ -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;
+ yExp = exp(x);
+ yTaylor = 1 + x + x.^2 / 2 + x.^3 / 6; % First few terms
+
+ % Plot the approximation
+ figure; % Create a new figure
+ plot(x, yExp, 'b-', 'LineWidth', 2); % Plot the actual exponential
+ hold on; % Keep the current plot
+ plot(x, yTaylor, ...
+ '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 2e39c39b9a..9b0b067b07 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -3351,30 +3351,113 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(setq ei-info (list ei-line new-line-offset (nth 2 ei-info) (nth
3 ei-info)))))))))
ei-info)
+(defun matlab-ts-mode--ei-trailing-comment-offset (ei-info)
+ "Get trailing comment offset from first char current line?
+See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents.
+To simplify implementation, we require that the first \"%\" character in
+the line be the start of the trailing comment. Thus,
+ s = \"foo % bar\" % comment
+is not identified as a trailing comment and
+ s = \"foo bar\" %comment
+is identified as a trailing comment."
+ (when ei-info
+ (save-excursion
+ (beginning-of-line)
+ (when (re-search-forward "%" (line-end-position) t)
+ (let ((node (treesit-node-at (point))))
+ (when (equal (treesit-node-type node) "comment")
+ (let* ((new-line (nth 0 ei-info))
+ (offset (- (string-match-p "%" new-line) (string-match-p
"[^ \t]" new-line))))
+ (when (> offset 0)
+ ;; have trailing comment at offset from first char in new-line
+ offset))))))))
+
+(defvar-local matlab-ts-mode--ei-align-comment-alist nil)
+
+(defun matlab-ts-mode--ei-align-trailing-comments (ei-info)
+ "Align trailing comments in EI-INFO.
+See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents."
+ (let* ((line-comment-offset (matlab-ts-mode--ei-trailing-comment-offset
ei-info)))
+ (when line-comment-offset
+ (let* (comment-offset
+ line-nums
+ line-start-pt)
+
+ (when (or (not matlab-ts-mode--ei-align-comment-alist)
+ (not (setq comment-offset (alist-get (line-number-at-pos)
+
matlab-ts-mode--ei-align-comment-alist))))
+ (setq comment-offset line-comment-offset)
+ (setq line-nums `(,(line-number-at-pos)))
+ (save-excursion
+ (beginning-of-line)
+ (setq line-start-pt (point))
+
+ ;; Look backwards and then forwards for lines with trailing
comments
+ (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* ((ei-l-info (matlab-ts-mode--ei-get-new-line))
+ (l-offset (matlab-ts-mode--ei-trailing-comment-offset
ei-l-info)))
+ (if l-offset
+ (progn
+ (push (line-number-at-pos) line-nums)
+ (when (> l-offset comment-offset)
+ (setq comment-offset l-offset)))
+ (cl-return))))))
+
+ (when matlab-ts-mode--ei-align-comment-alist
+ (dolist (line-num line-nums)
+ (push `(,line-num . ,comment-offset)
matlab-ts-mode--ei-align-comment-alist))))
+
+ (let ((diff (- comment-offset line-comment-offset)))
+ (when (> diff 0)
+ (let* ((ei-line (nth 0 ei-info))
+ (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))
+
+(defun matlab-ts-mode--ei-align (ei-info)
+ "Align elements in EI-INFO.
+See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents."
+ (setq ei-info (matlab-ts-mode--ei-align-assignments ei-info))
+ (setq ei-info (matlab-ts-mode--ei-align-trailing-comments 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."
- ;; If line was indented (ei-line is not same as current line), then update
the buffer
- (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))))
+ ;; If line was indented (ei-line is not same as current line), then update
the buffer
+ (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 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."
@@ -3424,7 +3507,8 @@ line is updated. Returns t if line was updated."
(progn
;; Add invalid entry to matlab-ts-mode--ei-align-assign-alist as a
marker to activate
;; caching of computed offsets for assignment alignment.
- (setq-local matlab-ts-mode--ei-align-assign-alist '((-1 . 0)))
+ (setq-local matlab-ts-mode--ei-align-assign-alist '((-1 . 0))
+ matlab-ts-mode--ei-align-comment-alist '((-1 . 0)))
(save-excursion
(goto-char beg)
(while (<= curr-line end-line)
@@ -3439,7 +3523,8 @@ line is updated. Returns t if line was updated."
(forward-line end-line)
(setq end (point))))
- (setq-local matlab-ts-mode--ei-align-assign-alist nil)))
+ (setq-local matlab-ts-mode--ei-align-assign-alist nil
+ matlab-ts-mode--ei-align-comment-alist nil)))
(treesit-indent-region beg end)))
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 55204cec9c..8fbc86da18 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
@@ -8,14 +8,14 @@
% 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
+ yExp=exp( x ) ;
+ yTaylor = 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
+ plot( x,yExp, 'b-','LineWidth',2); % Plot the actual
exponential
hold on ;% Keep the current plot
- plot(x, y_taylor, ...
+ plot(x, yTaylor, ...
'r--',...
'LineWidth', 1.5);
title('Exponential Function & Taylor Approximation');
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 8b9d93fff8..a2ae5affcc 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
@@ -7,15 +7,15 @@ 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
+x = -2 : 0.1 : 2;
+yExp = exp(x);
+yTaylor = 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, ...
+figure; % Create a new figure
+plot(x, yExp, 'b-', 'LineWidth', 2); % Plot the actual exponential
+hold on; % Keep the current plot
+plot(x, yTaylor, ...
'r--', ...
'LineWidth', 1.5);
title('Exponential Function & Taylor 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 0bcf351b1b..cf966c39b5 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
@@ -7,15 +7,15 @@ phi = (1 + sqrt(5)) / 2; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-
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)}>
-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)}>
+x = -2 : 0.1 : 2; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+yExp = exp(x); % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+yTaylor = 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)}>
-figure; % Create a new figure % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-plot(x, y_exp, 'b-', 'LineWidth', 2); % Plot the actual exponential %
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-hold on; % Keep the current plot % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-plot(x, y_taylor, ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+figure; % Create a new figure % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+plot(x, yExp, 'b-', 'LineWidth', 2); % Plot the actual exponential %
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+hold on; % Keep the current plot % <{Matched
rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+plot(x, yTaylor, ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
'r--', ... % <{Matched rule: ((parent-is "\\`arguments\\'") parent 0)}>
'LineWidth', 1.5); % <{Matched rule: ((parent-is "\\`arguments\\'")
parent 0)}>
title('Exponential Function & Taylor 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_trailing_comments.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments.m
new file mode 100644
index 0000000000..4eb1771748
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - need all lines to align
trailing comments
+
+ x = 1; % comment
+ foo = [1, 2, 3, 4]; % comment
+ b = 3; % comment
+
+% separator comment
+
+ a(1,2) = [1, 2, 3]; % comment
+ b(1,2) = 1; % commnet
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.m
new file mode 100644
index 0000000000..1ffbd6c382
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - need all lines to align
trailing comments
+
+x = 1; % comment
+foo = [1, 2, 3, 4]; % comment
+b = 3; % comment
+
+% separator comment
+
+a(1, 2) = [1, 2, 3]; % comment
+b(1, 2) = 1; % commnet
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected_msgs.m
new file mode 100644
index 0000000000..0e6667d50d
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_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 - need all lines to align
trailing comments % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+x = 1; % comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+foo = [1, 2, 3, 4]; % comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+b = 3; % comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+% separator comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+a(1, 2) = [1, 2, 3]; % comment % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+b(1, 2) = 1; % commnet % <{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_example.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_example.m
index 55204cec9c..8fbc86da18 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
@@ -8,14 +8,14 @@
% 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
+ yExp=exp( x ) ;
+ yTaylor = 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
+ plot( x,yExp, 'b-','LineWidth',2); % Plot the actual
exponential
hold on ;% Keep the current plot
- plot(x, y_taylor, ...
+ plot(x, yTaylor, ...
'r--',...
'LineWidth', 1.5);
title('Exponential Function & Taylor Approximation');
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 271dae11bc..7225c64363 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,5 +1,5 @@
# -*- t-utils-ts-parse-tree -*-
-(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)}@)
+(source_file<1,965> (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<190,216>
@@ -32,72 +32,72 @@
(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]
+ (assignment<426,443> left: (identifier[426,430]@{yExp}@) =[430,431]
right:
- (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]
+ (function_call<431,443> name: (identifier[431,434]@{exp}@) ([434,435]
+ (arguments<439,440> argument: (identifier[439,440]@{x}@))
+ )[442,443]))
+ ;[445,446]
+ (assignment<453,498> left: (identifier[453,460]@{yTaylor}@) =[461,462]
right:
- (binary_operator<465,500>
+ (binary_operator<463,498>
left:
- (binary_operator<465,488>
- left: (binary_operator<465,468> left: (number[465,466]@{1}@) +[466,467]
right: (identifier[467,468]@{x}@))
- +[472,473]
+ (binary_operator<463,486>
+ left: (binary_operator<463,466> left: (number[463,464]@{1}@) +[464,465]
right: (identifier[465,466]@{x}@))
+ +[470,471]
right:
- (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]
+ (binary_operator<473,486>
+ left: (binary_operator<473,480> left: (identifier[473,474]@{x}@)
.^[474,476] right: (number[479,480]@{2}@))
+ /[482,483] right: (number[485,486]@{2}@)))
+ +[486,487]
right:
- (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])
+ (binary_operator<487,498>
+ left: (binary_operator<487,491> left: (identifier[487,488]@{x}@)
.^[488,490] right: (number[490,491]@{3}@))
+ /[496,497] right: (number[497,498]@{6}@))))
+ ;[498,499] (comment[503,520]@{% First few terms}@) (comment[545,569]@{% Plot
the approximation}@)
+ (command<573,586> (command_name[573,579]@{figure}@)
(command_argument[586,586]@{}@))
+ ;[586,587] (comment[587,608]@{% Create a new figure}@)
+ (function_call<612,658> name: (identifier[612,616]@{plot}@) ([616,617]
+ (arguments<621,657> argument: (identifier[621,622]@{x}@) ,[622,623]
(identifier[623,627]@{yExp}@) ,[627,628]
+ (string<639,643> '[639,640] (string_content[640,642]@{b-}@) '[642,643])
+ ,[643,644]
+ (string<644,655> '[644,645] (string_content[645,654]@{LineWidth}@)
'[654,655])
+ ,[655,656] (number[656,657]@{2}@))
+ )[657,658])
+ ;[658,659] (comment[666,695]@{% Plot the actual exponential}@)
+ (command<700,707> (command_name[700,704]@{hold}@)
(command_argument[705,707]@{on}@))
+ ;[710,711] (comment[711,734]@{% Keep the current plot}@)
+ (function_call<737,806> name: (identifier[737,741]@{plot}@) ([741,742]
+ (arguments<742,805> argument: (identifier[742,743]@{x}@) ,[743,744]
(identifier[745,752]@{yTaylor}@) ,[752,753]
(line_continuation[768,772]@{...\n}@)
+ (string<779,784> '[779,780] (string_content[780,783]@{r--}@) '[783,784])
+ ,[784,785] (line_continuation[785,789]@{...\n}@)
+ (string<789,800> '[789,790] (string_content[790,799]@{LineWidth}@)
'[799,800])
+ ,[800,801] (number[802,805]@{1.5}@))
+ )[805,806])
+ ;[806,807]
+ (function_call<809,861> name: (identifier[809,814]@{title}@) ([814,815]
+ (arguments<815,860>
+ argument: (string<815,860> '[815,816] (string_content[816,859]@{Exponential
Function & Taylor Approximation}@) '[859,860]))
+ )[860,861])
+ ;[861,862]
+ (function_call<867,881> name: (identifier[867,873]@{xlabel}@) ([873,874]
+ (arguments<877,880>
+ argument: (string<877,880> '[877,878] (string_content[878,879]@{x}@)
'[879,880]))
+ )[880,881])
+ ;[881,882]
+ (function_call<883,894> name: (identifier[883,889]@{ylabel}@) ([889,890]
+ (arguments<890,893>
+ argument: (string<890,893> '[890,891] (string_content[891,892]@{y}@)
'[892,893]))
+ )[893,894])
+ ;[894,895]
+ (function_call<899,937> name: (identifier[899,905]@{legend}@) ([905,906]
+ (arguments<909,934>
+ argument: (string<909,917> '[909,910] (string_content[910,916]@{exp(x)}@)
'[916,917])
+ ,[917,918]
+ (string<919,934> '[919,920] (string_content[920,933]@{Taylor Series}@)
'[933,934]))
+ )[936,937])
+ ;[937,938]
+ (command<941,948> (command_name[941,945]@{grid}@)
(command_argument[946,948]@{on}@))
+ ;[950,951]
+ (command<953,961> (command_name[953,957]@{hold}@)
(command_argument[958,961]@{off}@))
+ ;[963,964] \n[964,965])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments.m
new file mode 100644
index 0000000000..4eb1771748
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - need all lines to align
trailing comments
+
+ x = 1; % comment
+ foo = [1, 2, 3, 4]; % comment
+ b = 3; % comment
+
+% separator comment
+
+ a(1,2) = [1, 2, 3]; % comment
+ b(1,2) = 1; % commnet
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.txt
new file mode 100644
index 0000000000..24bc4fb910
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_expected.txt
@@ -0,0 +1,30 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,270> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,111]@{%
t-utils-test-indent: no-line-by-line-indent - ne...}@)
+ (assignment<116,121> left: (identifier[116,117]@{x}@) =[118,119] right:
(number[120,121]@{1}@))
+ ;[121,122] (comment[123,132]@{% comment}@)
+ (assignment<135,153> left: (identifier[135,138]@{foo}@) =[139,140]
+ right:
+ (matrix<141,153> [[141,142]
+ (row<142,152> (number[142,143]@{1}@) ,[143,144] (number[145,146]@{2}@)
,[146,147] (number[148,149]@{3}@) ,[149,150] (number[151,152]@{4}@))
+ ][152,153]))
+ ;[153,154] (comment[155,164]@{% comment}@)
+ (assignment<174,179> left: (identifier[174,175]@{b}@) =[176,177] right:
(number[178,179]@{3}@))
+ ;[179,180] (comment[181,190]@{% comment}@) (comment[192,211]@{% separator
comment}@)
+ (assignment<215,233>
+ left:
+ (function_call<215,221> name: (identifier[215,216]@{a}@) ([216,217]
+ (arguments<217,220> argument: (number[217,218]@{1}@) ,[218,219]
(number[219,220]@{2}@))
+ )[220,221])
+ =[222,223]
+ right:
+ (matrix<224,233> [[224,225]
+ (row<225,232> (number[225,226]@{1}@) ,[226,227] (number[228,229]@{2}@)
,[229,230] (number[231,232]@{3}@))
+ ][232,233]))
+ ;[233,234] (comment[235,244]@{% comment}@)
+ (assignment<248,258>
+ left:
+ (function_call<248,254> name: (identifier[248,249]@{b}@) ([249,250]
+ (arguments<250,253> argument: (number[250,251]@{1}@) ,[251,252]
(number[252,253]@{2}@))
+ )[253,254])
+ =[255,256] right: (number[257,258]@{1}@))
+ ;[258,259] (comment[260,269]@{% commnet}@) \n[269,270])