Compare commits

...

40 commits
v1.1 ... master

Author SHA1 Message Date
Tim Pope 65846025c1 One last fix attempt before I revert everything
References: https://github.com/tpope/vim-repeat/issues/63
2024-07-08 17:25:42 -04:00
Tim Pope 5bd4c87a14 Restore unfolding during undo
References: https://github.com/tpope/vim-repeat/issues/63
2024-07-08 10:12:33 -04:00
Tim Pope a89a4d0760 Avoid stacktrace on undo in 'nomodifiable' buffer
References: https://github.com/tpope/vim-repeat
2024-07-07 15:08:09 -04:00
Tim Pope 4bac219cc0 Drop FUNDING.yml in favor of account-level default 2024-07-07 14:24:39 -04:00
Tim Pope 8b4435c5bb Account for Vim undo double-incrementing b:changedtick
Resolves: https://github.com/tpope/vim-repeat/issues/63
Resolves: https://github.com/tpope/vim-repeat/issues/94
Resolves: https://github.com/tpope/vim-repeat/pull/95
2024-07-07 13:00:05 -04:00
Tim Pope e0466d2b24 Bump minimum Vim version to 8.0 2024-07-07 13:00:03 -04:00
Ingo Karkat 24afe922e6 Rework error return to prevent off-by-one in Ex mode
My automated tests run Vim in silent batch mode (:help -s-ex), these also cover repeat of mappings via repeat.vim. Unfortunately, the combination of feedkeys() and :execute used in the repeat.vim implementation to return a potential caught error cause the line where the repeat mapping is executed to be increased, so for me the tests fail in a really strange way. The same problem can occur if someone uses repeats in silent batch mode (e.g. through a recorded macro) - though the source of the problem would be even harder to track down there - in my test run it at least was easily reproducible.

I raised this as a potential Vim bug in https://github.com/vim/vim/issues/7153, but Bram explained that it's a side effect of Ex mode (where empty lines make the cursor go to the next line, and as repeat#run() returns the empty String on the happy path, that's an empty line being executed). Recommendation from Bram is to pass the "x" flag for immediate execution to feedkeys() (which avoids the problem). However, in the context of repeat.vim this would mean that any errors resulting from the repeat mapping invocation would have to be caught inside repeat#run(), because they would then execute within the function's context, and not after it. Also, the "x" flag would not be supported by old Vim 7.3 and earlier.

Instead, I chose to avoid the problem by replacing the :execute with a more straightforward :call (actually an :if that tests a returned Boolean success flag), so instead of the clever direct execution of the returned :echoerr command, the error message instead is retrieved from a script-local variable via a new repeat#errmsg() getter. I use this idiom in all of my plugins through a set of utility functions (5bb32fd27a/autoload/ingo/err.vim (L38-L41)), too.
So by adding a little (well encapsulated) variable and getter, this problem can be avoided without touching the sensitive feedkeys() and try...catch logic within the plugin.
2021-01-24 22:11:08 -05:00
Tim Pope c947ad2b6a Add sponsor button 2019-11-12 19:31:06 -05:00
Anton Kochkov ae361bea99 Add vim-radical in the plugins list 2019-07-29 12:17:59 -04:00
Ingo Karkat 0b9b5e742f Make an explicit register on repeat override g:repeat_reg
As with built-in commands, this allows to override the original register on repeat, e.g. "a. uses register a instead of the original one.

One limitation is that we cannot detect whether no or the default register has been given, so an override from a non-default to the default register (e.g. via "".) is not possible.
2019-04-25 22:13:50 -04:00
Ingo Karkat 5974ea07ac Documentation fix for repeat#setreg()
Need to :execute the :silent! call to avoid that the remainder of the
command line is aborted together with the call when repeat.vim is not
installed. Otherwise, <SID>MyFunction() won't be invoked, and the
mapping does nothing.
2019-04-25 21:49:34 -04:00
Ingo Karkat eb97e729be feedkeys(..., 'i') sends keys in the wrong order in Vim 7.0/1/2
The current implementation prefers feedkeys(..., 'i') and only falls back to :normal if Vim 7.4 does not have the 'i' flag and if Vim 7.3 supports :normal with count. For Vim 8.0 (and later), and also for versions between 7.0 and 7.3.99, feedkeys(..., 'i') is used. Due to the prepending action of the 'i' flag, keys must be submitted in reverse order; that's why s is submitted before r . cnt.  Vim 7.0...7.3.99 ignore the 'i' flag, though, and append the keys, which are now in the wrong order (this only matters if a register or count is given).

Add a separate conditional branch for Vim versions before 7.3.100 that uses feedkeys() in the correct order and omits the ignored 'i' flag.
2019-04-25 21:48:12 -04:00
Tim Pope 43d2678fa5 Remove outdated plugin references 2018-07-02 15:03:55 -04:00
Tim Pope 1ea8a5325b Update installation instructions 2018-07-02 15:03:36 -04:00
Tim Pope 8fe8bde4f4 Change Markdown heading style 2018-07-02 15:03:25 -04:00
Tim Pope 8106e142df repeat.vim 1.2
* Provide <Plug> mappings.
* Enable repeating operators with custom motions.
* Assorted bug fixes.
2018-01-30 23:08:02 -05:00
Jacob Niehus 1b82cad74c Fix undo messages being hidden (#33) 2018-01-21 18:45:49 -05:00
Chris Paul 070ee90324 Remove unneeded exe in example mapping (#60) 2017-04-21 13:43:53 -04:00
Tim Pope 7a6675f092 Merge pull request #47 from orlp/master
Prevent stack trace of search errors.
2015-05-09 13:57:55 -04:00
Tim Pope 5bacc6f805 Fix bogus spaces in maps 2015-05-07 14:29:12 -04:00
Orson Peters e42a430e64 More realistic Vim error, and catch all normal exceptions. 2015-04-23 01:45:15 +02:00
Orson Peters 655dd3e2be Prevent stack trace of search errors. 2015-04-23 00:27:56 +02:00
Tim Pope c4f9f159e6 Merge pull request #46 from wellle/45-fix-feedkeys-count
Revert order of feedkeys calls to fix counts
2015-04-03 10:30:37 -04:00
Christian Wellenbrock 7568a9604b Revert order of feedkeys calls to fix counts
Since we are using the `i` flag, the feedkeys calls insert the keys
instead of appending. That's why we need to insert the second part of
the command before inserting the first part in front of it.
2015-04-03 12:30:43 +02:00
Tim Pope b01aafbd8d Merge pull request #43 from jasonkuhrt/patch-1
Update README.markdown
2015-03-07 21:28:23 -06:00
Jason Rose-Kuhrt 751b369cc3 Update README.markdown 2015-03-07 22:17:05 -05:00
Tim Pope d9fbf5a137 Merge pull request #42 from Konfekt/patch-2
remove trailing spaces in remaps
2015-02-20 14:33:20 -06:00
Konfekt 88e7d7e5c3 remove trailing spaces in remaps
Vim interprets `nmap <key> <mapping> ` as `nmap <key> <mapping><space>`. 
Here we do not want this and put `|` directly after `<mapping>`.
2015-02-20 21:28:28 +01:00
Tim Pope 4895d90a14 Merge pull request #41 from Konfekt/patch-2
more convenient remapping by using <plug> mappings
2015-02-20 14:17:44 -06:00
Konfekt cffb2e7578 more convenient remapping by using <plug> mappings
Now mappings can be remapped in `.vimrc` by
`nnoremap <key> <Plug>(RepeatUndoLine)`
and disablabled in `.vimrc` by
`nnoremap <SID>(DisableRepeatUndoLine) <Plug>(RepeatUndoLine)`
2015-02-20 21:14:38 +01:00
Tim Pope b06684a195 Merge pull request #39 from wellle/feedkeys-i
Pass flag 'i' to feedkeys() call
2015-01-31 14:17:00 -06:00
Christian Wellenbrock ad89be240f Pass flag 'i' to feedkeys() calls
Only fall back to :norm for versions 7.3.100 <= v < 7.4.601
2015-01-28 16:51:28 +01:00
Tim Pope bd3b517235 Merge pull request #37 from justinmk/fix703
Fix condition for Vim <= 7.3
2015-01-19 16:20:08 -06:00
Justin M. Keyes 006694e0f5 Fix condition for Vim <= 7.3 2015-01-19 17:09:05 -05:00
Tim Pope 7f09c18d2e Merge pull request #36 from justinmk/norm
Use :norm for Vim 7.3.100 or later
2015-01-19 14:42:53 -06:00
Justin M. Keyes 193f4866df Use :norm for Vim 7.3.100 or later
Fixes #23
2015-01-17 09:55:08 -05:00
Tim Pope b6bdd0f2d0 Merge pull request #35 from wilywampa/invalidate
Fix invalidate() being overridden by autocmd
2015-01-15 18:49:10 -06:00
Jacob Niehus 80261bc531 Fix invalidate() being overridden by autocmd 2015-01-10 18:47:31 -07:00
d125q 5eba0f19c8 Make repeat#wrap open a fold if &foldopen contains 'all'
Closes #31.
2014-12-08 19:48:38 -05:00
Tim Pope 2a3c5f8e3c Allow repeating operators with custom motions
Closes #8.
2013-12-24 10:44:09 -05:00
2 changed files with 83 additions and 47 deletions

View file

@ -1,5 +1,4 @@
repeat.vim
==========
# repeat.vim
If you've ever tried using the `.` command after a plugin map, you were
likely disappointed to discover it only repeated the last native command
@ -11,33 +10,30 @@ The following plugins support repeat.vim:
* [surround.vim](https://github.com/tpope/vim-surround)
* [speeddating.vim](https://github.com/tpope/vim-speeddating)
* [abolish.vim](https://github.com/tpope/vim-abolish)
* [unimpaired.vim](https://github.com/tpope/vim-unimpaired)
* [commentary.vim](https://github.com/tpope/vim-commentary)
* [vim-easyclip](https://github.com/svermeulen/vim-easyclip)
* [vim-radical](https://github.com/glts/vim-radical)
Adding support to a plugin is generally as simple as the following
command at the end of your map functions.
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
Installation
------------
## Installation
If you don't have a preferred installation method, I recommend
installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
then simply copy and paste:
Install using your favorite package manager, or use Vim's built-in package
support:
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-repeat.git
mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/repeat.git
Contributing
------------
## Contributing
See the contribution guidelines for
[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
Self-Promotion
--------------
## Self-Promotion
Like repeat.vim? Follow the repository on
[GitHub](https://github.com/tpope/vim-repeat) and vote for it on
@ -46,8 +42,7 @@ you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
[Twitter](http://twitter.com/tpope) and
[GitHub](https://github.com/tpope).
License
-------
## License
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
See `:help license`.

View file

@ -1,6 +1,6 @@
" repeat.vim - Let the repeat command repeat plugin maps
" Maintainer: Tim Pope
" Version: 1.1
" Version: 1.2
" GetLatestVimScripts: 2136 1 :AutoInstall: repeat.vim
" Installation:
@ -44,7 +44,7 @@
" \ call <SID>MyFunction(v:register, ...)<Bar>
" \ silent! call repeat#set("\<lt>Plug>MyMap")<CR>
if exists("g:loaded_repeat") || &cp || v:version < 700
if exists("g:loaded_repeat") || &cp || v:version < 800
finish
endif
let g:loaded_repeat = 1
@ -55,6 +55,7 @@ let g:repeat_reg = ['', '']
" Special function to avoid spurious repeats in a related, naturally repeating
" mapping when your repeatable mapping doesn't increase b:changedtick.
function! repeat#invalidate()
autocmd! repeat_custom_motion
let g:repeat_tick = -1
endfunction
@ -62,49 +63,89 @@ function! repeat#set(sequence,...)
let g:repeat_sequence = a:sequence
let g:repeat_count = a:0 ? a:1 : v:count
let g:repeat_tick = b:changedtick
augroup repeat_custom_motion
autocmd!
autocmd CursorMoved <buffer> let g:repeat_tick = b:changedtick | autocmd! repeat_custom_motion
augroup END
endfunction
function! repeat#setreg(sequence,register)
let g:repeat_reg = [a:sequence, a:register]
endfunction
function! repeat#run(count)
if g:repeat_tick == b:changedtick
let r = ''
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
if g:repeat_reg[1] ==# '='
" This causes a re-evaluation of the expression on repeat, which
" is what we want.
let r = '"=' . getreg('=', 1) . "\<CR>"
else
let r = '"' . g:repeat_reg[1]
endif
endif
let c = g:repeat_count
let s = g:repeat_sequence
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
call feedkeys(r . cnt, 'n')
call feedkeys(s)
function! s:default_register()
let values = split(&clipboard, ',')
if index(values, 'unnamedplus') != -1
return '+'
elseif index(values, 'unnamed') != -1
return '*'
else
call feedkeys((a:count ? a:count : '') . '.', 'n')
return '"'
endif
endfunction
function! repeat#run(count)
let s:errmsg = ''
try
if g:repeat_tick == b:changedtick
let r = ''
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
" Take the original register, unless another (non-default, we
" unfortunately cannot detect no vs. a given default register)
" register has been supplied to the repeat command (as an
" explicit override).
let regname = v:register ==# s:default_register() ? g:repeat_reg[1] : v:register
if regname ==# '='
" This causes a re-evaluation of the expression on repeat, which
" is what we want.
let r = '"=' . getreg('=', 1) . "\<CR>"
else
let r = '"' . regname
endif
endif
let c = g:repeat_count
let s = g:repeat_sequence
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
call feedkeys(s, 'i')
call feedkeys(r . cnt, 'ni')
else
call feedkeys((a:count ? a:count : '') . '.', 'ni')
endif
catch /^Vim(normal):/
let s:errmsg = v:errmsg
return 0
endtry
return 1
endfunction
function! repeat#errmsg()
return s:errmsg
endfunction
function! repeat#wrap(command,count)
let preserve = (g:repeat_tick == b:changedtick)
exe 'norm! '.(a:count ? a:count : '').a:command . (&foldopen =~# 'undo' ? 'zv' : '')
if preserve
let g:repeat_tick = b:changedtick
endif
let foldopen = &foldopen =~# 'undo\|all' ? 'zv' : ''
let preserve = g:repeat_tick == b:changedtick ? ":let g:repeat_tick = b:changedtick\r" : ''
return (a:count ? a:count : '') . a:command . preserve . foldopen
endfunction
nnoremap <silent> . :<C-U>call repeat#run(v:count)<CR>
nnoremap <silent> u :<C-U>call repeat#wrap('u',v:count)<CR>
if maparg('U','n') ==# ''
nnoremap <silent> U :<C-U>call repeat#wrap('U',v:count)<CR>
nnoremap <silent> <Plug>(RepeatDot) :<C-U>if !repeat#run(v:count)<Bar>echoerr repeat#errmsg()<Bar>endif<CR>
nmap <silent><expr><script> <Plug>(RepeatUndo) repeat#wrap('u',v:count)
nmap <silent><expr><script> <Plug>(RepeatUndoLine) repeat#wrap('U',v:count)
nmap <silent><expr><script> <Plug>(RepeatRedo) repeat#wrap("\022",v:count)
if !hasmapto('<Plug>(RepeatDot)', 'n')
nmap . <Plug>(RepeatDot)
endif
if !hasmapto('<Plug>(RepeatUndo)', 'n')
nmap u <Plug>(RepeatUndo)
endif
if maparg('U','n') ==# '' && !hasmapto('<Plug>(RepeatUndoLine)', 'n')
nmap U <Plug>(RepeatUndoLine)
endif
if !hasmapto('<Plug>(RepeatRedo)', 'n')
nmap <C-R> <Plug>(RepeatRedo)
endif
nnoremap <silent> <C-R> :<C-U>call repeat#wrap("\<Lt>C-R>",v:count)<CR>
augroup repeatPlugin
autocmd!