Files
doomemacs/modules/lang/rust/config.el
Henrik Lissner 51d3b1b424 💥 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-22 02:27:45 +02:00

90 lines
2.9 KiB
EmacsLisp

;;; lang/rust/config.el -*- lexical-binding: t; -*-
(def-package! rust-mode
:defer t
:config
(setq rust-indent-method-chain t)
;; 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'.
(defun +rust|init ()
"Switch to `rustic-mode', if it's available."
(when (require 'rustic nil t)
(rustic-mode)))
(add-hook 'rust-mode-hook #'+rust|init)
(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
'(rust-mode rust-indent-offset)
'(rustic-mode rustic-indent-offset)))))
(def-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))
(def-package! rustic
:when EMACS26+
: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)
;; `rustic-setup-rls' uses `package-installed-p' unnecessarily, which breaks
;; because Doom lazy loads package.el.
(def-advice! +rust--disable-package-call-a (orig-fn &rest args)
:around #'rustic-setup-rls
(cl-letf (((symbol-function 'package-installed-p)
(symbol-function 'ignore)))
(apply orig-fn args))))
;;
;;; 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)))