2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Scala Layer packages File for Spacemacs
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +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
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq scala-packages
|
2018-11-20 19:55:37 +00:00
|
|
|
'(
|
|
|
|
ensime
|
2019-09-22 17:52:28 +00:00
|
|
|
lsp-mode
|
2018-11-20 19:55:37 +00:00
|
|
|
ggtags
|
|
|
|
counsel-gtags
|
|
|
|
helm-gtags
|
|
|
|
noflet
|
|
|
|
org
|
|
|
|
scala-mode
|
|
|
|
sbt-mode
|
|
|
|
))
|
2014-12-14 04:29:23 +00:00
|
|
|
|
2017-02-09 22:22:38 +00:00
|
|
|
(defun scala/post-init-eldoc ()
|
2019-04-26 10:34:11 +00:00
|
|
|
(when (and scala-enable-eldoc (spacemacs//scala-backend-ensime-p))
|
2019-04-18 09:32:18 +00:00
|
|
|
(add-hook 'scala-mode-hook #'spacemacs//scala-setup-ensime-eldoc)))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
2019-04-18 09:32:18 +00:00
|
|
|
(defun scala/init-ensime ()
|
2014-12-14 04:29:23 +00:00
|
|
|
(use-package ensime
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2019-04-26 10:34:11 +00:00
|
|
|
:if (spacemacs//scala-backend-ensime-p)
|
2014-12-29 20:47:56 +00:00
|
|
|
:init
|
2017-02-09 22:22:38 +00:00
|
|
|
(progn
|
2019-04-18 09:32:18 +00:00
|
|
|
(setq ensime-startup-dirname (concat spacemacs-cache-directory "ensime/"))
|
|
|
|
(spacemacs/register-repl 'ensime 'ensime-inf-switch "ensime")
|
2017-02-09 22:22:38 +00:00
|
|
|
(add-hook 'scala-mode-hook #'spacemacs//scala-setup-ensime)
|
2019-04-26 10:34:11 +00:00
|
|
|
(when scala-auto-start-backend
|
2017-02-09 22:22:38 +00:00
|
|
|
(add-hook 'scala-mode-hook 'spacemacs//ensime-maybe-start)))
|
2014-12-29 20:40:56 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2019-04-18 09:32:18 +00:00
|
|
|
;; This function was renamed in ensime. Usually we don't need to do this,
|
|
|
|
;; but documentation recommends the stable version of ensime, so we must
|
|
|
|
;; try to support it, too.
|
|
|
|
(unless (fboundp 'ensime-type-at-point)
|
|
|
|
(defalias 'ensime-type-at-point 'ensime-print-type-at-point))
|
|
|
|
|
|
|
|
;; key bindings
|
|
|
|
(dolist (mode '(scala-mode))
|
|
|
|
(dolist (prefix '(("mb" . "build")
|
|
|
|
("mc" . "check")
|
|
|
|
("md" . "debug")
|
|
|
|
("mD" . "daemon")
|
|
|
|
("mE" . "errors")
|
|
|
|
("mg" . "goto")
|
|
|
|
("mh" . "docs")
|
|
|
|
("mi" . "inspect")
|
|
|
|
("mr" . "refactor")
|
|
|
|
("mt" . "test")
|
|
|
|
("ms" . "repl")
|
|
|
|
("my" . "yank")))
|
|
|
|
(spacemacs/declare-prefix-for-mode mode (car prefix) (cdr prefix)))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"/" 'ensime-search
|
|
|
|
"'" 'ensime-inf-switch
|
|
|
|
|
|
|
|
"bc" 'ensime-sbt-do-compile
|
|
|
|
"bC" 'ensime-sbt-do-clean
|
|
|
|
"bi" 'ensime-sbt-switch
|
|
|
|
"bp" 'ensime-sbt-do-package
|
|
|
|
"br" 'ensime-sbt-do-run
|
|
|
|
|
|
|
|
"ct" 'ensime-typecheck-current-buffer
|
|
|
|
|
|
|
|
"dA" 'ensime-db-attach
|
|
|
|
"db" 'ensime-db-set-break
|
|
|
|
"dB" 'ensime-db-clear-break
|
|
|
|
"dC" 'ensime-db-clear-all-breaks
|
|
|
|
"dc" 'ensime-db-continue
|
|
|
|
"di" 'ensime-db-inspect-value-at-point
|
|
|
|
"dn" 'ensime-db-next
|
|
|
|
"do" 'ensime-db-step-out
|
|
|
|
"dq" 'ensime-db-quit
|
|
|
|
"dr" 'ensime-db-run
|
|
|
|
"ds" 'ensime-db-step
|
|
|
|
"dt" 'ensime-db-backtrace
|
|
|
|
|
|
|
|
"Df" 'ensime-reload-open-files
|
|
|
|
"Dr" 'spacemacs/ensime-gen-and-restart
|
|
|
|
"Ds" 'ensime
|
|
|
|
|
|
|
|
"Ee" 'ensime-print-errors-at-point
|
|
|
|
"Es" 'ensime-stacktrace-switch
|
|
|
|
|
|
|
|
"gp" 'ensime-pop-find-definition-stack
|
|
|
|
|
|
|
|
"hh" 'ensime-show-doc-for-symbol-at-point
|
|
|
|
"hT" 'ensime-type-at-point-full-name
|
|
|
|
"ht" 'ensime-type-at-point
|
|
|
|
"hu" 'ensime-show-uses-of-symbol-at-point
|
|
|
|
|
|
|
|
"ra" 'ensime-refactor-add-type-annotation
|
|
|
|
"rd" 'ensime-refactor-diff-inline-local
|
|
|
|
"rD" 'ensime-undo-peek
|
|
|
|
"ri" 'ensime-refactor-diff-organize-imports
|
|
|
|
"rm" 'ensime-refactor-diff-extract-method
|
|
|
|
"rr" 'ensime-refactor-diff-rename
|
|
|
|
"rt" 'ensime-import-type-at-point
|
|
|
|
"rv" 'ensime-refactor-diff-extract-local
|
|
|
|
|
|
|
|
"ta" 'ensime-sbt-do-test-dwim
|
|
|
|
"tr" 'ensime-sbt-do-test-quick-dwim
|
|
|
|
"tt" 'ensime-sbt-do-test-only-dwim
|
|
|
|
|
|
|
|
"sa" 'ensime-inf-load-file
|
|
|
|
"sb" 'ensime-inf-eval-buffer
|
|
|
|
"sB" 'spacemacs/ensime-inf-eval-buffer-switch
|
|
|
|
"si" 'ensime-inf-switch
|
|
|
|
"sr" 'ensime-inf-eval-region
|
|
|
|
"sR" 'spacemacs/ensime-inf-eval-region-switch
|
|
|
|
|
|
|
|
"yT" 'spacemacs/ensime-yank-type-at-point-full-name
|
|
|
|
"yt" 'spacemacs/ensime-yank-type-at-point
|
|
|
|
|
|
|
|
"z" 'ensime-expand-selection-command))
|
|
|
|
(evil-define-key 'insert ensime-mode-map
|
|
|
|
(kbd ".") 'spacemacs/ensime-completing-dot
|
|
|
|
(kbd "M-.") 'ensime-edit-definition
|
|
|
|
(kbd "M-,") 'ensime-pop-find-definition-stack)
|
|
|
|
(evil-define-key 'normal ensime-mode-map
|
|
|
|
(kbd "M-.") 'ensime-edit-definition
|
|
|
|
(kbd "M-,") 'ensime-pop-find-definition-stack)
|
|
|
|
(evil-define-key 'normal ensime-popup-buffer-map
|
|
|
|
(kbd "q") 'ensime-popup-buffer-quit-function)
|
|
|
|
(evil-define-key 'normal ensime-inspector-mode-map
|
|
|
|
(kbd "q") 'ensime-popup-buffer-quit-function)
|
|
|
|
(evil-define-key 'normal ensime-refactor-info-map
|
|
|
|
(kbd "q") 'spacemacs/ensime-refactor-cancel
|
|
|
|
(kbd "c") 'spacemacs/ensime-refactor-accept
|
|
|
|
(kbd "RET") 'spacemacs/ensime-refactor-accept)
|
|
|
|
(evil-define-key 'normal ensime-compile-result-map
|
|
|
|
(kbd "g") 'ensime-show-all-errors-and-warnings
|
|
|
|
(kbd "TAB") 'forward-button
|
|
|
|
(kbd "<backtab>") 'backward-button
|
|
|
|
(kbd "M-n") 'forward-button
|
|
|
|
(kbd "M-p") 'backward-button
|
|
|
|
(kbd "n") 'forward-button
|
|
|
|
(kbd "N") 'backward-button)
|
|
|
|
(evil-define-key '(insert normal) ensime-search-mode-map
|
|
|
|
(kbd "C-q") 'ensime-search-quit
|
|
|
|
(kbd "C-j") 'ensime-search-next-match
|
|
|
|
(kbd "C-k") 'ensime-search-prev-match
|
|
|
|
(kbd "RET") 'ensime-search-choose-current-result
|
|
|
|
(kbd "C-i") 'ensime-search-insert-import-of-current-result)
|
|
|
|
|
2015-11-02 10:11:43 +00:00
|
|
|
;; Enable Expand Region integration from Ensime. Ignore load errors to
|
|
|
|
;; handle older Ensime versions gracefully.
|
2017-07-02 13:48:06 +00:00
|
|
|
(when (configuration-layer/package-used-p 'expand-region)
|
2015-11-02 10:11:43 +00:00
|
|
|
(require 'ensime-expand-region nil 'noerror)))))
|
2014-12-29 21:00:07 +00:00
|
|
|
|
2016-07-16 05:30:56 +00:00
|
|
|
(defun scala/post-init-flycheck ()
|
2017-02-14 03:27:29 +00:00
|
|
|
(spacemacs/enable-flycheck 'scala-mode)
|
2017-02-09 22:22:38 +00:00
|
|
|
;; Don't use scala checker if ensime mode is active, since it provides
|
|
|
|
;; better error checking.
|
|
|
|
(with-eval-after-load 'flycheck
|
2019-09-22 17:52:28 +00:00
|
|
|
(add-hook 'ensime-mode-hook 'spacemacs//scala-disable-flycheck-scala)))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
(defun scala/post-init-flyspell ()
|
|
|
|
(spell-checking/add-flyspell-hook 'scala-mode)
|
2019-04-18 09:32:18 +00:00
|
|
|
(add-hook 'scala-mode-hook #'spacemacs//scala-setup-ensime-flyspell))
|
2016-07-16 05:30:56 +00:00
|
|
|
|
2015-12-30 09:24:48 +00:00
|
|
|
(defun scala/init-noflet ()
|
|
|
|
(use-package noflet))
|
2015-04-03 21:35:33 +00:00
|
|
|
|
2016-07-03 05:48:24 +00:00
|
|
|
(defun scala/pre-init-org ()
|
|
|
|
(spacemacs|use-package-add-hook org
|
|
|
|
:post-config (add-to-list 'org-babel-load-languages '(scala . t))))
|
|
|
|
|
2015-10-13 10:39:37 +00:00
|
|
|
(defun scala/init-sbt-mode ()
|
|
|
|
(use-package sbt-mode
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2019-04-26 10:34:11 +00:00
|
|
|
:config
|
|
|
|
;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
|
|
|
|
;; allows for using SPACE in the minibuffer
|
|
|
|
(substitute-key-definition
|
|
|
|
'minibuffer-complete-word
|
|
|
|
'self-insert-command
|
|
|
|
minibuffer-local-completion-map)
|
2019-11-27 10:31:41 +00:00
|
|
|
;; sbt-supershell kills sbt-mode: https://github.com/hvesalai/emacs-sbt-mode/issues/152
|
|
|
|
(setq sbt:program-options '("-Dsbt.supershell=false"))
|
2019-04-26 10:34:11 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(spacemacs/declare-prefix-for-mode 'scala-mode "mb" "sbt")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'scala-mode "mg" "goto")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'scala-mode
|
|
|
|
"b." 'sbt-hydra
|
|
|
|
"bb" 'sbt-command))))
|
2015-04-03 21:35:33 +00:00
|
|
|
|
2016-05-22 01:59:31 +00:00
|
|
|
(defun scala/init-scala-mode ()
|
|
|
|
(use-package scala-mode
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2014-12-29 21:00:07 +00:00
|
|
|
:init
|
2016-08-13 13:43:37 +00:00
|
|
|
(progn
|
|
|
|
(dolist (ext '(".cfe" ".cfs" ".si" ".gen" ".lock"))
|
2016-09-05 02:29:41 +00:00
|
|
|
(add-to-list 'completion-ignored-extensions ext)))
|
2014-12-29 21:00:07 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2019-04-26 10:34:11 +00:00
|
|
|
;; Ensure only one of metals and ensime is loaded
|
|
|
|
(unless (spacemacs//scala-backend-ensime-p)
|
|
|
|
(progn
|
|
|
|
(fmakunbound 'ensime)
|
|
|
|
(remove-hook 'after-change-functions 'ensime-after-change-function)
|
|
|
|
(remove-hook 'window-configuration-change-hook
|
|
|
|
'ensime-show-left-margin-hook)))
|
|
|
|
|
2015-12-30 15:54:28 +00:00
|
|
|
;; Automatically insert asterisk in a comment when enabled
|
|
|
|
(defun scala/newline-and-indent-with-asterisk ()
|
|
|
|
(interactive)
|
|
|
|
(newline-and-indent)
|
2016-01-04 09:46:22 +00:00
|
|
|
(when scala-auto-insert-asterisk-in-comments
|
2015-12-30 15:54:28 +00:00
|
|
|
(scala-indent:insert-asterisk-on-multiline-comment)))
|
|
|
|
|
|
|
|
(evil-define-key 'insert scala-mode-map
|
|
|
|
(kbd "RET") 'scala/newline-and-indent-with-asterisk)
|
|
|
|
|
2016-01-18 08:58:01 +00:00
|
|
|
;; Automatically replace arrows with unicode ones when enabled
|
|
|
|
(defconst scala-unicode-arrows-alist
|
|
|
|
'(("=>" . "⇒")
|
|
|
|
("->" . "→")
|
|
|
|
("<-" . "←")))
|
|
|
|
|
|
|
|
(defun scala/replace-arrow-at-point ()
|
|
|
|
"Replace the arrow before the point (if any) with unicode ones.
|
|
|
|
An undo boundary is inserted before doing the replacement so that
|
|
|
|
it can be undone."
|
|
|
|
(let* ((end (point))
|
|
|
|
(start (max (- end 2) (point-min)))
|
|
|
|
(x (buffer-substring start end))
|
|
|
|
(arrow (assoc x scala-unicode-arrows-alist)))
|
|
|
|
(when arrow
|
|
|
|
(undo-boundary)
|
|
|
|
(backward-delete-char 2)
|
|
|
|
(insert (cdr arrow)))))
|
|
|
|
|
|
|
|
(defun scala/gt ()
|
2017-02-09 22:22:38 +00:00
|
|
|
"Insert a `>' to the buffer.
|
|
|
|
If it's part of a right arrow (`->' or `=>'),replace it with the corresponding
|
|
|
|
unicode arrow."
|
2016-01-18 08:58:01 +00:00
|
|
|
(interactive)
|
|
|
|
(insert ">")
|
|
|
|
(scala/replace-arrow-at-point))
|
|
|
|
|
|
|
|
(defun scala/hyphen ()
|
2017-02-09 22:22:38 +00:00
|
|
|
"Insert a `-' to the buffer.
|
|
|
|
If it's part of a left arrow (`<-'),replace it with the unicode arrow."
|
2016-01-18 08:58:01 +00:00
|
|
|
(interactive)
|
|
|
|
(insert "-")
|
|
|
|
(scala/replace-arrow-at-point))
|
|
|
|
|
|
|
|
(when scala-use-unicode-arrows
|
|
|
|
(define-key scala-mode-map
|
|
|
|
(kbd ">") 'scala/gt)
|
|
|
|
(define-key scala-mode-map
|
|
|
|
(kbd "-") 'scala/hyphen))
|
|
|
|
|
2014-12-30 21:53:03 +00:00
|
|
|
(evil-define-key 'normal scala-mode-map "J" 'spacemacs/scala-join-line)
|
|
|
|
|
2014-12-29 21:00:07 +00:00
|
|
|
;; Compatibility with `aggressive-indent'
|
2015-08-08 20:32:36 +00:00
|
|
|
(setq scala-indent:align-forms t
|
|
|
|
scala-indent:align-parameters t
|
2017-02-09 22:22:38 +00:00
|
|
|
scala-indent:default-run-on-strategy
|
|
|
|
scala-indent:operator-strategy))))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
2019-09-22 17:52:28 +00:00
|
|
|
(defun scala/post-init-lsp-mode ()
|
|
|
|
(when (spacemacs//scala-backend-metals-p)
|
|
|
|
(spacemacs//scala-setup-metals)))
|
2019-04-26 10:34:11 +00:00
|
|
|
|
2016-04-05 04:08:34 +00:00
|
|
|
(defun scala/post-init-ggtags ()
|
2016-08-15 19:24:44 +00:00
|
|
|
(add-hook 'scala-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
2017-08-26 21:18:09 +00:00
|
|
|
(defun scala/post-init-counsel-gtags ()
|
|
|
|
(spacemacs/counsel-gtags-define-keys-for-mode 'scala-mode))
|
|
|
|
|
2016-04-05 04:08:34 +00:00
|
|
|
(defun scala/post-init-helm-gtags ()
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'scala-mode))
|