[haskell] support dynamically set backend

This commit is contained in:
Boris Buliga 2018-11-04 19:57:07 +02:00 committed by duianto
parent 1519fc5639
commit 54f69e3a96
3 changed files with 80 additions and 26 deletions

View File

@ -113,6 +113,19 @@ completion, youll have to enable the =auto-completion= layer as well.
(haskell :variables haskell-completion-backend 'intero)))
#+END_SRC
Backend can be chosen on a per project basis using directory local variables
(files named =.dir-locals.el= at the root of a project), an example to use the
=intero= backend:
#+BEGIN_SRC elisp
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((haskell-mode (haskell-completion-backend . intero)))
#+END_SRC
*Note:* you can easily add a directory local variable with ~SPC f v d~.
*** =company-ghci=
[[https://github.com/juiko/company-ghci][company-ghci]] communicates directly with =ghci=, in order to provide completion.
To use it, you have to call =haskell-process-load-or-reload= (=SPC s b=).

View File

@ -22,7 +22,58 @@
(haskell-navigate-imports)
(haskell-mode-format-imports)))
;; Dante Functions
;; Completion setup functions
(defun spacemacs-haskell//setup-backend ()
"Conditionally setup haskell backend."
(pcase haskell-completion-backend
(`ghci (spacemacs-haskell//setup-ghci))
(`intero (spacemacs-haskell//setup-intero))
(`dante (spacemacs-haskell//setup-dante))
(`ghc-mod (spacemacs-haskell//setup-ghc-mod))))
(defun spacemacs-haskell//setup-company ()
"Conditionally setup haskell backend."
(pcase haskell-completion-backend
(`ghci (spacemacs-haskell//setup-ghci-company))
(`intero (spacemacs-haskell//setup-intero-company))
(`dante (spacemacs-haskell//setup-dante-company))
(`ghc-mod (spacemacs-haskell//setup-ghc-mod-company))))
;; ghci functions
(defun spacemacs-haskell//setup-ghci ()
(interactive-haskell-mode))
(defun spacemacs-haskell//setup-ghci-company ()
(spacemacs|add-company-backends
:backends (company-ghci company-dabbrev-code company-yasnippet)
:modes haskell-mode))
;; ghc-mod functions
(defun spacemacs-haskell//setup-ghc-mod ()
(ghc-init))
(defun spacemacs-haskell//setup-ghc-mod-company ()
(spacemacs|add-company-backends
:backends (company-ghc company-dabbrev-code company-yasnippet)
:modes haskell-mode))
;; Dante functions
(defun spacemacs-haskell//setup-dante ()
(dante-mode)
(add-to-list 'spacemacs-jump-handlers-haskell-mode 'xref-find-definitions))
(defun spacemacs-haskell//setup-dante-company ()
(spacemacs|add-company-backends
:backends (dante-company company-dabbrev-code company-yasnippet)
:modes haskell-mode))
(defun spacemacs-haskell//dante-insert-type ()
(interactive)
@ -31,6 +82,16 @@
;; Intero functions
(defun spacemacs-haskell//setup-intero ()
(interactive-haskell-mode)
(intero-mode)
(add-to-list 'spacemacs-jump-handlers-haskell-mode 'intero-goto-definition))
(defun spacemacs-haskell//setup-intero-company ()
(spacemacs|add-company-backends
:backends (company-intero company-dabbrev-code company-yasnippet)
:modes haskell-mode))
(defun haskell-intero/insert-type ()
(interactive)
(intero-type-at :insert))

View File

@ -53,7 +53,8 @@
(use-package cmm-mode
:defer t))
(defun haskell/post-init-company ())
(defun haskell/post-init-company ()
(add-hook 'haskell-mode-local-vars-hook #'spacemacs-haskell//setup-company))
(defun haskell/init-company-cabal ()
(use-package company-cabal
@ -65,12 +66,7 @@
(defun haskell/init-company-ghci ()
(use-package company-ghci
:defer t
:init
(spacemacs|add-company-backends
:backends (company-ghci company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)))
:defer t))
(defun haskell/init-company-ghc ()
(use-package company-ghc
@ -79,11 +75,6 @@
(defun haskell/init-ghc ()
(use-package ghc
:defer t
:init
(spacemacs|add-company-backends
:backends (company-ghc company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-hook 'haskell-mode-hook 'ghc-init)
:config
(progn
(dolist (mode haskell-modes)
@ -108,13 +99,6 @@
(defun haskell/init-intero ()
(use-package intero
:defer t
:init
(spacemacs|add-company-backends
:backends (company-intero company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(add-hook 'haskell-mode-hook 'intero-mode)
(add-to-list 'spacemacs-jump-handlers-haskell-mode 'intero-goto-definition)
:config
(progn
(spacemacs|diminish intero-mode " λ" " \\")
@ -152,12 +136,6 @@
(defun haskell/init-dante ()
(use-package dante
:defer t
:init
(spacemacs|add-company-backends
:backends (dante-company company-dabbrev-code company-yasnippet)
:modes haskell-mode)
(add-hook 'haskell-mode-hook 'dante-mode)
(add-to-list 'spacemacs-jump-handlers-haskell-mode 'xref-find-definitions)
:config
(progn
(dolist (mode haskell-modes)
@ -192,6 +170,8 @@
:defer t
:init
(progn
(add-hook 'haskell-mode-local-vars-hook #'spacemacs-haskell//setup-backend)
(defun spacemacs//force-haskell-mode-loading ()
"Force `haskell-mode' loading when visiting cabal file."
(require 'haskell-mode))