From 435c95393459d0c7825a4431f0ebcec6898ba16b Mon Sep 17 00:00:00 2001 From: JSDurand Date: Wed, 9 Feb 2022 22:35:31 +0800 Subject: 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): --- common.el | 2 +- init.el | 15 +++++++++++ rust-conf.el | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 rust-conf.el 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: 李俊緯 +;; 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 . + +;;; 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 -- cgit v1.2.3-18-g5258