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.

78 lines
2.6 KiB

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