Friday, December 5, 2014

Re: The window to be chosen for quickfix

On Friday, December 5, 2014 9:11:40 AM UTC-6, Ben Fritz wrote:
> On Thursday, December 4, 2014 12:58:33 PM UTC-6, Christian Brabandt wrote:
> > Hi Gary!
> >
> > On Mi, 03 Dez 2014, Gary Johnson wrote:
> >
> > > nnoremap <buffer> <CR> :call QfEnter()<CR>
> > >
> > > function! QfEnter()
> > > let l:lnum = line('.')
> > > wincmd p
> > > exe 'cc' l:lnum
> > > endfunction
> > >
> > > I put that in ~/.vim/after/ftplugin/qf.vim. The map will therefor
> > > apply only to the quickfix window.
> >
> > Thanks for that.
> >
> > >
> > > Someone commented in another thread a while back that the quickfix
> > > error number was not always the same as the quickfix window line
> > > number, but that assumption has always worked for me.
> >
> > I suppose this could happen for multi-line errorlists? But I have never
> > used them, so it should be okay for me.
> >
>
>
> Unfortunately, I often have quickfix lists with "cruft" lines, from my gcc-based compiler. Probably the cause is actually my makefile echoing out each command that runs. Example:
>
> || gcc -c -O2 -fno-builtin -Wall -s -UVARIOUS_UNDEFINED_THINGS -DVARIOUS_DEFINED_THINGS -I./various/include/paths src/main.c -o src/main.o
> || src/main.c: In function `ProcessIO':
> src/main.c|363 warning| unused variable `CurrentTime'
> src/main.c|355 warning| unused variable `CurrentTimeInMs'
> src/main.c|354 warning| unused variable `NextBroadcastTime'
> || src/main.c: In function `main':
> src/main.c|1545 warning| implicit declaration of function `set_callback'
> || gcc -c -O2 -fno-builtin -Wall -s -UWIN_AGS -D__true_false_are_keywords -DM145 -UDEBUG -DWRAPPER_DEBUG_DISABLED -UCANNED_DATA -UTEST_STUB -M -I./various/include/paths src/main.c > src/main.d.tmp
> || sed -e 's|.*:|src/main.o:|' < src/main.d.tmp > src/main.d
> || sed -e 's/.*://' -e 's/\\$//' < src/main.d.tmp | \
> || sed -e 's/\(.\)$/\1:/' >> src/main.d
> || rm -f src/main.d.tmp
>
> Only the lines not starting with "||" are actually error list positions.
>
> I do have a ftplugin set up to add the error number of the cursor line to the statusline...I'll see if I can use that for a similar mapping and post the result.

Oops, forgot to clean up the second defines list. How embarrassing.

Anyway...I actually experimented, and for this error list, :1cc tries jumping to the first "cruft" line, :2cc to the 2nd, etc. So actually in this case, the line number DOES correspond to the error number.

If you use getloclist(0) or getqflist() then each item returned has a "valid" field; the cruft lines have valid set false, but they ARE in the error list. So I don't actually know when the error list entries don't correspond to the line numbers, if that is ever the case.

I'm putting that mapping in my vim config now, thanks a ton! I only modified it slightly to also work with the location list. Here is something I do when setting filetype to quickfix, to detect whether it's a location list or a quickfix list:

if &buftype=='quickfix'
if v:version >= 700
if !exists('s:processing')
let listbufnr = bufnr("%")
let numwindows = winnr('$')
let curwin = winnr()
let s:processing = 1
copen
call setbufvar(listbufnr, 'errorlist_type', (curwin == winnr() ? 'quickfix' : 'location'))
" close the quickfix list if it was closed when we began
if numwindows != winnr('$')
cclose
endif
" return to quickfix/location list
exe curwin 'wincmd w'

It works by using "copen" to jump to the quickfix list, and if the current window changed then we must have been in the location list before.

Now I can use this as the map function:

function! QfEnter()
let l:lnum = line('.')
if b:errorlist_type == 'location'
let l:cmd = 'll'
else
let l:cmd = 'cc'
endif
wincmd p
exe l:cmd l:lnum
endfunction

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: