module-rust.el (2379B)
1 ;;; module-rust.el --- Packages used for rust 2 3 ;; Author: Mark Feller <mark.feller@member.fsf.org> 4 5 ;; This file is not part of GNU Emacs. 6 7 ;; This file is free software; you can redistribute it and/or modify 8 ;; it under the terms of the GNU General Public License as published by 9 ;; the Free Software Foundation; either version 3, or (at your option) 10 ;; any later version. 11 12 ;; This file is distributed in the hope that it will be useful, 13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ;; GNU General Public License for more details. 16 17 ;; You should have received a copy of the GNU General Public License 18 ;; along with this file. If not, see <http://www.gnu.org/licenses/>. 19 20 ;;; Commentary: 21 22 ;;; Code: 23 24 (defun mjf/rust-prog-init () 25 "if cargo is install get all depencies for emacs rust packages" 26 (interactive) 27 (if (not (eq (executable-find "cargo") nil)) 28 (progn 29 (mapcar (lambda (pkg) 30 (let ((cmd (concat "cargo install " pkg))) 31 (call-process-shell-command cmd nil "*cargo-output*" t))) 32 '("racer"))) 33 (message "cargo executable not found"))) 34 35 (defun mjf/setup-rust-mode-compile () 36 "Customize compile command to run go build" 37 (if (not (string-match "cargo" compile-command)) 38 (set (make-local-variable 'compile-command) 39 "cargo build"))) 40 41 (use-package rust-mode 42 :bind 43 (:map rust-mode-map 44 ("C-c C-c" . compile) 45 ("C-c <tab>" . rust-format-buffer)) 46 47 :config 48 (setq rust-format-on-save t) 49 (add-hook 'rust-mode-hook 'mjf/setup-rust-mode-compile)) 50 51 (use-package racer 52 :after (rust-mode) 53 :delight racer-mode 54 :bind 55 (:map rust-mode-map 56 ("TAB" . company-indent-or-complete-common) 57 ("C-c d" . racer-describe)) 58 59 :config 60 (setq racer-cmd "~/.cargo/bin/racer") ;; Rustup binaries PATH 61 (setq racer-rust-src-path (concat (getenv "HOME") "/prog/rust/src")) ;; Rust source code PATH 62 (setq company-tooltip-align-annotations t) 63 64 (add-hook 'rust-mode-hook #'racer-mode) 65 (add-hook 'racer-mode-hook #'eldoc-mode) 66 (add-hook 'racer-mode-hook #'company-mode)) 67 68 (use-package flycheck-rust 69 :disable 70 :after (flycheck-mode rust-mode) 71 :config 72 (progn (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))) 73 74 (provide 'module-rust) 75 76 ;;; module-rust.el ends here