spacemacs/layers/+lang/haskell/funcs.el
Miciah Masters e0b751bee3 Avoid non-idempotent use of push in init code
Replace push with add-to-list in layer init functions and related code.

Modify spacemacs|add-toggle to check for and update an existing toggle in
spacemacs-toggles and only create a new toggle if none already existed.

Replace a conditional push onto erc-packages with use of :toggle.

When initializing which-key, set which-key-replacement-alist to its default
or customized setting before adding all the Spacemacs replacements.  We
want to keep the stock replacements but avoid adding duplicates of the
Spacemacs replacements.

Replace the emacs-lisp-mode-hook lambda with a named function to avoid
adding duplicate hooks (which can add duplicate definitions of the
evil-surround pair).
2018-06-05 22:17:13 -04:00

140 lines
4.6 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; funcs.el --- Haskell Layer funcs File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; 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."
(when (configuration-layer/package-used-p 'company)
(pcase haskell-completion-backend
(`ghci (spacemacs-haskell//setup-ghci))
(`ghc-mod (spacemacs-haskell//setup-ghc-mod))
(`intero (spacemacs-haskell//setup-intero))
(`dante (spacemacs-haskell//setup-dante)))))
(defun spacemacs-haskell//setup-ghci ()
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(spacemacs|add-company-backends
:backends (company-ghci company-dabbrev-code company-yasnippet)
:modes haskell-mode))
(defun spacemacs-haskell//setup-ghc-mod ()
(spacemacs|add-company-backends
:backends (company-ghc company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(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))
(when (configuration-layer/package-used-p 'flycheck)
;; 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)))
(defun spacemacs-haskell//setup-dante ()
(spacemacs|add-company-backends
:backends (dante-company company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-to-list 'spacemacs-jump-handlers 'xref-find-definitions)
(dante-mode)
(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)))
(defun spacemacs-haskell//setup-intero ()
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(spacemacs|add-company-backends
:backends (company-intero company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-to-list 'spacemacs-jump-handlers 'intero-goto-definition)
(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
"rs" 'intero-apply-suggestions
"sb" 'intero-repl-load))
(dolist (mode (cons 'haskell-cabal-mode haskell-modes))
(spacemacs/set-leader-keys-for-major-mode mode
"sc" nil
"sS" 'haskell-intero/display-repl
"ss" 'haskell-intero/pop-to-repl))
(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))
(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)))
(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)))
;; Dante Functions
(defun spacemacs-haskell//dante-insert-type ()
(interactive)
(dante-type-at :insert))
;; Intero functions
(defun haskell-intero/insert-type ()
(interactive)
(intero-type-at :insert))
(defun haskell-intero/display-repl (&optional prompt-options)
(interactive "P")
(let ((buffer (intero-repl-buffer prompt-options t)))
(unless (get-buffer-window buffer 'visible)
(display-buffer buffer))))
(defun haskell-intero/pop-to-repl (&optional prompt-options)
(interactive "P")
(pop-to-buffer (intero-repl-buffer prompt-options t)))
(defun haskell-intero//preserve-focus (f &rest args)
(let ((buffer (current-buffer)))
(apply f args)
(pop-to-buffer buffer)))