Recently the scenario of editing project source code locally but building the project remotely on another machine (for example inside a Docker container or an Amazon Web Services host) is becoming more common. The setup typically involves starting a build from Emacs that first uses rsync to copy over the project directory to a remote host and then execute the build command there.

A problem arises however when there is a build error and the reported remote source code file paths do not match the paths on the local host. In this case Emacs' compilation mode is not able to automatically jump from the error to the local file (because it doesn't understand how to map the remote path to the local path). How can the Emacs compilation mode be configured to convert the remote paths to local paths?

Possibly the user would have to provide some basic remote path to local path mapping function. Or maybe some heuristic could be implemented which tries mapping only the part of the path relative to the project directory, which should be the same on the local and remote host.

  • 1
    Not quite what you're asking for I know, but if editing the code on the remote machine using Emacs' tramp mode is possible, then M-x compile will do the right thing and run the build on the remote machine and let you jump directly to the errors (also on the remote machine). Apologies if you knew that already.
    – stevoooo
    Commented Mar 22, 2017 at 22:01
  • I wrote a package, github.com/whatacold/ppcompile, to do the exact things, take a look if you're interested.
    – whatacold
    Commented Jun 23, 2019 at 2:46
  • @stevoooo But if you implement the solution below and go to next error in the compilation buffer, it takes you to a local file. If you recompile from that buffer, the compilation command is run locally and doesn't work. Is there a way to teach emacs to open the remote file from an error in compilation buffer? Commented Jan 20, 2021 at 10:43

1 Answer 1


If I understand your question correctly, the simplest solution that I have found is to set the variable directory-abbrev-alist to map directories in the compilation buffer to the host system.

For example I run my phpunit tests in a docker container as a compile command. When there are errors or failures the filepaths in the compilation buffer show up as /var/www/html/... but on my host machine I am working at /home/user/MyApp

So in my emacs config (would work better as .dir-locals) I have:

(setq directory-abbrev-alist '(("^/var/www/html" . "/home/user/MyApp")))

Now when I click on or jump to paths in compilation buffer Emacs goes to the correct file on the host machine.

See the official Emacs docs for details on how directory-abbrev-alist works: https://ftp.gnu.org/old-gnu/Manuals/elisp-manual-20-2.5/html_node/elisp_380.html

  • I tried to use directory-local and file-local variables, both failed. But modifying in the emacs config works for me. Great time saver! Commented Jan 20, 2021 at 9:55
  • Forgot to mention my compile command to build in a local docker container. Invoke this from a local source file: docker exec CONTAINER_NAME sh -c "cd path/to/source && make" Commented Jan 20, 2021 at 10:40
  • I had paths like /app/app in my compilation buffer (that should map to something like /home/ev/myapp/app). First /app being the path in container, and second /app being the path in my app, for some reason that wasn't working until I created differently name folder in my container, so in compilation I get /myapp/... which maps to /home/ev/myapp/.... Very handy, big thank you! Commented Apr 25 at 14:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.