branch: externals/matlab-mode
commit 1cb870856294b7e044e62f08ced88f8ac28a3007
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: update to abi/14 97f195a
Also handle typing with line continuations (...).
---
matlab-ts-mode.el | 45 ++++++++++++++-
.../font_lock_empty_endless_fun_issue93.skip.txt | 1 -
.../font_lock_if_greedness_issue92.skip.txt | 1 -
...k_line_cont_in_cell_or_matrix_issue116.skip.txt | 1 -
...ne_cont_in_cell_or_matrix_issue116_expected.txt | 64 ++++++++++++++++++++++
.../indent_line_cont_in_cell_or_matrix_issue116.m | 7 +--
...t_line_cont_in_cell_or_matrix_issue116.skip.txt | 1 -
...ine_cont_in_cell_or_matrix_issue116_expected.m} | 29 +++++-----
...cont_in_cell_or_matrix_issue116_expected_msgs.m | 63 +++++++++++++++++++++
.../indent_line_cont_multiple_times.m | 12 ++++
.../indent_line_cont_multiple_times_expected.m | 12 ++++
...indent_line_cont_multiple_times_expected_msgs.m | 12 ++++
12 files changed, 223 insertions(+), 25 deletions(-)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index c60482fbe3..c07f3d20bc 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1478,6 +1478,27 @@ Similar for case and otherwise statements."
(and prev-sibling
(string= (treesit-node-type prev-sibling) "line_continuation"))))
+(defvar matlab-ts-mode--i-prior-line-anchor-point nil)
+
+(defun matlab-ts-mode--i-prior-line-anchor (&rest _)
+ "Return anchor point for `matlab-ts-mode--i-prior-line-matcher'."
+ matlab-ts-mode--i-prior-line-anchor-point)
+
+(defun matlab-ts-mode--i-prior-line-matcher (node _parent bol &rest _)
+ "Keep current indent level when NODE is nil.
+This occurs when RET was typed on prior line.
+BOL is beginning of line point for NODE.
+See: tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times.m"
+ (when (not node) ;; RET on prior line?
+ (save-excursion
+ (goto-char bol)
+ (when (>= (forward-line -1) 0)
+ (beginning-of-line)
+ (when (looking-at "^[ \t]*\\.\\.\\.")
+ (back-to-indentation)
+ (setq matlab-ts-mode--i-prior-line-anchor-point (point))
+ t)))))
+
(defun matlab-ts-mode--i-cont-offset (node parent _bol &rest _)
"Get the ellipsis continuation offset based on NODE with PARENT.
This is `matlab-ts-mode--indent-level' or 0 when in a cell or matrix
@@ -1507,10 +1528,25 @@ row."
(defvar matlab-ts-mode--i-cont-incomplete-matcher-pair)
-(cl-defun matlab-ts-mode--i-cont-incomplete-matcher (node parent _bol &rest _)
+(cl-defun matlab-ts-mode--i-cont-incomplete-matcher (node parent bol &rest _)
"Is current line part of an ellipsis line continuation?
If so, set `matlab-ts-mode--i-cont-incomplete-matcher-pair'. This is for
-incomplete statements where NODE is nil and PARENT is line_continuation."
+incomplete statements where NODE is nil and PARENT is line_continuation
+or when NODE is non-nil and is a line_continuation only line.
+NODE is at BOL."
+
+ (when (and (equal (treesit-node-type node) "line_continuation")
+ (save-excursion
+ (goto-char bol)
+ (beginning-of-line)
+ (looking-at "^[ \t]*\\.\\.\\.")))
+ (save-excursion
+ (when (>= (forward-line -1) 0)
+ (beginning-of-line)
+ (back-to-indentation)
+ (setq matlab-ts-mode--i-cont-incomplete-matcher-pair
+ (cons (treesit-node-start (treesit-node-at (point))) 0))
+ (cl-return-from matlab-ts-mode--i-cont-incomplete-matcher t))))
;; Case when code is incomplete:
;;
@@ -2670,6 +2706,11 @@ Example:
;; See:
tests/test-matlab-ts-mode-indent-files/indent_line_continuation_row.m
(,#'matlab-ts-mode--i-cont-matcher parent
,#'matlab-ts-mode--i-cont-offset)
+ ;; I-Rule: prior line node
+ (,#'matlab-ts-mode--i-prior-line-matcher
+ ,#'matlab-ts-mode--i-prior-line-anchor
+ 0)
+
;; I-Rule: Assert if no rule matched and asserts are enabled.
,matlab-ts-mode--indent-assert-rule
))
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_empty_endless_fun_issue93.skip.txt
b/tests/test-matlab-ts-mode-font-lock-files/font_lock_empty_endless_fun_issue93.skip.txt
deleted file mode 100644
index b660e0b7a2..0000000000
---
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_empty_endless_fun_issue93.skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-See https://github.com/acristoffers/tree-sitter-matlab/issues/93
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_if_greedness_issue92.skip.txt
b/tests/test-matlab-ts-mode-font-lock-files/font_lock_if_greedness_issue92.skip.txt
deleted file mode 100644
index aee427a8a0..0000000000
---
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_if_greedness_issue92.skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-see https://github.com/acristoffers/tree-sitter-matlab/issues/92
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116.skip.txt
b/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116.skip.txt
deleted file mode 100644
index 76066e9894..0000000000
---
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116.skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-See https://github.com/acristoffers/tree-sitter-matlab/issues/116
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116_expected.txt
new file mode 100644
index 0000000000..df5b21bae7
--- /dev/null
+++
b/tests/test-matlab-ts-mode-font-lock-files/font_lock_line_cont_in_cell_or_matrix_issue116_expected.txt
@@ -0,0 +1,64 @@
+c ccc ccccccccc ccc
+
+c ccc ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+ddddbbccc
+ bSsssSbccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbb ccc
+ bSsssSb ccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbbDccc
+ bSsssSbDccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbbD ccc
+ bSsssSbD ccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbbccc
+ bSsssSbccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbb ccc
+ bSsssSb ccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbbDccc
+ bSsssSbDccc
+ ccc
+ bSsssSb
+ bbD
+
+ddddbbD ccc
+ bSsssSbD ccc
+ ccc
+ bSsssSb
+ bbD
+
+kkkkkkkk ffffbvb
+ BBBBbdbD
+kkk
+
+kkkkkkkk vvv o f
+ vvv o Ss ssssssSD
+kkk
+
+kkkkkkkk vvv o f
+ vvv o Ss ssssssSD
+kkk
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
index d23741585a..c6a8dee2ad 100644
---
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
@@ -3,9 +3,9 @@
% See https://github.com/acristoffers/tree-sitter-matlab/issues/116
fcn1({...
- {'one'}...
- ...
- {'two'}
+ {'one'}...
+ ...
+ {'two'}
});
fcn1({ ...
@@ -61,4 +61,3 @@ end
function out = b
out = "b string";
end
-
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.skip.txt
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.skip.txt
deleted file mode 100644
index 76066e9894..0000000000
---
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-See https://github.com/acristoffers/tree-sitter-matlab/issues/116
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected.m
similarity index 75%
copy from
tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
copy to
tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected.m
index d23741585a..8e2dab8f11 100644
---
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116.m
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected.m
@@ -10,20 +10,20 @@ fcn1({...
fcn1({ ...
{'one'} ...
- ...
+ ...
{'two'}
});
fcn1({,...
- {'one'},...
- ...
- {'two'}
+ {'one'},...
+ ...
+ {'two'}
});
fcn1({, ...
- {'one'}, ...
- ...
- {'two'}
+ {'one'}, ...
+ ...
+ {'two'}
});
fcn1([...
@@ -34,20 +34,20 @@ fcn1([...
fcn1([ ...
{'one'} ...
- ...
+ ...
{'two'}
]);
fcn1([,...
- {'one'},...
- ...
- {'two'}
+ {'one'},...
+ ...
+ {'two'}
]);
fcn1([, ...
- {'one'}, ...
- ...
- {'two'}
+ {'one'}, ...
+ ...
+ {'two'}
]);
function fcn1(x)
@@ -61,4 +61,3 @@ end
function out = b
out = "b string";
end
-
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected_msgs.m
new file mode 100644
index 0000000000..0741152996
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_cell_or_matrix_issue116_expected_msgs.m
@@ -0,0 +1,63 @@
+% -*- matlab-ts -*- % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+% See https://github.com/acristoffers/tree-sitter-matlab/issues/116 %
<{Matched rule: ((lambda (node parent _bol &rest _) (and node (not (string=
(treesit-node-type node) "line_continuation")) (equal (treesit-node-type
parent) "source_file"))) (lambda (_node _parent bol &rest _) (save-excursion
(goto-char bol) (line-beginning-position))) 0)}>
+
+fcn1({... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'}... % <{Matched rule: ((parent-is
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ }); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1({ ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'} ... % <{Matched rule: ((parent-is
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ }); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1({,... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'},... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ }); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1({, ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'}, ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ }); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1([... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'}... % <{Matched rule: ((parent-is
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ]); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1([ ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'} ... % <{Matched rule: ((parent-is
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ]); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1([,... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'},... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ]); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+fcn1([, ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'}, ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'} % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ]); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+function fcn1(x) % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ disp(x); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = a % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "a string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = b % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "b string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times.m
new file mode 100644
index 0000000000..42801495ec
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+someFcn({ ...
+ {'one'}...
+ ...
+ ...
+ {'two'}...
+ });
+
+function someFcn(in)
+ disp(in);
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected.m
new file mode 100644
index 0000000000..42801495ec
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+someFcn({ ...
+ {'one'}...
+ ...
+ ...
+ {'two'}...
+ });
+
+function someFcn(in)
+ disp(in);
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected_msgs.m
new file mode 100644
index 0000000000..35f4b5be46
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_multiple_times_expected_msgs.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*- % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+someFcn({ ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ {'one'}... % <{Matched rule: ((parent-is
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ ... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ {'two'}... % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+ }); % <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
+
+function someFcn(in) % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ disp(in); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>