Created
July 22, 2021 21:29
-
-
Save jimblandy/615862a737e4f65e49da016af2cf420a to your computer and use it in GitHub Desktop.
My Rust configuration for Emacs. Not tested or really prepared for publication, just offered as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Customizations. I think you need to integrate these into the existing calls to `custom-set-variables` | |
;; and `custom-set-faces`. | |
(custom-set-variables | |
'(lsp-keymap-prefix "C-S-l") | |
'(lsp-rust-all-features t) | |
'(lsp-rust-analyzer-diagnostics-disabled ["unresolved-proc-macro"]) | |
'(lsp-rust-analyzer-display-chaining-hints t) | |
'(lsp-rust-analyzer-display-parameter-hints t) | |
'(lsp-rust-analyzer-server-command '("rust-analyzer-linux")) | |
'(lsp-rust-analyzer-server-display-inlay-hints nil) | |
'(lsp-rust-features []) | |
'(lsp-rust-server 'rust-analyzer) | |
'(lsp-signature-render-documentation nil) | |
'(lsp-ui-doc-enable nil) | |
;; I hate company mode, because it interferes with typing. If you've figured out how | |
;; to make it not do that, or if you actually like that, then you don't need this. | |
'(company-backends | |
'(company-bbdb company-semantic company-cmake company-capf company-clang company-files | |
(company-dabbrev-code company-gtags company-etags company-keywords) | |
company-oddmuse)) | |
'(company-idle-delay nil) | |
) | |
(custom-set-faces | |
'(lsp-rust-analyzer-inlay-face ((t (:inherit nil :foreground "gray"))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cargo) | |
(global-set-key (kbd "C-S-c") 'cargo-minor-mode-command-map) | |
(setq lsp-keymap-prefix "C-S-l") | |
(require 'lsp) | |
(defun jimb-cargo-process-mode-hook () | |
(toggle-truncate-lines 0)) | |
(add-hook 'cargo-process-mode-hook 'jimb-cargo-process-mode-hook) | |
(defun jimb-find-cargo-package-top () | |
"Return the current buffer's governing Cargo.toml's directory name. | |
Return nil if there is none." | |
(if (not buffer-file-name) | |
nil | |
(let ((root (expand-file-name (file-name-directory buffer-file-name)))) | |
(while (and root (not (file-exists-p (concat root "Cargo.toml")))) | |
(let ((parent (file-name-directory (directory-file-name root)))) | |
(if (string= parent root) | |
(setq root nil) | |
(setq root parent)))) | |
root))) | |
(defvar jimb-lsp-auto-directories | |
'( | |
"/home/jimb/SPIRV-Tools" | |
"/home/jimb/rust/naga" | |
"/home/jimb/rust/rspirv" | |
"/home/jimb/rust/spirv-tree" | |
"/home/jimb/rust/wgpu" | |
"/home/jimb/rust/wgpu-rs" | |
"/home/jimb/p99" | |
"/home/jimb/rust/env_logger" | |
) | |
) | |
(require 'dash) | |
(defun jimb-buffer-in-whitelisted-directory () | |
"Return true if the current buffer visits a file in a whitelisted directory. | |
This checks the current buffer's file against the directories listed in | |
`jimb-lsp-auto-directories'." | |
(-when-let (buf-name (buffer-file-name)) | |
(-any? (lambda (whitelisted) (string-prefix-p whitelisted buf-name)) | |
jimb-lsp-auto-directories))) | |
(defun jimb-enable-lsp-in-selected-directories () | |
"Enable lsp in the current buffer if whitelisted. | |
This consults `jimb-lsp-auto-directories'." | |
(when (jimb-buffer-in-whitelisted-directory) | |
(lsp))) | |
(add-hook 'rust-mode-hook 'jimb-enable-lsp-in-selected-directories) | |
(add-hook 'c++-mode-hook 'jimb-enable-lsp-in-selected-directories) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment