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

    matlab-ts-mode: fix font-lock for copyright in doc comments when there's a 
starting blank line
---
 matlab-ts-mode.el                                  |  7 ++--
 .../indent_xr_copyright_in_block_comment.m         | 13 ++++++++
 ...dent_xr_copyright_in_block_comment_expected.org | 37 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index bb4894a02b..6cf1beee22 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -531,11 +531,12 @@ help doc comment."
   (let ((prev-node (treesit-node-prev-sibling comment-node)))
     (when prev-node
 
-      (while (string-match-p (rx bos (or "line_continuation" "\n") eos)
-                             (treesit-node-type prev-node))
+      (while (and prev-node
+                  (string-match-p (rx bos (or "line_continuation" "\n") eos)
+                                  (treesit-node-type prev-node)))
         (setq prev-node (treesit-node-prev-sibling prev-node)))
 
-      (let ((prev-type (treesit-node-type prev-node)))
+      (let ((prev-type (or (treesit-node-type prev-node) "")))
         ;; The true (t) cases. Note line continuation ellipsis are allowed.
         ;;    function foo          function foo(a)
         ;;    % doc comment         % doc comment
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment.m
 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment.m
new file mode 100644
index 0000000000..2c8fc12dc3
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment.m
@@ -0,0 +1,13 @@
+% -*- matlab-ts -*-
+
+%{
+  Copyright 2026 Testing
+
+  Case1:
+  (t-utils-xr
+  (goto-char (point-min))
+  "C-k"
+
+  (indent-region (point-min) (point-max))
+  )
+%}
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment_expected.org
 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment_expected.org
new file mode 100644
index 0000000000..83a567e2e2
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_copyright_in_block_comment_expected.org
@@ -0,0 +1,37 @@
+#+startup: showall
+
+* Executing commands from indent_xr_copyright_in_block_comment.m:7:2:
+
+  Case1: (t-utils-xr
+  (goto-char (point-min))
+  "C-k"
+
+  (indent-region (point-min) (point-max))
+  )
+
+- Invoking      : (goto-char (point-min))
+  Start point   :  154
+  Moved to point:    1
+  : 1:0: % -*- matlab-ts -*-
+  :      ^
+  No buffer modifications
+
+- Invoking      : "C-k" = kill-line
+  Start point   :    1
+  No point movement
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -1,4 +1,4 @@
+-% -*- matlab-ts -*-
++
+ 
+ %{
+   Copyright 2026 Testing
+  #+end_src diff
+
+- Invoking      : (indent-region (point-min) (point-max))
+  Start point   :    1
+  No point movement
+  No buffer modifications

Reply via email to