From f402179eebcaca1a7a2025c6a15686dc686f395d Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sun, 10 Apr 2022 21:12:13 -0400 Subject: [PATCH] Add rust config --- emacs/.emacs.d/config/init-run-command.el | 26 ++++++++++++++++++++++- emacs/.emacs.d/config/init-rust.el | 8 +++++++ emacs/.emacs.d/init.el | 1 + zsh/.zshenv | 5 ++--- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 emacs/.emacs.d/config/init-rust.el diff --git a/emacs/.emacs.d/config/init-run-command.el b/emacs/.emacs.d/config/init-run-command.el index 636126f..c85c850 100644 --- a/emacs/.emacs.d/config/init-run-command.el +++ b/emacs/.emacs.d/config/init-run-command.el @@ -262,6 +262,29 @@ :command-line (format "mvn test -Dtest=%s" test-method) :working-dir project-dir))))) + (defun get-cargo-commands (dir) + (when (executable-find "cargo") + (with-temp-buffer + (cd dir) + (-as-> (shell-command-to-string "cargo --list") v + (split-string v "\n") + (cdr v) + (-filter (-not (-partial 's-contains-p "alias")) v) + (-map 's-trim v) + (-map (-partial 's-split " ") v) + (-map 'car v) + (-filter (-not 's-blank?) v))))) + + (defun run-command-recipe-cargo () + (when-let* ((project-dir (locate-dominating-file default-directory "Cargo.toml")) + (cargo-cmds (get-cargo-commands project-dir))) + (-map + (lambda (cmd) + (list :command-name cmd + :command-line (format "cargo %s" cmd) + :working-dir project-dir)) + cargo-cmds))) + :general (leader-map "\"" #'run-command) :custom @@ -280,6 +303,7 @@ run-command-recipe-nosetests run-command-recipe-web-ext run-command-recipe-pip - run-command-recipe-maven))) + run-command-recipe-maven + run-command-recipe-cargo))) (provide 'init-run-command) diff --git a/emacs/.emacs.d/config/init-rust.el b/emacs/.emacs.d/config/init-rust.el new file mode 100644 index 0000000..97ce610 --- /dev/null +++ b/emacs/.emacs.d/config/init-rust.el @@ -0,0 +1,8 @@ +;; -*- lexical-binding: t; -*- + +(use-package rust-mode + :mode (("\\.rs\\'" . rust-mode)) + :config + (add-hook 'rust-mode-hook 'lsp-deferred)) + +(provide 'init-rust) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 08cf660..da53b13 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -92,6 +92,7 @@ (require 'init-java) (require 'init-scala) (require 'init-js) +(require 'init-rust) (require 'init-web) (require 'init-xml) (require 'init-yaml) diff --git a/zsh/.zshenv b/zsh/.zshenv index 0e6b520..fc71027 100644 --- a/zsh/.zshenv +++ b/zsh/.zshenv @@ -1,5 +1,5 @@ typeset -U path -path=(~/bin ~/.local/bin ~/.gem/ruby/2.6.0/bin ~/go/bin /opt/local/bin ~/.cargo/bin /usr/local/opt/make/libexec/gnubin $path) +path=(~/bin ~/.local/bin ~/.gem/ruby/2.6.0/bin ~/go/bin /opt/local/bin /usr/local/opt/make/libexec/gnubin $path) export INFOPATH="$HOME/info:/opt/homebrew/share/info:" @@ -8,8 +8,6 @@ export LEDGER_FILE="$HOME/journal.ledger" EDITOR="$(which emacsclient)" export EDITOR -export PATH="$HOME/.cargo/bin:$PATH" - export NVM_DIR="$HOME/.nvm" export WORKON_HOME="$HOME/.local/share/virtualenvs" @@ -34,3 +32,4 @@ fi export SDKMAN_DIR="$HOME/.sdkman" [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh" path=("$SDKMAN_DIR/candidates/java/current/bin" "$path[@]") +[[ -e "$HOME/.cargo/env" ]] && . "$HOME/.cargo/env"