This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/clojure/packages.el

415 lines
16 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Clojure Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; 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
(setq clojure-packages
'(
cider
cider-eval-sexp-fu
(clj-refactor :toggle clojure-enable-clj-refactor)
clojure-mode
(clojure-snippets :toggle (configuration-layer/layer-used-p 'auto-completion))
company
eldoc
evil-cleverparens
ggtags
counsel-gtags
helm-gtags
org
parinfer
popwin
2018-08-21 08:19:36 +00:00
(sayid :toggle clojure-enable-sayid)
smartparens
subword
))
2014-12-11 12:07:49 +00:00
(defun clojure/init-cider ()
(use-package cider
:defer t
2014-12-11 12:07:49 +00:00
:init
(progn
(spacemacs/register-repl 'cider 'cider-jack-in "cider")
(setq cider-stacktrace-default-filters '(tooling dup)
cider-repl-pop-to-buffer-on-connect nil
cider-prompt-save-file-on-load nil
cider-repl-use-clojure-font-lock t
cider-repl-history-file (concat spacemacs-cache-directory "cider-repl-history"))
2016-08-13 13:43:37 +00:00
(add-hook 'clojure-mode-hook 'cider-mode)
(dolist (x '(spacemacs-jump-handlers-clojure-mode
spacemacs-jump-handlers-clojurec-mode
spacemacs-jump-handlers-clojurescript-mode
spacemacs-jump-handlers-clojurex-mode
spacemacs-jump-handlers-cider-repl-mode))
(add-to-list x '(spacemacs/clj-find-var :async t)))
2017-05-30 09:58:17 +00:00
;; TODO: having this work for cider-macroexpansion-mode would be nice,
;; but the problem is that it uses clojure-mode as its major-mode
(let ((cider--key-binding-prefixes
'(("md" . "debug")
("me" . "evaluation")
("mf" . "format")
2017-05-30 09:58:17 +00:00
("mg" . "goto")
("mh" . "documentation")
("mp" . "profile")
2017-05-30 09:58:17 +00:00
("ms" . "repl")
("mt" . "test")
("mT" . "toggle")
)))
(spacemacs|forall-clojure-modes m
2017-05-30 09:58:17 +00:00
(mapc (lambda (x) (spacemacs/declare-prefix-for-mode
m (car x) (cdr x)))
cider--key-binding-prefixes)
(spacemacs/set-leader-keys-for-major-mode m
"ha" 'cider-apropos
"hc" 'cider-cheatsheet
2017-05-30 09:58:17 +00:00
"hg" 'cider-grimoire
"hh" 'cider-doc
2017-05-30 09:58:17 +00:00
"hj" 'cider-javadoc
"hn" 'cider-browse-ns
"hN" 'cider-browse-ns-all
2017-05-30 09:58:17 +00:00
"e;" 'cider-eval-defun-to-comment
"eb" 'cider-eval-buffer
"ee" 'cider-eval-last-sexp
"ef" 'cider-eval-defun-at-point
"em" 'cider-macroexpand-1
"eM" 'cider-macroexpand-all
"eP" 'cider-pprint-eval-last-sexp
"er" 'cider-eval-region
"eu" 'cider-undef
2017-05-30 09:58:17 +00:00
"ew" 'cider-eval-last-sexp-and-replace
"=" 'cider-format-buffer
"fb" 'cider-format-buffer
"gb" 'cider-pop-back
"gc" 'cider-classpath
"ge" 'cider-jump-to-compilation-error
"gn" 'cider-find-ns
"gr" 'cider-find-resource
"gs" 'cider-browse-spec
"gS" 'cider-browse-spec-all
2017-05-30 09:58:17 +00:00
"'" 'cider-jack-in
"\"" 'cider-jack-in-clojurescript
"sb" 'cider-load-buffer
"sB" 'spacemacs/cider-send-buffer-in-repl-and-focus
"sc" (if (eq m 'cider-repl-mode)
'cider-repl-clear-buffer
'cider-connect)
"sC" 'cider-find-and-clear-repl-output
"se" 'spacemacs/cider-send-last-sexp-to-repl
"sE" 'spacemacs/cider-send-last-sexp-to-repl-focus
"sf" 'spacemacs/cider-send-function-to-repl
"sF" 'spacemacs/cider-send-function-to-repl-focus
"si" 'cider-jack-in
"sI" 'cider-jack-in-clojurescript
"sn" 'spacemacs/cider-send-ns-form-to-repl
"sN" 'spacemacs/cider-send-ns-form-to-repl-focus
"so" 'cider-repl-switch-to-other
"sq" 'cider-quit
"sr" 'spacemacs/cider-send-region-to-repl
"sR" 'spacemacs/cider-send-region-to-repl-focus
"ss" (if (eq m 'cider-repl-mode)
'cider-switch-to-last-clojure-buffer
'cider-switch-to-repl-buffer)
"sx" 'cider-ns-refresh
2015-07-14 10:22:10 +00:00
"sX" 'cider-restart
2017-05-30 09:58:17 +00:00
"Te" 'cider-enlighten-mode
"Tf" 'spacemacs/cider-toggle-repl-font-locking
"Tp" 'spacemacs/cider-toggle-repl-pretty-printing
"Tt" 'cider-auto-test-mode
"ta" 'spacemacs/cider-test-run-all-tests
"tb" 'cider-test-show-report
"tl" 'spacemacs/cider-test-run-loaded-tests
"tn" 'spacemacs/cider-test-run-ns-tests
"tp" 'spacemacs/cider-test-run-project-tests
2017-05-30 09:58:17 +00:00
"tr" 'spacemacs/cider-test-rerun-failed-tests
"tt" 'spacemacs/cider-test-run-focused-test
"db" 'cider-debug-defun-at-point
"de" 'spacemacs/cider-display-error-buffer
"dv" 'cider-inspect
;; profile
"p+" 'cider-profile-samples
"pc" 'cider-profile-clear
"pn" 'cider-profile-ns-toggle
"ps" 'cider-profile-var-summary
"pS" 'cider-profile-summary
"pt" 'cider-profile-toggle
"pv" 'cider-profile-var-profiled-p
)))
2017-05-30 09:58:17 +00:00
;; cider-repl-mode only
(spacemacs/set-leader-keys-for-major-mode 'cider-repl-mode
"," 'cider-repl-handle-shortcut)
(spacemacs/set-leader-keys-for-major-mode 'cider-clojure-interaction-mode
"ep" 'cider-eval-print-last-sexp))
2014-12-11 12:07:49 +00:00
:config
(progn
;; add support for golden-ratio
(with-eval-after-load 'golden-ratio
(add-to-list 'golden-ratio-extra-commands 'cider-popup-buffer-quit-function))
;; add support for evil
(evil-set-initial-state 'cider-stacktrace-mode 'motion)
(evil-set-initial-state 'cider-popup-buffer-mode 'motion)
(add-hook 'cider--debug-mode-hook 'spacemacs/cider-debug-setup)
(evilified-state-evilify cider-stacktrace-mode cider-stacktrace-mode-map
(kbd "C-j") 'cider-stacktrace-next-cause
(kbd "C-k") 'cider-stacktrace-previous-cause
(kbd "TAB") 'cider-stacktrace-cycle-current-cause
(kbd "0") 'cider-stacktrace-cycle-all-causes
(kbd "1") 'cider-stacktrace-cycle-cause-1
(kbd "2") 'cider-stacktrace-cycle-cause-2
(kbd "3") 'cider-stacktrace-cycle-cause-3
(kbd "4") 'cider-stacktrace-cycle-cause-4
(kbd "5") 'cider-stacktrace-cycle-cause-5
(kbd "a") 'cider-stacktrace-toggle-all
(kbd "c") 'cider-stacktrace-toggle-clj
(kbd "d") 'cider-stacktrace-toggle-duplicates
(kbd "J") 'cider-stacktrace-toggle-java
(kbd "r") 'cider-stacktrace-toggle-repl
(kbd "T") 'cider-stacktrace-toggle-tooling)
;; open cider-doc directly and close it with q
(setq cider-prompt-for-symbol nil)
(evilified-state-evilify cider-docview-mode cider-docview-mode-map
(kbd "q") 'cider-popup-buffer-quit)
(evilified-state-evilify cider-inspector-mode cider-inspector-mode-map
(kbd "L") 'cider-inspector-pop
(kbd "n") 'cider-inspector-next-page
(kbd "N") 'cider-inspector-prev-page
(kbd "p") 'cider-inspector-prev-page
(kbd "r") 'cider-inspector-refresh)
(evilified-state-evilify cider-test-report-mode cider-test-report-mode-map
(kbd "C-j") 'cider-test-next-result
(kbd "C-k") 'cider-test-previous-result
(kbd "RET") 'cider-test-jump
(kbd "d") 'cider-test-ediff
(kbd "e") 'cider-test-stacktrace
(kbd "q") 'cider-popup-buffer-quit
(kbd "r") 'cider-test-rerun-tests
(kbd "t") 'cider-test-run-test
(kbd "T") 'cider-test-run-ns-tests)
(evil-define-key 'normal cider-repl-mode-map
(kbd "C-j") 'cider-repl-next-input
(kbd "C-k") 'cider-repl-previous-input
(kbd "RET") 'cider-repl-return)
2018-05-23 20:27:20 +00:00
(evil-define-key 'insert cider-repl-mode-map
(kbd "C-j") 'cider-repl-next-input
(kbd "C-k") 'cider-repl-previous-input)
(when clojure-enable-fancify-symbols
(clojure/fancify-symbols 'cider-repl-mode)
(clojure/fancify-symbols 'cider-clojure-interaction-mode)))
(defadvice cider-jump-to-var (before add-evil-jump activate)
(evil-set-jump))))
2014-12-11 12:07:49 +00:00
(defun clojure/init-cider-eval-sexp-fu ()
(with-eval-after-load 'eval-sexp-fu
(require 'cider-eval-sexp-fu)))
2014-12-11 12:07:49 +00:00
(defun clojure/init-clj-refactor ()
(use-package clj-refactor
:defer t
:init
(add-hook 'clojure-mode-hook 'clj-refactor-mode)
:config
(progn
(cljr-add-keybindings-with-prefix "C-c C-f")
2017-05-30 09:58:17 +00:00
;; Usually we do not set keybindings in :config, however this must be done
;; here because it reads the variable `cljr--all-helpers'. Since
;; `clj-refactor-mode' is added to the hook, this should trigger when a
;; clojure buffer is opened anyway, so there's no "keybinding delay".
(spacemacs|forall-clojure-modes m
(dolist (r cljr--all-helpers)
(let* ((binding (car r))
(func (cadr r)))
(when (not (string-prefix-p "hydra" (symbol-name func)))
(spacemacs/set-leader-keys-for-major-mode m
(concat "r" binding) func))))))))
(defun clojure/init-clojure-mode ()
(use-package clojure-mode
:defer t
2015-07-07 14:15:46 +00:00
:init
(progn
(add-to-list 'auto-mode-alist '("\\.boot\\'" . clojure-mode))
2016-05-05 21:38:13 +00:00
;; This regexp matches shebang expressions like `#!/usr/bin/env boot'
2017-05-30 09:58:17 +00:00
(add-to-list 'magic-mode-alist '("#!.*boot\\s-*$" . clojure-mode))
;; Define all the prefixes here, although most of them apply only to bindings in clj-refactor
(let ((clj-refactor--key-binding-prefixes
'(("mr" . "refactor")
("mra" . "add")
("mrc" . "cycle/clean/convert")
("mrd" . "destructure")
("mre" . "extract/expand")
("mrf" . "find/function")
("mrh" . "hotload")
("mri" . "introduce/inline")
("mrm" . "move")
("mrp" . "project/promote")
("mrr" . "remove/rename/replace")
("mrs" . "show/sort/stop")
("mrt" . "thread")
("mru" . "unwind/update"))))
(spacemacs|forall-clojure-modes m
(mapc (lambda (x) (spacemacs/declare-prefix-for-mode
m (car x) (cdr x)))
clj-refactor--key-binding-prefixes)
(spacemacs/set-leader-keys-for-major-mode m
"fl" 'clojure-align
"rci" 'clojure-cycle-if
"rcp" 'clojure-cycle-privacy
"rc#" 'clojure-convert-collection-to-set
"rc'" 'clojure-convert-collection-to-quoted-list
"rc(" 'clojure-convert-collection-to-list
"rc[" 'clojure-convert-collection-to-vector
"rc{" 'clojure-convert-collection-to-map
"rc:" 'clojure-toggle-keyword-string
"rtf" 'clojure-thread-first-all
"rth" 'clojure-thread
"rtl" 'clojure-thread-last-all
"rua" 'clojure-unwind-all
"ruw" 'clojure-unwind)
(unless clojure-enable-clj-refactor
(spacemacs/set-leader-keys-for-major-mode m
"r?" 'spacemacs/clj-describe-missing-refactorings)))))
2017-05-30 09:58:17 +00:00
:config
(when clojure-enable-fancify-symbols
(spacemacs|forall-clojure-modes m
2017-05-30 09:58:17 +00:00
(clojure/fancify-symbols m)))))
2016-04-11 18:30:47 +00:00
(defun clojure/post-init-eldoc ()
(add-hook 'cider-mode-hook 'eldoc-mode)
(add-hook 'cider-repl-mode-hook 'eldoc-mode)
(add-hook 'cider-clojure-interaction-mode-hook 'eldoc-mode))
2016-04-11 18:30:47 +00:00
(defun clojure/pre-init-evil-cleverparens ()
(spacemacs|use-package-add-hook evil-cleverparens
:pre-init
(spacemacs|forall-clojure-modes m
(add-to-list 'evil-lisp-safe-structural-editing-modes m))))
(defun clojure/pre-init-popwin ()
(spacemacs|use-package-add-hook popwin
:post-config
(push '("*cider-error*" :dedicated t :position bottom :stick t :noselect nil :height 0.4)
popwin:special-display-config)
(push '("*cider-doc*" :dedicated t :position bottom :stick t :noselect nil :height 0.4)
popwin:special-display-config)))
(defun clojure/post-init-smartparens ()
(add-hook 'cider-repl-mode-hook
(if dotspacemacs-smartparens-strict-mode
#'smartparens-strict-mode
#'smartparens-mode))
(with-eval-after-load 'smartparens
(sp-local-pair 'clojure-mode "`" nil :actions nil)))
(defun clojure/post-init-subword ()
(add-hook 'cider-mode-hook 'subword-mode))
2015-04-03 22:33:37 +00:00
(defun clojure/post-init-company ()
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 05:39:04 +00:00
(spacemacs|add-company-backends
:backends company-capf
:modes
cider-mode
cider-repl-mode))
(defun clojure/post-init-ggtags ()
(add-hook 'clojure-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun clojure/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'clojure-mode))
(defun clojure/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'clojure-mode))
(defun clojure/init-clojure-snippets ()
(use-package clojure-snippets
:defer t))
(defun clojure/pre-init-org ()
(spacemacs|use-package-add-hook org
:post-config (add-to-list 'org-babel-load-languages '(clojure . t))
(setq org-babel-clojure-backend 'cider)))
(defun clojure/init-sayid ()
(use-package sayid
:defer t
:init
(progn
(setq sayid--key-binding-prefixes
'(("mdt" . "trace")))
(spacemacs|forall-clojure-modes m
(mapc (lambda (x) (spacemacs/declare-prefix-for-mode m
(car x) (cdr x)))
sayid--key-binding-prefixes)
(spacemacs/set-leader-keys-for-major-mode m
;;These keybindings mostly preserved from the default sayid bindings
"d!" 'sayid-load-enable-clear
"dE" 'sayid-eval-last-sexp ;in default sayid bindings this is lowercase e, but that was already used in clojure mode
"dc" 'sayid-clear-log
"df" 'sayid-query-form-at-point
"dh" 'sayid-show-help
"ds" 'sayid-show-traced
"dS" 'sayid-show-traced-ns
"dtb" 'sayid-trace-ns-in-file
"dtd" 'sayid-trace-fn-disable
"dtD" 'sayid-trace-disable-all
"dte" 'sayid-trace-fn-enable
"dtE" 'sayid-trace-enable-all
"dtK" 'sayid-kill-all-traces
"dtn" 'sayid-inner-trace-fn
"dto" 'sayid-outer-trace-fn
"dtp" 'sayid-trace-ns-by-pattern
"dtr" 'sayid-remove-trace-fn
"dty" 'sayid-trace-all-ns-in-dir
"dV" 'sayid-set-view
"dw" 'sayid-get-workspace
"dx" 'sayid-reset-workspace
))
(evilified-state-evilify sayid-mode sayid-mode-map
(kbd "H") 'sayid-buf-show-help
(kbd "n") 'sayid-buffer-nav-to-next
(kbd "N") 'sayid-buffer-nav-to-prev
(kbd "C-s v") 'sayid-toggle-view
(kbd "C-s V") 'sayid-set-view
(kbd "L") 'sayid-buf-back
(kbd "e") 'sayid-gen-instance-expr) ;Originally this was bound to 'g', but I feel this is still mnemonic and doesn't overlap with evil
(evilified-state-evilify sayid-pprint-mode sayid-pprint-mode-map
(kbd "h") 'sayid-pprint-buf-show-help
(kbd "n") 'sayid-pprint-buf-next
(kbd "N") 'sayid-pprint-buf-prev
(kbd "l") 'sayid-pprint-buf-exit)
(evilified-state-evilify sayid-traced-mode sayid-traced-mode-map
(kbd "l") 'sayid-show-traced
(kbd "h") 'sayid-traced-buf-show-help))))
(defun clojure/post-init-parinfer ()
(add-hook 'clojure-mode-hook 'parinfer-mode))