@@ -494,7 +494,8 @@ fixes up only indentation."
494494 (" newtype" . haskell-indentation-data)
495495 (" import" . haskell-indentation-import)
496496 (" class" . haskell-indentation-class-declaration)
497- (" instance" . haskell-indentation-class-declaration))
497+ (" instance" . haskell-indentation-class-declaration)
498+ (" deriving" . haskell-indentation-deriving))
498499 " Alist of toplevel keywords with associated parsers." )
499500
500501(defconst haskell-indentation-type-list
@@ -633,6 +634,25 @@ After a lambda (backslash) there are two possible cases:
633634 (throw 'return nil )
634635 (funcall (cdr parser))))))))))
635636
637+ (defun haskell-indentation-type-1 ()
638+ " Parse a single type declaration."
639+ (let ((current-indent (current-column )))
640+ (catch 'return
641+ (cond
642+ ((member current-token '(value operator " ->" ))
643+ (haskell-indentation-read-next-token))
644+
645+ ((eq current-token 'end-tokens )
646+ (when (member following-token
647+ '(value operator no-following-token
648+ " ->" " (" " [" " {" " ::" ))
649+ (haskell-indentation-add-indentation current-indent))
650+ (throw 'return nil ))
651+ (t (let ((parser (assoc current-token haskell-indentation-type-list)))
652+ (if (not parser)
653+ (throw 'return nil )
654+ (funcall (cdr parser)))))))))
655+
636656(defun haskell-indentation-scoped-type ()
637657 " Parse scoped type declaration.
638658
@@ -655,13 +675,30 @@ For example
655675 (haskell-indentation-add-indentation current-indent)
656676 (throw 'parse-end nil )))
657677 ((string= current-token " =" )
658- (haskell-indentation-with-starter
659- (lambda ()
660- (haskell-indentation-separated
661- #'haskell-indentation-expression " |" " deriving" ))))
678+ (let ((starter-indent-inside (current-column )))
679+ (haskell-indentation-with-starter
680+ (lambda ()
681+ (haskell-indentation-separated
682+ #'haskell-indentation-expression " |" )))
683+ (cond
684+ ((equal current-token 'end-tokens )
685+ (when (string= following-token " deriving" )
686+ (haskell-indentation-push-indentation starter-indent-inside)
687+ (haskell-indentation-add-left-indent)))
688+ ((equal current-token " deriving" )
689+ (haskell-indentation-with-starter
690+ #'haskell-indentation-type-1 )))))
662691 ((string= current-token " where" )
663- (haskell-indentation-with-starter
664- #'haskell-indentation-expression-layout nil ))))
692+ (let ((starter-indent-inside (current-column )))
693+ (haskell-indentation-with-starter
694+ #'haskell-indentation-expression-layout nil )
695+ (cond
696+ ((equal current-token 'end-tokens )
697+ (when (string= following-token " deriving" )
698+ (haskell-indentation-add-left-indent)))
699+ ((equal current-token " deriving" )
700+ (haskell-indentation-with-starter
701+ #'haskell-indentation-type-1 )))))))
665702
666703(defun haskell-indentation-import ()
667704 " Parse import declaration."
@@ -678,6 +715,19 @@ For example
678715 (haskell-indentation-with-starter
679716 #'haskell-indentation-declaration-layout nil )))))
680717
718+ (defun haskell-indentation-deriving ()
719+ " Parse standalone declaration."
720+ (haskell-indentation-with-starter
721+ (lambda ()
722+ (when (string= " instance" current-token)
723+ (haskell-indentation-read-next-token))
724+ (when (equal current-token 'end-tokens )
725+ (haskell-indentation-add-left-indent)
726+ (throw 'parse-end nil ))
727+ (haskell-indentation-type)
728+ (when (string= current-token " |" )
729+ (haskell-indentation-fundep)))))
730+
681731(defun haskell-indentation-module ()
682732 " Parse module declaration."
683733 (haskell-indentation-with-starter
0 commit comments