spacemacs/layers/+lang/haskell/funcs.el
syl20bnr 74fdbb6795 Refactor and simplify company backends declaration
Enabling a company backend for a specific mode was a tedious tasks with code
scattered at different locations, one for local variable definitions, one for
company hook function definitions and another where the backends were pushed to
the local variables (which was problematic, since we ended up pushing the same
backends over and over again with `SPC f e R`, pushes have been replaced by
add-to-list calls in the new macro).

All these steps are now put together at one place with the new macro
spacemacs|add-company-backends, check its docstring for more info on its
arguments.

This macro also allows to define arbitrary buffer local variables to tune
company for specific modes (similar to layer variables via a keyword :variables)

The code related to company backends management has been moved to the
auto-completion layer in the funcs.el file. A nice side effect of this move is
that it enforces correct encapsulation of company backends related code. We can
now easily detect if there is some configuration leakage when the
auto-completion layer is not used. But we loose macro expansion at file loading
time (not sue it is a big concern though).

The function spacemacs|enable-auto-complete was never used so it has been
deleted which led to the deletion of the now empty file core-auto-completion.el.

The example in LAYERS.org regarding auto-completion is now out of date and has
been deleted. An example to setup auto-completion is provided in the README.org
file of the auto-completion layer.
2017-01-02 00:39:04 -05:00

105 lines
3.5 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-2016 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."
(unless (eq haskell-completion-backend 'ghc-mod)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode))
(when (configuration-layer/package-usedp 'company)
(pcase haskell-completion-backend
(`ghci (spacemacs-haskell//setup-ghci))
(`ghc-mod (spacemacs-haskell//setup-ghc-mod))
(`intero (spacemacs-haskell//setup-intero)))))
(defun spacemacs-haskell//setup-ghci ()
(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-usedp '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-intero ()
(spacemacs|add-company-backends
:backends (company-intero company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(push 'intero-goto-definition spacemacs-jump-handlers)
(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))
;; 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)))
(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)))
(defun haskell-intero//preserve-focus (f &rest args)
(let ((buffer (current-buffer)))
(apply f args)
(pop-to-buffer buffer)))