From 4fbff9f7ebc5ef38decfc8225d8a1ea026152a25 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 16 Sep 2022 01:16:29 -0600 Subject: supert.vim: implement proper redo for supert. This correctly implements redo for the supert functions. In addition, this changes the bindings to Zf, ZF, Zt, ZT. --- plugin/supert.vim | 108 +++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 49 deletions(-) (limited to 'plugin') diff --git a/plugin/supert.vim b/plugin/supert.vim index f4a8e85..752d70a 100644 --- a/plugin/supert.vim +++ b/plugin/supert.vim @@ -6,13 +6,9 @@ endif let s:last = [] -let s:last_char = '' +let s:insert_char = '' function! s:getchar() - echom "Is not repeating? " . string(! exists('v:repeating') || ! v:repeating) - if ! exists('v:repeating') || ! v:repeating - let s:last_char = nr2char(getchar()) - endif - return s:last_char + let s:insert_char = nr2char(getchar()) endfunction function! s:do_search(type, vis) abort @@ -21,16 +17,18 @@ function! s:do_search(type, vis) abort elseif a:type == ',' call s:do_last(1, a:vis) else - call s:do_search_ch(a:type, a:vis, s:getchar()) + call s:do_search_ch(a:type, a:vis, s:insert_char) endif endfunction function! s:do_last(inv, vis) abort if len(s:last) < 2 + + return return endif - let type = s:last[0] + le] type = s:last[0] let ch = s:last[1] if a:inv @@ -62,6 +60,10 @@ function! s:do_search_ch(type, vis, ch) let pattern = pattern . '\zs\_.\ze' endif + if a:vis != '' + exec "normal! v" + endif + let i = 0 while i < v:count1 call search(pattern, flags) @@ -69,53 +71,61 @@ function! s:do_search_ch(type, vis, ch) endwhile endfunction -nnoremap (supert-replace-t) call do_search('t', '') -nnoremap (supert-replace-T) call do_search('T', '') -nnoremap (supert-replace-f) call do_search('f', '') -nnoremap (supert-replace-F) call do_search('F', '') - -vnoremap (supert-replace-t) call do_search('t', 'v') -vnoremap (supert-replace-T) call do_search('T', 'v') -vnoremap (supert-replace-f) call do_search('f', 'v') -vnoremap (supert-replace-F) call do_search('F', 'v') - -onoremap (supert-replace-t) call do_search('t', 'o') -onoremap (supert-replace-T) call do_search('T', 'o') -onoremap (supert-replace-f) call do_search('f', 'o') -onoremap (supert-replace-F) call do_search('F', 'o') +nnoremap + \ call getchar() + \ call do_search('t', '') -onoremap (supert-replace-,) call do_search(',', 'o') -onoremap (supert-replace-;) call do_search(';', 'o') - -vnoremap (supert-replace-,) call do_search(',', 'v') -vnoremap (supert-replace-;) call do_search(';', 'v') - -nnoremap (supert-replace-,) call do_search(',', '') -nnoremap (supert-replace-;) call do_search(';', '') +" Prepares the operation by reading a character from the user, escapes the +" current operator-pending mode and then crafts a new command using the private- +" scoped (strf-post) command. +function! s:prepare_operation(t, op) + let s:operator = a:op + let s:type = a:t + let s:insert_char = nr2char(getchar()) + call feedkeys("\") + call feedkeys(printf("%s\(srtf-post)", s:operator)) +endfunction +" Include the bindings if the user wast to include them. if g:supert_provide_bindings - nnoremap (supert-replace-t) - nnoremap (supert-replace-T) - nnoremap (supert-replace-f) - nnoremap (supert-replace-F) + onoremap Zt (srtf-to) + onoremap Zf (srtf-fo) + onoremap ZT (srtf-To) + onoremap ZF (srtf-Fo) + + nnoremap Zt (srtf-t) + nnoremap Zf (srtf-f) + nnoremap ZT (srtf-T) + nnoremap ZF (srtf-F) + + vnoremap Zt (srtf-tv) + vnoremap Zf (srtf-fv) + vnoremap ZT (srtf-Tv) + vnoremap ZF (srtf-Fv) +endif - vnoremap (supert-replace-t) - vnoremap (supert-replace-T) - vnoremap (supert-replace-f) - vnoremap (supert-replace-F) +" test? - onoremap (supert-replace-t) - onoremap (supert-replace-T) - onoremap (supert-replace-f) - onoremap (supert-replace-F) +vnoremap (srtf-tv) call getchar()call do_search('t', '') +vnoremap (srtf-fv) call getchar()call do_search('f', '') +vnoremap (srtf-Tv) call getchar()call do_search('T', '') +vnoremap (srtf-Fv) call getchar()call do_search('F', '') - vnoremap (supert-replace-;) - vnoremap (supert-replace-,) +nnoremap (srtf-t) call getchar()call do_search('t', '') +nnoremap (srtf-f) call getchar()call do_search('f', '') +nnoremap (srtf-T) call getchar()call do_search('T', '') +nnoremap (srtf-F) call getchar()call do_search('F', '') - nnoremap (supert-replace-;) - nnoremap (supert-replace-,) +onoremap (srtf-to) call prepare_operation('t', v:operator) +onoremap (srtf-fo) call prepare_operation('f', v:operator) +onoremap (srtf-To) call prepare_operation('T', v:operator) +onoremap (srtf-Fo) call prepare_operation('F', v:operator) - onoremap (supert-replace-;) - onoremap (supert-replace-,) -endif +" is this a question? Or is that? + +onoremap (srtf-post) call do_search_postchar('v') +function! s:do_search_postchar(vis) abort + echom printf("do_search(%s, %s)", s:type, a:vis) + call s:do_search(s:type, a:vis) +endfunction -- cgit