From 4bf3f1ecf18612c1daad77d43d270068394d65b4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 19 Jun 2019 22:57:59 +1200 Subject: Apply a little more structure to events --- autoload/paste_insert.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/paste_insert.vim b/autoload/paste_insert.vim index 675fa5a..f055249 100644 --- a/autoload/paste_insert.vim +++ b/autoload/paste_insert.vim @@ -1,12 +1,13 @@ function! paste_insert#() abort augroup paste_insert autocmd! - autocmd CursorHold,CursorMoved,User * - \ set nopaste paste? - \|autocmd! paste_insert + autocmd User Error,Finish + \ set nopaste paste? | autocmd! paste_insert + autocmd CursorHold,CursorMoved,BufLeave,WinLeave * + \ doautocmd paste_insert User Error autocmd InsertEnter * \ autocmd paste_insert InsertLeave * - \ doautocmd paste_insert User + \ doautocmd paste_insert User Finish augroup END set paste paste? endfunction -- cgit v1.2.3 From 90c960afe270c51eb73e709d5117ef331aa7d44a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 20 Jun 2019 00:06:04 +1200 Subject: Add better messages, customisable stop key --- autoload/paste_insert.vim | 70 +++++++++++++++++++++++++++++++++++++++++++---- doc/paste_insert.txt | 8 +++++- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/autoload/paste_insert.vim b/autoload/paste_insert.vim index f055249..277f333 100644 --- a/autoload/paste_insert.vim +++ b/autoload/paste_insert.vim @@ -1,13 +1,71 @@ +" Autoloaded entry point function function! paste_insert#() abort + + " Set up an event table augroup paste_insert autocmd! - autocmd User Error,Finish - \ set nopaste paste? | autocmd! paste_insert - autocmd CursorHold,CursorMoved,BufLeave,WinLeave * - \ doautocmd paste_insert User Error + + " Set up the paste and tell the user + autocmd User Start + \ call s:Start() | echo 'Paste ready' + + " When starting insert mode, add completion hook for when we leave autocmd InsertEnter * \ autocmd paste_insert InsertLeave * - \ doautocmd paste_insert User Finish + \ doautocmd paste_insert User Complete + + " User waits too long in normal mode, timeout + autocmd CursorHold * + \ doautocmd paste_insert User Timeout + + " User leaves the buffer or window, abort + autocmd BufLeave,WinLeave * + \ doautocmd paste_insert User Abort + + " Exit condition reporting + autocmd User Abort + \ echo 'Paste aborted' + autocmd User Cancel + \ echo 'Paste cancelled' + autocmd User Complete + \ echo 'Paste completed' + autocmd User Timeout + \ echo 'Paste timeout' + + " End the paste and clear the events table + autocmd User Abort,Cancel,Complete,Timeout + \ call s:Stop() | autocmd! paste_insert + augroup END - set paste paste? + + " Trigger the starting actions + doautocmd paste_insert User Start + +endfunction + +" Key that cancels the pending paste in normal mode, defaults to CTRL-C +let s:cancel = get(g:, 'paste_insert_cancel', '') + +" Start the paste: save cancel key's prior function, remap it, set 'paste' +function! s:Start() abort + let s:maparg = maparg(s:cancel) + let command = join([ + \ 'nnoremap' + \,s:cancel + \,':doautocmd paste_insert User Cancel' + \]) + execute command + set paste +endfunction + +" Stop the paste: unset 'paste', restore prior function of cancel key +function! s:Stop() abort + set nopaste + let command = join( + \ s:maparg !=# '' + \ ? ['nnoremap', s:cancel, s:maparg] + \ : ['nunmap', s:cancel] + \) + execute command + unlet s:maparg endfunction diff --git a/doc/paste_insert.txt b/doc/paste_insert.txt index 9b63079..73036e4 100644 --- a/doc/paste_insert.txt +++ b/doc/paste_insert.txt @@ -8,7 +8,7 @@ after the insert ends, to avoid the annoyances caused by forgetting to do so. It includes a timeout if insert mode isn't entered within 'updatetime' seconds, or if the user navigates away from the buffer or window. It can also -be cancelled with CTRL-C in normal mode. +be cancelled with a key in normal mode, by default CTRL-C. REQUIREMENTS *paste_insert-requirements* @@ -25,6 +25,12 @@ MAPPINGS *paste_insert-mappings* *(PasteInsert)* The `(PasteInsert)` map in normal mode just does `:PasteInsert`. +OPTIONS *paste_insert-options* + + *g:paste_insert_cancel* +Set `g:paste_insert_cancel` to the key you want to cancel the pending paste in +normal mode. This defaults to '', for CTRL-C. + AUTHOR *paste_insert-author* Written and maintained by Tom Ryder . -- cgit v1.2.3 From 6690eb3acab230c440dc6d476702f4848f5b2031 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 20 Jun 2019 00:15:58 +1200 Subject: Add comments to plugin file --- plugin/paste_insert.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugin/paste_insert.vim b/plugin/paste_insert.vim index 2c17f80..a792a50 100644 --- a/plugin/paste_insert.vim +++ b/plugin/paste_insert.vim @@ -1,8 +1,21 @@ +" +" This small plugin provides a simple "one shot paste" method, with a command +" or mapping to prefix opening an insert, with the 'paste' option +" automatically set after the insert ends, to avoid the annoyances caused by +" forgetting to do so. +" +" Author: Tom Ryder +" License: Same as Vim itself +" if exists('loaded_paste_insert') || &compatible finish endif let loaded_paste_insert = 1 + +" Command interface command! -bar PasteInsert \ call paste_insert#() + +" Normal mode mapping interface nnoremap PasteInsert \ :PasteInsert -- cgit v1.2.3 From 34f10e94434aaa62fffb717a6f79bf65e48be40d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 20 Jun 2019 00:16:24 +1200 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6e8bf73..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 -- cgit v1.2.3