2016-06-24 15:37:01 +00:00
|
|
|
|
;;; funcs.el --- Haskell Layer funcs File for Spacemacs
|
|
|
|
|
;;
|
2020-09-16 21:34:40 +00:00
|
|
|
|
;; Copyright (c) 2012-2020 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
|
|
|
|
|
|
2019-04-16 20:35:42 +00:00
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
|
;; Completion setup functions
|
|
|
|
|
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(defun spacemacs//haskell-backend ()
|
|
|
|
|
"Returns selected backend."
|
|
|
|
|
(if haskell-completion-backend
|
|
|
|
|
haskell-completion-backend
|
|
|
|
|
(cond
|
|
|
|
|
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
2020-08-25 07:38:30 +00:00
|
|
|
|
(t 'dante))))
|
2019-09-30 04:49:44 +00:00
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
|
(defun spacemacs-haskell//setup-backend ()
|
|
|
|
|
"Conditionally setup haskell backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//haskell-backend)
|
2019-01-22 12:51:24 +00:00
|
|
|
|
(`lsp (spacemacs-haskell//setup-lsp))
|
2020-08-25 07:38:30 +00:00
|
|
|
|
(`dante (spacemacs-haskell//setup-dante))))
|
2018-11-04 17:57:07 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-company ()
|
2019-04-10 07:52:10 +00:00
|
|
|
|
"Conditionally setup haskell completion backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//haskell-backend)
|
2019-04-10 07:52:10 +00:00
|
|
|
|
(`lsp nil) ;; nothing to do, auto-configured by lsp-mode
|
2020-08-25 07:38:30 +00:00
|
|
|
|
(`dante (spacemacs-haskell//setup-dante-company))))
|
2018-11-04 17:57:07 +00:00
|
|
|
|
|
2019-04-16 20:35:42 +00:00
|
|
|
|
|
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.")))
|
|
|
|
|
|
2019-04-16 20:35:42 +00:00
|
|
|
|
|
2018-11-04 17:57:07 +00:00
|
|
|
|
;; Dante functions
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-haskell//setup-dante ()
|
|
|
|
|
(dante-mode)
|
2019-05-12 20:22:17 +00:00
|
|
|
|
(add-to-list 'spacemacs-jump-handlers 'xref-find-definitions))
|
2018-11-04 17:57:07 +00:00
|
|
|
|
|
|
|
|
|
(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))
|
|
|
|
|
|
2019-09-30 04:49:44 +00:00
|
|
|
|
|
|
|
|
|
;; misc
|
|
|
|
|
|
|
|
|
|
(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)))
|