From 10f7da71aefefeddf39ac0d2cd9c5fe144970c6a Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 9 Oct 2015 13:36:59 +0200 Subject: [PATCH 1/3] Make three indentation modes mutually turn each other off --- haskell-indent.el | 4 ++++ haskell-indentation.el | 6 ++++++ haskell-simple-indent.el | 3 +++ 3 files changed, 13 insertions(+) diff --git a/haskell-indent.el b/haskell-indent.el index 193847295..a10885c93 100644 --- a/haskell-indent.el +++ b/haskell-indent.el @@ -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) diff --git a/haskell-indentation.el b/haskell-indentation.el index db15d9bae..56c209388 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -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) diff --git a/haskell-simple-indent.el b/haskell-simple-indent.el index 51b4fdf9b..1d43d23f6 100644 --- a/haskell-simple-indent.el +++ b/haskell-simple-indent.el @@ -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))) From addde9d267e83e3f5dcd78631ac5893298694a4e Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Wed, 14 Oct 2015 18:20:02 +0200 Subject: [PATCH 2/3] Add tests that check if modes are mutually exclusive --- tests/haskell-indentation-tests.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index 99489a8b2..44e0d60e0 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -27,6 +27,8 @@ (require 'haskell-mode) (require 'haskell-font-lock) (require 'haskell-indentation) +(require 'haskell-indent) +(require 'haskell-simple-indent) ;;; Code: @@ -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 }" From ee5effd110cd0f23d36cc391fbba767816dfc83b Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Fri, 9 Oct 2015 13:37:38 +0200 Subject: [PATCH 3/3] Make haskell-indentation the default --- haskell-mode.el | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/haskell-mode.el b/haskell-mode.el index 369163f8d..8b7a11422 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -139,6 +139,7 @@ (require 'haskell-lexeme) (require 'haskell-sort-imports) (require 'haskell-string) +(require 'haskell-indentation) ;; All functions/variables start with `(literate-)haskell-'. @@ -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) @@ -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 @@ -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)