Arne
Arne

Reputation: 2674

How to adjust the path that Emacs' compile-goto-error gets from the compilation buffer?

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 "../"?

Upvotes: 16

Views: 3759

Answers (3)

Gauthier
Gauthier

Reputation: 41945

I haven't found a way to make this project specific, but this in my init.el works for going to errors:

(setq directory-abbrev-alist '(("^/src" . "./")))

You need to adapt this to the substitution you want.

In your case, you could try to substitute ../ with ./:

(setq directory-abbrev-alist '(("^../" . "./")))

If you know how to make this work only for the compilation buffer of a specific project, I'd be happy to know.

Upvotes: 0

uuu777
uuu777

Reputation: 901

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.

Upvotes: 0

cjm
cjm

Reputation: 62099

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).

Upvotes: 17

Related Questions