2016-06-24 15:37:01 +00:00
|
|
|
|
;;; funcs.el --- Haskell Layer funcs File for Spacemacs
|
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2016-06-24 15:37:01 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-completion-backend ()
|
|
|
|
|
"Conditionally setup haskell completion backend."
|
2017-07-02 13:48:06 +00:00
|
|
|
|
(when (configuration-layer/package-used-p 'company)
|
2016-06-24 15:37:01 +00:00
|
|
|
|
(pcase haskell-completion-backend
|
2016-06-28 08:24:54 +00:00
|
|
|
|
(`ghci (spacemacs-haskell//setup-ghci))
|
|
|
|
|
(`ghc-mod (spacemacs-haskell//setup-ghc-mod))
|
2017-05-27 20:57:22 +00:00
|
|
|
|
(`intero (spacemacs-haskell//setup-intero))
|
|
|
|
|
(`dante (spacemacs-haskell//setup-dante)))))
|
2016-06-24 15:37:01 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-ghci ()
|
2017-05-27 20:57:22 +00:00
|
|
|
|
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
|
2017-01-02 05:39:04 +00:00
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends (company-ghci company-dabbrev-code company-yasnippet)
|
|
|
|
|
:modes haskell-mode))
|
2016-06-24 15:37:01 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-ghc-mod ()
|
2017-01-02 05:39:04 +00:00
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends (company-ghc company-dabbrev-code company-yasnippet)
|
|
|
|
|
:modes haskell-mode)
|
2016-06-24 15:37:01 +00:00
|
|
|
|
(ghc-init)
|
|
|
|
|
(dolist (mode haskell-modes)
|
|
|
|
|
(spacemacs/declare-prefix-for-mode mode "mm" "haskell/ghc-mod")
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"mt" 'ghc-insert-template-or-signature
|
|
|
|
|
"mu" 'ghc-initial-code-from-signature
|
|
|
|
|
"ma" 'ghc-auto
|
|
|
|
|
"mf" 'ghc-refine
|
|
|
|
|
"me" 'ghc-expand-th
|
|
|
|
|
"mn" 'ghc-goto-next-hole
|
|
|
|
|
"mp" 'ghc-goto-prev-hole
|
|
|
|
|
"m>" 'ghc-make-indent-deeper
|
|
|
|
|
"m<" 'ghc-make-indent-shallower
|
|
|
|
|
"hi" 'ghc-show-info
|
|
|
|
|
"ht" 'ghc-show-type))
|
2017-07-02 13:48:06 +00:00
|
|
|
|
(when (configuration-layer/package-used-p 'flycheck)
|
2016-06-24 15:37:01 +00:00
|
|
|
|
;; remove overlays from ghc-check.el if flycheck is enabled
|
|
|
|
|
(set-face-attribute 'ghc-face-error nil :underline nil)
|
|
|
|
|
(set-face-attribute 'ghc-face-warn nil :underline nil)))
|
|
|
|
|
|
2017-05-27 20:57:22 +00:00
|
|
|
|
(defun spacemacs-haskell//setup-dante ()
|
|
|
|
|
(spacemacs|add-company-backends
|
2017-10-12 23:00:05 +00:00
|
|
|
|
:backends (dante-company company-dabbrev-code company-yasnippet)
|
2017-05-27 20:57:22 +00:00
|
|
|
|
:modes haskell-mode)
|
|
|
|
|
(push 'xref-find-definitions spacemacs-jump-handlers)
|
2017-05-28 12:41:33 +00:00
|
|
|
|
(dante-mode)
|
2017-05-27 20:57:22 +00:00
|
|
|
|
(dolist (mode haskell-modes)
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"ht" 'dante-type-at
|
|
|
|
|
"hT" 'spacemacs-haskell//dante-insert-type
|
|
|
|
|
"hi" 'dante-info
|
|
|
|
|
"rs" 'dante-auto-fix
|
|
|
|
|
"se" 'dante-eval-block
|
|
|
|
|
"sr" 'dante-restart)))
|
|
|
|
|
|
2016-06-24 15:37:01 +00:00
|
|
|
|
(defun spacemacs-haskell//setup-intero ()
|
2017-05-27 20:57:22 +00:00
|
|
|
|
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
|
2017-01-02 05:39:04 +00:00
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends (company-intero company-dabbrev-code company-yasnippet)
|
|
|
|
|
:modes haskell-mode)
|
2016-08-13 13:43:37 +00:00
|
|
|
|
(push 'intero-goto-definition spacemacs-jump-handlers)
|
2016-06-24 15:37:01 +00:00
|
|
|
|
(intero-mode)
|
|
|
|
|
(dolist (mode haskell-modes)
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"hi" 'intero-info
|
|
|
|
|
"ht" 'intero-type-at
|
|
|
|
|
"hT" 'haskell-intero/insert-type
|
2016-08-29 14:01:53 +00:00
|
|
|
|
"rs" 'intero-apply-suggestions
|
2016-06-24 15:37:01 +00:00
|
|
|
|
"sb" 'intero-repl-load))
|
|
|
|
|
|
|
|
|
|
(dolist (mode (cons 'haskell-cabal-mode haskell-modes))
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"sc" nil
|
2017-10-19 13:25:35 +00:00
|
|
|
|
"sS" 'haskell-intero/display-repl
|
|
|
|
|
"ss" 'haskell-intero/pop-to-repl))
|
2016-06-24 15:37:01 +00:00
|
|
|
|
|
|
|
|
|
(dolist (mode (append haskell-modes '(haskell-cabal-mode intero-repl-mode)))
|
|
|
|
|
(spacemacs/declare-prefix-for-mode mode "mi" "haskell/intero")
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"ic" 'intero-cd
|
|
|
|
|
"id" 'intero-devel-reload
|
|
|
|
|
"ik" 'intero-destroy
|
|
|
|
|
"il" 'intero-list-buffers
|
|
|
|
|
"ir" 'intero-restart
|
|
|
|
|
"it" 'intero-targets))
|
|
|
|
|
|
|
|
|
|
(evil-define-key '(insert normal) intero-mode-map
|
|
|
|
|
(kbd "M-.") 'intero-goto-definition))
|
2016-07-11 12:24:50 +00:00
|
|
|
|
|
2017-02-02 12:11:57 +00:00
|
|
|
|
(defun spacemacs-haskell//disable-electric-indent ()
|
|
|
|
|
"Disable electric indent mode if available"
|
|
|
|
|
;; use only internal indentation system from haskell
|
|
|
|
|
(if (fboundp 'electric-indent-local-mode)
|
|
|
|
|
(electric-indent-local-mode -1)))
|
|
|
|
|
|
2018-01-24 17:50:32 +00:00
|
|
|
|
(defun spacemacs/haskell-format-imports ()
|
|
|
|
|
"Sort and align import statements from anywhere in the source file."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(haskell-navigate-imports)
|
|
|
|
|
(haskell-mode-format-imports)))
|
|
|
|
|
|
2017-05-27 20:57:22 +00:00
|
|
|
|
;; Dante Functions
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//dante-insert-type ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(dante-type-at :insert))
|
|
|
|
|
|
2016-07-11 12:24:50 +00:00
|
|
|
|
|
|
|
|
|
;; Intero functions
|
|
|
|
|
|
|
|
|
|
(defun haskell-intero/insert-type ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(intero-type-at :insert))
|
|
|
|
|
|
|
|
|
|
(defun haskell-intero/display-repl (&optional prompt-options)
|
|
|
|
|
(interactive "P")
|
2017-10-19 13:25:35 +00:00
|
|
|
|
(let ((buffer (intero-repl-buffer prompt-options t)))
|
2016-07-11 12:24:50 +00:00
|
|
|
|
(unless (get-buffer-window buffer 'visible)
|
|
|
|
|
(display-buffer buffer))))
|
|
|
|
|
|
|
|
|
|
(defun haskell-intero/pop-to-repl (&optional prompt-options)
|
|
|
|
|
(interactive "P")
|
2017-10-19 13:25:35 +00:00
|
|
|
|
(pop-to-buffer (intero-repl-buffer prompt-options t)))
|
2016-07-11 12:24:50 +00:00
|
|
|
|
|
|
|
|
|
(defun haskell-intero//preserve-focus (f &rest args)
|
|
|
|
|
(let ((buffer (current-buffer)))
|
|
|
|
|
(apply f args)
|
|
|
|
|
(pop-to-buffer buffer)))
|