14

I am using Emacs 23 and have the following problem:

I run our project's build system from within Emacs like M-x compile -> cd /foo/bar && ./build

The build system now does some magic, "cd"s into some subdirectory for the build process and then gcc throws an error:

../src/somesource.cc:50 error: blablabla

Now the problem is that Emacs won't find that path, because it assumes the compile process started out in /foo/bar, and not in /foo/bar/builddir. So the leading "../" is not working for Emacs, e.g. when running compile-goto-error. Is there a way to tell Emacs to try skipping leading "../"?

Arne
  • 2,624
  • 3
  • 24
  • 45

2 Answers2

17

The best solution might be to change the build system to emit messages when it changes directories. Emacs looks for

Entering directory `...'
... 
Leaving directory `...'

(See the compilation-directory-matcher variable. If your build system does emit messages when it changes directories, but they're not in the format Emacs is looking for, you can add new regexps to compilation-directory-matcher.)

The other solution is to change compilation-search-path (which is a list of directories).

cjm
  • 61,471
  • 9
  • 126
  • 175
  • 1
    I didn't know about the "Entering..." functionality of Emacs. That'll probably help! – Arne May 05 '12 at 09:27
  • 2
    @Arne, GNU Make [prints messages in that form](http://www.gnu.org/software/make/manual/html_node/_002dw-Option.html) when using recursive makefiles. That's why Emacs looks for them. – cjm May 05 '12 at 09:31
  • 1
    This solution seems to be what I'm looking for, but I'm unable to edit `compilation-directory-matcher` variable (as you can see here : http://stackoverflow.com/q/21309720/61838). Moreover, the `compilation-search-path` doesn't seems to solve the problem (even when I only need emacs to look for sources in one directory). Any help would be appreciated! – claf Jan 23 '14 at 15:14
  • 1
    GNU make was recently changed/fixed to use U+0027 instead of U+0060 for the opening quotes and your version of emacs may still be looking for the old U+0060 characters only. See http://savannah.gnu.org/bugs/?34530 Try something like: (setq compilation-directory-matcher '("\\(?:Entering\\|Leavin\\(g\\)\\) directory ['`]\\(.+\\)'$" (2 . 1))) – Brad Spencer Apr 07 '15 at 19:49
0

On a few occasions I solved by passing output of the make through sed.

First, debugged it interactively 'Compile command: make | sed 's/x/y/' . And then repackaged it as a custom emacs interactive function.

uuu777
  • 765
  • 4
  • 21