After patch 0869 came out, implementing 'quickfixtextfunc', I thought perhaps
that would be the answer I was looking for. Alas, it seems to be useful only to
manipulate the text of the quickfix window, not the list loaded by :make. But
it got me looking at this again, and I decided to give the QuickFixCmdPost
solution a shot. It was easier than I thought, even though it doesn't work
quite right:
function! FixQuickFix()
let qflist = getqflist()
for i in qflist
let fname = buffer_name(i.bufnr)
if fname =~ "\.go$"
let fname = "down/down/down/" . fname
let i.bufnr = bufadd(fname)
" call bufload(i.bufnr)
" call setbufvar(i.bufnr, "&buflisted", 1)
endif
endfor
call setqflist(qflist, 'r')
endfunction
I run :make, and the build runs, and fails as expected, but vim doesn't switch
to the buffer with the file containing the first error. I get a "Press ENTER or
type command to continue" message after the make completes, and then a second
one after showing me the first line of the output (not the first error), but
then it just leaves me in the buffer I was originally in.
:clist is what I expect:
17 down/down/down/pkg/foo.go:503 col 14: undefined: tst
18 Makefile:981: recipe for target 'bin/foo' failed
and :cnext takes me to that first error, but it's not done automatically.
The "too many buffers loaded" problem is definitely here:
:ls!
1 %a "Makefile" line 6
2u "pkg/foo.go" line 0
3u "down/down/down/pkg/foo.go" line 0
4u h- "[Quickfix List]" line 19
Makefile was my original buffer. You can see that two buffers exist for the
file where the problem occurred: one prior to the edit made by FixQuickFix(),
and one after.
If I uncomment the setbufvar() line, it definitely ends up listed, and if I call
bufload(), then the buffer is definitely loaded (complaints about an existing
swapfile, if it's open in another vim), but neither one nor both together give
me the behavior I'm expecting. I can put "cnext" at the end of it (not
requiring either of the bufload() or setbufvar() calls), and that works, but
then I don't know of any way to distinguish between :make and :make!.
Is there anything else I can do without extra support from vim?
Thanks,
Danek