Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.20

BUG: Repeat always used the unnamed register. Add register registration to enhanced repeat.vim plugin. This also handles repetition when used together with the expression register "=. Requires a so far inofficial update to repeat.vim version 1.0 (that hopefully makes it into upstream), which is available at https://github.com/inkarkat/vim-repeat/zipball/1.0ENH1
  • Loading branch information...
commit 0799772cf9cdfc4d20cecc1caddb9c604c11c51b 1 parent 8a24b52
Ingo Karkat authored committed
Showing with 56 additions and 8 deletions.
  1. +7 −0 doc/UnconditionalPaste.txt
  2. +49 −8 plugin/UnconditionalPaste.vim
View
7 doc/UnconditionalPaste.txt
@@ -77,6 +77,13 @@ IDEAS *UnconditionalPaste-ideas*
==============================================================================
HISTORY *UnconditionalPaste-history*
+1.20 30-Sep-2011
+BUG: Repeat always used the unnamed register. Add register registration to
+enhanced repeat.vim plugin. This also handles repetition when used together
+with the expression register "=. Requires a so far inofficial update to
+repeat.vim version 1.0 (that hopefully makes it into upstream), which is
+available at https://github.com/inkarkat/vim-repeat/zipball/1.0ENH1
+
1.11 06-Jun-2011
ENH: Support repetition of mappings through repeat.vim.
View
57 plugin/UnconditionalPaste.vim
@@ -13,6 +13,12 @@
" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
"
" REVISION DATE REMARKS
+" 1.20.012 29-Sep-2011 BUG: Repeat always used the unnamed register.
+" Add register registration to enhanced repeat.vim
+" plugin, which also handles repetition when used
+" together with the expression register "=.
+" BUG: Move <silent> maparg to <Plug> mapping to
+" silence command repeat.
" 1.11.010 06-Jun-2011 ENH: Support repetition of mappings through
" repeat.vim.
" 1.10.009 12-Jan-2011 Incorporated suggestions by Peter Rincker
@@ -53,6 +59,10 @@ let g:loaded_UnconditionalPaste = 1
let s:save_cpo = &cpo
set cpo&vim
+function! s:HandleExprReg( exprResult )
+ let s:exprResult = a:exprResult
+endfunction
+
function! s:Flatten( text )
" Remove newline characters at the end of the text, convert all other
" newlines to a single space.
@@ -60,12 +70,30 @@ function! s:Flatten( text )
endfunction
function! s:Paste( regName, pasteType, pasteCmd )
+ let l:regType = getregtype(a:regName)
+ let l:regContent = getreg(a:regName, 1) " Expression evaluation inside function context may cause errors, therefore get unevaluated expression when a:regName ==# '='.
+
+ if a:regName ==# '='
+ " Cannot evaluate the expression register within a function; unscoped
+ " variables do not refer to the global scope. Therefore, evaluation
+ " happened earlier in the mappings, and stored this in s:exprResult.
+ " To get the expression result into the buffer, use the unnamed
+ " register, and restore it later.
+ let l:regName = '"'
+ let l:regContent = s:exprResult
+
+ let l:save_clipboard = &clipboard
+ set clipboard= " Avoid clobbering the selection and clipboard registers.
+ let l:save_reg = getreg(l:regName)
+ let l:save_regmode = getregtype(l:regName)
+ else
+ let l:regName = a:regName
+ endif
+
try
- let l:regType = getregtype(a:regName)
- let l:regContent = getreg(a:regName)
- call setreg(a:regName, (a:pasteType ==# 'c' ? s:Flatten(l:regContent) : l:regContent), a:pasteType)
- execute 'normal! "' . a:regName . (v:count ? v:count : '') . a:pasteCmd
- call setreg(a:regName, l:regContent, l:regType)
+ call setreg(l:regName, (a:pasteType ==# 'c' ? s:Flatten(l:regContent) : l:regContent), a:pasteType)
+ execute 'normal! "' . l:regName . (v:count ? v:count : '') . a:pasteCmd
+ call setreg(l:regName, l:regContent, l:regType)
catch /^Vim\%((\a\+)\)\=:E/
" v:exception contains what is normally in v:errmsg, but with extra
" exception source info prepended, which we cut away.
@@ -73,6 +101,11 @@ function! s:Paste( regName, pasteType, pasteCmd )
echohl ErrorMsg
echomsg v:errmsg
echohl None
+ finally
+ if a:regName ==# '='
+ call setreg('"', l:save_reg, l:save_regmode)
+ let &clipboard = l:save_clipboard
+ endif
endtry
endfunction
@@ -81,14 +114,22 @@ function! s:CreateMappings()
for [l:direction, l:pasteCmd] in [['After', 'p'], ['Before', 'P']]
let l:mappingName = 'UnconditionalPaste' . l:pasteName . l:direction
let l:plugMappingName = '<Plug>' . l:mappingName
- execute printf('nnoremap %s :<C-u>call <SID>Paste(v:register, %s, %s)<Bar>silent! call repeat#set("\<lt>Plug>%s")<CR>',
+ execute printf('nnoremap <silent> %s :<C-u>' .
+ \ 'silent! call repeat#setreg("\<lt>Plug>%s", v:register)<Bar>' .
+ \ 'if v:register ==# "="<Bar>' .
+ \ ' call <SID>HandleExprReg(getreg("="))<Bar>' .
+ \ 'endif<Bar>' .
+ \ 'call <SID>Paste(v:register, %s, %s)<Bar>' .
+ \ 'silent! call repeat#set("\<lt>Plug>%s")<CR>',
+ \
\ l:plugMappingName,
+ \ l:mappingName,
\ string(l:pasteType),
\ string(l:pasteCmd),
\ l:mappingName
\)
if ! hasmapto(l:plugMappingName, 'n')
- execute printf('nmap <silent> g%s%s %s',
+ execute printf('nmap g%s%s %s',
\ l:pasteType,
\ l:pasteCmd,
\ l:plugMappingName
@@ -102,4 +143,4 @@ delfunction s:CreateMappings
let &cpo = s:save_cpo
unlet s:save_cpo
-" vim: set sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
+" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
Please sign in to comment.
Something went wrong with that request. Please try again.