branch: externals/matlab-mode
commit dbce610a81bec504c2bc53322039be1bd736ed92
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode--ei: only align consecutive properties
---
matlab-ts-mode--ei.el | 13 ++++---
matlab-ts-mode.el | 45 +++++++++++-----------
.../electric_indent_prop2.m | 13 +++++++
.../electric_indent_prop2_expected.m | 13 +++++++
.../electric_indent_prop2_expected_msgs.m | 13 +++++++
5 files changed, 70 insertions(+), 27 deletions(-)
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 1a0926ef32..37b60cb52c 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -1205,7 +1205,8 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(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, enum field, or argument node."
+Returns nil if not a property, enum field, or argument node that ends on
+same line and has items to align."
(let* ((first-node-in-line (nth 3 ei-info))
(modified-node-type (cdr (matlab-ts-mode--ei-get-node-to-use
first-node-in-line)))
(prop-node (pcase modified-node-type
@@ -1213,10 +1214,12 @@ Returns nil if not a property, enum field, or argument
node."
first-node-in-line)
("property_name"
(treesit-node-parent first-node-in-line)))))
- ;; skip multi-line nodes for alignment (properties / arguments can
span multiple lines)
- (when (= (line-number-at-pos (treesit-node-start prop-node))
- (line-number-at-pos (treesit-node-end prop-node)))
- prop-node)))
+ ;; skip multi-line nodes for alignment (properties / arguments can span
multiple lines)
+ (when (and prop-node
+ (= (line-number-at-pos (treesit-node-start prop-node))
+ (line-number-at-pos (treesit-node-end prop-node)))
+ (> (length (treesit-node-children (treesit-node-parent
prop-node))) 1))
+ prop-node)))
(defun matlab-ts-mode--ei-prop-length (ei-info)
"Get the property length from the electric indented line in EI-INFO."
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 57ae3ccd49..77b10f5603 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1478,28 +1478,29 @@ For optional _NODE, PARENT, and _BOL see
`treesit-simple-indent-rules'."
;; - Otherwise, matlab-ts-mode--function-indent-level is 0, we will
"upgrade" it to
;; matlab-ts-mode--indent-level if function end's appear.
- (let ((root (if (and parent
- (string= (treesit-node-type parent)
"function_definition"))
- parent
- (treesit-buffer-root-node))))
- (if (treesit-search-subtree (treesit-buffer-root-node) "\\`ERROR\\'")
- ;; If we have syntax errors, assume that functions will have ends when
entering
- ;; matlab-ts-mode, otherwise leave matlab-ts--function-indent-level
unchanged.
- (when (equal matlab-ts-mode--function-indent-level 'unset)
- (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level))
- (let ((first-fcn (treesit-search-subtree root (rx bos
"function_definition" eos))))
- (if (not first-fcn)
- ;; assume that if functions are added they will have ends
- (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level)
- (let ((have-end (string= (treesit-node-type (treesit-node-child
first-fcn -1)) "end")))
- (if (equal matlab-ts-mode--function-indent-level 'unset)
- (setq-local matlab-ts-mode--function-indent-level
- (if have-end
- matlab-ts-mode--indent-level
- 0))
- (when have-end
- (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level))
- ))))))
+ (when (eq matlab-ts-mode--function-indent-level 'unset)
+ (let ((root (if (and parent
+ (string= (treesit-node-type parent)
"function_definition"))
+ parent
+ (treesit-buffer-root-node))))
+ (if (treesit-search-subtree (treesit-buffer-root-node) "\\`ERROR\\'")
+ ;; If we have syntax errors, assume that functions will have ends
when entering
+ ;; matlab-ts-mode, otherwise leave matlab-ts--function-indent-level
unchanged.
+ (when (equal matlab-ts-mode--function-indent-level 'unset)
+ (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level))
+ (let ((first-fcn (treesit-search-subtree root (rx bos
"function_definition" eos))))
+ (if (not first-fcn)
+ ;; assume that if functions are added they will have ends
+ (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level)
+ (let ((have-end (string= (treesit-node-type (treesit-node-child
first-fcn -1)) "end")))
+ (if (equal matlab-ts-mode--function-indent-level 'unset)
+ (setq-local matlab-ts-mode--function-indent-level
+ (if have-end
+ matlab-ts-mode--indent-level
+ 0))
+ (when have-end
+ (setq-local matlab-ts-mode--function-indent-level
matlab-ts-mode--indent-level))
+ )))))))
matlab-ts-mode--function-indent-level)
(defun matlab-ts-mode--set-function-indent-level-for-gp (node parent bol &rest
_)
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2.m
new file mode 100644
index 0000000000..2033056ba8
--- /dev/null
+++ b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2.m
@@ -0,0 +1,13 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+classdef electric_indent_prop2
+ properties
+ abc = true;
+ fubar;
+ b = false;
+ p1
+ lonPropertyName (1,1) double = 1.1;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected.m
new file mode 100644
index 0000000000..4f8196545f
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected.m
@@ -0,0 +1,13 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+classdef electric_indent_prop2
+ properties
+ abc = true;
+ fubar;
+ b = false;
+ p1
+ lonPropertyName (1,1) double = 1.1;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected_msgs.m
new file mode 100644
index 0000000000..e541abfe03
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_prop2_expected_msgs.m
@@ -0,0 +1,13 @@
+% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+classdef electric_indent_prop2 % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+ properties % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ abc = true; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ fubar; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ b = false; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ p1 % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ lonPropertyName (1,1) double = 1.1; % <{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)}>