Skip to content

Commit

Permalink
Implement pluggable module feature
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Apr 29, 2015
1 parent 9e8d866 commit 5c4db30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
25 changes: 20 additions & 5 deletions autoload/incsearch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ function! s:incsearch_exit.on_char_pre(cmdline) abort
endfunction
call s:cli.connect(s:incsearch_exit)

" Lazy connect
let s:InsertRegister = s:modules.get('InsertRegister').make()
call s:cli.connect(s:InsertRegister)

call s:cli.connect('Paste')
" XXX: better handling.
if expand("%:p") !=# expand("<sfile>:p")
Expand Down Expand Up @@ -228,6 +229,11 @@ let s:inc = {
\ "name" : "incsearch",
\}

" NOTE: for InsertRegister handling
function! s:inc.priority(event) abort
return a:event is# 'on_char' ? 10 : 0
endfunction

function! s:inc.on_enter(cmdline) abort
nohlsearch " disable previous highlight
let s:w = winsaveview()
Expand Down Expand Up @@ -491,12 +497,17 @@ function! incsearch#cli() abort
endfunction

function! s:make_cli(config) abort
let cli = copy(s:cli)
" deepcopy() for cli.connect(module) instead of copy()
let cli = deepcopy(s:cli)
let cli._base_key = a:config.command
let cli._vcount1 = a:config.count1
let cli._is_expr = a:config.is_expr
let cli._mode = a:config.mode
let cli._pattern = a:config.pattern
for module in a:config.modules
call cli.connect(module)
endfor
call cli.connect(s:InsertRegister)
return cli
endfunction

Expand All @@ -516,15 +527,19 @@ function! incsearch#go(...) abort
return cmd
endfunction

"" NOTE: this global variable is only for handling config from go_wrap func
" It avoids to make config string temporarily
let g:incsearch#_go_wrap_config = {}

" incsearch#go wrapper to call from non-expr state with mode and v:count1
" detection
" @api
" @return incsearch#go command to execute
function! incsearch#go_wrap(...) abort
let config = extend(get(a:, 1, {}), incsearch#config#lazy(), 'keep')
let esc = s:U.is_visual(config.mode) ? "\<ESC>" : ''
return printf("%s:\<C-u>call incsearch#go(%s)\<CR>",
\ esc, strtrans(string(config)))
let g:incsearch#_go_wrap_config = config
let esc = s:U.is_visual(g:incsearch#_go_wrap_config.mode) ? "\<ESC>" : ''
return printf("%s:\<C-u>call incsearch#go(g:incsearch#_go_wrap_config)\<CR>", esc)
endfunction

" similar to incsearch#forward() but do not move the cursor unless explicitly
Expand Down
3 changes: 2 additions & 1 deletion autoload/incsearch/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let s:config = {
\ 'is_expr': s:FALSE,
\ 'pattern': '',
\ 'mode': 'n',
\ 'count1': 1
\ 'count1': 1,
\ 'modules': []
\ }

" @return config for lazy value
Expand Down

0 comments on commit 5c4db30

Please sign in to comment.