From d3fc7d0fbfa6a178d11f43976adfd2bfc48db4c1 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 9 Jun 2021 16:16:29 +0200 Subject: [PATCH] Add ingo#buffers#Delete() --- README.md | 1 + autoload/ingo/buffers.vim | 46 ++++++++++++++++++++++++++++++++ autoload/ingo/window/iterate.vim | 1 - doc/ingo-library.txt | 1 + ingo-library.manifest | 1 + 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 autoload/ingo/buffers.vim diff --git a/README.md b/README.md index c1e2f09..3309442 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ HISTORY considered. - Add ingo/list/transform.vim module. - Add ingo#buffer#NameOrDefault(). +- Add ingo/buffers.vim module. ##### 1.042 03-Aug-2020 - BUG: ingo#join#Lines() inserts the separator before the line's last diff --git a/autoload/ingo/buffers.vim b/autoload/ingo/buffers.vim new file mode 100644 index 0000000..68b656a --- /dev/null +++ b/autoload/ingo/buffers.vim @@ -0,0 +1,46 @@ +" ingo/buffers.vim: Functions to manipulate buffers. +" +" DEPENDENCIES: +" +" Copyright: (C) 2021 Ingo Karkat +" The VIM LICENSE applies to this script; see ':help copyright'. +" +" Maintainer: Ingo Karkat + +function! ingo#buffers#Delete( buffersToDelete, isForce ) abort +"****************************************************************************** +"* PURPOSE: +" Delete (:bdelete) all buffers in a:buffersToDelete, and collect any +" encountered errors. +"* ASSUMPTIONS / PRECONDITIONS: +" None. +"* EFFECTS / POSTCONDITIONS: +" - Buffers in a:buffersToDelete are deleted from the buffer list. +"* INPUTS: +" a:buffersToDelete List of buffer numbers. +" a:isForce Force flag; uses :bdelete! if true. +"* RETURN VALUES: +" 1 if complete success, 0 if error(s) / exception(s) occurred. An error +" message is then available from ingo#err#Get(). +"****************************************************************************** + call ingo#err#Clear() + let l:errors = [] + for l:bufNr in a:buffersToDelete + try + execute l:bufNr . 'bdelete' . (a:isForce ? '!' : '') + catch /^Vim\%((\a\+)\)\=:/ + call add(l:errors, printf('%s: %s', ingo#buffer#NameOrDefault(bufname(l:bufNr)), ingo#msg#MsgFromVimException())) + endtry + endfor + + if empty(l:errors) + let l:isSuccess = 1 + else + call ingo#err#Set(join(l:errors)) + let l:isSuccess = 0 + endif + + return l:isSuccess +endfunction + +" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax : diff --git a/autoload/ingo/window/iterate.vim b/autoload/ingo/window/iterate.vim index 055d411..279c055 100644 --- a/autoload/ingo/window/iterate.vim +++ b/autoload/ingo/window/iterate.vim @@ -139,7 +139,6 @@ function! ingo#window#iterate#AllWithErrorsEchoed( Action, ... ) abort " v:val is inserted literally (as a Number, String, List, " Dict)! "* RETURN VALUES: -" 0 if an error / exception occurred; 1 if all iterations succeeded. " 1 if complete success, 0 if error(s) / exception(s) occurred. An error " message is then available from ingo#err#Get(). "****************************************************************************** diff --git a/doc/ingo-library.txt b/doc/ingo-library.txt index adb922f..f1a164a 100644 --- a/doc/ingo-library.txt +++ b/doc/ingo-library.txt @@ -183,6 +183,7 @@ HISTORY *ingo-library-history* considered. - Add ingo/list/transform.vim module. - Add ingo#buffer#NameOrDefault(). +- Add ingo/buffers.vim module. 1.042 03-Aug-2020 - BUG: ingo#join#Lines() inserts the separator before the line's last diff --git a/ingo-library.manifest b/ingo-library.manifest index 7a70267..b4ae219 100644 --- a/ingo-library.manifest +++ b/ingo-library.manifest @@ -14,6 +14,7 @@ autoload/ingo/buffer/scratch/converted.vim autoload/ingo/buffer/temp.vim autoload/ingo/buffer/temprange.vim autoload/ingo/buffer/visible.vim +autoload/ingo/buffers.vim autoload/ingo/change.vim autoload/ingo/change/processed.vim autoload/ingo/change/virtcols.vim