2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/rust/config.el -*- lexical-binding: t; -*-
|
2015-09-30 12:28:52 -04:00
|
|
|
|
2019-10-19 15:25:29 -04:00
|
|
|
(after! projectile
|
|
|
|
(add-to-list 'projectile-project-root-files "Cargo.toml"))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! rust-mode
|
2019-07-11 01:09:30 +02:00
|
|
|
:defer t
|
2019-07-09 17:54:18 +02:00
|
|
|
:config
|
2018-03-05 13:43:20 -05:00
|
|
|
(setq rust-indent-method-chain t)
|
2019-09-15 12:06:27 -04:00
|
|
|
(add-hook 'rust-mode-hook #'rainbow-delimiters-mode)
|
2018-03-14 19:07:31 -04:00
|
|
|
|
2019-07-11 01:09:30 +02:00
|
|
|
;; 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'.
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'rust-mode-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +rust-init-h ()
|
|
|
|
"Switch to `rustic-mode', if it's available."
|
|
|
|
(when (require 'rustic nil t)
|
|
|
|
(rustic-mode))))
|
2019-07-09 17:54:18 +02:00
|
|
|
|
|
|
|
(set-docsets! '(rust-mode rustic-mode) "Rust")
|
2019-02-21 16:08:27 -05:00
|
|
|
(when (featurep! +lsp)
|
2019-10-19 23:39:33 -04:00
|
|
|
(add-hook 'rust-mode-local-vars-hook #'lsp!)))
|
2015-09-30 12:28:52 -04:00
|
|
|
|
2015-11-30 05:31:20 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! racer
|
2019-02-21 16:08:27 -05:00
|
|
|
:unless (featurep! +lsp)
|
2019-07-09 17:54:18 +02:00
|
|
|
:hook ((rust-mode rustic-mode) . racer-mode)
|
2016-04-23 22:08:46 -04:00
|
|
|
:config
|
2019-04-30 20:19:13 -04:00
|
|
|
(set-lookup-handlers! 'rust-mode
|
|
|
|
:definition '(racer-find-definition :async t)
|
|
|
|
:documentation '+rust-racer-lookup-documentation))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! rustic
|
2019-07-09 17:54:18 +02:00
|
|
|
:when EMACS26+
|
2017-09-19 05:07:24 +02:00
|
|
|
:after rust-mode
|
2019-07-09 19:29:08 +02:00
|
|
|
:preface
|
|
|
|
(setq rustic-rls-pkg (if (featurep! +lsp) 'lsp-mode))
|
2019-07-09 17:54:18 +02:00
|
|
|
:config
|
2019-07-11 01:09:30 +02:00
|
|
|
(setq rustic-indent-method-chain t
|
2019-07-12 01:14:16 +02:00
|
|
|
rustic-flycheck-setup-mode-line-p nil
|
|
|
|
;; use :editor format instead
|
2019-10-22 19:36:32 -04:00
|
|
|
rustic-format-on-save nil
|
|
|
|
;; REVIEW `rust-ordinary-lt-gt-p' is terribly expensive in large rust
|
|
|
|
;; buffers, so we disable it, but only for evil users, because it
|
|
|
|
;; affects `forward-sexp' and its ilk. See
|
|
|
|
;; https://github.com/rust-lang/rust-mode/issues/288.
|
|
|
|
rustic-match-angle-brackets (not (featurep! :editor evil)))
|
2019-07-09 18:50:50 +02:00
|
|
|
|
2019-09-15 12:06:27 -04:00
|
|
|
(add-hook 'rustic-mode-hook #'rainbow-delimiters-mode)
|
|
|
|
|
2019-09-19 20:03:44 -04:00
|
|
|
(defadvice! +rust--dont-install-packages-p (orig-fn &rest args)
|
2019-09-20 21:49:44 +10:00
|
|
|
:around #'rustic-setup-rls
|
2019-09-20 14:49:39 -04:00
|
|
|
(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).
|
2019-09-19 20:03:44 -04:00
|
|
|
((symbol-function #'package-installed-p)
|
2019-09-20 14:49:39 -04:00
|
|
|
(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 _)
|
2019-10-26 13:57:54 -04:00
|
|
|
(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))))
|
2019-07-09 17:54:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Tools
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! cargo
|
2019-07-09 17:54:18 +02:00
|
|
|
:after rust-mode
|
|
|
|
:config
|
|
|
|
(defvar +rust-keymap
|
|
|
|
(if (boundp 'rustic-mode-map)
|
|
|
|
rustic-mode-map
|
|
|
|
rust-mode-map))
|
|
|
|
(map! :map +rust-keymap
|
|
|
|
:localleader
|
2019-10-04 17:49:28 -04:00
|
|
|
(:prefix ("b" . "build")
|
2019-07-09 17:54:18 +02:00
|
|
|
: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)))
|