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.

87 lines
2.8 KiB

  1. ;;; prelude-rust.el --- Emacs Prelude: Rust programming support.
  2. ;;
  3. ;; Authors: Doug MacEachern, Manoel Vilela, Ben Alex, Daniel Gerlach
  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. ;; * rustfmt (Rust Tool for formatting code)
  28. ;; * rust-analyzer as lsp server needs to be in global path, see:
  29. ;; https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary
  30. (prelude-require-packages '(rust-mode
  31. cargo
  32. flycheck-rust
  33. tree-sitter
  34. tree-sitter-langs
  35. yasnippet
  36. ron-mode))
  37. (require 'tree-sitter)
  38. (require 'tree-sitter-langs)
  39. (with-eval-after-load 'rust-mode
  40. (add-hook 'rust-mode-hook 'cargo-minor-mode)
  41. (add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
  42. ;; enable lsp for rust, by default it uses rust-analyzer as lsp server
  43. (add-hook 'rust-mode-hook 'lsp)
  44. ;; enable tree-sitter for nicer syntax highlighting
  45. (add-hook 'rust-mode-hook #'tree-sitter-mode)
  46. (add-hook 'rust-mode-hook #'tree-sitter-hl-mode)
  47. (defun prelude-rust-mode-defaults ()
  48. ;; format on save
  49. (setq rust-format-on-save t)
  50. ;; lsp settings
  51. (setq
  52. ;; enable macro expansion
  53. lsp-rust-analyzer-proc-macro-enable t
  54. lsp-rust-analyzer-experimental-proc-attr-macros t)
  55. ;; Prevent #! from chmodding rust files to be executable
  56. (remove-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
  57. ;; snippets are required for correct lsp autocompletions
  58. (yas-minor-mode)
  59. ;; CamelCase aware editing operations
  60. (subword-mode +1))
  61. (setq prelude-rust-mode-hook 'prelude-rust-mode-defaults)
  62. (add-hook 'rust-mode-hook (lambda ()
  63. (run-hooks 'prelude-rust-mode-hook))))
  64. (provide 'prelude-rust)
  65. ;;; prelude-rust.el ends here