branch: externals/matlab-mode
commit 043863bbc96dee1f8056a29db8e241aa544b6ccb
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: add electric indent property and argument alignment
---
matlab-ts-mode--ei.el | 125 ++++++++++++++++++---
matlab-ts-mode.el | 17 ++-
.../electric_indent_arguments.m | 18 +--
.../electric_indent_arguments_expected.m | 14 ++-
.../electric_indent_arguments_expected_msgs.m | 14 ++-
.../electric_indent_class_properties.m | 14 +++
.../electric_indent_class_properties_expected.m | 14 +++
...lectric_indent_class_properties_expected_msgs.m | 14 +++
.../electric_indent_prop.m | 3 +
.../electric_indent_prop_expected.m | 5 +-
.../electric_indent_prop_expected_msgs.m | 5 +-
.../electric_indent_arguments.m | 18 +--
.../electric_indent_arguments_expected.txt | 62 +++++-----
.../electric_indent_class_properties.m | 14 +++
.../electric_indent_class_properties_expected.txt | 20 ++++
.../electric_indent_prop.m | 3 +
.../electric_indent_prop_expected.txt | 58 +++++-----
17 files changed, 311 insertions(+), 107 deletions(-)
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 35ec7d2007..4e2640783e 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -5,7 +5,7 @@
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Author: John Ciolfi <[email protected]>
-;; Created: Jul-7-2025
+;; Created: Dec-29-2025
;; Keywords: MATLAB
;; Copyright (C) 2025-2026 Free Software Foundation, Inc.
@@ -25,7 +25,7 @@
;;; Commentary:
;;
-;; Electric indent for matlab-ts-mode
+;; Electric indent for matlab-ts-mode, see `matlab-ts-mode-electric-indent'
custom variable.
;;; Code:
@@ -42,7 +42,7 @@
(defcustom matlab-ts-mode-electric-indent t
"*If t, indent (format) language elements within code.
-- Canonicalize language elements spacing
+- Canonicalize language element spacing
Example | Result
----------------------------- | -----------------------------
a = b+ c *d ; | a = b + c * d;
@@ -66,11 +66,16 @@
m = [2,4000 | m = [ 2, 4000
3000,1] | 3000, 1]
-- Align properties
- Example:
- TODO
- is indented as:
- TODO"
+- Align properties and arguments
+ Example | Result
+ ----------------------------- | -----------------------------
+ classdef c1 | classdef c1
+ properties | properties
+ foo (1,3) | foo (1,3)
+ foobar (1,1) | foobar (1,1)
+ p1 (1,1) | p1 (1,1)
+ end | end
+ end | end"
:type 'boolean)
(defvar matlab-ts-mode--electric-indent-verbose nil)
@@ -450,7 +455,7 @@ or nil."
(when matlab-ts-mode--electric-indent-assert
(setq line-node-types (matlab-ts-mode--ei-update-line-node-types
line-node-types
- node
node-type)))
+
node node-type)))
(when (not n-spaces-between)
(cl-loop for tuple in matlab-ts-mode--ei-spacing do
@@ -612,7 +617,7 @@ Point is left at beginning of line containing the
ASSIGN-NODE text."
n-levels)
(with-current-buffer (treesit-node-buffer assign-node)
(let* ((assign-start-pos (save-excursion (goto-char (treesit-node-start
assign-node))
- (line-beginning-position)))
+ (line-beginning-position)))
(assign-end-pos (save-excursion (goto-char (treesit-node-end
assign-node))
(line-end-position)))
(indent-spaces (- (treesit-node-start assign-node)
assign-start-pos)))
@@ -900,16 +905,96 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(when (> diff 0)
(let* ((loc (1- (string-match "=" ei-line)))
(new-pt-offset (let ((pt-offset (nth 1 ei-info)))
- (when pt-offset
- (if (<= loc pt-offset)
- (+ pt-offset diff)
- pt-offset)))))
+ (when pt-offset
+ (if (<= loc pt-offset)
+ (+ pt-offset diff)
+ pt-offset)))))
(setq ei-line (concat (substring ei-line 0 loc)
(make-string diff ? )
(substring ei-line loc)))
(setq ei-info (list ei-line new-pt-offset (nth 2 ei-info) (nth 3
ei-info)))))))))
ei-info)
+(defun matlab-ts-mode--ei-get-prop-node (ei-info)
+ "Return property or argument node for first node in EI-INFO.
+Returns nil if not a property or argument node."
+ (let* ((first-node-in-line (nth 3 ei-info))
+ (parent (when first-node-in-line (treesit-node-parent
first-node-in-line)))
+ (prop-node (pcase (treesit-node-type parent)
+ ("property"
+ first-node-in-line)
+ ("property_name"
+ parent))))
+ ;; properties / arguments can span multiple lines, so skip these
+ (when (= (line-number-at-pos (treesit-node-start prop-node))
+ (line-number-at-pos (treesit-node-end prop-node)))
+ prop-node)))
+
+(defun matlab-ts-mode--ei-prop-length (ei-info)
+ "Get the property length from the electric indented line in EI-INFO."
+ ;; We need to use the ei-line and not the current content of the buffer
because the ei-line could
+ ;; have been adjusted. Example:
+ ;; arguments
+ ;; nameValueArgs . foo ( 1,1)
+ ;; end
+ ;; becomes "nameValueArgs.foo (1,1)" in EI-LINE.
+ (let ((ei-line (nth 0 ei-info)))
+ (when (not (string-match "[^ \t]+" ei-line))
+ (error "Assert: no property in ei-line %s" ei-line))
+ (- (match-end 0) (match-beginning 0))))
+
+;; This is used to cache aligned properties/arguments for indent-region, and
contains
+;; '(linenum . prop-length) entries.
+(defvar-local matlab-ts-mode--ei-align-prop-alist nil)
+
+(defun matlab-ts-mode--ei-align-properties (ei-info)
+ "Align properties and arguments in EI-INFO.
+See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents."
+ (when (matlab-ts-mode--ei-get-prop-node ei-info)
+ (let ((ei-info-p-length (matlab-ts-mode--ei-prop-length ei-info))
+ (p-length (when matlab-ts-mode--ei-align-prop-alist
+ (alist-get (line-number-at-pos)
matlab-ts-mode--ei-align-prop-alist))))
+ (when (not p-length)
+ (save-excursion
+ (beginning-of-line)
+ (let* ((line-nums `(,(line-number-at-pos)))
+ (line-start-pt (point)))
+
+ (setq p-length ei-info-p-length)
+
+ ;; Look backwards and then forwards for properties/arguments
+ (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-ei-info (matlab-ts-mode--ei-get-new-line)))
+ (if (matlab-ts-mode--ei-get-prop-node l-ei-info)
+ (let ((l-p-length (matlab-ts-mode--ei-prop-length
l-ei-info)))
+ (when matlab-ts-mode--ei-align-prop-alist
+ (push (line-number-at-pos) line-nums))
+ (when (> l-p-length p-length)
+ (setq p-length l-p-length)))
+ (cl-return)))))
+
+ (when matlab-ts-mode--ei-align-prop-alist
+ (dolist (line-num line-nums)
+ (push `(,line-num . ,p-length)
matlab-ts-mode--ei-align-prop-alist))))))
+
+ (when (not (= p-length ei-info-p-length))
+ (let* ((diff (- p-length ei-info-p-length))
+ (ei-line (nth 0 ei-info))
+ (p-end (when (string-match "\\([^ \t]+\\)[ \t]+[^ \t;]" ei-line)
+ (match-end 1))))
+ (when p-end
+ (setq ei-line (concat (substring ei-line 0 p-end)
+ (make-string diff ? )
+ (substring ei-line p-end)))
+ (setq ei-info (cons ei-line (cdr 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.
@@ -977,10 +1062,10 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(let* ((ei-line (nth 0 ei-info))
(loc (1- (string-match "%" ei-line)))
(new-pt-offset (let ((pt-offset (nth 1 ei-info)))
- (when pt-offset
- (if (<= loc pt-offset)
- (+ pt-offset diff)
- pt-offset)))))
+ (when pt-offset
+ (if (<= loc pt-offset)
+ (+ pt-offset diff)
+ pt-offset)))))
(setq ei-line (concat (substring ei-line 0 loc)
(make-string diff ? )
(substring ei-line loc)))
@@ -995,6 +1080,7 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(setq ei-info (matlab-ts-mode--ei-align-line-in-m-matrix matrix-node
ei-info)))
;; else do single-line alignments
(setq ei-info (matlab-ts-mode--ei-align-assignments ei-info))
+ (setq ei-info (matlab-ts-mode--ei-align-properties ei-info))
(setq ei-info (matlab-ts-mode--ei-align-trailing-comments ei-info)))
ei-info)
@@ -1026,3 +1112,6 @@ line is updated. Returns t if line was updated."
(provide 'matlab-ts-mode--ei)
;;; matlab-ts-mode--ei.el ends here
+
+;; LocalWords: SPDX gmail treesit defcustom bos eos isstring defun eol eobp
setq curr cdr xr progn
+;; LocalWords: listp alist dolist setf tmp buf utils linenum nums bobp pcase
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index b6ffe597e9..534bd12c1b 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1057,7 +1057,7 @@ Example, disp variable is overriding the disp builtin
function:
;; } ...
;; }
;;
-;;
+;;
;; 5. Canonicalize language elements spacing.
;; [Implemented in the indent engine]
;;
@@ -1175,8 +1175,17 @@ Example, disp variable is overriding the disp builtin
function:
;; length = 10;
;; area = width * length;
;;
-;; 10. Align properties
-;; TODO
+;; 10. Align properties and arguments
+;; [Implemented in the indent engine]
+;;
+;; Example:
+;; classdef c1
+;; properties
+;; foo (1,3)
+;; foobar (1,1)
+;; x {mustBeReal}
+;; end
+;; end
;;
;; 11. Align consecutive trailing comments
;; [Implemented in the indent engine]
@@ -2915,6 +2924,7 @@ Example:
;; 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))
+ matlab-ts-mode--ei-align-prop-alist '((-1 . 0))
matlab-ts-mode--ei-align-comment-alist '((-1 . 0))
matlab-ts-mode--ei-align-matrix-alist '((-1 . "")))
(save-excursion
@@ -2935,6 +2945,7 @@ Example:
(treesit-indent-region beg end))
(progn
(setq-local matlab-ts-mode--ei-align-assign-alist nil
+ matlab-ts-mode--ei-align-prop-alist nil
matlab-ts-mode--ei-align-comment-alist nil
matlab-ts-mode--ei-align-matrix-alist nil))))
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
index a48509c09f..99136a8b37 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
@@ -1,13 +1,17 @@
% -*- matlab-ts -*-
-function electric_indent_arguments(in1, in2, varargin)
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
+function electric_indent_arguments(a, param2, varargin)
arguments
- in1 {mustBeNumeric, mustBeReal, mustBeFinite}
- in2 {mustBeNumeric, mustBeReal, mustBeFinite}
+ a {mustBeNumeric, mustBeReal, mustBeFinite}
+ param2 {mustBeNumeric, mustBeReal, mustBeFinite}
end
- arguments (Repeating)
- varargin
+ arguments (Repeating)
+ varargin
end
- disp(in1);
- disp(in2);
+ disp(a);
+ disp(param2);
disp(varargin);
end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.m
index 4e48275e41..b42b7624a6 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.m
@@ -1,13 +1,17 @@
% -*- matlab-ts -*-
-function electric_indent_arguments(in1, in2, varargin)
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
+function electric_indent_arguments(a, param2, varargin)
arguments
- in1 {mustBeNumeric, mustBeReal, mustBeFinite}
- in2 {mustBeNumeric, mustBeReal, mustBeFinite}
+ a {mustBeNumeric, mustBeReal, mustBeFinite}
+ param2 {mustBeNumeric, mustBeReal, mustBeFinite}
end
arguments (Repeating)
varargin
end
- disp(in1);
- disp(in2);
+ disp(a);
+ disp(param2);
disp(varargin);
end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected_msgs.m
index ffbc9fc8dd..ba4e91628f 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected_msgs.m
@@ -1,13 +1,17 @@
% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-function electric_indent_arguments(in1, in2, varargin) % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% arguments because we don't have them all. % <{Matched rule:
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+
+function electric_indent_arguments(a, param2, varargin) % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
arguments % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
- in1 {mustBeNumeric, mustBeReal, mustBeFinite} % <{Matched rule:
((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
- in2 {mustBeNumeric, mustBeReal, mustBeFinite} % <{Matched rule:
((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ a {mustBeNumeric, mustBeReal, mustBeFinite} % <{Matched rule:
((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ param2 {mustBeNumeric, mustBeReal, mustBeFinite} % <{Matched rule:
((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
arguments (Repeating) % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
varargin % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
- disp(in1); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
- disp(in2); % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+ disp(a); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+ disp(param2); % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
disp(varargin); % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
new file mode 100644
index 0000000000..27efdd0a3e
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
@@ -0,0 +1,14 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% properties because we don't have them all.
+
+classdef electric_indent_class_properties
+ properties
+ foo(1,3)
+ foobar (1, 1)
+ p1 ( 1, 1)
+ x { mustBeReal}
+ y;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.m
new file mode 100644
index 0000000000..7ab0d57a23
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.m
@@ -0,0 +1,14 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% properties because we don't have them all.
+
+classdef electric_indent_class_properties
+ properties
+ foo (1,3)
+ foobar (1,1)
+ p1 (1,1)
+ x {mustBeReal}
+ y;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected_msgs.m
new file mode 100644
index 0000000000..e19de80d3a
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected_msgs.m
@@ -0,0 +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 - when typing line-by-line we
can't align the % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% properties because we don't have them all. % <{Matched rule:
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+
+classdef electric_indent_class_properties % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+ properties % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ foo (1,3) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ foobar (1,1) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ p1 (1,1) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ x {mustBeReal} % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ y; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
index 83082c0c6f..52efabb222 100644
--- a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
+++ b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
@@ -1,5 +1,8 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
function s= electric_indent_prop( s , NameValues)
arguments
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.m
index 825a0cced1..ffc3d1defb 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.m
@@ -1,9 +1,12 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
function s = electric_indent_prop(s, NameValues)
arguments
- s (1,1) double
+ s (1,1) double
NameValues.Rename (1,1) matlab.lang.OnOffSwitchState = "on"
end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected_msgs.m
index bd5001ddad..34cb477dd8 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected_msgs.m
@@ -1,9 +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 - when typing line-by-line we
can't align the % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+% arguments because we don't have them all. % <{Matched rule:
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+
function s = electric_indent_prop(s, NameValues) % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
arguments % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
- s (1,1) double % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ s (1,1) double % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
NameValues.Rename (1,1) matlab.lang.OnOffSwitchState = "on" %
<{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
index a48509c09f..99136a8b37 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments.m
@@ -1,13 +1,17 @@
% -*- matlab-ts -*-
-function electric_indent_arguments(in1, in2, varargin)
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
+function electric_indent_arguments(a, param2, varargin)
arguments
- in1 {mustBeNumeric, mustBeReal, mustBeFinite}
- in2 {mustBeNumeric, mustBeReal, mustBeFinite}
+ a {mustBeNumeric, mustBeReal, mustBeFinite}
+ param2 {mustBeNumeric, mustBeReal, mustBeFinite}
end
- arguments (Repeating)
- varargin
+ arguments (Repeating)
+ varargin
end
- disp(in1);
- disp(in2);
+ disp(a);
+ disp(param2);
disp(varargin);
end
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.txt
index 8595b624e3..1e4417092f 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.txt
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected.txt
@@ -1,32 +1,32 @@
# -*- t-utils-ts-parse-tree -*-
-(source_file<1,318> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,21]
- (function_definition<21,317> function[21,29] name:
(identifier[30,55]@{electric_indent_arguments}@)
- (function_arguments<55,75> ([55,56] arguments: (identifier[56,59]@{in1}@)
,[59,60] (identifier[61,64]@{in2}@) ,[64,65] (identifier[66,74]@{varargin}@)
)[74,75])
- \n[75,76]
- (arguments_statement<80,206> arguments[80,89] \n[89,90]
- (property<98,143> name: (identifier[98,101]@{in1}@)
- (validation_functions<102,143> {[102,103]
(identifier[103,116]@{mustBeNumeric}@) ,[116,117]
(identifier[118,128]@{mustBeReal}@) ,[128,129]
(identifier[130,142]@{mustBeFinite}@) }[142,143]))
- \n[143,144]
- (property<152,197> name: (identifier[152,155]@{in2}@)
- (validation_functions<156,197> {[156,157]
(identifier[157,170]@{mustBeNumeric}@) ,[170,171]
(identifier[172,182]@{mustBeReal}@) ,[182,183]
(identifier[184,196]@{mustBeFinite}@) }[196,197]))
- \n[197,198] end[202,205] \n[205,206])
- (arguments_statement<213,263> arguments[213,222]
- (attributes<227,238> ([227,228] argument:
(identifier[228,237]@{Repeating}@) )[237,238])
- \n[238,239]
- (property<247,255> name: (identifier[247,255]@{varargin}@))
- \n[255,256] end[260,263])
- (block<268,314>
- (function_call<268,277> name: (identifier[268,272]@{disp}@) ([272,273]
- (arguments<273,276> argument: (identifier[273,276]@{in1}@))
- )[276,277])
- ;[277,278]
- (function_call<283,292> name: (identifier[283,287]@{disp}@) ([287,288]
- (arguments<288,291> argument: (identifier[288,291]@{in2}@))
- )[291,292])
- ;[292,293]
- (function_call<298,312> name: (identifier[298,302]@{disp}@) ([302,303]
- (arguments<303,311> argument: (identifier[303,311]@{varargin}@))
- )[311,312])
- ;[312,313] \n[313,314])
- end[314,317])
- \n[317,318])
+(source_file<1,449> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,157]@{%
t-utils-test-indent: no-line-by-line-indent - wh...}@) \n[157,159]
+ (function_definition<159,448> function[159,167] name:
(identifier[168,193]@{electric_indent_arguments}@)
+ (function_arguments<193,214> ([193,194] arguments:
(identifier[194,195]@{a}@) ,[195,196] (identifier[197,203]@{param2}@)
,[203,204] (identifier[205,213]@{varargin}@) )[213,214])
+ \n[214,215]
+ (arguments_statement<219,346> arguments[219,228] \n[228,229]
+ (property<237,280> name: (identifier[237,238]@{a}@)
+ (validation_functions<239,280> {[239,240]
(identifier[240,253]@{mustBeNumeric}@) ,[253,254]
(identifier[255,265]@{mustBeReal}@) ,[265,266]
(identifier[267,279]@{mustBeFinite}@) }[279,280]))
+ \n[280,281]
+ (property<289,337> name: (identifier[289,295]@{param2}@)
+ (validation_functions<296,337> {[296,297]
(identifier[297,310]@{mustBeNumeric}@) ,[310,311]
(identifier[312,322]@{mustBeReal}@) ,[322,323]
(identifier[324,336]@{mustBeFinite}@) }[336,337]))
+ \n[337,338] end[342,345] \n[345,346])
+ (arguments_statement<350,393> arguments[350,359]
+ (attributes<360,371> ([360,361] argument:
(identifier[361,370]@{Repeating}@) )[370,371])
+ \n[371,372]
+ (property<377,385> name: (identifier[377,385]@{varargin}@))
+ \n[385,386] end[390,393])
+ (block<398,445>
+ (function_call<398,405> name: (identifier[398,402]@{disp}@) ([402,403]
+ (arguments<403,404> argument: (identifier[403,404]@{a}@))
+ )[404,405])
+ ;[405,406]
+ (function_call<411,423> name: (identifier[411,415]@{disp}@) ([415,416]
+ (arguments<416,422> argument: (identifier[416,422]@{param2}@))
+ )[422,423])
+ ;[423,424]
+ (function_call<429,443> name: (identifier[429,433]@{disp}@) ([433,434]
+ (arguments<434,442> argument: (identifier[434,442]@{varargin}@))
+ )[442,443])
+ ;[443,444] \n[444,445])
+ end[445,448])
+ \n[448,449])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
new file mode 100644
index 0000000000..27efdd0a3e
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties.m
@@ -0,0 +1,14 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% properties because we don't have them all.
+
+classdef electric_indent_class_properties
+ properties
+ foo(1,3)
+ foobar (1, 1)
+ p1 ( 1, 1)
+ x { mustBeReal}
+ y;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.txt
new file mode 100644
index 0000000000..3ac3fcf6a9
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_class_properties_expected.txt
@@ -0,0 +1,20 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,328> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,158]@{%
t-utils-test-indent: no-line-by-line-indent - wh...}@) \n[158,160]
+ (class_definition<160,327> classdef[160,168] name:
(identifier[169,201]@{electric_indent_class_properties}@) \n[201,202]
+ (properties<206,323> properties[206,216] \n[216,217]
+ (property<225,233> name: (identifier[225,228]@{foo}@)
+ (dimensions<228,233> ([228,229] (number[229,230]@{1}@) ,[230,231]
(number[231,232]@{3}@) )[232,233]))
+ \n[233,234]
+ (property<242,258> name: (identifier[242,248]@{foobar}@)
+ (dimensions<252,258> ([252,253] (number[253,254]@{1}@) ,[254,255]
(number[256,257]@{1}@) )[257,258]))
+ \n[258,259]
+ (property<267,278> name: (identifier[267,269]@{p1}@)
+ (dimensions<271,278> ([271,272] (number[273,274]@{1}@) ,[274,275]
(number[276,277]@{1}@) )[277,278]))
+ \n[278,279]
+ (property<287,304> name: (identifier[287,288]@{x}@)
+ (validation_functions<290,304> {[290,291]
(identifier[293,303]@{mustBeReal}@) }[303,304]))
+ \n[304,305]
+ (property<313,314> name: (identifier[313,314]@{y}@))
+ ;[314,315] \n[315,316] end[320,323])
+ \n[323,324] end[324,327])
+ \n[327,328])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
index 83082c0c6f..52efabb222 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop.m
@@ -1,5 +1,8 @@
% -*- matlab-ts -*-
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we
can't align the
+% arguments because we don't have them all.
+
function s= electric_indent_prop( s , NameValues)
arguments
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.txt
index b9aec00d91..301cd61af6 100644
---
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.txt
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_prop_expected.txt
@@ -1,31 +1,31 @@
# -*- t-utils-ts-parse-tree -*-
-(source_file<1,240> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
- (function_definition<22,239> function[22,30]
- (function_output<31,33> (identifier[31,32]@{s}@) =[32,33])
- name: (identifier[34,54]@{electric_indent_prop}@)
- (function_arguments<54,73> ([54,55] arguments: (identifier[57,58]@{s}@)
,[60,61] (identifier[62,72]@{NameValues}@) )[72,73])
- \n[73,75]
- (arguments_statement<79,195> arguments[79,88] \n[88,89]
- (property<97,112> name: (identifier[97,98]@{s}@)
- (dimensions<99,105> ([99,100] (number[100,101]@{1}@) ,[101,102]
(number[103,104]@{1}@) )[104,105])
- (identifier[106,112]@{double}@))
- \n[112,113]
- (property<121,187>
- name: (property_name<121,141> (identifier[121,131]@{NameValues}@)
.[131,132] (identifier[135,141]@{Rename}@))
- (dimensions<141,147> ([141,142] (number[142,143]@{1}@) ,[143,144]
(number[145,146]@{1}@) )[146,147])
- (property_name<148,176> (identifier[148,154]@{matlab}@) .[154,155]
(identifier[155,159]@{lang}@) .[159,160]
(identifier[160,176]@{OnOffSwitchState}@))
- (default_value<177,187> =[177,178]
- (string<183,187> "[183,184] (string_content[184,186]@{on}@) "[186,187])))
- \n[187,188] end[192,195])
- (block<201,236>
- (assignment<201,234> left: (identifier[201,202]@{s}@) =[203,204]
+(source_file<1,377> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,157]@{%
t-utils-test-indent: no-line-by-line-indent - wh...}@) \n[157,159]
+ (function_definition<159,376> function[159,167]
+ (function_output<168,170> (identifier[168,169]@{s}@) =[169,170])
+ name: (identifier[171,191]@{electric_indent_prop}@)
+ (function_arguments<191,210> ([191,192] arguments:
(identifier[194,195]@{s}@) ,[197,198] (identifier[199,209]@{NameValues}@)
)[209,210])
+ \n[210,212]
+ (arguments_statement<216,332> arguments[216,225] \n[225,226]
+ (property<234,249> name: (identifier[234,235]@{s}@)
+ (dimensions<236,242> ([236,237] (number[237,238]@{1}@) ,[238,239]
(number[240,241]@{1}@) )[241,242])
+ (identifier[243,249]@{double}@))
+ \n[249,250]
+ (property<258,324>
+ name: (property_name<258,278> (identifier[258,268]@{NameValues}@)
.[268,269] (identifier[272,278]@{Rename}@))
+ (dimensions<278,284> ([278,279] (number[279,280]@{1}@) ,[280,281]
(number[282,283]@{1}@) )[283,284])
+ (property_name<285,313> (identifier[285,291]@{matlab}@) .[291,292]
(identifier[292,296]@{lang}@) .[296,297]
(identifier[297,313]@{OnOffSwitchState}@))
+ (default_value<314,324> =[314,315]
+ (string<320,324> "[320,321] (string_content[321,323]@{on}@) "[323,324])))
+ \n[324,325] end[329,332])
+ (block<338,373>
+ (assignment<338,371> left: (identifier[338,339]@{s}@) =[340,341]
right:
- (function_call<205,234> name: (identifier[205,208]@{foo}@) ([208,209]
- (arguments<209,233> argument: (identifier[209,210]@{s}@) ,[210,211]
- (matrix<211,215> [[211,212] ][214,215])
- ,[215,216]
- (field_expression<216,233> object: (identifier[216,226]@{NameValues}@)
.[226,227] field: (identifier[227,233]@{Rename}@)))
- )[233,234]))
- ;[234,235] \n[235,236])
- end[236,239])
- \n[239,240])
+ (function_call<342,371> name: (identifier[342,345]@{foo}@) ([345,346]
+ (arguments<346,370> argument: (identifier[346,347]@{s}@) ,[347,348]
+ (matrix<348,352> [[348,349] ][351,352])
+ ,[352,353]
+ (field_expression<353,370> object: (identifier[353,363]@{NameValues}@)
.[363,364] field: (identifier[364,370]@{Rename}@)))
+ )[370,371]))
+ ;[371,372] \n[372,373])
+ end[373,376])
+ \n[376,377])