thinca/vim-qfreplace

In location list, qfreplace opens quickfix list

Opened this issue · 4 comments

How about the following check to see if qfreplace actually is called in a quickfix list and not a location list?

" let b:errorlist_type hold the type of quickfix list.
" See https://groups.google.com/forum/#!msg/vim_use/sfRlnrOwN2M/JAdzwHe51qYJ
if !exists('s:processing')
  let listbufnr = bufnr("%")
  let numwindows = winnr('$')
  let curwin = winnr()
  let s:processing = 1
  copen
  call setbufvar(listbufnr, 'isquickfix', (curwin == winnr() ? 1 : 0))
  " 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'
  unlet s:processing
endif

qfreplace.vim has not supported yet about location-list.
I would like to support some day.

Yes, I understand. It would perhaps therefore be less confusing if
qfreplace did not open at all if it is called in the location list window.
But unfortunately this is not easy to check, the best seems to be the
proposed workaround.

Thanks for this great tool and your latest additions.

Le 7 juin 2014 19:02:41 thinca notifications@github.com a écrit :

qfreplace.vim has not supported yet about location-list.
I would like to support some day.


Reply to this email directly or view it on GitHub:
#5 (comment)

I consider it.

Seems there's a simpler solution, found at https://github.com/romainl/dotvim/blob/44e87b3fbb829145a23bd5b2be1807cc958308e5/bundle/qf/after/ftplugin/qf.vim

" are we in a location list or a quickfix list?
let b:isLoc = len(getloclist(0)) > 0 ? 1 : 0

See :h getloclist() that gives

For a location list window, the displayed location list is returned. 

By the way, the old above code was flawed as it didn't restore the alternate window. Instead adding the following to qf.vim works fine

" See https://groups.google.com/forum/#!msg/vim_use/sfRlnrOwN2M/JAdzwHe51qYJ
if exists('s:processing')
  finish
endif
let listbufnr = bufnr("%")
let numwindows = winnr('$')
let altwin = winnr('#')
let curwin = winnr()
let s:processing = 1
copen
if curwin == winnr()
  call setbufvar(listbufnr, 'isQuickfix', '1')
endif
" close the quickfix list if it was closed when we began
if numwindows != winnr('$')
  cclose
endif
" return to quickfix/location list
exe altwin 'wincmd w'
exe curwin 'wincmd w'
unlet s:processing

However, the above solution is clearly preferable.