branch: elpa/haskell-ts-mode
commit 23137bf6cdb9b0a3f4a8f9f44c021be75655e5f1
Author: pranshu sharma <pranshu@pebl>
Commit: pranshu sharma <pranshu@pebl>

    Fixed indent comments
    
    When 2+ comments were next to each other, it would take lots of
    'C-M-q' presses. Now it ignores the sibling
---
 haskell-ts-mode.el | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/haskell-ts-mode.el b/haskell-ts-mode.el
index d867be279c..e93d0894f6 100644
--- a/haskell-ts-mode.el
+++ b/haskell-ts-mode.el
@@ -164,27 +164,34 @@
                                           (treesit-node-parent parent))
                                        nil)))))
 
-(defvar haskell-ts-indent-rules
-  (let ((p-prev-sib
-        (lambda (node _ _)
+(defvar haskell-ts--ignore-types
+  '("comment" "cpp" "haddock")
+  "Node types that will be ignored by indentation.")
+
+(setq haskell-ts-indent-rules
+  (let* ((p-sib
+        (lambda (node arg)
           (let ((n (treesit-node-prev-sibling node)))
-            (while (string-match (regexp-opt '("comment" "cpp" "haddock"))
+            (while (string-match (regexp-opt haskell-ts--ignore-types)
                                  (treesit-node-type n))
-              (setq n (treesit-node-prev-sibling n)))
-            (treesit-node-start n)))))
+              (setq n (if arg (treesit-node-prev-sibling n)
+                        (treesit-node-next-sibling n))))
+            (treesit-node-start n))))
+        (p-prev-sib
+         (lambda (node _ _) (funcall p-sib node t))))
     `((haskell
        ((node-is "comment")
        ;; Indenting comments by priorites:
-       ;; 1. next sibling if exists
-       ;; 2. pev sibling if exists
+       ;; 1. next relevent sibling if exists
+       ;; 2. previous relevent sibling if exists
        ;; 3. parent
+       ;; (relevent means type not it haskell-ts--ignore-types)
        (lambda (node parent _)
-         (treesit-node-start
-          (if-let ((next-sib (treesit-node-next-sibling node)))
+          (if-let ((next-sib (funcall ,p-sib node t)))
               next-sib
-            (if-let ((prev-sib (treesit-node-next-sibling node)))
+            (if-let ((prev-sib (funcall ,p-prev-sib node nil nil)))
               prev-sib
-            parent))))
+            parent)))
        0)
        ((node-is "cpp") column-0 0)
        ((parent-is "comment") column-0 0)

Reply via email to