spacemacs/layers/+lang/rust/packages.el
Miciah Masters e0b751bee3 Avoid non-idempotent use of push in init code
Replace push with add-to-list in layer init functions and related code.

Modify spacemacs|add-toggle to check for and update an existing toggle in
spacemacs-toggles and only create a new toggle if none already existed.

Replace a conditional push onto erc-packages with use of :toggle.

When initializing which-key, set which-key-replacement-alist to its default
or customized setting before adding all the Spacemacs replacements.  We
want to keep the stock replacements but avoid adding duplicates of the
Spacemacs replacements.

Replace the emacs-lisp-mode-hook lambda with a named function to avoid
adding duplicate hooks (which can add duplicate definitions of the
evil-surround pair).
2018-06-05 22:17:13 -04:00

117 lines
3.3 KiB
EmacsLisp

;;; packages.el --- Rust Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; 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
'(
cargo
company
racer
flycheck
(flycheck-rust :requires flycheck)
ggtags
exec-path-from-shell
helm-gtags
rust-mode
toml-mode
))
(defun rust/init-cargo ()
(use-package cargo
:defer t
:init
(progn
(spacemacs/declare-prefix-for-mode 'rust-mode "mc" "cargo")
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
"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
"ce" 'cargo-process-bench
"cf" 'cargo-process-fmt
"ci" 'cargo-process-init
"cl" 'cargo-process-clippy
"cn" 'cargo-process-new
"co" 'cargo-process-current-file-tests
"cs" 'cargo-process-search
"ct" 'cargo-process-current-test
"cu" 'cargo-process-update
"cx" 'cargo-process-run
"cv" 'cargo-process-check
"t" 'cargo-process-test))))
(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
(progn
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
"=" 'rust-format-buffer
"q" 'spacemacs/rust-quick-run))))
(defun rust/init-toml-mode ()
(use-package toml-mode
:mode "/\\(Cargo.lock\\|\\.cargo/config\\)\\'"))
(defun rust/post-init-company ()
(spacemacs|add-company-backends
:backends company-capf
:modes rust-mode
:variables company-tooltip-align-annotations t))
(defun rust/post-init-smartparens ()
(with-eval-after-load 'smartparens
;; Don't pair lifetime specifiers
(sp-local-pair 'rust-mode "'" nil :actions nil)))
(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))
(add-to-list 'exec-path-from-shell-variables var)))))
(defun rust/init-racer ()
(use-package racer
:defer t
:init
(progn
(spacemacs/add-to-hook 'rust-mode-hook '(racer-mode))
(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))))