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

    matlab-ts-mode: fix indent issue involving properties
---
 matlab-ts-mode.el                                  |  14 +-
 .../indent_xr_classdef2.m                          |  16 ++
 .../indent_xr_classdef2_expected.org               | 216 +++++++++++++++++++++
 3 files changed, 241 insertions(+), 5 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index a1aa776172..0a5bf93597 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1270,7 +1270,7 @@ Prev-siblings:
 
   (when (or (and node
                  (string= (treesit-node-type node) "ERROR"))
-            (string= (treesit-node-type parent) "\n"))
+            (string-match-p (treesit-node-type parent) (rx (seq bos (or 
"ERROR" "\n") eos))))
 
     (let ((anchors-rx (rx (seq bos (or "function_definition"
                                        "classdef"
@@ -1301,12 +1301,16 @@ Prev-siblings:
 
             (setq ancestor (if in-error
                                nil
-                             (treesit-node-parent ancestor))))))
+                             (treesit-node-parent ancestor)))))
+        (when (eq ancestor-to-check node-to-check)
+          (setq ancestor-to-check nil)))
 
       ;; prev-sibling-to-check
 
       (let ((prev-sibling (treesit-node-prev-sibling node-to-check)))
-        (while (and prev-sibling (not prev-sibling-has-error))
+        (while (and prev-sibling
+                    (not prev-sibling-to-check)
+                    (not prev-sibling-has-error))
           (let ((prev-sibling-type (treesit-node-type prev-sibling)))
             (cond
              ((string= prev-sibling-type "ERROR")
@@ -1426,8 +1430,8 @@ Prev-siblings:
       grand-parent ,matlab-ts-mode--indent-level)
 
      ;; I-Rule: continuation of properties
-     ((n-p-gp nil nil ,(rx bos "property" eos))
-      grand-parent ,matlab-ts-mode--indent-level)
+     ;; See: tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2.m
+     ((n-p-gp nil nil ,(rx bos "property" eos)) grand-parent 0)
 
      ;; I-Rule: code in if, for, methods, arguments statements, etc.
      ((parent-is ,(rx bos (or "if_statement" "for_statement" "while_statement"
diff --git a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2.m 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2.m
new file mode 100644
index 0000000000..54d15aeb9a
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2.m
@@ -0,0 +1,16 @@
+% -*- matlab-ts -*-
+
+%{
+
+  (t-utils-xr
+  (re-search-forward "^classdef") "C-e" "C-m"
+  (insert "properties") "C-m"
+  (insert "p1") "C-m"
+  (insert "p2 double;") "C-m"
+  (insert "end") "C-m"
+  (insert "end")
+  (re-search-backward "^classdef")
+  (print (buffer-substring-no-properties (point) (point-max)))
+  )
+%}
+classdef indent_xr_classdef2
diff --git 
a/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2_expected.org 
b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2_expected.org
new file mode 100644
index 0000000000..ad6c2913b8
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-xr-files/indent_xr_classdef2_expected.org
@@ -0,0 +1,216 @@
+#+startup: showall
+
+* Executing commands from indent_xr_classdef2.m:5:2:
+
+  (t-utils-xr
+  (re-search-forward "^classdef") "C-e" "C-m"
+  (insert "properties") "C-m"
+  (insert "p1") "C-m"
+  (insert "p2 double;") "C-m"
+  (insert "end") "C-m"
+  (insert "end")
+  (re-search-backward "^classdef")
+  (print (buffer-substring-no-properties (point) (point-max)))
+  )
+
+- Invoking      : (re-search-forward "^classdef")
+  Start point   :  309
+  Moved to point:  321
+  : 16:8: classdef indent_xr_classdef2
+  :               ^
+  No buffer modifications
+
+- Invoking      : "C-e" = move-end-of-line
+  Start point   :  321
+  Moved to point:  341
+  : 16:28: classdef indent_xr_classdef2
+  :                                    ^
+  No buffer modifications
+
+- Invoking      : "C-m" = newline
+  Start point   :  341
+  Moved to point:  346
+  : 17:4:     
+  :           ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -14,3 +14,4 @@
+   )
+ %}
+ classdef indent_xr_classdef2
++    
+  #+end_src diff
+
+- Invoking      : (insert "properties")
+  Start point   :  346
+  Moved to point:  356
+  : 17:14:     properties
+  :                      ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -14,4 +14,4 @@
+   )
+ %}
+ classdef indent_xr_classdef2
+-    
++    properties
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  356
+  Moved to point:  365
+  : 18:8:         
+  :               ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -15,3 +15,4 @@
+ %}
+ classdef indent_xr_classdef2
+     properties
++        
+  #+end_src diff
+
+- Invoking      : (insert "p1")
+  Start point   :  365
+  Moved to point:  367
+  : 18:10:         p1
+  :                  ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -15,4 +15,4 @@
+ %}
+ classdef indent_xr_classdef2
+     properties
+-        
++        p1
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  367
+  Moved to point:  376
+  : 19:8:         
+  :               ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -16,3 +16,4 @@
+ classdef indent_xr_classdef2
+     properties
+         p1
++        
+  #+end_src diff
+
+- Invoking      : (insert "p2 double;")
+  Start point   :  376
+  Moved to point:  386
+  : 19:18:         p2 double;
+  :                          ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -16,4 +16,4 @@
+ classdef indent_xr_classdef2
+     properties
+         p1
+-        
++        p2 double;
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  386
+  Moved to point:  395
+  : 20:8:         
+  :               ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -17,3 +17,4 @@
+     properties
+         p1
+         p2 double;
++        
+  #+end_src diff
+
+- Invoking      : (insert "end")
+  Start point   :  395
+  Moved to point:  398
+  : 20:11:         end
+  :                   ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -17,4 +17,4 @@
+     properties
+         p1
+         p2 double;
+-        
++        end
+  #+end_src diff
+
+- Invoking      : "C-m" = newline
+  Start point   :  398
+  Moved to point:  395
+  : 21:0: 
+  :       ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -17,4 +17,5 @@
+     properties
+         p1
+         p2 double;
+-        end
++    end
++
+  #+end_src diff
+
+- Invoking      : (insert "end")
+  Start point   :  395
+  Moved to point:  398
+  : 21:3: end
+  :          ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -18,4 +18,4 @@
+         p1
+         p2 double;
+     end
+-
++end
+  #+end_src diff
+
+- Invoking      : (re-search-backward "^classdef")
+  Start point   :  398
+  Moved to point:  313
+  : 16:0: classdef indent_xr_classdef2
+  :       ^
+  No buffer modifications
+
+- Invoking      : (print (buffer-substring-no-properties (point) (point-max)))
+  Start point   :  313
+  No point movement
+  standard-output:
+  #+begin_example
+classdef indent_xr_classdef2
+    properties
+        p1
+        p2 double;
+    end
+end
+  #+end_example
+  No buffer modifications

Reply via email to