On 08/17/2016 12:00 AM, Yegappan Lakshmanan wrote:
> I am in particular interested in any comments/suggestions about the
following
> new functions:
>
> getbufinfo()
> gettabinfo()
> getwininfo()
> getqflist()
> setqflist()
> getcompletion()
I've got some custom functions in my .vimrc related to QuickFix
and Location List windows. They are clunky and inefficient
because as far as I can tell, Vim doesn't expose quite enough
information. I've included the functions below for reference.
I haven't been able to track all of the new developments, but
perhaps someone can say whether there is a better way than the
below functions (either with pre-existing or recently added Vim
functionality). I'd like functions that:
- Return True if a given window is a QuickFix or Location List
window. (Both types of window have &buftype == "quickfix".)
- Return True if the QuickFix is window open.
- Return True if the Location List window is open for a given
window.
- Return the window number of the QuickFix window (0 if not
open).
- Return the window number of the associated Location List
for a given window (0 if not open).
When the current window has ``&buftype == "quickfix"``, I'd
originally tried to determine whether it was a QuickFix window
or a Location List using ``getloclist(0)``. I'd wanted to say
``isLocationList = (getloclist(0) > 0)``, but that fails when
it's a Location List that happens to be empty, so I resorted to
the uglier hacks you see below.
I thought I'd seen some activity along these lines that might
expose the details directly, but I haven't been keeping up with
all of the new changes.
Michael Henry
Sample functions for reference
================================================================
" Return 1 if current window is the QuickFix window.
function! IsQuickFixWin()
if &buftype == "quickfix"
" This is either a QuickFix window or a Location List window.
" Try to open a location list; if this window *is* a location list,
" then this will succeed and the focus will stay on this window.
" If this is a QuickFix window, there will be an exception and the
" focus will stay on this window.
try
noautocmd lopen
catch /E776:/
" This was a QuickFix window.
return 1
endtry
endif
return 0
endfunction
" Return 1 if current window is a Location List window.
function! IsLocListWin()
return (&buftype == "quickfix" && !IsQuickFixWin())
endfunction
" Return window number of QuickFix buffer (or zero if not found).
function! GetQuickFixWinNum()
let qfWinNum = 0
let curWinNum = winnr()
for winNum in range(1, winnr("$"))
execute "noautocmd " . winNum . "wincmd w"
if IsQuickFixWin()
let qfWinNum = winNum
break
endif
endfor
execute "noautocmd " . curWinNum . "wincmd w"
return qfWinNum
endfunction
" Return 1 if the QuickFix window is open.
function! QuickFixWinIsOpen()
return GetQuickFixWinNum() > 0
endfunction
" Return 1 if current window's location list window is open.
function! LocListWinIsOpen()
let curWinNum = winnr()
let numOpenWindows = winnr("$")
" Assume location list window is already open.
let isOpen = 1
try
noautocmd lopen
catch /E776:/
" No location list available; nothing was changed.
let isOpen = 0
endtry
if numOpenWindows != winnr("$")
" We just opened a new location list window. Revert to original
" window and close the newly opened window.
noautocmd wincmd p
noautocmd lclose
let isOpen = 0
endif
return isOpen
endfunction
" Open Quickfix window (if not already open).
function! Copen()
if !QuickFixWinIsOpen()
execute "silent botright copen " . g:QuickFixWinHeight
endif
endfunction
" Open QuickFix window using standard position and height.
command! -bar Copen call Copen()
" Open Location List window (if not already open).
function! Lopen()
if !LocListWinIsOpen()
execute "silent lopen " . g:LocListWinHeight
endif
endfunction
" Open Location List window using standard height.
command! -bar Lopen call Lopen()
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.