From ba5cf6b671a9fe8a54a45fb6d3600459084a609f Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 23 Jul 2019 22:17:28 +0200 Subject: [PATCH] ingo#buffer#scratch#CreateWithWriter(): Support empty a:Writer --- autoload/ingo/buffer/scratch.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autoload/ingo/buffer/scratch.vim b/autoload/ingo/buffer/scratch.vim index 51eed32..254f76f 100644 --- a/autoload/ingo/buffer/scratch.vim +++ b/autoload/ingo/buffer/scratch.vim @@ -99,6 +99,8 @@ function! ingo#buffer#scratch#CreateWithWriter( scratchFilename, Writer, scratch " (but isn't a scratch buffer), a different one will be " generated. " a:Writer Ex command or Funcref that is invoked on :write. +" If empty, writing will not be supported, and this will +" work like ingo#buffer#scratch#Create(). " a:scratchCommand Ex command(s) to populate the scratch buffer, e.g. " ":1read myfile". Use :1read so that the first empty line " will be kept (it is deleted automatically), and there @@ -125,6 +127,9 @@ function! ingo#buffer#scratch#CreateWithWriter( scratchFilename, Writer, scratch " exception is thrown. "******************************************************************************* let l:status = ingo#buffer#generate#Create('', a:scratchFilename, 0, a:scratchCommand, a:windowOpenCommand, (a:0 ? a:1 : function('ingo#buffer#scratch#NextFilename'))) + if empty(a:Writer) + return l:status + endif if l:status != 0 setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile if ! empty(a:scratchCommand)