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

    matlab-ts-mode: release 7.4.1, fix minor indent bug
---
 NEWS.org                                           | 13 ++++
 matlab-mode.el                                     |  2 +-
 matlab-ts-mode.el                                  | 78 +++++++++++++++-------
 matlab.el                                          |  2 +-
 .../indent_xr_ret_after_end.m                      | 17 +++++
 .../indent_xr_ret_after_end_expected.org           | 51 ++++++++++++++
 6 files changed, 137 insertions(+), 26 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index b9b7843a5b..cc6936b50b 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -3,6 +3,19 @@
 
 # Copyright (C) 2025 Free Software Foundation, Inc.
 
+* Release 7.4.1 Nov 26, 2025
+
+1. Fix indent bug. In following typing RET after the argument end statement, 
the indent now goes to
+   the 4th column and not the 8th column:
+
+   #+begin_src matlab
+     function test(A)
+         arguments
+             A
+         end
+     end
+   #+end_src
+
 * Release 7.4.0 Nov 26, 2025
 
 1. Place the =matlab-*-face= definitions in customize matlab-ts-faces group.
diff --git a/matlab-mode.el b/matlab-mode.el
index 59fd156f05..5f2852cf12 100644
--- a/matlab-mode.el
+++ b/matlab-mode.el
@@ -1,6 +1,6 @@
 ;;; matlab-mode.el --- Major mode for MATLAB(R) dot-m files -*- 
lexical-binding: t -*-
 
-;; Version: 7.4.0
+;; Version: 7.4.1
 ;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 8ccf8ca5a8..faed94ee1a 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1,6 +1,6 @@
 ;;; matlab-ts-mode.el --- MATLAB(R) Tree-Sitter Mode -*- lexical-binding: t -*-
 
-;; Version: 7.4.0
+;; Version: 7.4.1
 ;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -2454,6 +2454,49 @@ Example:
   "Return anchor for `matlab-ts-mode--i-row-matcher'."
   matlab-ts-mode--i-row-anchor-value)
 
+(defvar matlab-ts-mode--i-ret-pair)
+
+(defun matlab-ts-mode--i-ret-matcher (node parent bol &rest _)
+  "Is NODE, PARENT, and BOL for RET on prior line indent matcher?"
+  (when (and (not node)
+             (string= "\n" (treesit-node-type parent)))
+    (let ((grand-parent (treesit-node-parent parent))
+          offset)
+      (when (string-match-p (rx bos (or "class_definition"
+                                        "properties"
+                                        "enumeration"
+                                        "methods"
+                                        "events"
+                                        "function_definition"
+                                        "arguments_statement"
+                                        "spmd_statement"
+                                        "try_statement"
+                                        "catch_clause"
+                                        "while_statement"
+                                        "for_statement"
+                                        "if_statement"
+                                        "else_clause"
+                                        "elseif_clause"))
+                            (treesit-node-type grand-parent))
+        (save-excursion
+          (goto-char bol)
+          (if (and (looking-at "^[ \t]*$")
+                   (re-search-backward "[^ \t\r\n]" nil t)
+                   (string= "end" (treesit-node-type (treesit-node-at 
(point)))))
+              (setq offset 0)
+            (setq offset matlab-ts-mode--indent-level)))
+
+
+        (setq matlab-ts-mode--i-ret-pair (cons (treesit-node-start 
grand-parent) offset))))))
+
+(defun matlab-ts-mode--i-ret-anchor (&rest _)
+  "Return anchor for `matlab-ts-mode--i-ret-matcher'."
+  (car matlab-ts-mode--i-ret-pair))
+
+(defun matlab-ts-mode--i-ret-offset (&rest _)
+  "Return anchor for `matlab-ts-mode--i-ret-matcher'."
+  (cdr matlab-ts-mode--i-ret-pair))
+
 (defvar matlab-ts-mode--indent-rules
   `((matlab
 
@@ -2582,22 +2625,9 @@ Example:
      ;;             ^             <== TAB or RET on prior line
      ;;         end
      ;; See: 
tests/test-matlab-ts-mode-indent-xr-files/indent_xr_statement_body.m
-     ((n-p-gp nil ,(rx bos "\n" eos)
-              ,(rx bos (or "class_definition"
-                           "properties"
-                           "enumeration"
-                           "methods"
-                           "events"
-                           "function_definition"
-                           "arguments_statement"
-                           "spmd_statement"
-                           "try_statement"
-                           "catch_clause"
-                           "while_statement"
-                           "for_statement"
-                           "if_statement" "else_clause" "elseif_clause")
-                   eos))
-      grand-parent ,matlab-ts-mode--indent-level)
+     (,#'matlab-ts-mode--i-ret-matcher
+      ,#'matlab-ts-mode--i-ret-anchor
+      ,#'matlab-ts-mode--i-ret-offset)
 
      ;; I-Rule: grandparent is block
      ;;      for i=1:10
@@ -3876,7 +3906,7 @@ provided."
 ;; so the mode line indicator, "matlab-ts-parse-errors" is slightly shorter
 
 (define-compilation-mode matlab-ts-parse-errors-mode "m-ts-parse-errors"
-                         "Variant of `compilation-mode' used for 
`matlab-ts-view-parse-errors'.")
+  "Variant of `compilation-mode' used for `matlab-ts-view-parse-errors'.")
 
 (defun matlab-ts-view-parse-errors (&optional no-pop-to-buffer)
   "View parse errors in matlab-ts-mode current buffer.
@@ -3958,7 +3988,7 @@ EXTRA-DOC is extra doc info to add to the face 
documentation."
 
       (insert "The following faces are used by matlab-ts-mode when displaying 
code.
 A face includes the font, style, color, etc.\n")
-      
+
       (matlab-ts--face-section "Comments")
       (matlab-ts--face-button 'font-lock-doc-face
                               "% documentation comment for function's and 
classdef's\n")
@@ -3983,7 +4013,7 @@ A face includes the font, style, color, etc.\n")
       (matlab-ts--face-section "Brackets")
       (matlab-ts--face-button 'font-lock-bracket-face
                               "( ) [ ] { }\n")
-      
+
       (matlab-ts--face-section "Delimiters")
       (matlab-ts--face-button 'font-lock-delimiter-face
                               ". , : ;\n")
@@ -4026,7 +4056,7 @@ A face includes the font, style, color, etc.\n")
                               "! ls *.m *.txt")
 
       (matlab-ts--face-section "Builtins")
-      
+
       (matlab-ts--face-button 'font-lock-builtin-face
                               "disp"
                               (concat "This includes any builtin identifier, 
function, etc.\n"
@@ -4051,7 +4081,7 @@ A face includes the font, style, color, etc.\n")
       (matlab-ts--face-section "Keywords")
       (matlab-ts--face-button 'font-lock-keyword-face
                               "if else elseif end")
-       
+
       (matlab-ts--face-section "Code")
       (matlab-ts--face-button 'default
                               "sample"
@@ -4063,7 +4093,7 @@ A face includes the font, style, color, etc.\n")
       (matlab-ts--face-section "Type Functions")
       (matlab-ts--face-button 'font-lock-type-face
                               "int8 int16")
-                               
+
       (matlab-ts--face-section "Numbers")
       (matlab-ts--face-button 'matlab-ts-mode-number-face
                               "1234")
@@ -4079,7 +4109,7 @@ A face includes the font, style, color, etc.\n")
                               "a*/*b"
                               (concat "Used when 
`matlab-ts-mode-font-lock-level' is set to "
                                       "show syntax errors"))
-      
+
       )))
 
 ;;; Our M-q matlab-ts-mode-prog-fill-reindent-defun
diff --git a/matlab.el b/matlab.el
index 79a369f1b4..84ed234802 100644
--- a/matlab.el
+++ b/matlab.el
@@ -1,6 +1,6 @@
 ;;; matlab.el --- major mode for MATLAB(R) dot-m files -*- lexical-binding: t 
-*-
 
-;; Version: 7.4.0
+;; Version: 7.4.1
 ;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end.m 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end.m
new file mode 100644
index 0000000000..1a1d05b2d4
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+function indent_xr_ret_after_end(A)
+
+    %{
+      Case1:
+      (t-utils-xr
+
+      (re-search-forward "end")
+      "C-m"
+      (insert "%comment"))
+    %}
+      
+    arguments
+        A
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end_expected.org
 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end_expected.org
new file mode 100644
index 0000000000..84c67a4a5d
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_ret_after_end_expected.org
@@ -0,0 +1,51 @@
+#+startup: showall
+
+* Executing commands from indent_xr_ret_after_end.m:7:6:
+
+  Case1: (t-utils-xr
+
+      (re-search-forward "end")
+      "C-m"
+      (insert "%comment"))
+
+- Invoking      : (re-search-forward "end")
+  Start point   :  168
+  Moved to point:  214
+  : 16:7:     end
+  :              ^
+  No buffer modifications
+
+- Invoking      : "C-m" = newline
+  Start point   :  214
+  Moved to point:  219
+  : 17:4:     
+  :           ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -14,4 +14,5 @@
+     arguments
+         A
+     end
++    
+ end
+  #+end_src diff
+
+- Invoking      : (insert "%comment")
+  Start point   :  219
+  Moved to point:  227
+  : 17:12:     %comment
+  :                    ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -14,5 +14,5 @@
+     arguments
+         A
+     end
+-    
++    %comment
+ end
+  #+end_src diff

Reply via email to