Skip to content

Commit

Permalink
Merge branch 'dev': Bump up version to 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Jun 28, 2015
2 parents acd7147 + e0af990 commit 94119ba
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 135 deletions.
76 changes: 11 additions & 65 deletions autoload/incsearch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ let s:U = incsearch#util#import()

" Main: {{{

" @return vital-over command-line interface object. it's experimental!!!
" @return vital-over command-line interface object. [experimental]
function! incsearch#cli() abort
return incsearch#cli#get()
endfunction

"" Make vital-over command-line interface object and return it [experimental]
function! incsearch#make(...) abort
return incsearch#cli#make(incsearch#config#make(get(a:, 1, {})))
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_config = {}
Expand Down Expand Up @@ -169,7 +174,7 @@ nnoremap <silent> <Plug>(_incsearch-winrestview) :<C-u>call winrestview(g:incsea
xnoremap <silent> <Plug>(_incsearch-winrestview) :<C-u>call winrestview(g:incsearch#_view)<CR>gv
function! s:stay(cli, input) abort
let [raw_pattern, offset] = incsearch#cli_parse_pattern(a:cli)
let [raw_pattern, offset] = a:cli._parse_pattern()
let pattern = incsearch#convert(raw_pattern)

" NOTE: do not move cursor but need to handle {offset} for n & N ...! {{{
Expand All @@ -180,7 +185,7 @@ function! s:stay(cli, input) abort
call s:cleanup_cmdline()
elseif !empty(offset) && mode(1) !=# 'no'
let cmd = incsearch#with_ignore_foldopen(
\ function('s:generate_command'), a:cli, a:input)
\ s:U.dictfunction(a:cli._generate_command, a:cli), a:input)
call feedkeys(cmd, 'n')
let g:incsearch#_view = a:cli._w
call feedkeys("\<Plug>(_incsearch-winrestview)", 'm')
Expand All @@ -203,7 +208,7 @@ endfunction

function! s:search(cli, input) abort
call incsearch#autocmd#auto_nohlsearch(1) " NOTE: `.` repeat doesn't handle this
return s:generate_command(a:cli, a:input)
return a:cli._generate_command(a:input)
endfunction

function! s:get_input(cli) abort
Expand All @@ -223,47 +228,6 @@ function! s:get_input(cli) abort
return input
endfunction

function! s:generate_command(cli, input) abort
let is_cancel = a:cli.exit_code()
if is_cancel
return s:U.is_visual(a:cli._mode) ? "\<ESC>gv" : "\<ESC>"
else
call s:call_execute_event(a:cli)
let [pattern, offset] = incsearch#parse_pattern(a:input, a:cli._base_key)
" TODO: implement convert input method
let p = incsearch#combine_pattern(a:cli, incsearch#convert(pattern), offset)
return a:cli._build_search_cmd(p)
endif
endfunction

"" Call on_execute_pre and on_execute event
" assume current position is the destination and a:cli._w is the position to
" start search
function! s:call_execute_event(cli, ...) abort
let view = get(a:, 1, winsaveview())
try
call winrestview(a:cli._w)
call a:cli.callevent('on_execute_pre')
finally
call winrestview(view)
endtry
call a:cli.callevent('on_execute')
endfunction

function! incsearch#build_search_cmd(cli, mode, pattern) abort
let op = (a:mode == 'no') ? v:operator
\ : s:U.is_visual(a:mode) ? 'gv'
\ : ''
let zv = (&foldopen =~# '\vsearch|all' && a:mode !=# 'no' ? 'zv' : '')
" NOTE:
" Should I consider o_v, o_V, and o_CTRL-V cases and do not
" <Esc>? <Esc> exists for flexible v:count with using s:cli._vcount1,
" but, if you do not move the cursor while incremental searching,
" there are no need to use <Esc>.
return printf("\<Esc>\"%s%s%s%s%s\<CR>%s",
\ v:register, op, a:cli._vcount1, a:cli._base_key, a:pattern, zv)
endfunction

" Assume the cursor move is already done.
" This function handle search related stuff which doesn't be set by :execute
" in function like @/, hisory, jumplist, offset, error & warning emulation.
Expand All @@ -278,7 +242,7 @@ function! s:set_search_related_stuff(cli, cmd, ...) abort
call s:cleanup_cmdline()
return
endif
let [raw_pattern, offset] = incsearch#cli_parse_pattern(a:cli)
let [raw_pattern, offset] = a:cli._parse_pattern()
let should_execute = !empty(offset) || empty(raw_pattern)
if should_execute
" Execute with feedkeys() to work with
Expand All @@ -294,7 +258,7 @@ function! s:set_search_related_stuff(cli, cmd, ...) abort
" Add history if necessary
" Do not save converted pattern to history
let pattern = incsearch#convert(raw_pattern)
let input = incsearch#combine_pattern(a:cli, raw_pattern, offset)
let input = a:cli._combine_pattern(raw_pattern, offset)
call histadd(a:cli._base_key, input)
let @/ = pattern

Expand Down Expand Up @@ -346,24 +310,6 @@ function! incsearch#parse_pattern(expr, search_key) abort
return result
endfunction

" CommandLine Interface parse pattern wrapper
" function! s:cli_parse_pattern(cli) abort
function! incsearch#cli_parse_pattern(cli) abort
if v:version == 704 && !has('patch421')
" Ignore \ze* which clash vim 7.4 without 421 patch
" Assume `\m`
let [p, o] = incsearch#parse_pattern(a:cli.getline(), a:cli._base_key)
let p = (p =~# s:non_escaped_backslash . 'z[se]\%(\*\|\\+\)' ? '' : p)
return [p, o]
else
return incsearch#parse_pattern(a:cli.getline(), a:cli._base_key)
endif
endfunction

function! incsearch#combine_pattern(cli, pattern, offset) abort
return empty(a:offset) ? a:pattern : a:pattern . a:cli._base_key . a:offset
endfunction

" convert implementation. assume pattern is not empty
function! s:_convert(pattern) abort
return incsearch#magic() . a:pattern
Expand Down
52 changes: 4 additions & 48 deletions autoload/incsearch/cli.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endfunction

" @config: whole configuration
function! incsearch#cli#make(config) abort
let cli = s:copy_cli(s:cli)
let cli = deepcopy(s:cli)
call incsearch#cli#set(cli, a:config)
return cli
endfunction
Expand All @@ -37,6 +37,7 @@ function! incsearch#cli#set(cli, config) abort
let a:cli._mode = a:config.mode
let a:cli._pattern = a:config.pattern
let a:cli._prompt = a:config.prompt
let a:cli._keymap = a:config.keymap
let a:cli._flag = a:config.is_stay ? 'n'
\ : a:config.command is# '/' ? ''
\ : a:config.command is# '?' ? 'b'
Expand All @@ -53,13 +54,6 @@ function! incsearch#cli#set(cli, config) abort
return a:cli
endfunction

"" partial deepcopy() for cli.connect(module) instead of copy()
function! s:copy_cli(cli) abort
let cli = copy(a:cli)
let cli.variables = deepcopy(a:cli.variables)
return cli
endfunction

let s:cli = s:V.import('Over.Commandline').make_default("/")
let s:modules = s:V.import('Over.Commandline.Modules')

Expand Down Expand Up @@ -102,46 +96,8 @@ unlet s:KeyMapping s:emacs_like s:vim_cmap s:smartbackword
call s:cli.connect(incsearch#over#modules#pattern_saver#make())
call s:cli.connect(incsearch#over#modules#incsearch#make())

let s:default_keymappings = {
\ "\<Tab>" : {
\ "key" : "<Over>(incsearch-next)",
\ "noremap" : 1,
\ },
\ "\<S-Tab>" : {
\ "key" : "<Over>(incsearch-prev)",
\ "noremap" : 1,
\ },
\ "\<C-j>" : {
\ "key" : "<Over>(incsearch-scroll-f)",
\ "noremap" : 1,
\ },
\ "\<C-k>" : {
\ "key" : "<Over>(incsearch-scroll-b)",
\ "noremap" : 1,
\ },
\ "\<C-l>" : {
\ "key" : "<Over>(buffer-complete)",
\ "noremap" : 1,
\ },
\ "\<CR>" : {
\ "key": "\<CR>",
\ "noremap": 1
\ },
\ }

" https://github.com/haya14busa/incsearch.vim/issues/35
if has('mac')
call extend(s:default_keymappings, {
\ '"+gP' : {
\ 'key': "\<C-r>+",
\ 'noremap': 1
\ },
\ })
endif

" FIXME: arguments?
function! s:cli.keymapping(...) abort
return extend(copy(s:default_keymappings), g:incsearch_cli_key_mappings)
function! s:cli.__keymapping__() abort
return copy(self._keymap)
endfunction

call incsearch#over#extend#enrich(s:cli)
Expand Down
55 changes: 52 additions & 3 deletions autoload/incsearch/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let s:TRUE = !0
let s:FALSE = 0
lockvar s:TRUE s:FALSE

let s:U = incsearch#util#import()

"" incsearch config
" TODO: more detail documentation
" @command is equivalent with base_key TODO: fix this inconsistence
Expand All @@ -24,25 +26,72 @@ let s:config = {
\ 'mode': 'n',
\ 'count1': 1,
\ 'prompt': '',
\ 'modules': []
\ 'modules': [],
\ 'keymap': {}
\ }

" @return config for lazy value
function! s:lazy_config() abort
let m = mode(1)
return {'count1': v:count1, 'mode': m, 'is_expr': (m is# 'no')}
return {
\ 'count1': v:count1,
\ 'mode': m,
\ 'is_expr': (m is# 'no'),
\ 'keymap': s:keymap()
\ }
endfunction

" @return config with default value
function! incsearch#config#make(additional) abort
let default = extend(copy(s:config), s:lazy_config())
let c = extend(default, a:additional)
let c = s:U.deepextend(default, a:additional)
if c.prompt is# ''
let c.prompt = c.command
endif
return c
endfunction

let s:default_keymappings = {
\ "\<Tab>" : {
\ "key" : "<Over>(incsearch-next)",
\ "noremap" : 1,
\ },
\ "\<S-Tab>" : {
\ "key" : "<Over>(incsearch-prev)",
\ "noremap" : 1,
\ },
\ "\<C-j>" : {
\ "key" : "<Over>(incsearch-scroll-f)",
\ "noremap" : 1,
\ },
\ "\<C-k>" : {
\ "key" : "<Over>(incsearch-scroll-b)",
\ "noremap" : 1,
\ },
\ "\<C-l>" : {
\ "key" : "<Over>(buffer-complete)",
\ "noremap" : 1,
\ },
\ "\<CR>" : {
\ "key": "\<CR>",
\ "noremap": 1
\ },
\ }

" https://github.com/haya14busa/incsearch.vim/issues/35
if has('mac')
call extend(s:default_keymappings, {
\ '"+gP' : {
\ 'key': "\<C-r>+",
\ 'noremap': 1
\ },
\ })
endif

function! s:keymap() abort
return extend(copy(s:default_keymappings), g:incsearch_cli_key_mappings)
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
Expand Down
33 changes: 28 additions & 5 deletions autoload/incsearch/over/extend.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim

let s:non_escaped_backslash = '\m\%(\%(^\|[^\\]\)\%(\\\\\)*\)\@<=\\'

let s:U = incsearch#util#import()

function! incsearch#over#extend#enrich(cli) abort
Expand All @@ -23,17 +25,18 @@ function! s:cli._generate_command(input) abort
call self._call_execute_event()
let [pattern, offset] = incsearch#parse_pattern(a:input, self._base_key)
" TODO: implement convert input method
let p = incsearch#combine_pattern(self, incsearch#convert(pattern), offset)
let p = self._combine_pattern(incsearch#convert(pattern), offset)
return self._build_search_cmd(p)
endif
endfunction

" @return search cmd
function! s:cli._build_search_cmd(pattern) abort
let op = (self._mode == 'no') ? v:operator
\ : s:U.is_visual(self._mode) ? 'gv'
function! s:cli._build_search_cmd(pattern, ...) abort
let mode = get(a:, 1, self._mode)
let op = (mode == 'no') ? v:operator
\ : s:U.is_visual(mode) ? 'gv'
\ : ''
let zv = (&foldopen =~# '\vsearch|all' && self._mode !=# 'no' ? 'zv' : '')
let zv = (&foldopen =~# '\vsearch|all' && mode !=# 'no' ? 'zv' : '')
" NOTE:
" Should I consider o_v, o_V, and o_CTRL-V cases and do not
" <Esc>? <Esc> exists for flexible v:count with using s:cli._vcount1,
Expand All @@ -43,6 +46,9 @@ function! s:cli._build_search_cmd(pattern) abort
\ v:register, op, self._vcount1, self._base_key, a:pattern, zv)
endfunction

"" Call on_execute_pre and on_execute event
" assume current position is the destination and a:cli._w is the position to
" start search
function! s:cli._call_execute_event(...) abort
let view = get(a:, 1, winsaveview())
try
Expand All @@ -54,6 +60,23 @@ function! s:cli._call_execute_event(...) abort
call self.callevent('on_execute')
endfunction

function! s:cli._parse_pattern() abort
if v:version == 704 && !has('patch421')
" Ignore \ze* which clash vim 7.4 without 421 patch
" Assume `\m`
let [p, o] = incsearch#parse_pattern(self.getline(), self._base_key)
let p = (p =~# s:non_escaped_backslash . 'z[se]\%(\*\|\\+\)' ? '' : p)
return [p, o]
else
return incsearch#parse_pattern(self.getline(), self._base_key)
endif
endfunction

function! s:cli._combine_pattern(pattern, offset) abort
return empty(a:offset) ? a:pattern : a:pattern . self._base_key . a:offset
endfunction


let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
Expand Down
9 changes: 5 additions & 4 deletions autoload/incsearch/over/modules/incsearch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ endfunction
function! s:on_char_pre(cmdline) abort
" NOTE:
" `:call a:cmdline.setchar('')` as soon as possible!
let [pattern, offset] = incsearch#cli_parse_pattern(a:cmdline)
let [raw_pattern, offset] = a:cmdline._parse_pattern()
let pattern = incsearch#convert(raw_pattern)

" Interactive :h last-pattern if pattern is empty
if ( a:cmdline.is_input("<Over>(incsearch-next)")
Expand Down Expand Up @@ -186,7 +187,7 @@ function! s:on_char_pre(cmdline) abort
endfunction

function! s:on_char(cmdline) abort
let [raw_pattern, offset] = incsearch#cli_parse_pattern(a:cmdline)
let [raw_pattern, offset] = a:cmdline._parse_pattern()

if raw_pattern ==# ''
call s:hi.disable_all()
Expand Down Expand Up @@ -249,8 +250,8 @@ function! s:move_cursor(cli, pattern, ...) abort
" doesn't reach this block
let is_visual_mode = s:U.is_visual(mode(1))
let cmd = incsearch#with_ignore_foldopen(
\ function('incsearch#build_search_cmd'),
\ a:cli, 'n', incsearch#combine_pattern(a:cli, a:pattern, offset))
\ s:U.dictfunction(a:cli._build_search_cmd, a:cli),
\ a:cli._combine_pattern(a:pattern, offset), 'n')
" NOTE:
" :silent!
" Shut up errors! because this is just for the cursor emulation
Expand Down

0 comments on commit 94119ba

Please sign in to comment.