一、参考
emacs系列文章目录——更新ing
emacs rust-mode
Configuring Emacs for Rust development
My Emacs Rust Language Config
二、心愿实现的个性
个性 | 形容 |
---|---|
源码之间挪动 | 找到函数的源码为止,回到函数援用处 |
代码主动填充 | |
代码语法检查和谬误高亮 | |
代码语法规范化 | |
cargo编译和运行 |
三、通过emacs-racer
实现
3.1 依赖装置
程序 | 装置 |
---|---|
rust | 非emacs包 |
cargo | 非emacs包 |
rust-mode | M-x package-install rust-mode |
cargo | M-x package-install cargo |
racer | 非emacs包 |
rustup toolchain add nightlyrustup component add rust-srccargo +nightly install racer
3.2 更新配置
;; 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))))))