Skip to content

Commit fb07fdb

Browse files
author
Amerlyq
committed
Allow reverse action (and count) in lambda substitutions
Resolves #86
1 parent 68d2693 commit fb07fdb

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

autoload/switch.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function! switch#Switch(...)
3535
endfor
3636

3737
if !min_match.IsNull()
38-
call min_match.Replace()
38+
call min_match.Replace(options)
3939
return 1
4040
else
4141
return 0
@@ -46,12 +46,12 @@ function! switch#Switch(...)
4646
endfunction
4747

4848
function! switch#OpfuncForward(type)
49-
silent call switch#Switch()
49+
silent call switch#Switch({'count': v:count})
5050
return ''
5151
endfunction
5252

5353
function! switch#OpfuncReverse(type)
54-
silent call switch#Switch({'reverse': 1})
54+
silent call switch#Switch({'reverse': 1, 'count': v:count})
5555
return ''
5656
endfunction
5757

autoload/switch/mapping.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ endfunction
9898
" Replaces the pattern from the match data with its Replacement. Takes care of
9999
" both simple replacements and nested ones.
100100
"
101-
function! switch#mapping#Replace(match) dict
101+
function! switch#mapping#Replace(match, options) dict
102102
let pattern = a:match.pattern
103103
let Replacement = self.definitions[pattern]
104104
let oldsearch = @/
@@ -128,7 +128,9 @@ function! switch#mapping#Replace(match) dict
128128
let g:Switch_replacer = Replacement
129129
let submatch_expression = join(map(range(0, 9), '"submatch(".v:val.")"'), ',')
130130

131-
let Replacement = '\=call(g:Switch_replacer, [['.submatch_expression.']])'
131+
let rev = get(a:options, 'reverse')
132+
let cnt = get(a:options, 'count')
133+
let Replacement = '\=call(g:Switch_replacer, [['.submatch_expression.'],'.rev.','.cnt.'])'
132134
exe 's/'.pattern.'/'.Replacement.'/'
133135

134136
unlet g:Switch_replacer

autoload/switch/match.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ function! switch#match#IsBetter(other) dict
4343
endif
4444
endfunction
4545

46-
function! switch#match#Replace() dict
47-
call self.mapping.Replace(self)
46+
function! switch#match#Replace(...) dict
47+
call self.mapping.Replace(self, get(a:,1))
4848
endfunction
4949

5050
function! switch#match#IsNull() dict

plugin/switch.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ function! s:SwitchReverse()
251251
silent! call repeat#set(":SwitchReverse\<cr>")
252252
endfunction
253253

254-
nnoremap <silent> <Plug>(Switch) :set opfunc=switch#OpfuncForward<cr>g@l
255-
nnoremap <silent> <Plug>(SwitchReverse) :set opfunc=switch#OpfuncReverse<cr>g@l
254+
nnoremap <silent><expr> <Plug>(Switch) execute("set opfunc=switch#OpfuncForward").'g@l'
255+
nnoremap <silent><expr> <Plug>(SwitchReverse) execute("set opfunc=switch#OpfuncReverse").'g@l'
256256
257257
command! -nargs=* SwitchExtend call s:SwitchExtend(<args>)
258258
fun! s:SwitchExtend(...)

0 commit comments

Comments
 (0)