I have two different compile commands, and they need to run in different directories.
I've gone through the trouble of making sure that if at all possible, I re-use the open compile buffer, rather than open a new view to it over and over again. The problem is that the default-directory of the buffer is set after I run one command, and subsequent calls don't seem to be able to override the default directory.
So:
(defun build-engine ()
"Build the exe."
(interactive)
(let ((default-directory "f:/Projects/build/"))
(compile "build.pl -target=release_fastbuild -platform=win64 %*")))
(defun build-test (name)
"Build a test from the current tool executable with the specified name"
(interactive "sMap Name: ")
(let ((default-directory "f:/Projects/bin/"))
(compile (concat "tool_win64.exe /genfastload:PC /name:" name))))
Those are the two compile commands.
This is how I always switch to the open compile buffer, so I don't keep opening new ones. (It's also how I keep the buffer from vertically splitting.)
(defadvice compile (around split-vertically activate)
(if (and (get-buffer "*compilation*")
(not (eq (current-buffer) (get-buffer "*compilation*"))))
(switch-to-buffer-other-frame (get-buffer "*compilation*"))
(let ((split-width-threshold 9999)
(split-height-threshold 0))))
ad-do-it)
If I run the first build command, it works. Then if I build the second, it fails because the default-directory is still set to f:/Projects/build/. If I kill the first compile buffer, my command works.
I could write some infrastructure so that the build-engine command only uses build buffers and the build-test command only uses test buffers, but it seems like that let should override the previous one, shouldn't it?
let
only rebindsdefault-directory
for the current buffer. See the warning in(info "(elisp) Intro to Buffer-Local")
. – Kyle Meyer May 21 '15 at 19:19