From a773e7ed865a1a7eb5bf00b9f0481e888534831a Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sat, 9 Nov 2024 13:04:13 +0100 Subject: Upgrade markdown-mode, nginx-mode, rust-mode, yaml-mode and python-mode/property_getter --- .emacs.d/lisp/rust-cargo.el | 55 +++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to '.emacs.d/lisp/rust-cargo.el') diff --git a/.emacs.d/lisp/rust-cargo.el b/.emacs.d/lisp/rust-cargo.el index bda23d8..d9f1be5 100644 --- a/.emacs.d/lisp/rust-cargo.el +++ b/.emacs.d/lisp/rust-cargo.el @@ -19,6 +19,13 @@ :type 'boolean :group 'rust-mode) +(defcustom rust-cargo-locate-default-arguments '("--workspace") + "Arguments for `cargo locate-project`. Remove `--workspace` if you +would prefer to use the local crate Cargo.toml instead of the +worksapce for commands like `cargo check`." + :type '(repeat string) + :group 'rust-mode) + (defcustom rust-cargo-default-arguments "" "Default arguments when running common cargo commands." :type 'string @@ -42,7 +49,13 @@ (setq-local process-environment env) ;; Set PATH so we can find cargo. (setq-local exec-path path) - (let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace"))) + (let ((ret + (let ((args + (append + (list rust-cargo-bin nil (list (current-buffer) nil) nil + "locate-project") + rust-cargo-locate-default-arguments))) + (apply #'process-file args)))) (when (/= ret 0) (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) (goto-char 0) @@ -67,46 +80,54 @@ ;;; Internal -(defun rust--compile (format-string &rest args) +(defun rust--compile (comint format-string &rest args) (when (null rust-buffer-project) (rust-update-buffer-project)) (let ((default-directory (or (and rust-buffer-project (file-name-directory rust-buffer-project)) - default-directory))) - (compile (apply #'format format-string args)))) + default-directory)) + ;; make sure comint is a boolean value + (comint (not (not comint)))) + (compile (apply #'format format-string args) comint))) ;;; Commands (defun rust-check () "Compile using `cargo check`" (interactive) - (rust--compile "%s check %s" rust-cargo-bin rust-cargo-default-arguments)) + (rust--compile nil "%s check %s" rust-cargo-bin rust-cargo-default-arguments)) (defun rust-compile () "Compile using `cargo build`" (interactive) - (rust--compile "%s build %s" rust-cargo-bin rust-cargo-default-arguments)) + (rust--compile nil "%s build %s" rust-cargo-bin rust-cargo-default-arguments)) (defun rust-compile-release () "Compile using `cargo build --release`" (interactive) - (rust--compile "%s build --release" rust-cargo-bin)) + (rust--compile nil "%s build --release" rust-cargo-bin)) -(defun rust-run () - "Run using `cargo run`" - (interactive) - (rust--compile "%s run %s" rust-cargo-bin rust-cargo-default-arguments)) +(defun rust-run (&optional comint) + "Run using `cargo run` -(defun rust-run-release () - "Run using `cargo run --release`" - (interactive) - (rust--compile "%s run --release" rust-cargo-bin)) +If optional arg COMINT is t or invoked with universal prefix arg, +output buffer will be in comint mode, i.e. interactive." + (interactive "P") + (rust--compile comint "%s run %s" rust-cargo-bin rust-cargo-default-arguments)) + +(defun rust-run-release (&optional comint) + "Run using `cargo run --release` + +If optional arg COMINT is t or invoked with universal prefix arg, +output buffer will be in comint mode, i.e. interactive." + (interactive "P") + (rust--compile comint "%s run --release" rust-cargo-bin)) (defun rust-test () "Test using `cargo test`" (interactive) - (rust--compile "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) + (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) (defun rust-run-clippy () "Run `cargo clippy'." @@ -118,7 +139,7 @@ ;; set `compile-command' temporarily so `compile' doesn't ;; clobber the existing value (compile-command (mapconcat #'shell-quote-argument args " "))) - (rust--compile compile-command))) + (rust--compile nil compile-command))) ;;; _ (provide 'rust-cargo) -- cgit v1.3