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
|
|
|
|
|
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)))
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
;; Completion setup functions
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-backend ()
|
|
|
|
"Conditionally setup haskell backend."
|
|
|
|
(pcase haskell-completion-backend
|
|
|
|
(`ghci (spacemacs-haskell//setup-ghci))
|
2019-01-22 12:51:24 +00:00
|
|
|
(`lsp (spacemacs-haskell//setup-lsp))
|
2018-11-04 17:57:07 +00:00
|
|
|
(`intero (spacemacs-haskell//setup-intero))
|
|
|
|
(`dante (spacemacs-haskell//setup-dante))
|
|
|
|
(`ghc-mod (spacemacs-haskell//setup-ghc-mod))))
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-company ()
|
2019-04-10 07:52:10 +00:00
|
|
|
"Conditionally setup haskell completion backend."
|
2018-11-04 17:57:07 +00:00
|
|
|
(pcase haskell-completion-backend
|
|
|
|
(`ghci (spacemacs-haskell//setup-ghci-company))
|
2019-04-10 07:52:10 +00:00
|
|
|
(`lsp nil) ;; nothing to do, auto-configured by lsp-mode
|
2018-11-04 17:57:07 +00:00
|
|
|
(`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))
|
|
|
|
|
2019-01-22 12:51:24 +00:00
|
|
|
;; LSP functions
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-lsp ()
|
|
|
|
"Setup lsp backend"
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
(progn
|
|
|
|
;; The functionality we require from this is not an autoload, but rather some
|
|
|
|
;; top-level code that registers a LSP server type. So we need to load it
|
|
|
|
;; directly and can't rely on it being autoloaded.
|
|
|
|
(require 'lsp-haskell)
|
|
|
|
(lsp))
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
;; 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))
|
2017-05-27 20:57:22 +00:00
|
|
|
|
|
|
|
(defun spacemacs-haskell//dante-insert-type ()
|
|
|
|
(interactive)
|
|
|
|
(dante-type-at :insert))
|
|
|
|
|
2016-07-11 12:24:50 +00:00
|
|
|
;; Intero functions
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
(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))
|
|
|
|
|
2016-07-11 12:24:50 +00:00
|
|
|
(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)))
|