doomemacs/modules/lang/rust/config.el

100 lines
3.4 KiB
EmacsLisp
Raw Normal View History

;;; lang/rust/config.el -*- lexical-binding: t; -*-
2015-09-30 12:28:52 -04:00
(use-package! rust-mode
:defer t
:config
(setq rust-indent-method-chain t)
(add-hook 'rust-mode-hook #'rainbow-delimiters-mode)
;; This is necessary because both plugins are fighting for supremacy in
;; `auto-mode-alist', so rustic-mode *must* load second. It only needs to
;; happen once.
;;
;; rust-mode is still required for `racer'.
(add-hook! 'rust-mode-hook
(defun +rust-init-h ()
"Switch to `rustic-mode', if it's available."
(when (require 'rustic nil t)
(rustic-mode))))
(set-docsets! '(rust-mode rustic-mode) "Rust")
(when (featurep! +lsp)
(add-hook 'rust-mode-local-vars-hook #'lsp!))
;; TODO PR these upstream
(after! dtrt-indent
(pushnew! dtrt-indent-hook-mapping-list
'(rust-mode default rust-indent-offset)
'(rustic-mode default rustic-indent-offset)))
(when (featurep! :tools editorconfig)
(after! editorconfig
(pushnew! editorconfig-indentation-alist
'(rustic-mode rustic-indent-offset)))))
2015-09-30 12:28:52 -04:00
(use-package! racer
:unless (featurep! +lsp)
:hook ((rust-mode rustic-mode) . racer-mode)
:config
(set-lookup-handlers! 'rust-mode
:definition '(racer-find-definition :async t)
:documentation '+rust-racer-lookup-documentation))
2017-02-19 18:57:16 -05:00
(use-package! rustic
:when EMACS26+
2017-09-19 05:07:24 +02:00
:after rust-mode
:preface
(setq rustic-rls-pkg (if (featurep! +lsp) 'lsp-mode))
:config
(setq rustic-indent-method-chain t
rustic-flycheck-setup-mode-line-p nil
;; use :editor format instead
rustic-format-on-save nil)
(add-hook 'rustic-mode-hook #'rainbow-delimiters-mode)
(defadvice! +rust--dont-install-packages-p (orig-fn &rest args)
:around #'rustic-setup-rls
(cl-letf (;; `rustic-setup-rls' uses `package-installed-p' to determine if
;; lsp-mode/elgot are available. This breaks because Doom doesn't
;; use package.el to begin with (and lazy loads it).
((symbol-function #'package-installed-p)
(lambda (pkg)
(require pkg nil t)))
;; If lsp/elgot isn't available, it attempts to install lsp-mode
;; via package.el. Doom manages its own dependencies so we disable
;; that behavior.
((symbol-function #'rustic-install-rls-client-p)
(lambda (&rest _)
(message "No RLS server running."))))
:boom: revise advice naming convention (1/2) This is first of three big naming convention updates that have been a long time coming. With 2.1 on the horizon, all the breaking updates will batched together in preparation for the long haul. In this commit, we do away with the asterix to communicate that a function is an advice function, and we replace it with the '-a' suffix. e.g. doom*shut-up -> doom-shut-up-a doom*recenter -> doom-recenter-a +evil*static-reindent -> +evil--static-reindent-a The rationale behind this change is: 1. Elisp's own formatting/indenting tools would occasionally struggle with | and * (particularly pp and cl-prettyprint). They have no problem with / and :, fortunately. 2. External syntax highlighters (like pygmentize, discord markdown or github markdown) struggle with it, sometimes refusing to highlight code beyond these symbols. 3. * and | are less expressive than - and -- in communicating the intended visibility, versatility and stability of a function. 4. It complicated the regexps we must use to search for them. 5. They were arbitrary and over-complicated to begin with, decided on haphazardly way back when Doom was simply "my private config". Anyhow, like how predicate functions have the -p suffix, we'll adopt the -a suffix for advice functions, -h for hook functions and -fn for variable functions. Other noteable changes: - Replaces advice-{add,remove}! macro with new def-advice! macro. The old pair weren't as useful. The new def-advice! saves on a lot of space. - Removed "stage" assertions to make sure you were using the right macros in the right place. Turned out to not be necessary, we'll employ better checks later.
2019-07-18 15:42:52 +02:00
(apply orig-fn args))))
;;
;;; Tools
(use-package! cargo
:after rust-mode
:config
(defvar +rust-keymap
(if (boundp 'rustic-mode-map)
rustic-mode-map
rust-mode-map))
(map! :map +rust-keymap
:localleader
(:prefix "b"
:desc "cargo add" "a" #'cargo-process-add
:desc "cargo build" "b" #'cargo-process-build
:desc "cargo bench" "B" #'cargo-process-bench
:desc "cargo check" "c" #'cargo-process-check
:desc "cargo clippy" "C" #'cargo-process-clippy
:desc "cargo doc" "d" #'cargo-process-doc
:desc "cargo run" "r" #'cargo-process-run
:desc "cargo search" "s" #'cargo-process-search
:desc "cargo update" "u" #'cargo-process-update)
(:prefix ("t" . "cargo test")
:desc "all" "a" #'cargo-process-test
:desc "current file" "f" #'cargo-process-current-file-tests
:desc "current test" "t" #'cargo-process-current-test)))