diff --git a/rustic-cargo.el b/rustic-cargo.el index 010bcd5a..a2acf206 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -619,7 +619,7 @@ in your project like `pwd'" (let ((c (if (listp command) command (split-string command)))) - (rustic-compilation-start c args))) + (rustic-compilation-start c (append (list :no-default-dir t) args)))) ;;;###autoload (defun rustic-cargo-build () diff --git a/rustic-compile.el b/rustic-compile.el index 49f337e0..1b10a070 100644 --- a/rustic-compile.el +++ b/rustic-compile.el @@ -288,7 +288,7 @@ ARGS is a plist that affects how the process is run. (process (or (plist-get args :process) rustic-compilation-process-name)) (mode (or (plist-get args :mode) 'rustic-compilation-mode)) (directory (or (plist-get args :directory) (funcall rustic-compile-directory-method))) - (workspace (rustic-buffer-workspace)) + (workspace (rustic-buffer-workspace (plist-get args :no-default-dir))) (sentinel (or (plist-get args :sentinel) #'rustic-compilation-sentinel)) (file-buffer (current-buffer))) (rustic-compilation-setup-buffer buf directory mode) diff --git a/rustic.el b/rustic.el index cdf45ea2..f34a2747 100644 --- a/rustic.el +++ b/rustic.el @@ -64,16 +64,20 @@ (defun rustic-buffer-workspace (&optional nodefault) "Get workspace for the current buffer." + ;; this variable is buffer local so we can use the cached value (if rustic--buffer-workspace rustic--buffer-workspace (with-temp-buffer (let ((ret (call-process (rustic-cargo-bin) nil (list (current-buffer) nil) nil "locate-project" "--workspace"))) - (when (and (/= ret 0) (not nodefault)) - (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) - (goto-char 0) - (let* ((output (json-read)) - (dir (file-name-directory (cdr (assoc-string "root" output))))) - (setq rustic--buffer-workspace dir)))))) + (cond ((and (/= ret 0) nodefault) + (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) + ((and (/= ret 0) (not nodefault)) + (setq rustic--buffer-workspace default-directory)) + (t + (goto-char 0) + (let* ((output (json-read)) + (dir (file-name-directory (cdr (assoc-string "root" output))))) + (setq rustic--buffer-workspace dir)))))))) (defun rustic-buffer-crate (&optional nodefault) "Return the crate for the current buffer.