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/scala/packages.el

270 lines
9.2 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Scala Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2016 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 scala-packages
2014-12-14 04:29:23 +00:00
'(
ensime
noflet
2016-07-03 05:48:24 +00:00
org
scala-mode
2016-07-03 05:48:24 +00:00
sbt-mode
))
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
:defer t
2014-12-29 20:47:56 +00:00
:init
;; note ensime-mode is hooked to scala-mode-hook automatically by
;; ensime-mode via an autoload
(progn
(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))
(add-hook 'scala-mode-hook 'scala/configure-flyspell)
(add-hook 'scala-mode-hook 'scala/configure-ensime)
(when scala-auto-start-ensime
(add-hook 'scala-mode-hook 'scala/maybe-start-ensime)))
2014-12-29 20:40:56 +00:00
:config
(progn
(setq user-emacs-ensime-directory ".cache/ensime")
(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)
2014-12-29 20:40:56 +00:00
(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)
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
(kbd "M-p") 'backward-button
(kbd "n") 'forward-button
(kbd "N") 'backward-button)
2014-12-29 20:59:27 +00:00
(defun ensime-gen-and-restart()
"Regenerate `.ensime' file and restart the ensime server."
(interactive)
(progn
(sbt-command ";ensimeConfig;ensimeConfigProject")
(ensime-shutdown)
(ensime)))
(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))
(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))
(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")
("ms" . "scala/repl")
("my" . "scala/yank")))
(spacemacs/declare-prefix-for-mode 'scala-mode (car prefix) (cdr prefix)))
(spacemacs/set-leader-keys-for-major-mode 'scala-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
"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
"hT" 'ensime-type-at-point-full-name
"ht" 'ensime-type-at-point
"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
"ra" 'ensime-refactor-add-type-annotation
"rd" 'ensime-refactor-diff-inline-local
"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
"rt" 'ensime-import-type-at-point
2016-03-04 11:09:00 +00:00
"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" 'ensime-inf-eval-buffer-switch
"si" 'ensime-inf-switch
"sr" 'ensime-inf-eval-region
"sR" 'ensime-inf-eval-region-switch
"yT" 'scala/yank-type-at-point-full-name
"yt" 'scala/yank-type-at-point
"z" 'ensime-expand-selection-command
)
2014-12-29 20:59:27 +00:00
;; Don't use scala checker if ensime mode is active, since it provides
;; better error checking.
(with-eval-after-load 'flycheck
(defun scala/disable-flycheck-scala ()
(push 'scala flycheck-disabled-checkers))
(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
(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))))
(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
(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
;; Automatically insert asterisk in a comment when enabled
(defun scala/newline-and-indent-with-asterisk ()
(interactive)
(newline-and-indent)
(when scala-auto-insert-asterisk-in-comments
(scala-indent:insert-asterisk-on-multiline-comment)))
(evil-define-key 'insert scala-mode-map
(kbd "RET") 'scala/newline-and-indent-with-asterisk)
;; 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))
(evil-define-key 'normal scala-mode-map "J" 'spacemacs/scala-join-line)
2014-12-29 21:00:07 +00:00
;; Compatibility with `aggressive-indent'
(setq scala-indent:align-forms t
scala-indent:align-parameters t
scala-indent:default-run-on-strategy scala-indent:operator-strategy))))