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 Mar 22 '17 at 22:01
  • I wrote a package, github.com/whatacold/ppcompile, to do the exact things, take a look if you're interested. – whatacold Jun 23 at 2:46

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

Your Answer

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

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