branch: externals/matlab-mode commit 2d9f04a2a17e82b2f8ac0abd4a5b7a4eb0f8b0f3 Author: John Ciolfi <cio...@mathworks.com> Commit: John Ciolfi <cio...@mathworks.com>
matlab-ts-mode: fix indent on return/tab after block --- matlab-ts-mode.el | 21 ++-- .../indent_xr_grandparent_is_block.m | 13 +++ .../indent_xr_grandparent_is_block_expected.org | 115 +++++++++++++++++++++ 3 files changed, 143 insertions(+), 6 deletions(-) diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el index 172bc5440a..a4cd50731f 100644 --- a/matlab-ts-mode.el +++ b/matlab-ts-mode.el @@ -1347,6 +1347,14 @@ incomplete statements where NODE is nil and PARENT is line_continuation." eos)) grand-parent ,matlab-ts-mode--indent-level) + ;; I-Rule: grandparent is block + ;; for i=1:10 + ;; disp(i) + ;; ^ <== RET on prior line or tab goes here + ;; end + ;; See: tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block.m + ((n-p-gp nil ,(rx bos "\n" eos) ,(rx bos "block" eos)) grand-parent 0) + ;; I-Rule: disp(myMatrix(1: ... ;; <TAB> end)); ((parent-is ,(rx bos "range" eos)) parent 0) @@ -2480,12 +2488,6 @@ is t, add the following to an Init File (e.g. `user-init-file' or ;; end ;; end ;; - ;; TODO indent - ;; for i=1:10 - ;; disp(i) - ;; ^ <== TAB on empty line or RET previous line should go here - ;; end - ;; ;; TODO font-lock ;; classdef fooenum ;; enumeration @@ -2513,6 +2515,13 @@ is t, add the following to an Init File (e.g. `user-init-file' or ;; TODO matlab.el, matlab-is-matlab-file - handle matlab-ts-mode ;; ;; TODO matlab-shell-mode: update help to have matlab-ts-mode or matlab-mode + ;; + ;; TODO font-lock highlight variable refences to match variable assignements, e.g. + ;; var = [1:10]; + ;; disp(var) % var usage has same face as var. + ;; + ;; TODO add rename identifier + (treesit-major-mode-setup) diff --git a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block.m b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block.m new file mode 100644 index 0000000000..cd7669908d --- /dev/null +++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block.m @@ -0,0 +1,13 @@ +% -*- matlab-ts -*- + +for i=1:10 + % (t-utils-xr "C-n" "C-e" "C-m" (insert "disp(i*2)")) + disp(i) +end + + +for j=1:10 + % (t-utils-xr "C-n" "C-n" "C-a" "C-i" (insert "disp(j*2)")) + disp(j) + +end diff --git a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block_expected.org b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block_expected.org new file mode 100644 index 0000000000..5d3df2f6fd --- /dev/null +++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_grandparent_is_block_expected.org @@ -0,0 +1,115 @@ +#+startup: showall + +* Executing commands from indent_xr_grandparent_is_block.m:4:6: + + (t-utils-xr "C-n" "C-e" "C-m" (insert "disp(i*2)")) + +- Invoking : "C-n" = next-line + Start point : 90 + Moved to point: 102 + : 5:11: disp(i) + : ^ + No buffer modifications + +- Invoking : "C-e" = move-end-of-line + Start point : 102 + No point movement + No buffer modifications + +- Invoking : "C-m" = newline + Start point : 102 + Moved to point: 107 + : 6:4: + : ^ + Buffer modified: + #+begin_src diff +--- start_contents ++++ end_contents +@@ -3,6 +3,7 @@ + for i=1:10 + % (t-utils-xr "C-n" "C-e" "C-m" (insert "disp(i*2)")) + disp(i) ++ + end + + + #+end_src diff + +- Invoking : (insert "disp(i*2)") + Start point : 107 + Moved to point: 116 + : 6:13: disp(i*2) + : ^ + Buffer modified: + #+begin_src diff +--- start_contents ++++ end_contents +@@ -3,7 +3,7 @@ + for i=1:10 + % (t-utils-xr "C-n" "C-e" "C-m" (insert "disp(i*2)")) + disp(i) +- ++ disp(i*2) + end + + + #+end_src diff + +* Executing commands from indent_xr_grandparent_is_block.m:11:6: + + (t-utils-xr "C-n" "C-n" "C-a" "C-i" (insert "disp(j*2)")) + +- Invoking : "C-n" = next-line + Start point : 197 + Moved to point: 209 + : 12:11: disp(j) + : ^ + No buffer modifications + +- Invoking : "C-n" = next-line + Start point : 209 + Moved to point: 210 + : 13:0: + : ^ + No buffer modifications + +- Invoking : "C-a" = move-beginning-of-line + Start point : 210 + No point movement + No buffer modifications + +- Invoking : "C-i" = indent-for-tab-command + Start point : 210 + Moved to point: 214 + : 13:4: + : ^ + Buffer modified: + #+begin_src diff +--- start_contents ++++ end_contents +@@ -10,5 +10,5 @@ + for j=1:10 + % (t-utils-xr "C-n" "C-n" "C-a" "C-i" (insert "disp(j*2)")) + disp(j) +- ++ + end + #+end_src diff + +- Invoking : (insert "disp(j*2)") + Start point : 214 + Moved to point: 223 + : 13:13: disp(j*2) + : ^ + Buffer modified: + #+begin_src diff +--- start_contents ++++ end_contents +@@ -10,5 +10,5 @@ + for j=1:10 + % (t-utils-xr "C-n" "C-n" "C-a" "C-i" (insert "disp(j*2)")) + disp(j) +- ++ disp(j*2) + end + #+end_src diff