On 09/04/09 06:15, bill lam wrote:
> On Thu, 09 Apr 2009, Tony Mechelynck wrote:
>> The following (untested) does it without changing buffers:
>>
>> function ClearBuffers(wipeout)
>> " usage:
>> " call ClearBuffers(0) to delete all buffers except the current one
>> " call ClearBuffers(1) to wipe them out
>> let i=1
>> while i<= bufnr("$")
>> if bufexists(i)&& i != bufnr("")
>> exe (a:wipeout? "bwipeout!" : "bdelete!") i
>> endif
>> let i += 1
>> endwhile
>> endfunction
>
> Hi Tony,
> I tested it ok. However could it be further modified to make it
> delete only listed buffers, ie. leaved unlisted buffers untouched.
>
Sure, replace bufexists( by buflisted( in the if statement. Or here's a
variation with more options:
function ClearBuffers(...)
" usage:
" call ClearBufffers([wipeout [, listed [, unlisted]]])
" where each of the optional arguments is a Boolean
" wipeout != 0 to wipeout (otherwise delete)
" listed != 0 to clear listed buffers
" unlisted != 0 to clear unlisted buffers
" the current buffer is always kept
if a:0 > 3
echoerr "ClearBuffers: Invalid number of arguments"
return -1
endif
let wipeout = a:0 > 0 && a:1
let listed = a:0 > 1 && a:2
let unlisted = a:0 > 2 && a:3
let i = 1
while i <= bufnr("$")
if bufexists(i) && i != bufnr("")
if (buflisted(i)? listed : unlisted)
exe (wipeout? "bw!" : "bd!") i
endif
endif
let i += 1
endwhile
" return 0
endfunction
Best regards,
Tony.
--
The National Short-Sleeved Shirt Association says:
Support your right to bare arms!
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---