mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-05-29 11:18:51 +02:00
Add ingo#buffers#Delete()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 :
|
||||
@@ -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().
|
||||
"******************************************************************************
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user