Add ingo#buffers#Delete()

This commit is contained in:
Ingo Karkat
2021-06-09 16:16:29 +02:00
parent b1542641a4
commit d3fc7d0fbf
5 changed files with 49 additions and 1 deletions
+1
View File
@@ -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
+46
View File
@@ -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 <ingo@karkat.de>
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 :
-1
View File
@@ -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().
"******************************************************************************
+1
View File
@@ -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
+1
View File
@@ -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