One, reference
emacs series article directory-update ing
emacs rust-mode
Configuring Emacs for Rust development
My Emacs Rust Language Config
Second, the desired characteristics
characteristic | describe |
---|
Move between source code | Until the source code of the function is found, go back to the function reference |
Code auto-fill | |
Code syntax checking and error highlighting | |
Code syntax standardization | |
cargo compile and run | |
3. emacs-racer
3.1 Dependent installation
program | Install |
---|
rust | Non-emacs package |
cargo | Non-emacs package |
rust-mode | M-x package-install rust-mode |
cargo | M-x package-install cargo |
racer | Non-emacs package |
rustup toolchain add nightly
rustup component add rust-src
cargo +nightly install racer
3.2 Update configuration
;; started from http://emacs-bootstrap.com/
;; rust-mode
;; https://github.com/rust-lang/rust-mode
(use-package rust-mode
:bind ( :map rust-mode-map
(("C-c C-t" . racer-describe)
([?\t] . company-indent-or-complete-common)))
:config
(progn
;; add flycheck support for rust (reads in cargo stuff)
;; https://github.com/flycheck/flycheck-rust
(use-package flycheck-rust)
;; cargo-mode for all the cargo related operations
;; https://github.com/kwrooijen/cargo.el
(use-package cargo
:hook (rust-mode . cargo-minor-mode)
:bind
("C-c C-c C-n" . cargo-process-new)) ;; global binding
;;; racer-mode for getting IDE like features for rust-mode
;; https://github.com/racer-rust/emacs-racer
(use-package racer
:hook (rust-mode . racer-mode)
:config
(progn
;; package does this by default ;; set racer rust source path environment variable
;; (setq racer-rust-src-path (getenv "RUST_SRC_PATH"))
(defun my-racer-mode-hook ()
(set (make-local-variable 'company-backends)
'((company-capf company-files)))
(setq company-minimum-prefix-length 1)
(setq indent-tabs-mode nil))
(add-hook 'racer-mode-hook 'my-racer-mode-hook)
;; enable company and eldoc minor modes in rust-mode (racer-mode)
(add-hook 'racer-mode-hook #'company-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)))
(add-hook 'rust-mode-hook 'flycheck-mode)
(add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
;; format rust buffers on save using rustfmt
(add-hook 'before-save-hook
(lambda ()
(when (eq major-mode 'rust-mode)
(rust-format-buffer))))))
3.3 Final configuration
(use-package rust-mode
:mode
(("\\.rs\\'" . rust-mode))
:hook
(rust-mode . global-linum-mode) ;; 行显示
(rust-mode . hs-minor-mode) ;; 折叠模式
(rust-mode . eldoc-mode) ;; 代码追踪
(rust-mode . company-mode) ;; 自动填充
(rust-mode . cargo-minor-mode)
(rust-mode . racer-mode)
(rust-mode . flycheck-mode)
(flycheck-mode . flycheck-rust-setup)
(rust-mode . (lambda () (setq indent-tabs-mode nil))) ;; 设置缩进
:config
(setq rust-format-on-save t) ;; 设置格式化
)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。