diff --git a/haskell-indentation.el b/haskell-indentation.el index 60cadd281..f5d721696 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -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) @@ -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 @@ -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") diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index b8877ac1a..4889b76a7 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -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