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

116 lines
3.3 KiB
EmacsLisp
Raw Normal View History

2015-05-07 13:19:56 +00:00
;;; packages.el --- Rust Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
2015-05-07 13:19:56 +00:00
;;
;; Author: Chris Hoeppner <me@mkaito.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq rust-packages
2015-05-07 13:19:56 +00:00
'(
2016-08-07 15:37:12 +00:00
cargo
company
2015-08-24 16:00:19 +00:00
racer
2015-06-03 03:18:31 +00:00
flycheck
2017-07-03 07:52:54 +00:00
(flycheck-rust :requires flycheck)
ggtags
exec-path-from-shell
helm-gtags
2015-05-07 13:19:56 +00:00
rust-mode
toml-mode
))
2015-05-07 13:19:56 +00:00
(defun rust/init-cargo ()
(use-package cargo
2015-05-07 13:19:56 +00:00
:defer t
:init
(progn
(spacemacs/declare-prefix-for-mode 'rust-mode "mc" "cargo")
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
2016-08-07 15:37:12 +00:00
"c." 'cargo-process-repeat
"cC" 'cargo-process-clean
"cX" 'cargo-process-run-example
"cc" 'cargo-process-build
"cd" 'cargo-process-doc
"cD" 'cargo-process-doc-open
2016-08-07 15:37:12 +00:00
"ce" 'cargo-process-bench
"cf" 'cargo-process-current-test
"cf" 'cargo-process-fmt
2016-08-07 15:37:12 +00:00
"ci" 'cargo-process-init
2017-06-26 09:14:48 +00:00
"cl" 'cargo-process-clippy
2016-08-07 15:37:12 +00:00
"cn" 'cargo-process-new
"co" 'cargo-process-current-file-tests
"cs" 'cargo-process-search
"cu" 'cargo-process-update
"cx" 'cargo-process-run
"t" 'cargo-process-test))))
2015-05-07 13:19:56 +00:00
(defun rust/post-init-flycheck ()
(spacemacs/enable-flycheck 'rust-mode))
(defun rust/init-flycheck-rust ()
(use-package flycheck-rust
:defer t
:init (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
(defun rust/post-init-ggtags ()
(add-hook 'rust-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun rust/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'rust-mode))
(defun rust/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'rust-mode))
(defun rust/init-rust-mode ()
(use-package rust-mode
:defer t
:init
2016-08-13 13:43:37 +00:00
(progn
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
"=" 'rust-format-buffer
"q" 'spacemacs/rust-quick-run))))
2015-05-07 13:19:56 +00:00
(defun rust/init-toml-mode ()
(use-package toml-mode
:mode "/\\(Cargo.lock\\|\\.cargo/config\\)\\'"))
(defun rust/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 rust-mode
:variables company-tooltip-align-annotations t))
2016-01-10 12:36:56 +00:00
(defun rust/post-init-smartparens ()
(with-eval-after-load 'smartparens
;; Don't pair lifetime specifiers
(sp-local-pair 'rust-mode "'" nil :actions nil)))
2015-08-24 16:00:19 +00:00
(defun rust/pre-init-exec-path-from-shell ()
(spacemacs|use-package-add-hook exec-path-from-shell
:pre-config
(let ((var "RUST_SRC_PATH"))
(unless (or (member var exec-path-from-shell-variables) (getenv var))
(push var exec-path-from-shell-variables)))))
(defun rust/init-racer ()
2015-08-24 16:00:19 +00:00
(use-package racer
:defer t
2016-01-10 12:36:56 +00:00
:init
(progn
(spacemacs/add-to-hook 'rust-mode-hook '(racer-mode))
2016-01-10 12:36:56 +00:00
(spacemacs/declare-prefix-for-mode 'rust-mode "mg" "goto")
(add-to-list 'spacemacs-jump-handlers-rust-mode 'racer-find-definition)
(spacemacs/declare-prefix-for-mode 'rust-mode "mh" "help")
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
"hh" 'spacemacs/racer-describe))
:config
(progn
(spacemacs|hide-lighter racer-mode)
(evilified-state-evilify-map racer-help-mode-map
:mode racer-help-mode))))