I often got to work with projects organized as follows:





Is there a way to teach emacs' "compile" function to always use that top-level Makefile regardless which file I'm editing in the current buffer? For example it can be any of





In all those cases I want "compile" command to go as many times "up" in hierarchy as necessary to get into top-level directory (the one in the directory with 'src', 'include' and 'tests' entries) and run Makefile in there. Additional problem is that any of sub directories can have Makefiles of its own.

  • You should check out projectile. It has a handy function for this – Jules Jun 20 '16 at 3:08
  • You could write a function that uses locate-dominating-file on default-directory to find the top-level dir, then sets default-directory to that dir path and runs compile – Croad Langshan Jun 21 '16 at 21:26
  • Thanks for hint on projectile - will look into it. As for writing function - I'll leave it as a last resort - the task seems to be way to common so I'd rather not reinvent a wheel. – god Jun 25 '16 at 13:21

Your Answer

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

Browse other questions tagged or ask your own question.