1

I run several applications, in several languages, that store their error stacks locally. I made a small emacs mode that allows me to browse those errors and navigate the related code. The code I wrote, at its core, is basically loading those stacks from the database in a buffer and setting that buffer in compilation code. Then I can browse code by using previous-error, next-error, etc. to navigate the code. compilation-mode is great because it knows many error regexps so I don't need to deal with them (I add to add just 3 new regexps to local variable compilation-error-regexp-alist)

Very convenient and that has been working fine for years. The paths of the stacks are absolute, which suits fine to compilation mode.

But more and more I run those applications in lightweight containers. Then, the path of those stacks does not works because I have mounted the container filesystem in different paths in my host (I run emacs exclusivelly in the host, and I store the stacks there). Then, emacs cannot find the path the files are and I cannot browse them.

I mount the root filesystem os my containers in known locations. So, for a stack /a/b/c/d.c:80 in container "foo", I can calculate the path very easily: /containers/foo/a/b/c/d.c:80

I tried to use compilation-search-path, with no avail (compilation-find-file does not concatenate an absolute path to the elements of the search path, only the basename)

I would appreciate some hint of how to achieve what I want (basically smarting compilation-find-file to prepend a path to those paths in its "error lines") that does not violates compile.el encapsulation.

juanleon
  • 163
  • 6

2 Answers2

2

Just for the record, I ended up solving it via defadvice (it is a hackish solution imho). When browsing the stacks, I set the value of a local variable (container-path) to the container path of that specific stack and then I have the following defadvice:

(defadvice compilation-find-file (around relocate-to-container (marker filename directory &rest formats) activate)
  (if (and container-path (file-name-absolute-p filename))
      (let ((filename (concat container-path filename)))
        ad-do-it)
    ad-do-it))
juanleon
  • 163
  • 6
1

I think you might be able to use an old hack in compile.el:

(setq-local comint-file-name-prefix "/containers/foo/a/b/c/d.c:80")

This was meant originally for use inside rlogin.el buffers (i.e. a remote shell), but your situation is basically the same.

You might like to M-x report-emacs-bug and ask for its name to be fixed since it really doesn't have much to do with comint.

Stefan
  • 26,404
  • 3
  • 48
  • 85
  • Sadly, that does not work. In compilation-find-file, there is an (if (file-name-absolute-p filename) ... (setq filename (file-name-nondirectory filename)) that strips the directory part. I need the full absolute path to be appended to /containers/foo – juanleon Sep 18 '16 at 14:43
  • Then you should report this via M-x report-emacs-bug. – Stefan Sep 18 '16 at 16:13