0

I've tried making compile-command buffer-local via

(defun compilation-make-locals (process)
  (set (make-local-variable 'compile-command)
       compile-command))
(add-hook 'compilation-start-hook 'compilation-make-locals)

but without success.

The variable compile-command is not updated the to latest value when I interactively set a new command when doing M-x compile.

1 Answer 1

1
(set (make-local-variable 'compile-command)
     compile-command))

The latter compile-command is evaluated after (make-local-variable 'compile-command) so this should be a no-op -- you're making the variable buffer-local, and then setting the buffer-local value to whatever the buffer-local value already was.


I'm unsure what you are wanting to happen here, though. What would "the latest value" be?

If it's the global value that you're wanting to copy to the buffer-local value, then you can obtain that with (default-value 'compile-command)

In the case where the buffer had a pre-existing buffer-local value, there may well be a difference between that and the global value.

3
  • So it should suffice to write (make-local-variable 'compile-command), then?
    – Nordlöw
    Commented Sep 21, 2020 at 12:01
  • 1
    I think that should work.
    – NickD
    Commented Sep 21, 2020 at 14:11
  • I've just noticed and fixed a mistake in the latter part of my answer -- I had stated that the symbol-value function gives the global value of a variable, when it's actually the default-value function which does this.
    – phils
    Commented Sep 22, 2020 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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