0

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?

  • 1
    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
  • That's a really obtuse bit of reading. :) So basically, it sounds like my timing is bad. I'm binding default-directory too soon, and then when I switch to that buffer, the prior default-directory binding is still in effect. – RealityMonster May 21 '15 at 19:25
  • 1
    Yes, I think that's it. – Kyle Meyer May 21 '15 at 19:36
0

Based on Kyle's observation, I've made a few changes.

(defun build-engine ()
  "Build the exe."
  (interactive)
  (setq global-default-compile-directory "f:/Projects/build")
  (let (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: ")
  (setq global-default-compile-directory "f:/Projects/bin")
  (let (compile (concat "tool_win64.exe /genfastload:PC /name:" name))))

(defadvice compile (around split-vertically activate)
    (let ( ((default-directory global-default-compile-directory))
     (split-width-threshold 9999)
     (split-height-threshold 0)))
    (switch-to-appropriate-compile-buffer)
    ad-do-it)

This works perfectly well.

  • Could you please accept your own answer so we can mark the question as answered? – Dan Jun 21 '15 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.