summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-09 22:35:31 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-09 22:35:31 +0800
commit435c95393459d0c7825a4431f0ebcec6898ba16b (patch)
treeaf55520cd89ca7a98df7861e036bb9d98f85b48d
parent76747a2aadd216596ee386e0025ab651a32f16fa (diff)
add configurations for rust
* common.el (common): * init.el (rustic-mode): (assoc): * rust-conf.el ("dash.el"): ("s.el"): ("f.el"): (let-alist): ("markdown-mode"): (project): ("rust-mode"): (seq): ("spinner.el"): ("xterm-color"): ("eglot"): (eglot-mode-map): (eglot-autoshutdown): ("rustic"): (rustic-lsp-client): (rustic-format-on-save): (eglot-managed-mode-hook): (durand-rust-mode-hook): (durand-rustic-cargo-doc-a): (#'rustic-cargo-doc): (rust-conf):
-rw-r--r--common.el2
-rw-r--r--init.el15
-rw-r--r--rust-conf.el83
3 files changed, 99 insertions, 1 deletions
diff --git a/common.el b/common.el
index 35e16f2..e983e6d 100644
--- a/common.el
+++ b/common.el
@@ -469,7 +469,7 @@ If the length of LS is less than N, then return the whole LS."
(reverse result)))))
(provide 'common)
-;; common.el ends here.
+;;; common.el ends here.
diff --git a/init.el b/init.el
index 85ddc2e..ca88df7 100644
--- a/init.el
+++ b/init.el
@@ -382,6 +382,21 @@ no effect."
((add-to-list 'auto-mode-alist
(cons "\\.go$" #'go-mode))))
+;;; Rust
+
+(load-after-function rustic-mode "rust-conf.el"
+ "Load Rust configurations." nil
+ (rustic-mode))
+
+(cond
+ ((assoc "\\.rs$" auto-mode-alist #'string=)
+ (setcdr
+ (assoc "\\.rs$" auto-mode-alist #'string=)
+ #'rustic-mode))
+ ((add-to-list
+ 'auto-mode-alist
+ (cons "\\.rs$" #'rustic-mode))))
+
;;; Cat and mouse
(cond ((display-mouse-p) (mouse-avoidance-mode 'none)))
diff --git a/rust-conf.el b/rust-conf.el
new file mode 100644
index 0000000..10adb5c
--- /dev/null
+++ b/rust-conf.el
@@ -0,0 +1,83 @@
+;;; rust-conf.el --- Configurations of rust-mode -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 李俊緯
+
+;; Author: 李俊緯 <mmemmew@gmail.com>
+;; Keywords: convenience, c, data, emulations, faces, files, languages, local, tools
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This configures rust-mode.
+
+;;; Code:
+
+;;; Dependencies
+
+(use-package "dash.el" 'dash)
+(use-package "s.el" 's)
+(use-package "f.el" 'f)
+(require 'let-alist)
+(use-package "markdown-mode" 'markdown-mode)
+(require 'project)
+(use-package "rust-mode" 'rust-mode)
+(require 'seq)
+(use-package "spinner.el" 'spinner)
+(use-package "xterm-color" 'xterm-color)
+(use-package "eglot" 'eglot)
+
+(define-key eglot-mode-map (kbd "C-c r") #'eglot-rename)
+(define-key eglot-mode-map (kbd "C-c o")
+ #'eglot-code-action-organize-imports)
+(define-key eglot-mode-map (kbd "C-c h") #'eldoc)
+
+(setq eglot-autoshutdown t)
+
+;; NOTE: I have manually commented out the line which requires
+;; lsp-mode.
+(use-package "rustic" 'rustic)
+(setq rustic-lsp-client 'eglot)
+(setq rustic-format-on-save t)
+
+(add-hook 'eglot-managed-mode-hook #'durand-rust-mode-hook)
+
+(defun durand-rust-mode-hook ()
+ "Set up basic settings."
+ ;; (remove-hook 'eldoc-documentation-functions
+ ;; #'eglot-hover-eldoc-function)
+ )
+
+;;; Fix a weird function
+
+(defun durand-rustic-cargo-doc-a ()
+ "Open the documentation for the current project in a browser.
+The documentation is built if necessary.
+Modified by Durand -- 2022-02-09 21:43:19.966224"
+ (interactive)
+ (if (y-or-n-p "Open docs for dependencies as well?")
+ ;; open docs only works with synchronous process
+ (shell-command (mapconcat #'identity
+ (list (rustic-cargo-bin) "doc --open")
+ " "))
+ (shell-command (mapconcat #'identity
+ (list (rustic-cargo-bin)
+ "doc --open --no-deps")
+ " "))))
+
+(advice-add #'rustic-cargo-doc :override
+ #'durand-rustic-cargo-doc-a)
+
+(provide 'rust-conf)
+;;; rust-conf.el ends here