branch: externals/matlab-mode
commit c6ec05086c26d96da8b1725281f8369a3a83d8f6
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: improve indent for bad code in a classdef
---
matlab-ts-mode.el | 3 +++
.../indent_parse_error_in_class.m | 15 +++++++++++++++
.../indent_parse_error_in_class_expected.m | 15 +++++++++++++++
.../indent_parse_error_in_class_expected_msgs.m | 15 +++++++++++++++
4 files changed, 48 insertions(+)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index c07f3d20bc..f73e23e554 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -2151,6 +2151,9 @@ Prev-siblings:
prev-sibling-error-node)))
(when (and (or (not node)
(not (equal node error-node)))
+ ;; For condition (not (= bol (treesit-node-start
error-node))), see
+ ;;
tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class.m
+ (not (= bol (treesit-node-start error-node)))
(> (treesit-node-start error-node)
(treesit-node-start anchor-node)))
(setq anchor-node error-node)))
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class.m
b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class.m
new file mode 100644
index 0000000000..fcb82b9cd1
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class.m
@@ -0,0 +1,15 @@
+% -*- matlab-ts -*-
+
+classdef dVCEnum2 < Simulink.IntEnumType
+% doc
+
+ enumeration
+ mChoiceArchSubsys1(0)
+ mChoiceSLMdl1(1)
+ mChoiceArchMdl1(2)
+ end
+
+ % Cause a parse error
+ 4/*
+
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected.m
b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected.m
new file mode 100644
index 0000000000..fcb82b9cd1
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected.m
@@ -0,0 +1,15 @@
+% -*- matlab-ts -*-
+
+classdef dVCEnum2 < Simulink.IntEnumType
+% doc
+
+ enumeration
+ mChoiceArchSubsys1(0)
+ mChoiceSLMdl1(1)
+ mChoiceArchMdl1(2)
+ end
+
+ % Cause a parse error
+ 4/*
+
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected_msgs.m
new file mode 100644
index 0000000000..a813ab002d
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_parse_error_in_class_expected_msgs.m
@@ -0,0 +1,15 @@
+% -*- 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)}>
+
+classdef dVCEnum2 < Simulink.IntEnumType % <{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)}>
+% doc % <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
+
+ enumeration % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ mChoiceArchSubsys1(0) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ mChoiceSLMdl1(1) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ mChoiceArchMdl1(2) % <{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)}>
+
+ % Cause a parse error % <{Matched rule: ((parent-is
"\\`class_definition\\'") parent 4)}>
+ 4/* % <{Matched rule: (matlab-ts-mode--i-next-line-matcher
matlab-ts-mode--i-next-line-anchor matlab-ts-mode--i-next-line-offset)}>
+
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>