1

I often got to work with projects organized as follows:

src/

include/

...

Makefile

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

src/sub1/s1.c

include/protocol/p.h

src/x.c

tests/test1/test_x.c

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.

3
  • You should check out projectile. It has a handy function for this
    – Jules
    Jun 20, 2016 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 Jun 21, 2016 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, 2016 at 13:21

0

Your Answer

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