For example, take any buffer. Maybe one named my-file. I want to run M-x compile in it and have access to the my-file buffer in compilation-finish-functions. You'd think think might work:

(setq compilation-finish-functions
      (lambda (buf string)
        (message "Buffer name: %s" (buffer-name (other-buffer buf)))))

But it actually echos my-file's other-buffer. current-buffer just returns the compilation buffer.

How would I reference the my-file buffer in a compilation-finish-functions function?


While hardly a clean alternative, a workaround would be to advice compile and store the calling buffer in a "global" var. This wouldn't work for concurrent executions of compile though. So keep that in mind.

  • 1
    That works for my needs, I'm not sure why I didn't think of advice before. Instead of using a variable to store it I'm just using a :before advice.
    – nanny
    Mar 11 '15 at 18:59
  • That's even better :)
    – rlazo
    Mar 12 '15 at 13:59

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.