From 8997e69e63d19d833e7ec748f2aec5fdc5d7cf80 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 15 Dec 2016 11:30:23 -0800 Subject: Try to do the right thing for the default-directory. When getting the list of targets, or running an action, the value for the default directory should not be changed. Until now, if you were to open a file, then get the list of targets, then open a new file, you'll be prompted for a new file with a starting directory set by the value of `pants--get-source-tree`. We now set a value for `default-directory` as a local variable when running an action. --- pants.el | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pants.el b/pants.el index 9fe23a9..0cb2fb2 100644 --- a/pants.el +++ b/pants.el @@ -85,10 +85,10 @@ (defun pants--python-repl-action (target) "Starts a Python REPL." - (let ((pants-repl-command (format "%s repl %s" (pants--build-command) target))) - (set (make-local-variable 'default-directory) pants-source-tree-root) - (set (make-local-variable 'python-shell-exec-path) '(pants-source-tree-root)) - (set (make-local-variable 'python-shell-interpreter) pants-source-tree-root) + (let ((pants-repl-command (format "%s repl %s" (pants--build-command) target)) + (default-directory (pants--get-source-tree))) + (set (make-local-variable 'python-shell-exec-path) '(pants--get-source-tree)) + (set (make-local-variable 'python-shell-interpreter) (pants--get-source-tree)) (set (make-local-variable 'python-shell-interpreter-args) pants-repl-command) (set (make-local-variable 'python-shell-prompt-detect-failure-warning) nil) (run-python pants-repl-command t) @@ -130,7 +130,8 @@ (defun pants--complete-read (prompt choices action) "Generates a list of existing targets" - (let (res) + (let ((default-directory (pants--get-source-tree)) + res) (setq res (cond ((eq pants-completion-system 'ivy) @@ -164,18 +165,24 @@ (defun pants--get-targets () "Get the targets for the current file." - (let ((build-file (pants--get-build-file-for-current-buffer))) - (let ((build-command (format "%s list %s:" (pants--build-command) build-file)) - targets target) - (set (make-local-variable 'default-directory) (pants--get-source-tree)) - (with-temp-buffer + (let ((build-command (format "%s list %s:" + (pants--build-command) + (pants--get-build-file-for-current-buffer))) + (default-directory (pants--get-source-tree)) + targets) + (with-temp-buffer + (let (target) (insert (shell-command-to-string build-command)) (goto-char (point-min)) (while (re-search-forward "^\\(.+\\)$" nil t) (setq target (match-string 1)) - (push target targets))) - targets))) + (push target targets)))) + (push (format "%s::" (string-remove-prefix + (pants--get-source-tree) + (pants--get-build-file-for-current-buffer))) + targets) + targets)) (define-compilation-mode pants-mode "pants" (set (make-local-variable 'compilation-process-setup-function) -- cgit v1.2.3