branch: externals/matlab-mode
commit 61b6a80ded8d8c471878c29db71477579319f19c
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode--ei: fix indent/TAB point movement on multi-output variable
---
NEWS.org | 20 +++++++
matlab-mode.el | 2 +-
matlab-ts-mode--ei.el | 67 +++++++++++-----------
matlab-ts-mode.el | 2 +-
matlab.el | 2 +-
...ndent_m_matrix_assign_to_matrix_expected_msgs.m | 2 +-
.../electric_indent_xr_matrix_on_left_of_assign.m | 17 ++++++
...indent_xr_matrix_on_left_of_assign_expected.org | 36 ++++++++++++
.../electric_indent_xr_matrix_on_left_of_assign.m | 17 ++++++
...indent_xr_matrix_on_left_of_assign_expected.txt | 25 ++++++++
10 files changed, 153 insertions(+), 37 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 7c8d7b229b..2eb6fc3164 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -3,6 +3,26 @@
# Copyright (C) 2025-2026 Free Software Foundation, Inc.
+* Release 8.0.4 Feb-7-2026
+
+This release fixes a minor issue when using matlab-ts-mode with point location
when indenting
+(TAB) a multi-output variable line of the form:
+
+#+begin_src matlab
+ a([ 1, 2], :) = ...
+ [ 3, 4, 5; ...
+ 300, 400, 500];
+#+end_src
+
+If point is on the ~1~ and we indent the line (TAB), the point will remain on
the ~1~ and the result
+will be:
+
+#+begin_src matlab
+ a([1, 2], :) = ...
+ [ 3, 4, 5; ...
+ 300, 400, 500];
+#+end_src
+
* Release 8.0.3 Feb-5-2026
This release updates to the latest tree-sitter-matlab grammar which addresses
a couple issues in
diff --git a/matlab-mode.el b/matlab-mode.el
index 4a91ec10ed..600838d92d 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: 8.0.3
+;; Version: 8.0.4
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 4131d7799e..e62df71848 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -1,6 +1,6 @@
;;; matlab-ts-mode--ei.el --- MATLAB electric indent -*- lexical-binding: t -*-
-;; Version: 8.0.3
+;; Version: 8.0.4
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -509,7 +509,7 @@ Assumes that current point is at `back-to-indentation'."
;; Make invisible comma visible by returning it.
",")
- ;; Case: invisible at end of array row
+ ;; Case: invisible comma to insert at at end of array row
;; foo = {'one', 'two' ...
;; ^ missing comma, return a comma to have
it inserted
((and (string= node-type "line_continuation")
@@ -788,23 +788,23 @@ Returns alist where each element in the alist is
(COLUMN-NUM . WIDTH)"
column-widths))
-(defun matlab-ts-mode--ei-get-m-matrix-row-in-line (use-matrix-node)
+(defun matlab-ts-mode--ei-get-m-matrix-row-in-line (t-matrix-node)
"Given point within a matrix assignment statement, return row node or nil.
Example: v = [1 2; ...
...
3 4];
when on the 2nd continuation only line, nil is returned otherwise a row node.
-If USE-MATRIX-NODE is non-nil, we use that to locate the first row."
+If tmp T-MATRIX-NODE is non-nil, we use that to locate the first row."
(save-excursion
- (if use-matrix-node
+ (if t-matrix-node
;; [1, 2, 3; // child 0 is the '[', child 1 is the first row
;; 4, 5, 6]
;; [ ... // child 0 is the '[', child 1 is line_continuation
;; 1, 2, 3;
;; 4, 5, 6]
- (let ((child1 (treesit-node-child use-matrix-node 1)))
+ (let ((child1 (treesit-node-child t-matrix-node 1)))
(when (and (string= (treesit-node-type child1) "row")
- (= (line-number-at-pos (treesit-node-start
use-matrix-node))
+ (= (line-number-at-pos (treesit-node-start t-matrix-node))
(line-number-at-pos (treesit-node-start child1))))
;; row-now on same line as use-matrix-node
child1))
@@ -903,41 +903,42 @@ Returns the line number after the ASSIGN-NODE in the
tmp-buf."
(cl-defun matlab-ts-mode--ei-align-line-in-m-matrix (assign-node ei-info)
"Align current line with EI-INFO in a multi-line matrix of ASSIGN-NODE.
See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents."
- (let* ((assign-start-linenum (line-number-at-pos (treesit-node-start
assign-node)))
- (tmp-buf-ei-linenum (1+ (- (line-number-at-pos)
assign-start-linenum)))
- (tmp-buf-row-linenum (if matlab-ts-mode--ei-align-matrix-alist 1
tmp-buf-ei-linenum))
- (matrix-alist matlab-ts-mode--ei-align-matrix-alist)
- end-linenum)
+ (let* ((matrix-alist matlab-ts-mode--ei-align-matrix-alist)
+ (assign-start-linenum (line-number-at-pos (treesit-node-start
assign-node)))
+ (t-buf-ei-linenum (1+ (- (line-number-at-pos) assign-start-linenum)))
+ (t-buf-row-linenum (if matlab-ts-mode--ei-align-matrix-alist 1
t-buf-ei-linenum)))
(with-temp-buffer
(unwind-protect
(progn
- (setq end-linenum (matlab-ts-mode--ei-indent-matrix-in-tmp-buf
assign-node))
- (let* ((assign-node (save-excursion
- (matlab-ts-mode--ei-fast-back-to-indentation)
- (treesit-parent-until (treesit-node-at
(point) 'matlab)
- "assignment")))
- (matrix-node (if assign-node
- (treesit-node-child-by-field-name
assign-node "right")
- (treesit-node-parent (treesit-search-subtree
;; else a property
+ (let* (t-curr-linenum
+ (t-end-linenum (matlab-ts-mode--ei-indent-matrix-in-tmp-buf
assign-node))
+ (t-assign-node (save-excursion
+
(matlab-ts-mode--ei-fast-back-to-indentation)
+ (treesit-parent-until (treesit-node-at
(point) 'matlab)
+ "assignment")))
+ (t-matrix-node (if t-assign-node
+ (treesit-node-child-by-field-name
t-assign-node "right")
+ (treesit-node-parent
(treesit-search-subtree ;; else a property
(treesit-buffer-root-node)
(rx bos "[" eos) nil
t))))
- (use-matrix-node matrix-node) ;; used when current line is
matrix-node start
- (first-col-extra
(matlab-ts-mode--ei-m-matrix-first-col-extra matrix-node))
- (col-widths (matlab-ts-mode--ei-m-matrix-col-widths
matrix-node
+ (t-matrix-node-linenum (line-number-at-pos
(treesit-node-start t-matrix-node)))
+ (first-col-extra
(matlab-ts-mode--ei-m-matrix-first-col-extra t-matrix-node))
+ (col-widths (matlab-ts-mode--ei-m-matrix-col-widths
t-matrix-node
first-col-extra)))
;; Move to the line of interest when we called from
matlab-ts-mode--treesit-indent,
;; otherwise calculate all matrix rows for indent-region.
(when (and (not matrix-alist)
- (> tmp-buf-ei-linenum 1))
- (setq use-matrix-node nil) ;; TAB on a later line in a matrix
- (forward-line (1- tmp-buf-ei-linenum)))
+ (> t-buf-ei-linenum 1))
+ (forward-line (1- t-buf-ei-linenum)))
- (while (< (line-number-at-pos) end-linenum) ;; Adjust column
widths
+ ;; Adjust column widths
+ (while (< (setq t-curr-linenum (line-number-at-pos))
t-end-linenum)
(matlab-ts-mode--ei-fast-back-to-indentation)
- (let* ((row-node (matlab-ts-mode--ei-get-m-matrix-row-in-line
use-matrix-node))
+ (let* ((row-node (when (>= t-curr-linenum
t-matrix-node-linenum)
+ (matlab-ts-mode--ei-get-m-matrix-row-in-line
+ (when (= t-curr-linenum
t-matrix-node-linenum) t-matrix-node))))
(indent-offset (when (looking-at "[^ \t\n\r]+")
(current-column)))
ei-line)
- (setq use-matrix-node nil)
(matlab--eilb-setup)
(if (and row-node indent-offset)
(let* ((col-num (length col-widths)) ;; Iterate last col
down to first col
@@ -945,7 +946,7 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO contents."
(r-content (buffer-substring indent-start-pt
(pos-eol)))
(pt-offset (nth 1 ei-info))
(matrix-offset (save-excursion
- (goto-char (treesit-node-start
matrix-node))
+ (goto-char (treesit-node-start
t-matrix-node))
(1+ (- (point) (pos-bol))))))
;; Adjust matrix row in eilb using r-content w/o
leading indent-level spaces
(with-current-buffer matlab--eilb
@@ -987,20 +988,20 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
(goto-char (point-max)))
(setq ei-line (matlab--eilb-content))
- (when (= tmp-buf-row-linenum tmp-buf-ei-linenum)
+ (when (= t-buf-row-linenum t-buf-ei-linenum)
(setq ei-info (list ei-line pt-offset (nth 2
ei-info) (nth 3 ei-info)))))
;; Else a blank or continuation line w/o matrix content
(setq ei-line (buffer-substring (pos-bol) (pos-eol))))
(when matrix-alist
- (let* ((buf-linenum (1- (+ assign-start-linenum
tmp-buf-row-linenum))))
+ (let* ((buf-linenum (1- (+ assign-start-linenum
t-buf-row-linenum))))
(push `(,buf-linenum . ,ei-line) matrix-alist)))
(if (not matrix-alist)
(goto-char (point-max))
(forward-line)
- (setq tmp-buf-row-linenum (1+ tmp-buf-row-linenum)))))))
+ (setq t-buf-row-linenum (1+ t-buf-row-linenum)))))))
;; unwind forms
(matlab--eilb-kill)))
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 3b6a81f82a..dbcf36a0de 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: 8.0.3
+;; Version: 8.0.4
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
diff --git a/matlab.el b/matlab.el
index c027c8afd9..3957927e53 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: 8.0.3
+;; Version: 8.0.4
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_assign_to_matrix_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_assign_to_matrix_expected_msgs.m
index 8bf9b41750..dcf68bbd7a 100644
---
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_assign_to_matrix_expected_msgs.m
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_m_matrix_assign_to_matrix_expected_msgs.m
@@ -2,6 +2,6 @@
% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
-a([1, 2], :) = ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+a([1, 2], :) = ... % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
[ 1, 2, 3; ... % <{Matched rule: ((parent-is "\\`assignment\\'")
parent 4)}>
100, 200, 300]; % <{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-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
b/tests/test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
new file mode 100644
index 0000000000..49fb7cbf5b
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+%{
+ Case1:
+ (t-utils-xr
+
+ (re-search-forward "1,")
+ "C-i"
+ )
+%}
+
+if a
+ a( [1, 2], :) = ...
+ [1, 2, 3; ...
+ 100, 200, 300];
+end
+
diff --git
a/tests/test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.org
b/tests/test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.org
new file mode 100644
index 0000000000..c312d9a878
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.org
@@ -0,0 +1,36 @@
+#+startup: showall
+
+* Executing commands from electric_indent_xr_matrix_on_left_of_assign.m:5:2:
+
+ Case1: (t-utils-xr
+
+ (re-search-forward "1,")
+ "C-i"
+ )
+
+- Invoking : (re-search-forward "1,")
+ Start point : 87
+ Moved to point: 109
+ : 13:12: a( [1, 2], :) = ...
+ : ^
+ No buffer modifications
+
+- Invoking : "C-i" = indent-for-tab-command
+ Start point : 109
+ Moved to point: 106
+ : 13:9: a([1, 2], :) = ...
+ : ^
+ Buffer modified:
+ #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -10,7 +10,7 @@
+ %}
+
+ if a
+- a( [1, 2], :) = ...
++ a([1, 2], :) = ...
+ [1, 2, 3; ...
+ 100, 200, 300];
+ end
+ #+end_src diff
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
new file mode 100644
index 0000000000..49fb7cbf5b
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign.m
@@ -0,0 +1,17 @@
+% -*- matlab-ts -*-
+
+%{
+ Case1:
+ (t-utils-xr
+
+ (re-search-forward "1,")
+ "C-i"
+ )
+%}
+
+if a
+ a( [1, 2], :) = ...
+ [1, 2, 3; ...
+ 100, 200, 300];
+end
+
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.txt
new file mode 100644
index 0000000000..f6ea7e4516
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-xr-files/electric_indent_xr_matrix_on_left_of_assign_expected.txt
@@ -0,0 +1,25 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,259> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
(comment[22,90]@{%\{\n Case1:\n (t-utils-xr\n\n (re-search-forwa...}@)
\n[90,92]
+ (if_statement<92,253> if[92,94] condition: (identifier[95,96]@{a}@)
+ (block<101,250>
+ (assignment<101,248>
+ left:
+ (function_call<101,119> name: (identifier[101,102]@{a}@) ([102,103]
+ (arguments<106,118>
+ argument:
+ (matrix<106,115> [[106,107]
+ (row<107,114> (number[107,108]@{1}@) ,[108,109]
(number[113,114]@{2}@))
+ ][114,115])
+ ,[115,116]
+ (spread_operator<117,118> :[117,118]))
+ )[118,119])
+ =[120,121] (line_continuation[122,192]@{...
...}@)
+ right:
+ (matrix<200,248> [[200,201]
+ (row<201,219> (number[201,202]@{1}@) ,[202,203] (number[213,214]@{2}@)
,[214,215] (number[218,219]@{3}@))
+ (line_continuation[221,225]@{...\n}@)
+ (row<234,247> (number[234,237]@{100}@) ,[237,238]
(number[239,242]@{200}@) ,[242,243] (number[244,247]@{300}@))
+ ][247,248]))
+ ;[248,249] \n[249,250])
+ end[250,253])
+ \n[253,254] \n[258,259])