Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB

  1. ;;; prelude-rust.el --- Emacs Prelude: Rust programming support.
  2. ;;
  3. ;; Authors: Doug MacEachern, Manoel Vilela, Ben Alex
  4. ;; This file is not part of GNU Emacs.
  5. ;;; Commentary:
  6. ;; Prelude configuration for Rust
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or
  9. ;; modify it under the terms of the GNU General Public License
  10. ;; as published by the Free Software Foundation; either version 3
  11. ;; of the License, or (at your option) any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Code:
  23. (require 'prelude-programming)
  24. ;; You may need to install the following packages on your system:
  25. ;; * rustc (Rust Compiler)
  26. ;; * cargo (Rust Package Manager)
  27. ;; * racer (Rust Completion Tool)
  28. ;; * rustfmt (Rust Tool for formatting code)
  29. ;; * rls (Rust Language Server, if the prelude-lsp feature is enabled)
  30. (prelude-require-packages '(rust-mode
  31. cargo
  32. flycheck-rust
  33. ron-mode))
  34. (unless (featurep 'prelude-lsp)
  35. (prelude-require-packages '(racer)))
  36. (setq rust-format-on-save t)
  37. (with-eval-after-load 'rust-mode
  38. (add-hook 'rust-mode-hook 'cargo-minor-mode)
  39. (add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
  40. (if (featurep 'prelude-lsp)
  41. (add-hook 'rust-mode-hook 'lsp)
  42. (add-hook 'rust-mode-hook 'racer-mode)
  43. (add-hook 'racer-mode-hook 'eldoc-mode))
  44. (defun prelude-rust-mode-defaults ()
  45. (unless (featurep 'prelude-lsp)
  46. (local-set-key (kbd "C-c C-d") 'racer-describe)
  47. (local-set-key (kbd "C-c .") 'racer-find-definition)
  48. (local-set-key (kbd "C-c ,") 'pop-tag-mark))
  49. ;; Prevent #! from chmodding rust files to be executable
  50. (remove-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
  51. ;; CamelCase aware editing operations
  52. (subword-mode +1))
  53. (setq prelude-rust-mode-hook 'prelude-rust-mode-defaults)
  54. (add-hook 'rust-mode-hook (lambda ()
  55. (run-hooks 'prelude-rust-mode-hook))))
  56. (provide 'prelude-rust)
  57. ;;; prelude-rust.el ends here