2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/rust/config.el -*- lexical-binding: t; -*-
|
2015-09-30 12:28:52 -04:00
|
|
|
|
2019-07-09 17:54:18 +02:00
|
|
|
(def-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)
|
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-09 17:54:18 +02:00
|
|
|
(defun +rust|init ()
|
2019-07-11 01:09:30 +02:00
|
|
|
"Switch to `rustic-mode', if it's available."
|
|
|
|
(when (require 'rustic nil t)
|
|
|
|
(rustic-mode)))
|
|
|
|
(add-hook 'rust-mode-hook #'+rust|init)
|
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-07-07 17:39:19 +02:00
|
|
|
(add-hook 'rust-mode-local-vars-hook #'lsp!))
|
2019-02-21 16:08:27 -05:00
|
|
|
|
2019-07-09 17:54:18 +02:00
|
|
|
;; 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
|
|
|
|
'(rust-mode rust-indent-offset)
|
|
|
|
'(rustic-mode rustic-indent-offset)))))
|
2015-09-30 12:28:52 -04:00
|
|
|
|
2015-11-30 05:31:20 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-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-09 17:54:18 +02:00
|
|
|
(def-package! rustic
|
|
|
|
: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
|
|
|
|
rustic-format-on-save nil)
|
2019-07-09 18:50:50 +02:00
|
|
|
|
|
|
|
;; `rustic-setup-rls' uses `package-installed-p' unnecessarily, which breaks
|
|
|
|
;; because Doom lazy loads package.el.
|
: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
|
|
|
(def-advice! +rust--disable-package-call-a (orig-fn &rest args)
|
|
|
|
:around #'rustic-setup-rls
|
2019-07-09 18:50:50 +02:00
|
|
|
(cl-letf (((symbol-function 'package-installed-p)
|
|
|
|
(symbol-function 'ignore)))
|
: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
|
|
|
|
|
|
|
|
(def-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)))
|