branch: externals/matlab-mode
commit 35f37c76869845d7bf52edd68786a70a8ea89d53
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: improve electric indent of trailing comments
---
 matlab-ts-mode--ei.el                              | 22 ++++++++-
 matlab-ts-mode.el                                  | 40 ++++++++++++----
 ...ectric_indent_align_assignments_expected_msgs.m |  4 +-
 .../electric_indent_arguments_expected_msgs.m      |  2 +-
 ...lectric_indent_class_properties_expected_msgs.m |  2 +-
 .../electric_indent_keywords_expected_msgs.m       |  2 +-
 .../electric_indent_labmda_expected_msgs.m         |  2 +-
 .../electric_indent_matrix_basic_expected_msgs.m   |  2 +-
 .../electric_indent_matrix_cols_expected_msgs.m    |  2 +-
 .../electric_indent_matrix_expected_msgs.m         |  2 +-
 ...electric_indent_matrix_n_levels_expected_msgs.m |  2 +-
 .../electric_indent_prop_expected_msgs.m           |  2 +-
 .../electric_indent_range_expected_msgs.m          |  2 +-
 ...ectric_indent_trailing_comments_expected_msgs.m |  2 +-
 ...ailing_comments_long_then_short_expected_msgs.m |  6 +--
 ...ectric_indent_trailing_comments_on_statements.m | 34 ++++++++++++++
 ...dent_trailing_comments_on_statements_expected.m | 34 ++++++++++++++
 ...trailing_comments_on_statements_expected_msgs.m | 34 ++++++++++++++
 .../electric_indent_two_matrices_expected_msgs.m   |  4 +-
 .../indent_class_prop_continued_expected_msgs.m    |  2 +-
 .../indent_comment_fcn_expected_msgs.m             |  4 +-
 .../indent_comments_expected_msgs.m                |  4 +-
 ...cont_statement_without_ellipsis_expected_msgs.m |  8 ++--
 .../indent_copyright_in_code_expected_msgs.m       |  4 +-
 .../indent_endless_function_expected_msgs.m        |  2 +-
 .../indent_expr_continued_expected_msgs.m          |  2 +-
 ...dent_fcn_call_in_fcn_call_rules_expected_msgs.m | 34 +++++++-------
 .../indent_if_continued_expected_msgs.m            |  2 +-
 ...ndent_if_with_transpose_issue93_expected_msgs.m | 24 +++++-----
 .../indent_keywords_expected_msgs.m                |  2 +-
 .../indent_lots_of_end_words_expected_msgs.m       |  2 +-
 ...nt_with_ellipsis_error_issue135_expected_msgs.m |  4 +-
 .../indent_old_indents_expected_msgs.m             | 36 +++++++--------
 .../indent_old_indents_for_typing_expected.m       |  2 +-
 .../indent_old_indents_for_typing_expected_msgs.m  | 28 +++++------
 .../indent_with_syntax_error_expected_msgs.m       |  2 +-
 ...ectric_indent_trailing_comments_on_statements.m | 34 ++++++++++++++
 ...nt_trailing_comments_on_statements_expected.txt | 54 ++++++++++++++++++++++
 38 files changed, 341 insertions(+), 109 deletions(-)

diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 0174e0162b..aca379a380 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -111,7 +111,7 @@
               "switch"
               "try"
               "while")
-      eos))
+      ))
 
 (defvar matlab-ts-mode--ei-pad-op-re
   (rx bos (or "+" "-" "*" "/" ".*" "./" ".\\" "\\"
@@ -1120,7 +1120,25 @@ is identified as a trailing comment."
       (forward-line 0)
       (when (re-search-forward "%" (pos-eol) t)
         (let ((node (treesit-node-at (point))))
-          (when (equal (treesit-node-type node) "comment")
+          (when (and (equal (treesit-node-type node) "comment")
+                     ;; And not for a control flow or definition statement. 
For example,
+                     ;;    if a % comment1                  <= we shouldn't 
align this
+                     ;;       b = [1, 2, 3]; % comment2
+                     ;;       c = 1;         % comment3
+                     (progn
+                       (forward-line 0)
+                       (while (and (not (bobp))
+                                   (save-excursion
+                                     (backward-char)
+                                     (when (re-search-backward "[^ \t]" 
(pos-bol) t)
+                                       (equal (treesit-node-type 
(treesit-node-at (point)))
+                                              "line_continuation"))))
+                         (forward-line -1))
+                       (matlab-ts-mode--ei-fast-back-to-indentation)
+                       (let ((node (treesit-node-at (point))))
+                         (not (string-match-p matlab-ts-mode--ei-keywords-re
+                                              (treesit-node-type node))))))
+
             (let* ((new-line (nth 0 ei-info))
                    (offset (- (string-match-p "%" new-line) (string-match-p 
"[^ \t]" new-line))))
               (when (> offset 0)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 0072c90442..3f287463de 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1404,6 +1404,12 @@ node."
        (not (save-excursion (goto-char bol)
                             (looking-at "%" t)))))
 
+(defvar matlab-ts-mode--i-block-comment-end-matcher-anchor-val)
+
+(defun matlab-ts-mode--i-block-comment-end-anchor (&rest _)
+  "Return the anchor computed by 
`matlab-ts-mode--i-block-comment-end-matcher'."
+  matlab-ts-mode--i-block-comment-end-matcher-anchor-val)
+
 (defun matlab-ts-mode--i-block-comment-end-matcher (node parent bol &rest _)
   "Is NODE, PARENT, BOL last line of \"{% ... %)\"?
 Also handle single-line comment blocks, e.g.
@@ -1413,13 +1419,29 @@ but not
         function foo %#ok
    TAB> % doc comment line 1"
 
-  (and (not node)
-       (string= "comment" (treesit-node-type parent))
-       (save-excursion
-         (goto-char bol)
-         (and (looking-at "%" t)
-              (not (matlab-ts-mode--i-doc-comment-matcher node parent bol))))))
-
+  (when (and (not node)
+             (string= "comment" (treesit-node-type parent))
+             ;; AND comment only line
+             (save-excursion
+               (goto-char bol)
+               (looking-at "%" t))
+             ;; AND not a function/classdef doc comment
+             (not (matlab-ts-mode--i-doc-comment-matcher node parent bol)))
+    (let ((anchor (if (save-excursion
+                        (forward-line 0)
+                        (backward-char)
+                        (forward-line 0) ;; beginning of prior line
+                        (looking-at "^[ \t]*end[ \t]*%"))
+                      ;; Prior line isn't an end statement, e.g.
+                      ;;        if x
+                      ;;           y = 1;
+                      ;;        end % foo
+                      ;;   TAB> % this comment should be at column 1
+                      (treesit-node-parent parent)
+                    parent)))
+      (setq matlab-ts-mode--i-block-comment-end-matcher-anchor-val
+            (treesit-node-start anchor)))))
+        
 ;; `matlab-ts-mode--function-indent-level'
 ;;
 ;; It is recommended that all function statements have terminating end 
statements.  In some cases
@@ -2540,7 +2562,9 @@ Example:
   `((matlab
 
      ;; I-Rule: last line of code block comment "%{ ... %}"?
-     (,#'matlab-ts-mode--i-block-comment-end-matcher parent 0)
+     (,#'matlab-ts-mode--i-block-comment-end-matcher
+      ,#'matlab-ts-mode--i-block-comment-end-anchor
+      0)
 
      ;; I-Rule: within a code block comment "%{ ... %}"?
      (,#'matlab-ts-mode--i-in-block-comment-matcher parent 2)
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
index aadfa45f24..ef594ec8a7 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_align_assignments_expected_msgs.m
@@ -3,8 +3,8 @@
 % Consecuitvie assignment alignment %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 
 % t-utils-test-indent: no-line-by-line-indent - when we type line-by-line, we 
don't see later %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-%                      assignment values, thus to fully indent, need to 
re-indent the file after %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%                      typing line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+%                      assignment values, thus to fully indent, need to 
re-indent the file after %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%                      typing line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 a             = 10; %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 bLongVariable = [1, 2, 3]; %  <{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_arguments_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_arguments_expected_msgs.m
index ba4e91628f..5772e11aaf 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,7 +1,7 @@
 % -*- 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)}>
+% arguments because we don't have them all. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 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)}>
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
index e19de80d3a..36bfce5ad6 100644
--- 
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
@@ -1,7 +1,7 @@
 % -*- 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)}>
+% properties because we don't have them all. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 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)}>
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_keywords_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_keywords_expected_msgs.m
index b3844ca183..51fee01b71 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_keywords_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_keywords_expected_msgs.m
@@ -11,7 +11,7 @@ classdef electric_indent_keywords < handle %  <{Matched rule: 
(matlab-ts-mode--i
 
         %{ %  <{Matched rule: ((parent-is 
"\\`\\(?:arguments_statement\\|e\\(?:numeration\\|vents\\)\\|f\\(?:or_statement\\|unction_definition\\)\\|if_statement\\|methods\\|properties\\|while_statement\\)\\'")
 parent 4)}>
           foo %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-        %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+        %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     end % comment after end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
     methods %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
         function method1(in) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_labmda_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_labmda_expected_msgs.m
index f2034773d6..3b1f16699b 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_labmda_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_labmda_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 we type line-by-line, the 
continuation lines %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 
 l1 = @(x) ((ischar(x) || isstring(x))); %  <{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_matrix_basic_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_basic_expected_msgs.m
index 095ec72a3e..85bb08d994 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_basic_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_basic_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 matrix 
line-by-line, there are %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 m6 = [1 2 %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
       3 4]; %  <{Matched rule: (matlab-ts-mode--i-row-matcher 
matlab-ts-mode--i-row-matcher-anchor matlab-ts-mode--i-row-matcher-offset)}>
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
index a48af673a8..a3c7cb37d6 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_cols_expected_msgs.m
@@ -3,7 +3,7 @@
 % Exercise matlab-ts-mode--ei-align-line-in-m-matrix %  <{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 matrix 
line-by-line, there are %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 m = [1111,     2, 223 %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
       ... %  <{Matched rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'") parent 
2)}>
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
index 8925e835f2..5e538ce881 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 we type line-by-line, the 
continuation lines %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 a0 = [1; 1]; %  <{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_matrix_n_levels_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_n_levels_expected_msgs.m
index c8cb6d362f..213b9b593c 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_n_levels_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_matrix_n_levels_expected_msgs.m
@@ -3,7 +3,7 @@
 % Exercise matrix indentation with varying indent levels %  <{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 matrix 
line-by-line, there are %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 if foo1 %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
     m1 = [ 23, 2 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
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 34cb477dd8..9bab723d54 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,7 +1,7 @@
 % -*- 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)}>
+% arguments because we don't have them all. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function s = electric_indent_prop(s, NameValues) %  <{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_range_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_range_expected_msgs.m
index 3a0972f261..d69f0d0179 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_range_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_range_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 we type line-by-line, the 
continuation lines %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% have a syntax error because the continued portion isn't there. %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 dataTbl = [dataTbl(:, 1 : varColNumbers(1) - 1) ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
            tableWithDateColumnOnly dataTbl(:, varColNumbers(1) + 1 : end)]; %  
<{Matched rule: ((parent-is "\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
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
index 42888e5597..feb7315c39 100644
--- 
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
@@ -12,7 +12,7 @@ a(1, 2) = [1, 2, 3]; % comment %  <{Matched rule: 
(matlab-ts-mode--i-top-level m
 b(1, 2) = 1;         % commnet %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
 % We don't align the trailing comments in the following becaue of the "%" in 
the string %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% matlab-ts-mode could be updated to handle this case, but it's likely rare. % 
 <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% matlab-ts-mode could be updated to handle this case, but it's likely rare. % 
 <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 foo       = 1; % comment 1 %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 d         = dictionary("%", 1); % comment 2 %  <{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_long_then_short_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_long_then_short_expected_msgs.m
index e769cb7e69..7619fedc9a 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_long_then_short_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_long_then_short_expected_msgs.m
@@ -1,11 +1,11 @@
 % -*- 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 we type line-by-line, we 
don't see later %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-%                      assignment values, thus to fully indent, need to 
re-indent the file after %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%                      typing line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+%                      assignment values, thus to fully indent, need to 
re-indent the file after %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%                      typing line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 % When computing trailing comment location, need to have lines electric 
indented including %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% assignment and properties %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% assignment and properties %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 classdef electric_indent_trailing_comments_long_then_short %  <{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)}>
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
new file mode 100644
index 0000000000..e9c3718583
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
@@ -0,0 +1,34 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we 
can't align the
+% trailing comments because we don't see later lines
+
+x = [1, 2, 3]; % comment 1 (aligned)
+xyz = 2; % comment 2 (aligned)
+
+
+if x
+    y = 1
+end % end if x
+             % other comment
+z = y;
+
+if x
+y = 1
+end     % end if x
+x = 1            % this shouldn't be aligned with prior
+
+if z    % some comment
+    y = [1,2] % some comment
+end
+
+foo1 blah % comment (aligned)
+c = 1; % comment (aligned)
+
+; % comment (aligned)
+cfooo % comment (aligned)
+
+if a && ...
+   b % comment
+    z = [1, 2, 2, 4] % comment (not aligned)
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.m
new file mode 100644
index 0000000000..da9d7bc4df
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.m
@@ -0,0 +1,34 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we 
can't align the
+% trailing comments because we don't see later lines
+
+x   = [1, 2, 3]; % comment 1 (aligned)
+xyz = 2;         % comment 2 (aligned)
+
+
+if x
+    y = 1
+end % end if x
+% other comment
+z = y;
+
+if x
+    y = 1
+end % end if x
+x = 1 % this shouldn't be aligned with prior
+
+if z % some comment
+    y = [1, 2] % some comment
+end
+
+foo1 blah % comment (aligned)
+c = 1;    % comment (aligned)
+
+;     % comment (aligned)
+cfooo % comment (aligned)
+
+if a && ...
+   b % comment
+    z = [1, 2, 2, 4] % comment (not aligned)
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected_msgs.m
new file mode 100644
index 0000000000..bfbaea6fde
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected_msgs.m
@@ -0,0 +1,34 @@
+% -*- 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)}>
+% trailing comments because we don't see later lines %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+
+x   = [1, 2, 3]; % comment 1 (aligned) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+xyz = 2;         % comment 2 (aligned) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+
+
+if x %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
+    y = 1 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+end % end if x %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+% other comment %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+z = y; %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+if x %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
+    y = 1 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+end % end if x %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+x = 1 % this shouldn't be aligned with prior %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+
+if z % some comment %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+    y = [1, 2] % some comment %  <{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)}>
+
+foo1 blah % comment (aligned) %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+c = 1;    % comment (aligned) %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+;     % comment (aligned) %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+cfooo % comment (aligned) %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+if a && ... %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+   b % comment %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
+    z = [1, 2, 2, 4] % comment (not aligned) %  <{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-electric-indent-files/electric_indent_two_matrices_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_two_matrices_expected_msgs.m
index a1bc935664..4d088f1c9d 100644
--- 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_two_matrices_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_two_matrices_expected_msgs.m
@@ -1,10 +1,10 @@
 % -*- 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 matrix 
line-by-line, there are %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% error nodes and thus the matrix alignment doesn't occur %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 % The following two matrices do not have blank lines between them. This 
validates that %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% the indent-region of the matrix in the temporary buffer doesn't pickup 
invalid content. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% the indent-region of the matrix in the temporary buffer doesn't pickup 
invalid content. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 if 1 %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
     tp_taper_BorderVertices = [    neg_BorderVertices; ... %  <{Matched rule: 
((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued_expected_msgs.m
index 6c972629a5..203d7a33f7 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_class_prop_continued_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 to improve continued 
properties in %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-%                                               
matlab-ts-mode--i-next-line-matcher %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+%                                               
matlab-ts-mode--i-next-line-matcher %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 classdef indent_class_prop_continued %  <{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)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_comment_fcn_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_comment_fcn_expected_msgs.m
index 1b946f8ccb..6ae45cde3d 100644
--- a/tests/test-matlab-ts-mode-indent-files/indent_comment_fcn_expected_msgs.m
+++ b/tests/test-matlab-ts-mode-indent-files/indent_comment_fcn_expected_msgs.m
@@ -1,6 +1,6 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% t-utils-test-indent: no-line-by-line-indent - nested functions require an 
end %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% t-utils-test-indent: no-line-by-line-indent - nested functions require an 
end %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function indent_comment_fcn %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 % This is the %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_comments_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_comments_expected_msgs.m
index bc1035823a..e6e9f7fa63 100644
--- a/tests/test-matlab-ts-mode-indent-files/indent_comments_expected_msgs.m
+++ b/tests/test-matlab-ts-mode-indent-files/indent_comments_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 - not possible to indent 
line-by-line %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% because of the multi-line comments. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% because of the multi-line comments. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function b = indent_comments(a) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 % this the doc help %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
@@ -45,7 +45,7 @@ function fcn2 %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--co
       for following %  <{Matched rule: 
(matlab-ts-mode--i-in-block-comment-matcher parent 2)}>
 
       line %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     disp('2'); %  <{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_cont_statement_without_ellipsis_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_cont_statement_without_ellipsis_expected_msgs.m
index 1adbbfbf53..7d0a43e6e0 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_cont_statement_without_ellipsis_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_cont_statement_without_ellipsis_expected_msgs.m
@@ -1,8 +1,8 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% t-utils-test-indent: no-line-by-line-indent - typing the incomplete 
expression line-by-line %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% results in a parse tree that can't match below. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% t-utils-test-indent: no-line-by-line-indent - typing the incomplete 
expression line-by-line %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% results in a parse tree that can't match below. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 function a=indent_cont_statement_without_ellipsis %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 % The matlab-tree-sitter, by design for simplicity treats "..." as comments so 
the following %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
 % is an error in MATLAB, but doesn't generate a parse error and indents the 
same as if %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_copyright_in_code_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_copyright_in_code_expected_msgs.m
index 80878c0320..f248cffb59 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_copyright_in_code_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_copyright_in_code_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 - multiline comments cannot be 
indented correctly %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% when typing line-by-line because we don't know where in a multiline comment 
until we see the end. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% when typing line-by-line because we don't know where in a multiline comment 
until we see the end. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function b = indent_copyright_in_code %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 %{ %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
@@ -10,7 +10,7 @@ function b = indent_copyright_in_code %  <{Matched rule: 
(matlab-ts-mode--i-top-
   asdfasd %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
 %} %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
     % foo %  <{Matched rule: ((parent-is "\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
-    % foo %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % foo %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 
 
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_endless_function_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_endless_function_expected_msgs.m
index 46c82e95be..6e91fc48a2 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_endless_function_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_endless_function_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 - can't indent typing 
line-by-line %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% because on start, we assume an empty file has function indent level of 4 %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% because on start, we assume an empty file has function indent level of 4 %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function indent_endless_function(a) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 % function without a terminating end %  <{Matched rule: 
(matlab-ts-mode--i-doc-comment-matcher matlab-ts-mode--i-doc-comment-anchor 
matlab-ts-mode--i-doc-comment-offset)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_expr_continued_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_expr_continued_expected_msgs.m
index d0786097c9..f9836c6ce9 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_expr_continued_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_expr_continued_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
 % For boolean expressions when in an if statement or assignement to a 
variable, %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% we align them. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% we align them. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 if obj.IsSomeLongFunction && ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
    ~strcmp(obj.property1, obj.property2) && ... %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_fcn_call_in_fcn_call_rules_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_call_in_fcn_call_rules_expected_msgs.m
index 7dd28ec361..c38ba7aa16 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_fcn_call_in_fcn_call_rules_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_call_in_fcn_call_rules_expected_msgs.m
@@ -1,39 +1,39 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
 % Here MATLAB indent "SomeLongString" to be 4 from the '(' in "someFunction1(" 
%  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-% This differs from clang-format on C code where it will produce: %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%        "SomeLongString")); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% This differs from clang-format on C code where it will produce: %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%        "SomeLongString")); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 something.foo = someFunction1(someFunction2( ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
                                   "SomeLongString")); %  <{Matched rule: 
((node-is "\\`arguments\\'") parent 4)}>
 
 % Here MATLAB indents similar to the prior. %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-% clang-format C also indents this way: %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%                                      "SomeLongString"), %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%                                  arg2, %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%                                  arg3); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% clang-format C also indents this way: %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%                                      "SomeLongString"), %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%                                  arg2, %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%                                  arg3); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 something.foo = someFunction1(someFunction2( ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
                                   "SomeLongString"), ... %  <{Matched rule: 
((node-is "\\`arguments\\'") parent 4)}>
                               arg2, ... %  <{Matched rule: ((parent-is 
"\\`arguments\\'") parent 0)}>
                               arg3); %  <{Matched rule: ((parent-is 
"\\`arguments\\'") parent 0)}>
 
 % Here MATLAB indents similar to the prior. %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-% This differs from clang-format on C code where it will produce: %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%        "SomeLongString", %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%        arg2, %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-%        arg3)); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% This differs from clang-format on C code where it will produce: %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%    something.foo = someFunction1(someFunction2( %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%        "SomeLongString", %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%        arg2, %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%        arg3)); %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 something.foo = someFunction1(someFunction2( ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
                                   "SomeLongString", ... %  <{Matched rule: 
((node-is "\\`arguments\\'") parent 4)}>
                                   arg2, ... %  <{Matched rule: ((parent-is 
"\\`arguments\\'") parent 0)}>
                                   arg3)); %  <{Matched rule: ((parent-is 
"\\`arguments\\'") parent 0)}>
 
 % *** Conclusion *** %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-%   For consistency, MATLAB is correct. Adding an argument to a function 
shouldn't cause %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-%   indent differences. This is likely a miss on clang-format indent rules 
part. %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+%   For consistency, MATLAB is correct. Adding an argument to a function 
shouldn't cause %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%   indent differences. This is likely a miss on clang-format indent rules 
part. %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 
 % --- Test unnecessary spaces --- %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected_msgs.m
index fab74edd92..f005dcff2a 100644
--- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected_msgs.m
+++ b/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- 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 - continued "fcn_call(arg1, ..." 
%  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-% isn't identified as a function call, so indenting line by line fails on 
this. %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+% isn't identified as a function call, so indenting line by line fails on 
this. %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function indent_if_continued %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_if_with_transpose_issue93_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_if_with_transpose_issue93_expected_msgs.m
index 88d54a7ef7..7d9d1c65cf 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_if_with_transpose_issue93_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_if_with_transpose_issue93_expected_msgs.m
@@ -3,11 +3,11 @@
 % t-utils-test-indent: no-line-by-line-indent - if conditions don't require a 
terminator %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
 % The following produces %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-%    ans = %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%         2 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%    here %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+%    ans = %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%         2 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%    here %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 a=1; %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
 b=2; %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
@@ -17,11 +17,11 @@ if a'b' %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0
 end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
 
 % MATLAB does not require a statement terminator after the if-condition, so, 
for example, you can %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% write: %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-%  if 1 < 2 a = 3; end %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% Thus above is equivalent to: %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% write: %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+%  if 1 < 2 a = 3; end %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% Thus above is equivalent to: %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 a=1; %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
 b=2; %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
@@ -34,7 +34,7 @@ end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\
 % Note, the Code Analyzer suggests that a line terminator should be added. %  
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 
 % Information on tree-sitter handling from %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-% https://github.com/acristoffers/tree-sitter-matlab/issues/93 %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% https://github.com/acristoffers/tree-sitter-matlab/issues/93 %  <{Matched 
rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 %{ %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 
0)}>
 
@@ -110,4 +110,4 @@ end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\
 
   So, that's my not 100% accurate but hopefully comprehensible enough 
explanation of how it works. I hope I made things clearer instead of more 
confusing :) %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
 
-%} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+%} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_keywords_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_keywords_expected_msgs.m
index 3da4b97d1b..c0d2af84d3 100644
--- a/tests/test-matlab-ts-mode-indent-files/indent_keywords_expected_msgs.m
+++ b/tests/test-matlab-ts-mode-indent-files/indent_keywords_expected_msgs.m
@@ -10,7 +10,7 @@ classdef indent_keywords < handle %  <{Matched rule: 
(matlab-ts-mode--i-top-leve
 
         %{ %  <{Matched rule: ((parent-is 
"\\`\\(?:arguments_statement\\|e\\(?:numeration\\|vents\\)\\|f\\(?:or_statement\\|unction_definition\\)\\|if_statement\\|methods\\|properties\\|while_statement\\)\\'")
 parent 4)}>
           foo %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-        %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+        %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
     methods %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
         function method1(in) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
index a89b52d7c4..5f42ddc374 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
@@ -62,7 +62,7 @@ function result = goo(b) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-
 
     result=1; %  <{Matched rule: ((parent-is "\\`function_definition\\'") 
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
     % see xyz function %  <{Matched rule: ((parent-is "\\`block\\'") parent 
0)}>
-    % foobar %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % foobar %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     for x = 1:length(b) %  <{Matched rule: ((parent-is "\\`block\\'") parent 
0)}>
         result = x + result; %  <{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-indent-files/indent_multiline_comment_with_ellipsis_error_issue135_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_multiline_comment_with_ellipsis_error_issue135_expected_msgs.m
index a06f9e9e1b..fafacf35b0 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_multiline_comment_with_ellipsis_error_issue135_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_multiline_comment_with_ellipsis_error_issue135_expected_msgs.m
@@ -3,7 +3,7 @@
 % See: https://github.com/acristoffers/tree-sitter-matlab/issues/135 %  
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 
 % t-utils-test-indent: no-line-by-line-indent - multi-line comment below can 
not be indented %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% line-by-line %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+% line-by-line %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 
 a = 1; %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
@@ -13,7 +13,7 @@ if a == 10 || ... %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode
    %{ %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
      block %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
      comment %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-   %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+   %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
    b == 2 %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
     disp('here') %  <{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-indent-files/indent_old_indents_expected_msgs.m 
b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_expected_msgs.m
index f67a9f5409..75b276c22e 100644
--- a/tests/test-matlab-ts-mode-indent-files/indent_old_indents_expected_msgs.m
+++ b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_expected_msgs.m
@@ -1,6 +1,6 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% See ../indents.m which is used in testing matlab-mode %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-% t-utils-test-indent: no-line-by-line-indent - contains %{ block comments %} 
%  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% See ../indents.m which is used in testing matlab-mode %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+% t-utils-test-indent: no-line-by-line-indent - contains %{ block comments %} 
%  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 function indent_old_indents(a,b,stuff,cmddual1fake,cmddual2fake) %  <{Matched 
rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 % Help text %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
 % !!0 %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
@@ -8,7 +8,7 @@ function 
indent_old_indents(a,b,stuff,cmddual1fake,cmddual2fake) %  <{Matched ru
 % !!0 %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
 
     % including a gap - comment for following code %  <{Matched rule: 
((parent-is "\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
-    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     arguments (Repeating) % !!4 %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
         a (1,1) {mustBeNumeric}                                 % !!8 %  
<{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
@@ -42,7 +42,7 @@ function 
indent_old_indents(a,b,stuff,cmddual1fake,cmddual2fake) %  <{Matched ru
     continuations_and_block_comments(); %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
 
     % $$$ !!0 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % $$$ special ignore comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % $$$ special ignore comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     has_nested_fcn(); % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
 
@@ -112,7 +112,7 @@ function B = ends_in_comments_and_strings() %  <{Matched 
rule: (matlab-ts-mode--
     1; % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
 
     % Multi- end s %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % >>8 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % >>8 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     if foo %#ok %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
         if bar %#ok %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
             if baz %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
@@ -167,8 +167,8 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
         };                  %!!8 %  <{Matched rule: ((node-is "\\`[])}]\\'") 
parent 0)}>
 
     % TODO %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % I don't know why the below indents this way. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-    % It should either do all max indent, or all lined up with parens. %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % I don't know why the below indents this way. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+    % It should either do all max indent, or all lined up with parens. %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     thing.thing.long.long.longname({ 'str' %!!4 %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
                                      'str' %!!37 %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
                                      'str' %!!37 %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
@@ -186,7 +186,7 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
               end));   %!!14 %  <{Matched rule: ((parent-is "\\`range\\'") 
parent 0)}>
 
     % This array has bad syntactic expression parsing due to the %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    % apostrophy %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % apostrophy %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     Closures = [ %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
                  755009 ; ... % 21-Feb-2067 Washington's Birthday (Mon) %  
<{Matched rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
                  755010 ;     % !!8 %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
@@ -198,7 +198,7 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
           ]; %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
 
     % This long fcn name last symbol starts with 'get' which %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    % used to confuse and move to indent past 1st arg. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % used to confuse and move to indent past 1st arg. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     if qesimcheck.utils.GetYesNoAnswer('Do ',... !!4 %  <{Matched rule: 
((parent-is "\\`block\\'") parent 0)}>
                                        'n',...  !!39 %  <{Matched rule: 
((parent-is "\\`arguments\\'") parent 0)}>
                                        'once') %!!39 %  <{Matched rule: 
((parent-is "\\`arguments\\'") parent 0)}>
@@ -235,14 +235,14 @@ function C = 
block_starts_in_comments_and_strings(varargin) %  <{Matched rule: (
 
 
     % see previous function %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
-    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     for x=1:length(C) % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
         if varargin{2}  % !!8 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
             continue    % !!12 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
         end   % !!8 %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
 
         break % !!8 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-              % !!14 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+              % !!14 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
         %!!8 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
     end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
@@ -278,18 +278,18 @@ function B = continuations_and_block_comments %  
<{Matched rule: (matlab-ts-mode
       blank line means this block comment is not part of help and is for 
following code %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
       !!6  {  } %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
       !!6 %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     arg1=1; %  <{Matched rule: ((parent-is "\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
 
     %{ %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    %  !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    %  !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
       !!6 %  <{Matched rule: (matlab-ts-mode--i-in-block-comment-matcher 
parent 2)}>
-    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
-    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 
0)}>
+    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+    %} %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     % Block comment indicators MUST be on a line by themselves. %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    %{ Not a block comment } %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    %{ Not a block comment } %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     foo(1); % !!4   - don't indent this special %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
 
@@ -314,10 +314,10 @@ function B = continuations_and_block_comments %  
<{Matched rule: (matlab-ts-mode
         + 6; % !!8 %  <{Matched rule: ((parent-is "\\`binary_operator\\'") 
parent 0)}>
 
     foo_code();  % eol-comment !!4 %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
-                 % continuation-comment !!17 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+                 % continuation-comment !!17 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     % !!4 -blank between this & continuation comment %  <{Matched rule: 
((parent-is "\\`block\\'") parent 0)}>
-    % !!4 - more comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % !!4 - more comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     if condition1 || ...  % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
        fcn_call(arg1, ... % !!12 %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected.m
index 45c49cb6c0..8d3471c089 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected.m
@@ -103,7 +103,7 @@ function B = ends_in_comments_and_strings()
         A = E;
 
     end % the other end
-        % !! 4
+    % !! 4
 
     B = [ B A ]; % !!4
 
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected_msgs.m
index 343f00f6c6..f64298c684 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_old_indents_for_typing_expected_msgs.m
@@ -1,7 +1,7 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
 
 %  To be used for "typing" line-by-line. Same as ./indent_old_indents.m, but 
no %  <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
-%  %{ block comments %} and no nested functions. These do not support 
indenting line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+%  %{ block comments %} and no nested functions. These do not support 
indenting line-by-line. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
 function indent_old_indents_for_typing(a,b,stuff,cmddual1fake,cmddual2fake) %  
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
 % Help text %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
@@ -10,7 +10,7 @@ function 
indent_old_indents_for_typing(a,b,stuff,cmddual1fake,cmddual2fake) %  <
 % !!0 %  <{Matched rule: (matlab-ts-mode--i-doc-comment-matcher 
matlab-ts-mode--i-doc-comment-anchor matlab-ts-mode--i-doc-comment-offset)}>
 
     % including a gap - comment for following code %  <{Matched rule: 
((parent-is "\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
-    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     arguments (Repeating) % !!4 %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
         a (1,1) {mustBeNumeric}                                 % !!8 %  
<{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
@@ -44,7 +44,7 @@ function 
indent_old_indents_for_typing(a,b,stuff,cmddual1fake,cmddual2fake) %  <
     continuations_and_block_comments(); %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
 
     % $$$ !!0 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % $$$ special ignore comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % $$$ special ignore comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     has_nested_fcn(); % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
 
@@ -103,7 +103,7 @@ function B = ends_in_comments_and_strings() %  <{Matched 
rule: (matlab-ts-mode--
         A = E; %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
 
     end % the other end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
-        % !! 4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % !! 4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     B = [ B A ]; % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") parent 
0)}>
 
@@ -114,7 +114,7 @@ function B = ends_in_comments_and_strings() %  <{Matched 
rule: (matlab-ts-mode--
     1; % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
 
     % Multi- end s %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % >>8 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % >>8 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     if foo %#ok %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
         if bar %#ok %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
             if baz %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
@@ -169,8 +169,8 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
         };                  %!!8 %  <{Matched rule: ((node-is "\\`[])}]\\'") 
parent 0)}>
 
     % TODO %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-    % I don't know why the below indents this way. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
-    % It should either do all max indent, or all lined up with parens. %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % I don't know why the below indents this way. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+    % It should either do all max indent, or all lined up with parens. %  
<{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     thing.thing.long.long.longname({ 'str' %!!4 %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
                                      'str' %!!37 %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
                                      'str' %!!37 %  <{Matched rule: 
(matlab-ts-mode--i-row-matcher matlab-ts-mode--i-row-matcher-anchor 
matlab-ts-mode--i-row-matcher-offset)}>
@@ -188,7 +188,7 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
               end));   %!!14 %  <{Matched rule: ((parent-is "\\`range\\'") 
parent 0)}>
 
     % This array has bad syntactic expression parsing due to the %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    % apostrophy %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % apostrophy %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     Closures = [ %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
                  755009 ; ... % 21-Feb-2067 Washington's Birthday (Mon) %  
<{Matched rule: ((parent-is "\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
                  755010 ;     % !!8 %  <{Matched rule: ((parent-is 
"\\`\\(?:cell\\|matrix\\)\\'") parent 2)}>
@@ -200,7 +200,7 @@ function out = array_constant_decls() %  <{Matched rule: 
(matlab-ts-mode--i-top-
           ]; %  <{Matched rule: ((node-is "\\`[])}]\\'") parent 0)}>
 
     % This long fcn name last symbol starts with 'get' which %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    % used to confuse and move to indent past 1st arg. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % used to confuse and move to indent past 1st arg. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     if qesimcheck.utils.GetYesNoAnswer('Do ',... !!4 %  <{Matched rule: 
((parent-is "\\`block\\'") parent 0)}>
                                        'n',...  !!39 %  <{Matched rule: 
((parent-is "\\`arguments\\'") parent 0)}>
                                        'once') %!!39 %  <{Matched rule: 
((parent-is "\\`arguments\\'") parent 0)}>
@@ -237,14 +237,14 @@ function C = 
block_starts_in_comments_and_strings(varargin) %  <{Matched rule: (
 
 
     % see previous function %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
-    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
parent 0)}>
+    % !!4 %  <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
     for x=1:length(C) % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
         if varargin{2}  % !!8 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
             continue    % !!12 %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
         end   % !!8 %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
 
         break % !!8 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
-              % !!14 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+              % !!14 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
         %!!8 %  <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
     end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
@@ -276,7 +276,7 @@ function B = continuations_and_block_comments %  <{Matched 
rule: (matlab-ts-mode
 
 
     % Block comment indicators MUST be on a line by themselves. %  <{Matched 
rule: ((parent-is "\\`block\\'") parent 0)}>
-    %{ Not a block comment } %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    %{ Not a block comment } %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     foo(1); % !!4   - don't indent this special %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
 
@@ -301,10 +301,10 @@ function B = continuations_and_block_comments %  
<{Matched rule: (matlab-ts-mode
         + 6; % !!8 %  <{Matched rule: ((parent-is "\\`binary_operator\\'") 
parent 0)}>
 
     foo_code();  % eol-comment !!4 %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
-                 % continuation-comment !!17 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+                 % continuation-comment !!17 %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     % !!4 -blank between this & continuation comment %  <{Matched rule: 
((parent-is "\\`block\\'") parent 0)}>
-    % !!4 - more comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+    % !!4 - more comments %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 
     if condition1 || ...  % !!4 %  <{Matched rule: ((parent-is "\\`block\\'") 
parent 0)}>
        fcn_call(arg1, ... % !!12 %  <{Matched rule: ((parent-is 
"\\`\\(?:\\(?:boolea\\|compariso\\)n_operator\\)\\'") parent 0)}>
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_with_syntax_error_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_with_syntax_error_expected_msgs.m
index 43dd2de2e6..8238aabaf8 100644
--- 
a/tests/test-matlab-ts-mode-indent-files/indent_with_syntax_error_expected_msgs.m
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_with_syntax_error_expected_msgs.m
@@ -1,5 +1,5 @@
 % -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
-% function args have syntax error %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher parent 0)}>
+% function args have syntax error %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
 function foo=indent_with_syntax_error(bar1, ... % a comment for bar1 %  
<{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
                                       % help comment %  <{Matched rule: 
(matlab-ts-mode--i-next-line-matcher matlab-ts-mode--i-next-line-anchor 
matlab-ts-mode--i-next-line-offset)}>
                                       foo = bar1 + bar2 * 2; %  <{Matched 
rule: (matlab-ts-mode--i-next-line-matcher matlab-ts-mode--i-next-line-anchor 
matlab-ts-mode--i-next-line-offset)}>
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
new file mode 100644
index 0000000000..e9c3718583
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements.m
@@ -0,0 +1,34 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - when typing line-by-line we 
can't align the
+% trailing comments because we don't see later lines
+
+x = [1, 2, 3]; % comment 1 (aligned)
+xyz = 2; % comment 2 (aligned)
+
+
+if x
+    y = 1
+end % end if x
+             % other comment
+z = y;
+
+if x
+y = 1
+end     % end if x
+x = 1            % this shouldn't be aligned with prior
+
+if z    % some comment
+    y = [1,2] % some comment
+end
+
+foo1 blah % comment (aligned)
+c = 1; % comment (aligned)
+
+; % comment (aligned)
+cfooo % comment (aligned)
+
+if a && ...
+   b % comment
+    z = [1, 2, 2, 4] % comment (not aligned)
+end
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.txt
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.txt
new file mode 100644
index 0000000000..41370cb824
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_trailing_comments_on_statements_expected.txt
@@ -0,0 +1,54 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,632> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,166]@{% 
t-utils-test-indent: no-line-by-line-indent - wh...}@)
+ (assignment<168,181> left: (identifier[168,169]@{x}@) =[170,171]
+  right: 
+   (matrix<172,181> [[172,173]
+    (row<173,180> (number[173,174]@{1}@) ,[174,175] (number[176,177]@{2}@) 
,[177,178] (number[179,180]@{3}@))
+    ][180,181]))
+ ;[181,182] (comment[183,204]@{% comment 1 (aligned)}@)
+ (assignment<205,212> left: (identifier[205,208]@{xyz}@) =[209,210] right: 
(number[211,212]@{2}@))
+ ;[212,213] (comment[214,235]@{% comment 2 (aligned)}@) \n[235,238]
+ (if_statement<238,256> if[238,240] condition: (identifier[241,242]@{x}@)
+  (block<247,253>
+   (assignment<247,252> left: (identifier[247,248]@{y}@) =[249,250] right: 
(number[251,252]@{1}@))
+   \n[252,253])
+  end[253,256])
+ (comment[257,296]@{% end if x\n             % other comment}@) \n[296,297]
+ (assignment<297,302> left: (identifier[297,298]@{z}@) =[299,300] right: 
(identifier[301,302]@{y}@))
+ ;[302,303] \n[303,305]
+ (if_statement<305,319> if[305,307] condition: (identifier[308,309]@{x}@)
+  (block<310,316>
+   (assignment<310,315> left: (identifier[310,311]@{y}@) =[312,313] right: 
(number[314,315]@{1}@))
+   \n[315,316])
+  end[316,319])
+ (comment[324,334]@{% end if x}@) \n[334,335]
+ (assignment<335,340> left: (identifier[335,336]@{x}@) =[337,338] right: 
(number[339,340]@{1}@))
+ (comment[352,390]@{% this shouldn't be aligned with prior}@) \n[390,392]
+ (if_statement<392,447> if[392,394] condition: (identifier[395,396]@{z}@) 
(comment[400,414]@{% some comment}@)
+  (block<419,444>
+   (assignment<419,428> left: (identifier[419,420]@{y}@) =[421,422]
+    right: 
+     (matrix<423,428> [[423,424]
+      (row<424,427> (number[424,425]@{1}@) ,[425,426] (number[426,427]@{2}@))
+      ][427,428]))
+   (comment[429,443]@{% some comment}@) \n[443,444])
+  end[444,447])
+ \n[447,449]
+ (command<449,458> (command_name[449,453]@{foo1}@) 
(command_argument[454,458]@{blah}@))
+ (comment[459,478]@{% comment (aligned)}@) \n[478,479]
+ (assignment<479,484> left: (identifier[479,480]@{c}@) =[481,482] right: 
(number[483,484]@{1}@))
+ ;[484,485] (comment[486,505]@{% comment (aligned)}@) \n[505,507] ;[507,508] 
(comment[509,528]@{% comment (aligned)}@)
+ (command<529,534> (command_name[529,534]@{cfooo}@))
+ (comment[535,554]@{% comment (aligned)}@) \n[554,556]
+ (if_statement<556,631> if[556,558]
+  condition: (boolean_operator<559,572> left: (identifier[559,560]@{a}@) 
&&[561,563] (line_continuation[564,568]@{...\n}@) right: 
(identifier[571,572]@{b}@))
+  (comment[573,582]@{% comment}@)
+  (block<587,628>
+   (assignment<587,603> left: (identifier[587,588]@{z}@) =[589,590]
+    right: 
+     (matrix<591,603> [[591,592]
+      (row<592,602> (number[592,593]@{1}@) ,[593,594] (number[595,596]@{2}@) 
,[596,597] (number[598,599]@{2}@) ,[599,600] (number[601,602]@{4}@))
+      ][602,603]))
+   (comment[604,627]@{% comment (not aligned)}@) \n[627,628])
+  end[628,631])
+ \n[631,632])


Reply via email to