Skip to content

Make haskell indentation the default indentation mode #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2015
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
4 changes: 4 additions & 0 deletions haskell-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,10 @@ One indentation cycle is used."
;;;###autoload
(defun turn-on-haskell-indent ()
"Turn on ``intelligent'' Haskell indentation mode."
(when (and (bound-and-true-p haskell-indentation-mode)
(fboundp 'haskell-indentation-mode))
(haskell-indentation-mode 0))

(set (make-local-variable 'indent-line-function) 'haskell-indent-cycle)
(set (make-local-variable 'indent-region-function) 'haskell-indent-region)
(setq haskell-indent-mode t)
Expand Down
6 changes: 6 additions & 0 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ clashing with other modes."
(kill-local-variable 'indent-region-function)

(when haskell-indentation-mode
(when (and (bound-and-true-p haskell-indent-mode)
(fboundp 'turn-off-haskell-indent))
(turn-off-haskell-indent))
(when (and (bound-and-true-p haskell-simple-indent-mode)
(fboundp 'haskell-simple-indent-mode))
(haskell-simple-indent-mode 0))
(set (make-local-variable 'indent-line-function)
'haskell-indentation-indent-line)
(set (make-local-variable 'indent-region-function)
Expand Down
13 changes: 3 additions & 10 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
(require 'haskell-lexeme)
(require 'haskell-sort-imports)
(require 'haskell-string)
(require 'haskell-indentation)

;; All functions/variables start with `(literate-)haskell-'.

Expand Down Expand Up @@ -656,7 +657,7 @@ Minor modes that work well with `haskell-mode':
(set (make-local-variable 'comment-end-skip) "[ \t]*\\(-}\\|\\s>\\)")
(set (make-local-variable 'forward-sexp-function) #'haskell-forward-sexp)
(set (make-local-variable 'parse-sexp-ignore-comments) nil)
(set (make-local-variable 'indent-line-function) 'haskell-mode-suggest-indent-choice)

;; Set things up for eldoc-mode.
(set (make-local-variable 'eldoc-documentation-function)
'haskell-doc-current-info)
Expand Down Expand Up @@ -693,7 +694,7 @@ Minor modes that work well with `haskell-mode':
(setq haskell-literate nil)
(add-hook 'before-save-hook 'haskell-mode-before-save-handler nil t)
(add-hook 'after-save-hook 'haskell-mode-after-save-handler nil t)
)
(haskell-indentation-mode))

(defun haskell-fill-paragraph (justify)
(save-excursion
Expand Down Expand Up @@ -979,14 +980,6 @@ To be added to `flymake-init-create-temp-buffer-copy'."

(add-to-list 'flymake-allowed-file-name-masks '("\\.l?hs\\'" haskell-flymake-init))

(defun haskell-mode-suggest-indent-choice ()
"Ran when the user tries to indent in the buffer but no indentation mode has been selected.
Explains what has happened and suggests reading docs for `haskell-mode-hook'."
(interactive)
(error "You tried to do an indentation command, but an indentation mode has not been enabled yet.

Run M-x describe-variable haskell-mode-hook for a list of such modes."))

(defun haskell-mode-format-imports ()
"Format the imports by aligning and sorting them."
(interactive)
Expand Down
3 changes: 3 additions & 0 deletions haskell-simple-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ Runs `haskell-simple-indent-hook' on activation."
(kill-local-variable 'comment-indent-function)
(kill-local-variable 'indent-line-function)
(when haskell-simple-indent-mode
(when (and (bound-and-true-p haskell-indentation-mode)
(fboundp 'haskell-indentation-mode))
(haskell-indentation-mode 0))
(set (make-local-variable 'comment-indent-function) #'haskell-simple-indent-comment-indent-function)
(set (make-local-variable 'indent-line-function) 'haskell-simple-indent)
(run-hooks 'haskell-simple-indent-hook)))
Expand Down
28 changes: 28 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
(require 'haskell-mode)
(require 'haskell-font-lock)
(require 'haskell-indentation)
(require 'haskell-indent)
(require 'haskell-simple-indent)

;;; Code:

Expand Down Expand Up @@ -113,6 +115,32 @@ macro quotes them for you."
(list 'quote x))
test-cases))))))

(ert-deftest haskell-indentation-turns-off-haskell-indent ()
(with-temp-buffer
(haskell-mode)
(haskell-indent-mode)
(should haskell-indent-mode)
(haskell-indentation-mode)
(should haskell-indentation-mode)
(should-not haskell-indent-mode)

(haskell-indent-mode)
(should-not haskell-indentation-mode)
(should haskell-indent-mode)))

(ert-deftest haskell-indentation-turns-off-haskell-simple-indent ()
(with-temp-buffer
(haskell-mode)
(haskell-simple-indent-mode)
(should haskell-simple-indent-mode)
(haskell-indentation-mode)
(should haskell-indentation-mode)
(should-not haskell-simple-indent-mode)

(haskell-simple-indent-mode)
(should-not haskell-indentation-mode)
(should haskell-simple-indent-mode)))

(hindent-test "1 Check if '{' on its own line gets properly indented""
function = Record
{ field = 123 }"
Expand Down