branch: elpa/haskell-tng-mode commit 8c2e3f76a0791e1adcb941414b3403ec40dd4df4 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
better symid indentation --- haskell-tng-smie.el | 30 ++++++++++++++++++++++-------- test/src/indentation.hs | 11 +++++++++-- test/src/indentation.hs.append.indent | 32 +++++++++++++++++++++++--------- test/src/indentation.hs.insert.indent | 30 ++++++++++++++++++++++-------- test/src/indentation.hs.layout | 13 ++++++++++--- test/src/indentation.hs.lexer | 13 ++++++++++--- test/src/indentation.hs.reindent | 30 ++++++++++++++++++++++-------- test/src/indentation.hs.sexps | 15 +++++++++++---- test/src/indentation.hs.syntax | 11 +++++++++-- 9 files changed, 138 insertions(+), 47 deletions(-) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 0d7ba97..8b2f647 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -92,6 +92,8 @@ (id "<-" id) (id "->" id) ) + (lambdas + ("\\" id)) (logic ("if" id "then" id "else" id)) @@ -157,7 +159,7 @@ information, to aid in the creation of new rules." (when-let (grand (caddr (smie-indent--grandparent))) (with-current-buffer haskell-tng-smie:debug (insert (format " GRAND: %S\n" grand)))) - (when-let (prev (caddr (smie-indent--previous-line-start))) + (when-let (prev (caddr (smie-indent--prev-line-start))) (with-current-buffer haskell-tng-smie:debug (insert (format " PREV: %S\n" prev))))) @@ -176,7 +178,7 @@ information, to aid in the creation of new rules." ((or (smie-rule-parent-p "|") (and (smie-rule-parent-p "=") (smie-rule-grandparent-p "data")) - (smie-rule-previous-line-start-p "|")) + (smie-rule-prev-line-start-p "|")) "|") ((save-excursion @@ -198,15 +200,17 @@ information, to aid in the creation of new rules." (:list-intro (pcase arg - ((or "<-" "$") t) + ((or "<-" "$" "SYMID") t) ("=" (not (smie-rule-parent-p "data"))) )) (:after (pcase arg - ((or "let" "do" "of" "=" "in" "$" "->") 2) + ((or "let" "do" "of" "=" "in" "->" "\\") 2) ("\\case" 2) ;; LambdaCase ("where" (if (smie-rule-parent-p "module") 0 2)) + ((or "$" "SYMID") + (if (smie-rule-hanging-p) 2 (smie-rule-parent))) )) (:before @@ -221,7 +225,7 @@ information, to aid in the creation of new rules." ;; ;; blah = bloo where ;; bloo = blu - ((or "{" "where" "let" "do" "case" "$" "->") + ((or "{" "where" "let" "do" "case" "->" "$" "SYMID") ;; TODO { here should only be for WLDOs (smie-rule-parent)) ("\\case" ;; LambdaCase @@ -230,6 +234,8 @@ information, to aid in the creation of new rules." (if (smie-rule-parent-p "=") (smie-rule-parent-column) (smie-rule-separator method))) + (_ (when (smie-rule-parent-p "$" "SYMID") + (smie-rule-parent))) )) )) @@ -241,6 +247,10 @@ information, to aid in the creation of new rules." haskell-tng-smie:debug-newline) "Users with custom newlines should add their command.") +;; TODO newline and indent at the beginning of a line should be the same as +;; newline and indent at the end of the previous line. Newline in the middle of +;; a line is trickier. + (defvar-local haskell-tng-smie:indentations nil) (defun haskell-tng-smie:indent-cycle () "When invoked more than once, returns an alternative indentation level." @@ -384,7 +394,7 @@ use the column indentation as the parent. Note that "Like `smie-rule-parent-p' but for the parent's parent." (member (nth 2 (smie-indent--grandparent)) grandparents)) -(defun smie-indent--previous-line-start () +(defun smie-indent--prev-line-start () "Like `smie-indent--parent' but for the previous line's first token." (save-excursion @@ -393,9 +403,13 @@ use the column indentation as the parent. Note that (tok (funcall smie-forward-token-function))) (list nil pos tok)))) -(defun smie-rule-previous-line-start-p (&rest tokens) +(defun smie-rule-prev-line-start-p (&rest tokens) "Like `smie-rule-parent-p' but for the parent's parent." - (member (nth 2 (smie-indent--previous-line-start)) tokens)) + (member (nth 2 (smie-indent--prev-line-start)) tokens)) + +(defun smie-prev-token-p (&rest tokens) + "Like `smie-rule-prev-p' but doesn't filter based on the grammar table." + (member (save-excursion (funcall smie-backward-token-function)) tokens)) (provide 'haskell-tng-smie) ;;; haskell-tng-smie.el ends here diff --git a/test/src/indentation.hs b/test/src/indentation.hs index b981d2f..2b0db4e 100644 --- a/test/src/indentation.hs +++ b/test/src/indentation.hs @@ -53,8 +53,10 @@ implicit_let foo bar = in rar case_of wibble = case wibble of - Nothing -> "" - Just fish -> fish + Nothing -> + "" + Just fish -> + fish lambda_case = \case Nothing -> "" @@ -66,6 +68,11 @@ dollars f Nothing = f $ dollars f (Just a) = f $ \s -> a +not_dollars = do + db' <- liftIO $ readMVar db + shouldGoHere <$> + here + data Wibble = Wibble Int | Wobble Int | Vibble Int diff --git a/test/src/indentation.hs.append.indent b/test/src/indentation.hs.append.indent index 3c3e1db..1392bd9 100644 --- a/test/src/indentation.hs.append.indent +++ b/test/src/indentation.hs.append.indent @@ -108,12 +108,16 @@ v 1 2 v 1 2 case_of wibble = case wibble of 1 v - Nothing -> "" -1 v - Just fish -> fish -1 v + Nothing -> +2 1 v + "" +2 v 1 + Just fish -> +2 1 v + fish +2 v 1 -1 v +1 v 2 lambda_case = \case 1 v Nothing -> "" @@ -125,15 +129,25 @@ lambda_case = \case dollars f Nothing = f $ 1 v "" "" -1 v +v 1 "" -1 v +v 1 dollars f (Just a) = f $ \s -> 1 v a -2 1 v +v 1 + +v 1 +not_dollars = do +1 v + db' <- liftIO $ readMVar db +2 v 1 + shouldGoHere <$> +2 1 v 3 + here +2 v 1 3 -1 2 v +1 v 2 3 data Wibble = Wibble Int v | Wobble Int diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent index ea7776d..f7eedd9 100644 --- a/test/src/indentation.hs.insert.indent +++ b/test/src/indentation.hs.insert.indent @@ -108,12 +108,16 @@ v 1 2 v 1 2 case_of wibble = case wibble of 1 v - Nothing -> "" -1 v - Just fish -> fish -1 v + Nothing -> +2 1 v + "" +2 v 1 + Just fish -> +2 1 v + fish +2 v 1 -1 v +1 v 2 lambda_case = \case 1 v Nothing -> "" @@ -127,13 +131,23 @@ dollars f Nothing = f $ "" "" 1 v "" -1 v +v 1 dollars f (Just a) = f $ \s -> 1 v a -2 1 v +v 1 + +v 1 +not_dollars = do +1 v + db' <- liftIO $ readMVar db +2 v 1 + shouldGoHere <$> +2 1 v 3 + here +2 v 1 3 -1 2 v +1 v 2 3 data Wibble = Wibble Int 1 v | Wobble Int diff --git a/test/src/indentation.hs.layout b/test/src/indentation.hs.layout index 7014959..b7767cd 100644 --- a/test/src/indentation.hs.layout +++ b/test/src/indentation.hs.layout @@ -53,8 +53,10 @@ module Indentation where }in rar ;case_of wibble = case wibble of - {Nothing -> "" - ;Just fish -> fish + {Nothing -> + "" + ;Just fish -> + fish };lambda_case = \case {Nothing -> "" @@ -66,7 +68,12 @@ module Indentation where ;dollars f (Just a) = f $ \s -> a -;data Wibble = Wibble Int +;not_dollars = do + {db' <- liftIO $ readMVar db + ;shouldGoHere <$> + here + +};data Wibble = Wibble Int | Wobble Int | Vibble Int } \ No newline at end of file diff --git a/test/src/indentation.hs.lexer b/test/src/indentation.hs.lexer index 8e81755..5ff22ed 100644 --- a/test/src/indentation.hs.lexer +++ b/test/src/indentation.hs.lexer @@ -53,8 +53,10 @@ let { VARID = VARID } in VARID ; VARID VARID = case VARID of -{ CONID -> § -; CONID VARID -> VARID +{ CONID -> +§ +; CONID VARID -> +VARID } ; VARID = \case { CONID -> § @@ -66,7 +68,12 @@ let { VARID = VARID ; VARID VARID « CONID VARID » = VARID $ \ VARID -> VARID -; data CONID = CONID CONID +; VARID = do +{ VARID <- VARID $ VARID VARID +; VARID SYMID +VARID + +} ; data CONID = CONID CONID | CONID CONID | CONID CONID } diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent index 2a22693..b6181e0 100644 --- a/test/src/indentation.hs.reindent +++ b/test/src/indentation.hs.reindent @@ -108,13 +108,17 @@ v 1 2 v 1 2 case_of wibble = case wibble of -1 v - Nothing -> "" -v 1 - Just fish -> fish -1 v +1 v 2 + Nothing -> +2 1 v + "" +v 2 1 + Just fish -> +2 1 v + fish +2 v 1 -v 1 +v 1 2 lambda_case = \case 1 v Nothing -> "" @@ -132,9 +136,19 @@ v 1 dollars f (Just a) = f $ \s -> 1 v a -2 1 v +v 1 + +v 1 +not_dollars = do +1 v 2 + db' <- liftIO $ readMVar db +v 1 3 2 + shouldGoHere <$> +2 1 v 3 + here +2 v 1 3 -v 2 1 +v 2 3 4 1 data Wibble = Wibble Int 1 v | Wobble Int diff --git a/test/src/indentation.hs.sexps b/test/src/indentation.hs.sexps index 73ea076..32ad8d7 100644 --- a/test/src/indentation.hs.sexps +++ b/test/src/indentation.hs.sexps @@ -53,8 +53,10 @@ )in) (rar) ((case_of) (wibble) = ((case (wibble) (of) - ((Nothing) -> ("") - ((Just) (fish) -> (fish)) + ((Nothing) -> + ("") + ((Just) (fish) -> + (fish)) )(lambda_case) = (\(case ((Nothing) -> ("") @@ -66,7 +68,12 @@ ((dollars) (f) ((Just) (a)) = (f) $ (\)(s) -> (a) -(data (Wibble) = (Wibble) (Int) +((not_dollars) = (do + ((db') <- (liftIO) $ (readMVar) (db) + ((shouldGoHere) <$> + (here)) + +)data (Wibble) = (Wibble) (Int) | (Wobble) (Int) - | (Vibble) (Int)))))))))))) + | (Vibble) (Int))))))))))))) ))) \ No newline at end of file diff --git a/test/src/indentation.hs.syntax b/test/src/indentation.hs.syntax index ede9586..115fdcb 100644 --- a/test/src/indentation.hs.syntax +++ b/test/src/indentation.hs.syntax @@ -53,8 +53,10 @@ wwwwwwwwwwww www www _> ww www> > wwwwwww wwwwww _ wwww wwwwww ww> - wwwwwww __ ""> - wwww wwww __ wwww> + wwwwwww __> + ""> + wwww wwww __> + wwww> > wwwwwwwwwww _ _wwww> wwwwwww __ ""> @@ -66,6 +68,11 @@ wwwwwww w wwwwwww _ w _> wwwwwww w (wwww w) _ w _ _w __> w> > +wwwwwwwwwww _ ww> + www __ wwwwww _ wwwwwwww ww> + wwwwwwwwwwww ___> + wwww> +> wwww wwwwww _ wwwwww www> _ wwwwww www> _ wwwwww www>