Variable: haskell-ts-indent-rules

haskell-ts-indent-rules is a variable defined in haskell-ts-mode.el.

Value

Large value
((haskell ((node-is "^cpp$") column-0 0)
	  ((parent-is "^comment$") column-0 0)
	  ((parent-is "^haddock$") column-0 0)
	  ((parent-is "^imports$") column-0 0)
	  ((n-p-gp nil "infix" "infix")
	   (lambda (_ node _)
	     (let ((first-inf nil))
	       (while
		   (string= "infix"
			    (treesit-node-type
			     (setq node (treesit-node-parent node))))
		 (setq first-inf node))
	       (funcall
		#[771 "\300\301\302\"!\207"
		      [treesit-node-start treesit-node-child 0] 7
		      "\n\n(fn _ PARENT _)"]
		nil first-inf nil)))
	   2)
	  ((parent-is "^infix$") parent 2)
	  ((node-is "^infix$") standalone-parent 2)
	  ((parent-is "^lambda$") haskell-ts--stand-alone-parent 2)
	  ((parent-is "^class_declarations$") prev-sibling 0)
	  ((node-is "^where$") parent 2) ((node-is "^in$") parent 1)
	  ((parent-is "qualifiers") parent 0)
	  ((node-is "^]$") parent 0)
	  ((parent-is "^list$") standalone-parent 2)
	  ((node-is "^)$") parent 0)
	  ((parent-is "^field$") standalone-parent 2)
	  ((node-is "^}$")
	   (lambda (_ parent bol)
	     (let ((sib (treesit-node-child parent 0)))
	       (while
		   (and sib
			(not (string= (treesit-node-type sib) "{")))
		 (setq sib (treesit-node-next-sibling sib)))
	       (if sib (treesit-node-start sib) bol)))
	   0)
	  ((parent-is "^apply$") haskell-ts--stand-alone-parent 2)
	  ((node-is "^quasiquote$") grand-parent 2)
	  ((parent-is "^quasiquote_body$") (lambda (_ _ c) c) 0)
	  ((lambda (node parent bol)
	     (when-let ((n (treesit-node-prev-sibling node)))
	       (while (string= "comment" (treesit-node-type n))
		 (setq n (treesit-node-prev-sibling n)))
	       (string= "do" (treesit-node-type n))))
	   haskell-ts--stand-alone-parent 2)
	  ((parent-is "^do$")
	   #[769 "\301\300\302\"!\207"
		 [#[513
		    "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		    [haskell-ts--ignore-types
		     treesit-node-prev-sibling
		     treesit-node-next-sibling string-match
		     treesit-node-type]
		    8 "\n\n(fn NODE &optional ARG)"]
		  treesit-node-start t]
		 7 "\n\n(fn NODE &optional _ _)"]
	   0)
	  ((parent-is "^alternatives$")
	   #[769 "\301\300\302\"!\207"
		 [#[513
		    "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		    [haskell-ts--ignore-types
		     treesit-node-prev-sibling
		     treesit-node-next-sibling string-match
		     treesit-node-type]
		    8 "\n\n(fn NODE &optional ARG)"]
		  treesit-node-start t]
		 7 "\n\n(fn NODE &optional _ _)"]
	   0)
	  (no-node
	   (lambda (_ _ _)
	     (save-excursion
	       (goto-char (line-beginning-position 0))
	       (back-to-indentation) (if (looking-at "\n") 0 (point))))
	   0)
	  ((node-is "^data_constructors$") parent 4)
	  ((node-is "^data_constructor$") parent 0)
	  ((n-p-gp "^|$" "^data_constructors$" nil) parent -2)
	  ((node-is "local_binds")
	   #[769 "\301\300\302\"!\207"
		 [#[513
		    "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		    [haskell-ts--ignore-types
		     treesit-node-prev-sibling
		     treesit-node-next-sibling string-match
		     treesit-node-type]
		    8 "\n\n(fn NODE &optional ARG)"]
		  treesit-node-start t]
		 7 "\n\n(fn NODE &optional _ _)"]
	   2)
	  ((parent-is "local_binds\\|instance_declarations")
	   #[769 "\301\300\302\"!\207"
		 [#[513
		    "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		    [haskell-ts--ignore-types
		     treesit-node-prev-sibling
		     treesit-node-next-sibling string-match
		     treesit-node-type]
		    8 "\n\n(fn NODE &optional ARG)"]
		  treesit-node-start t]
		 7 "\n\n(fn NODE &optional _ _)"]
	   0)
	  ((node-is "^then$") parent 2) ((node-is "^else$") parent 2)
	  ((parent-is "^conditional$") parent 4)
	  ((lambda (_ p _)
	     (let ((gp "let_in"))
	       (or (string= gp (treesit-node-type p))
		   (string= gp
			    (treesit-node-type (treesit-node-parent p))))))
	   haskell-ts--stand-alone-parent 2)
	  ((lambda (node _ _)
	     (and (string= "match" (treesit-node-type node))
		  (string-match (regexp-opt '("patterns" "variable"))
				(treesit-node-type
				 (funcall
				  #[257 "\300\301\"\207"
					[#[513
					   "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
					   [haskell-ts--ignore-types
					    treesit-node-prev-sibling
					    treesit-node-next-sibling
					    string-match
					    treesit-node-type]
					   8
					   "\n\n(fn NODE &optional ARG)"]
					 t]
					4 "\n\n(fn NODE)"]
				  node)))))
	   parent 2)
	  ((node-is "^match$")
	   #[769 "\301\300\302\"!\207"
		 [#[513
		    "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		    [haskell-ts--ignore-types
		     treesit-node-prev-sibling
		     treesit-node-next-sibling string-match
		     treesit-node-type]
		    8 "\n\n(fn NODE &optional ARG)"]
		  treesit-node-start t]
		 7 "\n\n(fn NODE &optional _ _)"]
	   0)
	  ((parent-is "^match$") haskell-ts--stand-alone-parent 2)
	  ((parent-is "^haskell$") column-0 0)
	  ((parent-is "^declarations$") column-0 0)
	  ((parent-is "^record$") standalone-parent 2)
	  ((parent-is "^exports$")
	   (lambda (_ b _)
	     (treesit-node-start (treesit-node-prev-sibling b)))
	   0)
	  ((n-p-gp nil "signature" "foreign_import") grand-parent 3)
	  ((parent-is "^\\(lambda_\\)?case$")
	   haskell-ts--stand-alone-parent 2)
	  ((node-is "^alternatives$")
	   (lambda (_ b _)
	     (treesit-node-start (treesit-node-child b 0)))
	   2)
	  ((node-is "^comment$")
	   (lambda (node parent _)
	     (pcase node
	       ((app
		 #[513
		   "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
		   [haskell-ts--ignore-types treesit-node-prev-sibling
					     treesit-node-next-sibling
					     string-match
					     treesit-node-type]
		   8 "\n\n(fn NODE &optional ARG)"]
		 (and (pred (not null)) n))
		(treesit-node-start n))
	       ((app
		 #[769 "\301\300\302\"!\207"
		       [#[513
			  "\211\203�\301\202	�\302\211!\211\203!�\303\304!\"\203!�!\262\202\f�\207"
			  [haskell-ts--ignore-types
			   treesit-node-prev-sibling
			   treesit-node-next-sibling string-match
			   treesit-node-type]
			  8 "\n\n(fn NODE &optional ARG)"]
			treesit-node-start t]
		       7 "\n\n(fn NODE &optional _ _)"]
		 (and (pred (not null)) n))
		n)
	       (_ (treesit-node-start parent))))
	   0)
	  ((node-is "^|$") parent 0)
	  ((n-p-gp nil "function" "function\\|signature") parent 0)
	  (catch-all parent 2)))

Documentation

"Simple" treesit indentation rules for haskell.

Source Code

;; Defined in /nix/store/84k99g1lc4gz6zw2djcsyzr9zviz842h-emacs-packages-deps/share/emacs/site-lisp/elpa/haskell-ts-mode-1.3.5/haskell-ts-mode.el
(defvar haskell-ts-indent-rules
  (let* ((p-sib
          (lambda (node &optional arg)
            (let* ((func (if arg
                             #'treesit-node-prev-sibling
                           #'treesit-node-next-sibling))
                   (n (funcall func node)))
              (while (and n (string-match haskell-ts--ignore-types
                                          (treesit-node-type n)))
                (setq n (funcall func n)))
              n)))
         (p-prev-sib
          (lambda (node &optional _ _) (treesit-node-start (funcall p-sib node t))))
         (p-n-prev (lambda (node) (funcall p-sib node t)))
         (parent-first-child (lambda (_ parent _)
                               (treesit-node-start (treesit-node-child parent 0)))))
    `((haskell
       ((node-is "^cpp$") column-0 0)
       ((parent-is "^comment$") column-0 0)
       ((parent-is "^haddock$") column-0 0)
       ((parent-is "^imports$") column-0 0)
       ;; Infix
       ((n-p-gp nil "infix" "infix")
        (lambda (_ node _)
          (let ((first-inf nil))
            (while (string= "infix"
                            (treesit-node-type
                             (setq node (treesit-node-parent node))))
              (setq first-inf node))
            (funcall ,parent-first-child nil first-inf nil)))
        2)
       ((parent-is "^infix$") parent 2)
       ((node-is "^infix$") standalone-parent 2)

       ;; Lambda
       ((parent-is "^lambda$") haskell-ts--stand-alone-parent 2)

       ((parent-is "^class_declarations$") prev-sibling 0)

       ((node-is "^where$") parent 2)

       ;; in
       ((node-is "^in$") parent 1)

       ((parent-is "qualifiers") parent 0)

       ;; list
       ((node-is "^]$") parent 0)
       ((parent-is "^list$") standalone-parent 2)

       ;; Parens
       ((node-is "^)$") parent 0)

       ;; Structs
       ((parent-is "^field$") standalone-parent 2)
       ((node-is "^}$")
        (lambda (_ parent bol)
          (let ((sib (treesit-node-child parent 0)))
            (while (and sib (not (string= (treesit-node-type sib)
                                          "{"))) ; } Srry for ocd
              (setq sib (treesit-node-next-sibling sib)))
            (if sib
                (treesit-node-start sib)
              bol)))
        0)

       ((parent-is "^apply$") haskell-ts--stand-alone-parent 2)
       ((node-is "^quasiquote$") grand-parent 2)
       ((parent-is "^quasiquote_body$") (lambda (_ _ c) c) 0)
       ((lambda (node parent bol)
          (when-let ((n (treesit-node-prev-sibling node)))
            (while (string= "comment" (treesit-node-type n))
              (setq n (treesit-node-prev-sibling n)))
            (string= "do" (treesit-node-type n))))
        haskell-ts--stand-alone-parent
        2)
       ((parent-is "^do$") ,p-prev-sib 0)

       ((parent-is "^alternatives$") ,p-prev-sib 0)

       ;; prev-adaptive-prefix is broken sometimes
       (no-node
        (lambda (_ _ _)
          (save-excursion
            (goto-char (line-beginning-position 0))
            (back-to-indentation)
            (if (looking-at "\n")
                0
              (point))))
        0)

       ((node-is "^data_constructors$") parent 4)
       ((node-is "^data_constructor$") parent 0)
       ((n-p-gp "^\|$" "^data_constructors$" nil) parent -2)

       ;; where
       ((node-is "local_binds") ,p-prev-sib 2)

       ((parent-is "local_binds\\|instance_declarations") ,p-prev-sib 0)

       ;; Conditionals This builds up on the hackiness of what happens
       ;; in haskell-ts--stand-alone-parent
       ((node-is "^then$") parent 2)
       ((node-is "^else$") parent 2)
       ((parent-is "^conditional$") parent 4)

       ;; let.  It is important this one is in the bottom.
       ((lambda (_ p _)
          (let ((gp "let_in"))
            (or (string= gp (treesit-node-type p))
                (string= gp (treesit-node-type (treesit-node-parent p))))))
        haskell-ts--stand-alone-parent 2)


       ;; Match
       ((lambda (node _ _)
          (and (string= "match" (treesit-node-type node))
               (string-match (regexp-opt '("patterns" "variable"))
                             (treesit-node-type (funcall ,p-n-prev node)))))
        parent 2)

       ((node-is "^match$") ,p-prev-sib 0)
       ((parent-is "^match$") haskell-ts--stand-alone-parent 2)

       ((parent-is "^haskell$") column-0 0)
       ((parent-is "^declarations$") column-0 0)

       ((parent-is "^record$") standalone-parent 2)

       ((parent-is "^exports$")
        (lambda (_ b _) (treesit-node-start (treesit-node-prev-sibling b)))
        0)
       ((n-p-gp nil "signature" "foreign_import") grand-parent 3)
       ((parent-is "^\\(lambda_\\)?case$") haskell-ts--stand-alone-parent 2)
       ((node-is "^alternatives$")
        (lambda (_ b _)
          (treesit-node-start (treesit-node-child b 0)))
        2)
       ((node-is "^comment$")
        (lambda (node parent _)
          (pcase node
            ;; (relevent means type not it haskell-ts--ignore-types)
            ;; 1. next relevent sibling if exists
            ((app ,p-sib (and (pred (not null)) n))
             (treesit-node-start n))
            ;; 2. previous relevent sibling if exists
            ((app ,p-prev-sib (and (pred (not null)) n))
             n)
            ;; 3. parent
            (_ (treesit-node-start parent))))
        0)

       ;; TODO: I reckon this needs a variable
       ((node-is "^|$") parent 0)

       ;; Signature
       ((n-p-gp nil "function" "function\\|signature") parent 0)

       ;; Backup
       (catch-all parent 2))))
  "\"Simple\" treesit indentation rules for haskell.")