-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev': Bump up version to 1.2.0
- Loading branch information
Showing
22 changed files
with
970 additions
and
655 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"============================================================================= | ||
" FILE: autoload/incsearch/autocmd.vim | ||
" AUTHOR: haya14busa | ||
" License: MIT license | ||
"============================================================================= | ||
scriptencoding utf-8 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
noremap <silent><expr> <Plug>(_incsearch-nohlsearch) incsearch#autocmd#auto_nohlsearch(0) | ||
noremap! <silent><expr> <Plug>(_incsearch-nohlsearch) incsearch#autocmd#auto_nohlsearch(0) | ||
nnoremap <silent> <Plug>(_incsearch-nohlsearch) :<C-u>nohlsearch<CR> | ||
xnoremap <silent> <Plug>(_incsearch-nohlsearch) :<C-u>nohlsearch<CR>gv | ||
" Make sure move cursor by search related action __after__ calling this | ||
" function because the first move event just set nested autocmd which | ||
" does :nohlsearch | ||
" @expr | ||
function! incsearch#autocmd#auto_nohlsearch(nest) abort | ||
" NOTE: see this value inside this function in order to toggle auto | ||
" :nohlsearch feature easily with g:incsearch#autocmd#auto_nohlsearch option | ||
if !g:incsearch#auto_nohlsearch | return '' | endif | ||
return s:auto_nohlsearch(a:nest) | ||
endfunction | ||
|
||
function! s:auto_nohlsearch(nest) abort | ||
" NOTE: :h autocmd-searchpat | ||
" You cannot implement this feature without feedkeys() because of | ||
" :h autocmd-searchpat | ||
augroup incsearch-auto-nohlsearch | ||
autocmd! | ||
autocmd InsertEnter * :call <SID>attach_on_insert_leave() | autocmd! incsearch-auto-nohlsearch | ||
execute join([ | ||
\ 'autocmd CursorMoved *' | ||
\ , repeat('autocmd incsearch-auto-nohlsearch CursorMoved * ', a:nest) | ||
\ , 'call feedkeys("\<Plug>(_incsearch-nohlsearch)", "m")' | ||
\ , '| autocmd! incsearch-auto-nohlsearch' | ||
\ ], ' ') | ||
augroup END | ||
return '' | ||
endfunction | ||
|
||
function! s:attach_on_insert_leave() abort | ||
augroup incsearch-auto-nohlsearch-on-insert-leave | ||
autocmd! | ||
autocmd InsertLeave * :call incsearch#autocmd#auto_nohlsearch(1) | ||
\ | autocmd! incsearch-auto-nohlsearch-on-insert-leave | ||
augroup END | ||
return '' | ||
endfunction | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
" __END__ | ||
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
"============================================================================= | ||
" FILE: autoload/incsearch/cli.vim | ||
" AUTHOR: haya14busa | ||
" License: MIT license | ||
"============================================================================= | ||
scriptencoding utf-8 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
let s:DIRECTION = { 'forward': 1, 'backward': 0 } " see :h v:searchforward | ||
|
||
let s:V = incsearch#vital() | ||
|
||
function! incsearch#cli#get() abort | ||
try | ||
" It returns current cli object | ||
return s:Doautocmd.get_cmdline() | ||
catch /vital-over(_incsearch) Exception/ | ||
" If there are no current cli object, return default one | ||
return incsearch#cli#make(incsearch#config#make({})) | ||
endtry | ||
endfunction | ||
|
||
" @config: whole configuration | ||
function! incsearch#cli#make(config) abort | ||
let cli = s:copy_cli(s:cli) | ||
call incsearch#cli#set(cli, a:config) | ||
return cli | ||
endfunction | ||
|
||
" To reuse cli object, you should re-set configuration | ||
" @config: whole configuration | ||
function! incsearch#cli#set(cli, config) abort | ||
let a:cli._base_key = a:config.command | ||
let a:cli._vcount1 = a:config.count1 | ||
let a:cli._is_expr = a:config.is_expr | ||
let a:cli._mode = a:config.mode | ||
let a:cli._pattern = a:config.pattern | ||
let a:cli._prompt = a:config.prompt | ||
let a:cli._flag = a:config.is_stay ? 'n' | ||
\ : a:config.command is# '/' ? '' | ||
\ : a:config.command is# '?' ? 'b' | ||
\ : '' | ||
let a:cli._direction = | ||
\ (a:cli._base_key is# '/' ? s:DIRECTION.forward : s:DIRECTION.backward) | ||
" TODO: provide config? but it may conflict with <expr> mapping | ||
" NOTE: _w: default cursor view | ||
let a:cli._w = winsaveview() | ||
for module in a:config.modules | ||
call a:cli.connect(module) | ||
endfor | ||
call a:cli.set_prompt(a:cli._prompt) | ||
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') | ||
|
||
" Add modules | ||
call s:cli.connect('BufferComplete') | ||
call s:cli.connect('Cancel') | ||
call s:cli.connect('CursorMove') | ||
call s:cli.connect('Digraphs') | ||
call s:cli.connect('Delete') | ||
call s:cli.connect('DrawCommandline') | ||
call s:cli.connect('ExceptionExit') | ||
call s:cli.connect('LiteralInsert') | ||
" call s:cli.connect('Exit') | ||
call s:cli.connect(incsearch#over#modules#exit#make()) | ||
call s:cli.connect('InsertRegister') | ||
call s:cli.connect('Paste') | ||
let s:Doautocmd = s:modules.get('Doautocmd') | ||
call s:cli.connect(s:Doautocmd.make('IncSearch')) | ||
call s:cli.connect(s:modules.get('ExceptionMessage').make('incsearch.vim: ', 'echom')) | ||
call s:cli.connect(s:modules.get('History').make('/')) | ||
call s:cli.connect(s:modules.get('NoInsert').make_special_chars()) | ||
|
||
" Dynamic Module Loading Management | ||
let s:KeyMapping = s:modules.get('KeyMapping') | ||
let s:emacs_like = s:KeyMapping.make_emacs() | ||
let s:vim_cmap = s:KeyMapping.make_vim_cmdline_mapping() | ||
let s:smartbackword = s:modules.get('IgnoreRegexpBackwardWord').make() | ||
function! s:emacs_like._condition() abort | ||
return g:incsearch#emacs_like_keymap | ||
endfunction | ||
function! s:vim_cmap._condition() abort | ||
return g:incsearch#vim_cmdline_keymap | ||
endfunction | ||
function! s:smartbackword._condition() abort | ||
return g:incsearch#smart_backward_word | ||
endfunction | ||
call s:cli.connect(incsearch#over#modules#module_management#make([s:emacs_like, s:vim_cmap, s:smartbackword])) | ||
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) | ||
endfunction | ||
|
||
call incsearch#over#extend#enrich(s:cli) | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
" __END__ | ||
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"============================================================================= | ||
" FILE: autoload/incsearch/over/extend.vim | ||
" AUTHOR: haya14busa | ||
" License: MIT license | ||
"============================================================================= | ||
scriptencoding utf-8 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
let s:U = incsearch#util#import() | ||
|
||
function! incsearch#over#extend#enrich(cli) abort | ||
return extend(a:cli, s:cli) | ||
endfunction | ||
|
||
let s:cli = {} | ||
|
||
function! s:cli._generate_command(input) abort | ||
let is_cancel = self.exit_code() | ||
if is_cancel | ||
return s:U.is_visual(self._mode) ? '\<ESC>gv' : "\<ESC>" | ||
else | ||
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) | ||
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' | ||
\ : '' | ||
let zv = (&foldopen =~# '\vsearch|all' && self._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, self._vcount1, self._base_key, a:pattern, zv) | ||
endfunction | ||
|
||
function! s:cli._call_execute_event(...) abort | ||
let view = get(a:, 1, winsaveview()) | ||
try | ||
call winrestview(self._w) | ||
call self.callevent('on_execute_pre') | ||
finally | ||
call winrestview(view) | ||
endtry | ||
call self.callevent('on_execute') | ||
endfunction | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
" __END__ | ||
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"============================================================================= | ||
" FILE: autoload/incsearch/over/modules/exit.vim | ||
" AUTHOR: haya14busa | ||
" License: MIT license | ||
"============================================================================= | ||
scriptencoding utf-8 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
" NOTE: | ||
" <CR> in {rhs} wil be remapped even after exiting vital-over command line | ||
" interface, so do not use <Over>(exit) | ||
" See also s:cli.keymapping() | ||
let s:incsearch_exit = { | ||
\ 'name' : 'IncsearchExit', | ||
\ 'exit_code' : 0 | ||
\} | ||
function! s:incsearch_exit.on_char_pre(cmdline) abort | ||
if a:cmdline.is_input("\<CR>") | ||
\ || a:cmdline.is_input("\<NL>") | ||
call a:cmdline.setchar('') | ||
call a:cmdline.exit(self.exit_code) | ||
endif | ||
endfunction | ||
|
||
function! incsearch#over#modules#exit#make() abort | ||
return deepcopy(s:incsearch_exit) | ||
endfunction | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
" __END__ | ||
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker |
Oops, something went wrong.