vim: is there a way to preprocess a file opened by copen

151 views Asked by At

I'm trying to use errorformat to shorten the code-compile-code loop. My setup is such:

  1. MacOS where my editor (vim) sits. Along with git, etc. Everything except the compiler (VCS).
  2. A Ubuntu VM that runs on the same computer.
  3. A folder that's shared between the two. It mounts as ~/projects/my_proj on MacOS and /media/psf/projects/my_proj on the VM.

My workflow:

  1. Edit code on MacOS.
  2. Send SSH command to VM to compile the code and dump the results in /media/psf/projects/my_proj/results:
ssh remote_user@remote_host cd /media/psf/projects/my_proj/results; vcs <options_string> -f filelist.f
  1. Examine results of log and edit errors.

In step #3 of the workflow above, I would like to use quickfix to scan the log file. I've found that :cfile works to load the file.

However, the compiler on the VM writes out file paths using the absolute path:

/media/psf/projects/my_proj

When I try to read this into vim on MacOS, /media/psf/projects doesn't exist. And vim cannot display the errors.

What would be the best way (vimscript? macro?) that I can preprocess the log file (replace all folder paths), spit out an intermediate logfile and run :cfile on that?

1

There are 1 answers

4
romainl On

The signal to noise ratio of your question is low. Here is how I understand your problem:

  • you have a virtual machine with a shared directory,
  • the code of your project resides in that directory,
  • the directory is /media/psf/ in the VM and ~/projects/foobar/ in the host,
  • when the compiler outputs errors, the paths start with /media/psf/,
  • when you pull those errors in Vim on the host, /media/psf/ doesn't exist so Vim can't jump to the errors,
  • you need a way to translate /media/psf/ to ~/projects/foobar/ before or while the error list is fed to Vim.

The following solution assumes that the error list retrieved from the VM is saved into a file named errorfile at the root of the shared directory:

:cexpr readfile('~/projects/foobar/errorfile')->join("\n")->substitute('/media/psf/', '~/projects/foobar/', 'g')

Reference:

:help :cexpr
:help readfile()
:help join()
:help substitute()

FWIW, telling your compiler to write the error list to the file mentioned above would allow you to remove the SSH step from your workflow.