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

    matlab-ts-mode: handle indent continuation for fcn open
---
 matlab-ts-mode.el                                  |  30 +++---
 .../indent_xr_i_cont_incomplete4.m                 |   4 +
 .../indent_xr_i_cont_incomplete4_expected.org      | 105 +++++++++++++++++++++
 .../indent_xr_i_cont_incomplete5.m                 |   4 +
 .../indent_xr_i_cont_incomplete5_expected.org      | 105 +++++++++++++++++++++
 5 files changed, 236 insertions(+), 12 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index f1a484cea4..12540e1f1c 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1012,14 +1012,20 @@ incomplete statements where NODE is nil and PARENT is 
line_continuation."
             (setq check-node nil)))
 
         (when check-node
-          (let ((anchor-node check-node))
+          (let ((anchor-node check-node)
+                paren-with-args)
 
-            ;; Look for prev-sibling we can anchor on
+            ;; Look for open paren of a function-call, index, or expression 
grouping
             (while (and anchor-node
                         (not (string-match-p (rx bos "(" eos)
                                              (treesit-node-type anchor-node))))
+              (setq paren-with-args t)
               (setq anchor-node (treesit-node-prev-sibling anchor-node)))
 
+            ;; If we found "( ..." then we anchor off parent
+            (when (and anchor-node (not paren-with-args))
+              (setq anchor-node nil))
+
             ;; Look for parent that we can use for indent
             (when (not anchor-node)
               (setq anchor-node check-node)
@@ -2066,21 +2072,21 @@ is t, add the following to an Init File (e.g. 
`user-init-file' or
     ;; TODO update --indent-rules to have "See: test file" comments.
     ;;
     ;; TODO indent
-    ;;          outResult = longFunction(...
-    ;;              ^              <== RET on previous line or TAB should be 
here
-    ;;
-    ;; TODO indent
-    ;;          a = f(1) + f2(1, ...
-    ;;                        ^              <== RET on previous line or TAB 
should be here
-    ;;
-    ;; TODO indent
-    ;;      filesToCheck = ...
-    ;;          ^                  <== RET on previous line or TAB should be 
here
+    ;;      function outResult = foo
+    ;;                  outResult = longFunction(...    <== TAB should shift, 
w/o "..." it shifts
+    ;;      end
+    ;;      Requires ERROR node be located under the function_output.
+    ;;      See https://github.com/acristoffers/tree-sitter-matlab/issues/47
     ;;
     ;; TODO indent
     ;;      filesToCheck = ...
     ;;          [
     ;;            ^                <== RET on previous line or TAB should be 
here
+    ;;      See https://github.com/acristoffers/tree-sitter-matlab/issues/47
+    ;;
+    ;; TODO indent
+    ;;          outResult = longFunction(...
+    ;;              ^              <== RET on previous line or TAB should be 
here
     ;;
     ;; TODO indent
     ;;      for fIdx = 1:10
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4.m 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4.m
new file mode 100644
index 0000000000..66f2dc09bc
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4.m
@@ -0,0 +1,4 @@
+% -*- matlab-ts -*-
+% (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+function a = indent_xr_i_cont_incomplete4
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4_expected.org
 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4_expected.org
new file mode 100644
index 0000000000..7f8b8047be
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete4_expected.org
@@ -0,0 +1,105 @@
+#+startup: showall
+
+* Executing commands from indent_xr_i_cont_incomplete4.m:2:2:
+
+  (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+
+- Invoking      : "C-n" = next-line
+  Start point   :  199
+  Moved to point:  241
+  : 3:41: function a = indent_xr_i_cont_incomplete4
+  :                                                ^
+  No buffer modifications
+
+- Invoking      : "C-e" = move-end-of-line
+  Start point   :  241
+  No point movement
+  No buffer modifications
+
+- Invoking      : "C-m" = newline
+  Start point   :  241
+  Moved to point:  246
+  : 4:4:     
+  :          ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -1,4 +1,5 @@
+ % -*- matlab-ts -*-
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function a = indent_xr_i_cont_incomplete4
++    
+ end
+  #+end_src diff
+
+- Invoking      : (insert "a = foo((1+2)*3, a, ...")
+  Start point   :  246
+  Moved to point:  269
+  : 4:27:     a = foo((1+2)*3, a, ...
+  :                                  ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -1,5 +1,5 @@
+ % -*- matlab-ts -*-
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function a = indent_xr_i_cont_incomplete4
+-    
++    a = foo((1+2)*3, a, ...
+ end
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  269
+  Moved to point:  282
+  : 5:12:             
+  :                   ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -2,4 +2,5 @@
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function a = indent_xr_i_cont_incomplete4
+     a = foo((1+2)*3, a, ...
++            
+ end
+  #+end_src diff
+
+- Invoking      : (insert "99);")
+  Start point   :  282
+  Moved to point:  286
+  : 5:16:             99);
+  :                       ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -2,5 +2,5 @@
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "a = foo((1+2)*3, a, ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function a = indent_xr_i_cont_incomplete4
+     a = foo((1+2)*3, a, ...
+-            
++            99);
+ end
+  #+end_src diff
+
+- Invoking      : (re-search-backward "^fun")
+  Start point   :  286
+  Moved to point:  200
+  : 3:0: function a = indent_xr_i_cont_incomplete4
+  :      ^
+  No buffer modifications
+
+- Invoking      : (print (buffer-substring-no-properties (point) (point-max)))
+  Start point   :  200
+  No point movement
+  standard-output:
+    "function a = indent_xr_i_cont_incomplete4
+      a = foo((1+2)*3, a, ...
+              99);
+  end
+  "
+  No buffer modifications
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5.m 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5.m
new file mode 100644
index 0000000000..14c00fc992
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5.m
@@ -0,0 +1,4 @@
+% -*- matlab-ts -*-
+% (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+function result = indent_xr_i_cont_incomplete5
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5_expected.org
 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5_expected.org
new file mode 100644
index 0000000000..69a2221af9
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_i_cont_incomplete5_expected.org
@@ -0,0 +1,105 @@
+#+startup: showall
+
+* Executing commands from indent_xr_i_cont_incomplete5.m:2:2:
+
+  (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+
+- Invoking      : "C-n" = next-line
+  Start point   :  202
+  Moved to point:  249
+  : 3:46: function result = indent_xr_i_cont_incomplete5
+  :                                                     ^
+  No buffer modifications
+
+- Invoking      : "C-e" = move-end-of-line
+  Start point   :  249
+  No point movement
+  No buffer modifications
+
+- Invoking      : "C-m" = newline
+  Start point   :  249
+  Moved to point:  254
+  : 4:4:     
+  :          ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -1,4 +1,5 @@
+ % -*- matlab-ts -*-
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function result = indent_xr_i_cont_incomplete5
++    
+ end
+  #+end_src diff
+
+- Invoking      : (insert "result = longFunction( ...")
+  Start point   :  254
+  Moved to point:  280
+  : 4:30:     result = longFunction( ...
+  :                                     ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -1,5 +1,5 @@
+ % -*- matlab-ts -*-
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function result = indent_xr_i_cont_incomplete5
+-    
++    result = longFunction( ...
+ end
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  280
+  Moved to point:  289
+  : 5:8:         
+  :              ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -2,4 +2,5 @@
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function result = indent_xr_i_cont_incomplete5
+     result = longFunction( ...
++        
+ end
+  #+end_src diff
+
+- Invoking      : (insert "99);")
+  Start point   :  289
+  Moved to point:  293
+  : 5:12:         99);
+  :                   ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -2,5 +2,5 @@
+ % (t-utils-xr "C-n" "C-e" "C-m" (insert "result = longFunction( ...") "C-m" 
(insert "99);") (re-search-backward "^fun") (print 
(buffer-substring-no-properties (point) (point-max))))
+ function result = indent_xr_i_cont_incomplete5
+     result = longFunction( ...
+-        
++        99);
+ end
+  #+end_src diff
+
+- Invoking      : (re-search-backward "^fun")
+  Start point   :  293
+  Moved to point:  203
+  : 3:0: function result = indent_xr_i_cont_incomplete5
+  :      ^
+  No buffer modifications
+
+- Invoking      : (print (buffer-substring-no-properties (point) (point-max)))
+  Start point   :  203
+  No point movement
+  standard-output:
+    "function result = indent_xr_i_cont_incomplete5
+      result = longFunction( ...
+          99);
+  end
+  "
+  No buffer modifications

Reply via email to