From 051bab1e627643f0dfcf46c869c17602494d2eb2 Mon Sep 17 00:00:00 2001 From: Troy Hinckley Date: Fri, 11 Aug 2023 18:12:50 -0500 Subject: [PATCH] Correctly handle directory on rerun Currently rustic will override the default-directory to the workspace root after a compilation is finished. This enables it to correctly find the paths in error messages. But it also means that if you rerun a command it will rerun in the root crate instead of the original one. This change adds a new variable to track the original directory and resets it when we rerun. --- rustic-cargo.el | 6 ++++-- rustic-compile.el | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rustic-cargo.el b/rustic-cargo.el index 10097db..495a0af 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -195,7 +195,8 @@ If ARG is not nil, use value as argument and store it in (defun rustic-cargo-test-rerun () "Run 'cargo test' with `rustic-test-arguments'." (interactive) - (rustic-cargo-test-run rustic-test-arguments)) + (let ((default-directory (or rustic-compilation-directory default-directory))) + (rustic-cargo-test-run rustic-test-arguments))) ;;;###autoload (defun rustic-cargo-current-test () @@ -619,7 +620,8 @@ When calling this function from `rustic-popup-mode', always use the value of (defun rustic-cargo-run-rerun () "Run 'cargo run' with `rustic-run-arguments'." (interactive) - (rustic-cargo-run-command rustic-run-arguments)) + (let ((default-directory (or rustic-compilation-directory default-directory))) + (rustic-cargo-run-command rustic-run-arguments))) (defun rustic--get-run-arguments () "Helper utility for getting arguments related to 'examples' directory." diff --git a/rustic-compile.el b/rustic-compile.el index 2556e94..bce6d79 100644 --- a/rustic-compile.el +++ b/rustic-compile.el @@ -209,6 +209,9 @@ Error matching regexes from compile.el are removed." ;;; Compilation Process +(defvar-local rustic-compilation-directory nil + "original directory for rust compilation process.") + (defvar rustic-compilation-process-name "rustic-compilation-process" "Process name for rust compilation processes.") @@ -251,6 +254,7 @@ Set environment variables for rust process." (erase-buffer) (setq default-directory dir) (funcall mode) + (setq-local rustic-compilation-directory dir) (unless no-mode-line (setq mode-line-process '((:propertize ":%s" face compilation-mode-line-run)