From faf9b29a25da337431e1ddaaf95d06c8783262cf Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 16 Sep 2022 06:30:48 +0000 Subject: wip --- plugin/supert.vim | 108 +++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'plugin/supert.vim') diff --git a/plugin/supert.vim b/plugin/supert.vim index f4a8e85..e3db464 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 @@ -56,10 +54,22 @@ function! s:do_search_ch(type, vis, ch) let pattern = a:ch - if a:type == 't' - let pattern = '\zs\_.\ze' . pattern - elseif a:type == 'T' - let pattern = pattern . '\zs\_.\ze' + " if a:vis != '' + if a:type == 'f' + let pattern = pattern + elseif a:type == 'F' + let pattern = pattern + endif + " else + " if a:type == 't' + " let pattern = '\zs\_.\ze' . pattern + " elseif a:type == 'T' + " let pattern = pattern . '\zs\_.\ze' + " endif + " endif + + if a:vis != '' + exec "normal! v" endif let i = 0 @@ -69,53 +79,43 @@ 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(';', '') +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 -if g:supert_provide_bindings - nnoremap (supert-replace-t) - nnoremap (supert-replace-T) - nnoremap (supert-replace-f) - nnoremap (supert-replace-F) +onoremap t (srtf-to) +onoremap f (srtf-fo) +onoremap T (srtf-To) +onoremap F (srtf-Fo) - vnoremap (supert-replace-t) - vnoremap (supert-replace-T) - vnoremap (supert-replace-f) - vnoremap (supert-replace-F) +nnoremap t (srtf-t) +nnoremap f (srtf-f) +nnoremap T (srtf-T) +nnoremap F (srtf-F) - onoremap (supert-replace-t) - onoremap (supert-replace-T) - onoremap (supert-replace-f) - onoremap (supert-replace-F) +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', '') - vnoremap (supert-replace-;) - vnoremap (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) - nnoremap (supert-replace-;) - nnoremap (supert-replace-,) +" is this a question? Or is that? - onoremap (supert-replace-;) - onoremap (supert-replace-,) -endif +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