2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Scala Layer packages File for Spacemacs
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 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
|
2014-12-14 04:29:23 +00:00
|
|
|
'(
|
|
|
|
ensime
|
2015-04-03 02:43:21 +00:00
|
|
|
noflet
|
2016-07-03 05:48:24 +00:00
|
|
|
org
|
2016-05-22 01:59:31 +00:00
|
|
|
scala-mode
|
2016-07-03 05:48:24 +00:00
|
|
|
sbt-mode
|
2015-04-19 03:40:24 +00:00
|
|
|
))
|
2014-12-14 04:29:23 +00:00
|
|
|
|
2014-12-30 21:51:41 +00:00
|
|
|
(defun scala/init-ensime ()
|
2014-12-14 04:29:23 +00:00
|
|
|
(use-package ensime
|
2016-07-04 03:05:32 +00:00
|
|
|
:defer t
|
2014-12-29 20:47:56 +00:00
|
|
|
:init
|
2016-07-04 03:05:32 +00:00
|
|
|
;; note ensime-mode is hooked to scala-mode-hook automatically by
|
|
|
|
;; ensime-mode via an autoload
|
2015-01-03 02:29:02 +00:00
|
|
|
(progn
|
2016-01-26 16:31:15 +00:00
|
|
|
(spacemacs/register-repl 'ensime 'ensime-inf-switch "ensime")
|
2015-11-23 19:09:57 +00:00
|
|
|
(when scala-enable-eldoc
|
|
|
|
(add-hook 'ensime-mode-hook 'scala/enable-eldoc))
|
2015-01-03 02:29:02 +00:00
|
|
|
(add-hook 'scala-mode-hook 'scala/configure-flyspell)
|
2015-02-20 07:41:28 +00:00
|
|
|
(add-hook 'scala-mode-hook 'scala/configure-ensime)
|
2016-03-23 23:05:51 +00:00
|
|
|
(when scala-auto-start-ensime
|
|
|
|
(add-hook 'scala-mode-hook 'scala/maybe-start-ensime)))
|
2014-12-29 20:40:56 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2015-06-01 21:15:12 +00:00
|
|
|
(setq user-emacs-ensime-directory ".cache/ensime")
|
|
|
|
|
2015-02-20 07:17:42 +00:00
|
|
|
(evil-define-key 'insert ensime-mode-map
|
|
|
|
(kbd ".") 'scala/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)
|
2015-01-03 02:30:17 +00:00
|
|
|
|
2014-12-29 20:40:56 +00:00
|
|
|
(evil-define-key 'normal ensime-popup-buffer-map
|
|
|
|
(kbd "q") 'ensime-popup-buffer-quit-function)
|
|
|
|
|
2015-02-20 07:17:42 +00:00
|
|
|
(evil-define-key 'normal ensime-inspector-mode-map
|
|
|
|
(kbd "q") 'ensime-popup-buffer-quit-function)
|
|
|
|
|
2014-12-29 20:40:56 +00:00
|
|
|
(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
|
2014-12-30 22:19:43 +00:00
|
|
|
(kbd "M-p") 'backward-button
|
|
|
|
(kbd "n") 'forward-button
|
|
|
|
(kbd "N") 'backward-button)
|
2014-12-29 20:59:27 +00:00
|
|
|
|
2015-02-18 02:57:08 +00:00
|
|
|
(defun ensime-gen-and-restart()
|
|
|
|
"Regenerate `.ensime' file and restart the ensime server."
|
2015-02-14 15:26:20 +00:00
|
|
|
(interactive)
|
|
|
|
(progn
|
2016-05-24 16:27:36 +00:00
|
|
|
(sbt-command ";ensimeConfig;ensimeConfigProject")
|
2015-02-14 15:26:20 +00:00
|
|
|
(ensime-shutdown)
|
2015-02-18 02:57:08 +00:00
|
|
|
(ensime)))
|
2015-02-14 15:26:20 +00:00
|
|
|
|
2015-02-18 02:57:08 +00:00
|
|
|
(defun ensime-inf-eval-buffer-switch ()
|
|
|
|
"Send buffer content to shell and switch to it in insert mode."
|
|
|
|
(interactive)
|
|
|
|
(ensime-inf-eval-buffer)
|
|
|
|
(ensime-inf-switch)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2015-02-18 02:57:08 +00:00
|
|
|
|
|
|
|
(defun ensime-inf-eval-region-switch (start end)
|
|
|
|
"Send region content to shell and switch to it in insert mode."
|
|
|
|
(interactive "r")
|
|
|
|
(ensime-inf-switch)
|
|
|
|
(ensime-inf-eval-region start end)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2015-02-18 02:57:08 +00:00
|
|
|
|
2015-10-20 07:59:53 +00:00
|
|
|
(dolist (prefix '(("mb" . "scala/build")
|
|
|
|
("mc" . "scala/check")
|
|
|
|
("md" . "scala/debug")
|
|
|
|
("me" . "scala/errors")
|
|
|
|
("mg" . "scala/goto")
|
|
|
|
("mh" . "scala/docs")
|
|
|
|
("mi" . "scala/inspect")
|
|
|
|
("mn" . "scala/ensime")
|
|
|
|
("mr" . "scala/refactor")
|
|
|
|
("mt" . "scala/test")
|
2016-06-03 06:40:14 +00:00
|
|
|
("ms" . "scala/repl")
|
|
|
|
("my" . "scala/yank")))
|
2015-10-20 07:59:53 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'scala-mode (car prefix) (cdr prefix)))
|
|
|
|
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'scala-mode
|
2016-01-26 16:31:15 +00:00
|
|
|
"/" 'ensime-search
|
|
|
|
"'" 'ensime-inf-switch
|
2015-11-18 00:38:05 +00:00
|
|
|
|
|
|
|
"bc" 'ensime-sbt-do-compile
|
|
|
|
"bC" 'ensime-sbt-do-clean
|
|
|
|
"bi" 'ensime-sbt-switch
|
|
|
|
"bp" 'ensime-sbt-do-package
|
|
|
|
"br" 'ensime-sbt-do-run
|
|
|
|
|
2016-04-05 01:52:45 +00:00
|
|
|
"ct" 'ensime-typecheck-current-buffer
|
2015-11-18 00:38:05 +00:00
|
|
|
"cT" 'ensime-typecheck-all
|
|
|
|
|
|
|
|
"dA" 'ensime-db-attach
|
|
|
|
"db" 'ensime-db-set-break
|
|
|
|
"dB" 'ensime-db-clear-break
|
|
|
|
"dC" 'ensime-db-clear-all-breaks
|
|
|
|
"dc" 'ensime-db-continue
|
|
|
|
"dd" 'ensime-db-start
|
|
|
|
"di" 'ensime-db-inspect-value-at-point
|
|
|
|
"dl" 'ensime-db-list-locals
|
|
|
|
"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
|
|
|
|
|
|
|
|
"ee" 'ensime-print-errors-at-point
|
|
|
|
"el" 'ensime-show-all-errors-and-warnings
|
|
|
|
"es" 'ensime-stacktrace-switch
|
|
|
|
|
|
|
|
"gg" 'ensime-edit-definition
|
|
|
|
"gp" 'ensime-pop-find-definition-stack
|
|
|
|
"gi" 'ensime-goto-impl
|
|
|
|
"gt" 'ensime-goto-test
|
|
|
|
|
|
|
|
"hh" 'ensime-show-doc-for-symbol-at-point
|
2016-06-05 04:44:51 +00:00
|
|
|
"hT" 'ensime-type-at-point-full-name
|
|
|
|
"ht" 'ensime-type-at-point
|
2015-11-18 00:38:05 +00:00
|
|
|
"hu" 'ensime-show-uses-of-symbol-at-point
|
|
|
|
|
|
|
|
"ii" 'ensime-inspect-type-at-point
|
|
|
|
"iI" 'ensime-inspect-type-at-point-other-frame
|
|
|
|
"ip" 'ensime-inspect-project-package
|
|
|
|
|
|
|
|
"nF" 'ensime-reload-open-files
|
|
|
|
"ns" 'ensime
|
|
|
|
"nS" 'ensime-gen-and-restart
|
|
|
|
|
2016-03-09 04:09:40 +00:00
|
|
|
"ra" 'ensime-refactor-add-type-annotation
|
2016-02-29 21:07:25 +00:00
|
|
|
"rd" 'ensime-refactor-diff-inline-local
|
2015-11-18 00:38:05 +00:00
|
|
|
"rD" 'ensime-undo-peek
|
|
|
|
"rf" 'ensime-format-source
|
2016-03-04 11:09:00 +00:00
|
|
|
"ri" 'ensime-refactor-diff-organize-imports
|
|
|
|
"rm" 'ensime-refactor-diff-extract-method
|
|
|
|
"rr" 'ensime-refactor-diff-rename
|
2015-11-18 00:38:05 +00:00
|
|
|
"rt" 'ensime-import-type-at-point
|
2016-03-04 11:09:00 +00:00
|
|
|
"rv" 'ensime-refactor-diff-extract-local
|
2015-11-18 00:38:05 +00:00
|
|
|
|
|
|
|
"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" 'ensime-inf-eval-buffer-switch
|
|
|
|
"si" 'ensime-inf-switch
|
|
|
|
"sr" 'ensime-inf-eval-region
|
|
|
|
"sR" 'ensime-inf-eval-region-switch
|
|
|
|
|
2016-06-05 04:44:51 +00:00
|
|
|
"yT" 'scala/yank-type-at-point-full-name
|
2016-06-03 06:40:14 +00:00
|
|
|
"yt" 'scala/yank-type-at-point
|
|
|
|
|
2015-11-18 00:38:05 +00:00
|
|
|
"z" 'ensime-expand-selection-command
|
2015-02-14 15:26:20 +00:00
|
|
|
)
|
|
|
|
|
2014-12-29 20:59:27 +00:00
|
|
|
;; Don't use scala checker if ensime mode is active, since it provides
|
|
|
|
;; better error checking.
|
2015-09-29 05:07:57 +00:00
|
|
|
(with-eval-after-load 'flycheck
|
2015-10-14 12:35:05 +00:00
|
|
|
(defun scala/disable-flycheck-scala ()
|
|
|
|
(push 'scala flycheck-disabled-checkers))
|
|
|
|
|
2015-11-02 10:11:43 +00:00
|
|
|
(add-hook 'ensime-mode-hook 'scala/disable-flycheck-scala))
|
|
|
|
|
|
|
|
;; Enable Expand Region integration from Ensime. Ignore load errors to
|
|
|
|
;; handle older Ensime versions gracefully.
|
|
|
|
(when (configuration-layer/package-usedp 'expand-region)
|
|
|
|
(require 'ensime-expand-region nil 'noerror)))))
|
2014-12-29 21:00:07 +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
|
2016-04-03 04:35:35 +00:00
|
|
|
:defer t
|
|
|
|
:init (spacemacs/set-leader-keys-for-major-mode 'scala-mode
|
|
|
|
"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
|
2014-12-29 21:00:07 +00:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(dolist (ext '(".cfe" ".cfs" ".si" ".gen" ".lock"))
|
|
|
|
(add-to-list 'completion-ignored-extensions ext))
|
|
|
|
:config
|
|
|
|
(progn
|
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 ()
|
|
|
|
"Insert a `>' to the buffer. If it's part of a right arrow (`->' or `=>'),
|
|
|
|
replace it with the corresponding unicode arrow."
|
|
|
|
(interactive)
|
|
|
|
(insert ">")
|
|
|
|
(scala/replace-arrow-at-point))
|
|
|
|
|
|
|
|
(defun scala/hyphen ()
|
|
|
|
"Insert a `-' to the buffer. If it's part of a left arrow (`<-'),
|
|
|
|
replace it with the unicode arrow."
|
|
|
|
(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
|
2015-12-30 09:24:48 +00:00
|
|
|
scala-indent:default-run-on-strategy scala-indent:operator-strategy))))
|