Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ and indent when all of the following are true:
("type" . haskell-indentation-data)
("newtype" . haskell-indentation-data)
("import" . haskell-indentation-import)
("foreign" . haskell-indentation-foreign)
("where" . haskell-indentation-toplevel-where)
("class" . haskell-indentation-class-declaration)
("instance" . haskell-indentation-class-declaration)
Expand Down Expand Up @@ -739,6 +740,10 @@ For example
"Parse import declaration."
(haskell-indentation-with-starter #'haskell-indentation-expression))

(defun haskell-indentation-foreign ()
"Parse foreign import declaration."
(haskell-indentation-with-starter (apply-partially #'haskell-indentation-expression '(value operator "import"))))

(defun haskell-indentation-class-declaration ()
"Parse class declaration."
(haskell-indentation-with-starter
Expand Down Expand Up @@ -927,13 +932,15 @@ parser. If parsing ends here, set indentation to left-indent."
'("if" "let" "do" "case" "\\" "(" "{" "[" "::"
value operator no-following-token)))

(defun haskell-indentation-expression ()
(defun haskell-indentation-expression (&optional accepted-tokens)
"Parse an expression until an unknown token is encountered."
(catch 'return
(let ((current-indent (current-column)))
(unless accepted-tokens
(setq accepted-tokens '(value operator)))
(while t
(cond
((memq current-token '(value operator))
((memq current-token accepted-tokens)
(haskell-indentation-read-next-token))
((eq current-token 'end-tokens)
(cond ((string= following-token "where")
Expand Down
5 changes: 5 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,11 @@ func = \"unterminated
(1 0)
(2 2))

(hindent-test "62 foreign import""
import javascript unsafe
\"$2[$1]\" js_getProp :: S.JSString -> O.Object -> T.JSVal"
(1 0)
(2 0 2 7))

(ert-deftest haskell-indentation-ret-indents ()
(with-temp-switch-to-buffer
Expand Down