branch: externals/matlab-mode commit 65d5d4bc1e1b21cd49e1efb871dde319cdff6c6a Author: John Ciolfi <john.ciolfi...@gmail.com> Commit: John Ciolfi <john.ciolfi...@gmail.com>
matlab-ts-mode: fix indent of incomplete if statements --- matlab-ts-mode.el | 12 +++++++----- .../test-matlab-ts-mode-indent-files/indent_if_continued.m | 12 ++++++++---- .../indent_if_continued.skip.typing.txt | 1 - .../{indent_if_continued.m => indent_if_continued2.m} | 13 ++++++------- ...continued_expected.m => indent_if_continued2_expected.m} | 13 ++++++------- .../indent_if_continued_expected.m | 12 ++++++++---- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el index 710462d9c0..7b2d39aed7 100644 --- a/matlab-ts-mode.el +++ b/matlab-ts-mode.el @@ -1478,8 +1478,11 @@ Prev-siblings: (if (save-excursion (goto-char (treesit-node-start anchor-node)) (while (and (re-search-backward "[^ \t\r\n]" nil t) - (string= (treesit-node-type (treesit-node-at (point))) "line_continuation"))) - (string= (treesit-node-type (treesit-node-at (point))) "function")) + (string= (treesit-node-type + (treesit-node-at (point))) + "line_continuation"))) + (string= (treesit-node-type (treesit-node-at (point))) + "function")) ;; function output 1 matlab-ts-mode--array-indent-level)) @@ -1504,9 +1507,8 @@ Prev-siblings: ("if" (if (and node - (string-match-p (rx bos (or "elseif_clause" - "else_clause") - eos) + ;; else, else_clause, elseif, or elseif_clause + (string-match-p (rx bos "else") (treesit-node-type node))) 0 matlab-ts-mode--indent-level)) diff --git a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m b/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m index b33f6f1d21..16f95c2254 100644 --- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m +++ b/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m @@ -1,4 +1,8 @@ % -*- matlab-ts -*- + +% t-utils-test-indent: no-line-by-line-indent - continued "fcn_call(arg1, ..." +% isn't identified as a function call, so indenting line by line fails on this. + function indent_if_continued if condition1 || ... @@ -9,9 +13,9 @@ function indent_if_continued line_in_if(); elseif condition1 + condition2 == ... - 2770000 ... - fcn_call(arg1, ... - arg2) + 2770000 || ... + fcn_call(arg1, ... + arg2) line_in_if(); elseif (condition2 || ... (condition3 && ... @@ -35,7 +39,7 @@ function indent_if_continued if ... foo + ... - bar + bar2 == 10 end diff --git a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.skip.typing.txt b/tests/test-matlab-ts-mode-indent-files/indent_if_continued.skip.typing.txt deleted file mode 100644 index ebe6ed2ee5..0000000000 --- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.skip.typing.txt +++ /dev/null @@ -1 +0,0 @@ -Items not indented correctly diff --git a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m b/tests/test-matlab-ts-mode-indent-files/indent_if_continued2.m similarity index 74% copy from tests/test-matlab-ts-mode-indent-files/indent_if_continued.m copy to tests/test-matlab-ts-mode-indent-files/indent_if_continued2.m index b33f6f1d21..f0a6851d73 100644 --- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued.m +++ b/tests/test-matlab-ts-mode-indent-files/indent_if_continued2.m @@ -1,17 +1,16 @@ % -*- matlab-ts -*- -function indent_if_continued + +function indent_if_continued2 if condition1 || ... condition2 || ... - fcn_call(arg1, ... - arg2) + fcn_call(arg1, arg2) line_in_if(); elseif condition1 + condition2 == ... - 2770000 ... - fcn_call(arg1, ... - arg2) + 2770000 || ... + fcn_call(arg1, arg2) line_in_if(); elseif (condition2 || ... (condition3 && ... @@ -35,7 +34,7 @@ function indent_if_continued if ... foo + ... - bar + bar2 == 10 end diff --git a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m b/tests/test-matlab-ts-mode-indent-files/indent_if_continued2_expected.m similarity index 74% copy from tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m copy to tests/test-matlab-ts-mode-indent-files/indent_if_continued2_expected.m index 3247d19446..a70edc2e37 100644 --- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m +++ b/tests/test-matlab-ts-mode-indent-files/indent_if_continued2_expected.m @@ -1,17 +1,16 @@ % -*- matlab-ts -*- -function indent_if_continued + +function indent_if_continued2 if condition1 || ... condition2 || ... - fcn_call(arg1, ... - arg2) + fcn_call(arg1, arg2) line_in_if(); elseif condition1 + condition2 == ... - 2770000 ... - fcn_call(arg1, ... - arg2) + 2770000 || ... + fcn_call(arg1, arg2) line_in_if(); elseif (condition2 || ... (condition3 && ... @@ -35,7 +34,7 @@ function indent_if_continued if ... foo + ... - bar + bar2 == 10 end diff --git a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m b/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m index 3247d19446..81405e34c0 100644 --- a/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m +++ b/tests/test-matlab-ts-mode-indent-files/indent_if_continued_expected.m @@ -1,4 +1,8 @@ % -*- matlab-ts -*- + +% t-utils-test-indent: no-line-by-line-indent - continued "fcn_call(arg1, ..." +% isn't identified as a function call, so indenting line by line fails on this. + function indent_if_continued if condition1 || ... @@ -9,9 +13,9 @@ function indent_if_continued line_in_if(); elseif condition1 + condition2 == ... - 2770000 ... - fcn_call(arg1, ... - arg2) + 2770000 || ... + fcn_call(arg1, ... + arg2) line_in_if(); elseif (condition2 || ... (condition3 && ... @@ -35,7 +39,7 @@ function indent_if_continued if ... foo + ... - bar + bar2 == 10 end