Skip to content

Commit

Permalink
Merge branch 'dev': Bump up version to 2.0.0 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Jul 5, 2015
2 parents 94119ba + 04e32c6 commit 5b79457
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 113 deletions.
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ install:
- if [ x"$PPA" == "xyes" ] ; then sudo add-apt-repository ppa:pi-rho/dev -y; fi
- sudo apt-get update -q
- sudo apt-get install vim-nox

before_script:
- vim --version
- sudo pip install vim-vint
- git clone https://github.com/thinca/vim-themis
- git clone https://github.com/syngan/vim-vimlint /tmp/vim-vimlint
- git clone https://github.com/ynkdir/vim-vimlparser /tmp/vim-vimlparser
- git clone https://github.com/vim-jp/vital.vim /tmp/vital.vim

before_script:
- vim --version
- vint --version

script:
- vim-themis/bin/themis --reporter spec
- vim-themis/bin/themis --runtimepath /tmp/vital.vim --reporter spec
- vim --cmd "try | helptags doc/ | catch | cquit | endtry" --cmd quit
- sh /tmp/vim-vimlint/bin/vimlint.sh -l /tmp/vim-vimlint -p /tmp/vim-vimlparser -e EVL102.l:_=1 -c func_abort=1 autoload/incsearch.vim
- sh /tmp/vim-vimlint/bin/vimlint.sh -l /tmp/vim-vimlint -p /tmp/vim-vimlparser -e EVL102.l:_=1 -c func_abort=1 autoload/incsearch
- vint autoload/incsearch autoload/incsearch.vim plugin
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,45 @@ Move the cursor to next/previous matches while incremental searching like Emacs.
| `<Over>(incsearch-scroll-f)` | scroll to the next page match. default: `<C-j>` |
| `<Over>(incsearch-scroll-b)` | scroll to the previous page match. default: `<C-k>` |

:tada: Version 2.0 :tada:
-------------------------
Now, incsearch.vim provides some (experimental) API.
You can implement or use very useful yet another search command :mag_right:

### Experimental API
- `:h incsearch#go()`
- `:h incsearch-config`

Starts incsearch.vim with your custom configuration. See help docs for more detail.

### Converter feature
- `:h incsearch-config-converters`
- The list of converter extensions: https://github.com/haya14busa/incsearch.vim/wiki/List-of-plugins-for-incsearch.vim#converter-extensions

#### Example

```vim
function! s:noregexp(pattern) abort
return '\V' . escape(a:pattern, '\')
endfunction
function! s:config() abort
return {'converters': [function('s:noregexp')]}
endfunction
noremap <silent><expr> z/ incsearch#go(<SID>config())
```

incsearch.vim x fuzzy https://github.com/haya14busa/incsearch-fuzzy.vim
![incsearch-fuzzy.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-fuzzy.gif)

### Module extension
- `:h incsearch-config-modules`
- The list of module extentions: https://github.com/haya14busa/incsearch.vim/wiki/List-of-plugins-for-incsearch.vim#module-extensions

incsearch.vim x fuzzy x vim-easymotion https://github.com/haya14busa/incsearch-easymotion.vim
![incsearch-fuzzy-easymotion.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-fuzzy-easymotion.gif)

Author
------
haya14busa (https://github.com/haya14busa)
Expand Down
58 changes: 21 additions & 37 deletions autoload/incsearch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,24 @@ function! incsearch#_go(config) abort
normal! gv
endif
let cli = incsearch#cli#make(a:config)
let l:Search = function(a:config.is_stay ? 'incsearch#stay' : 'incsearch#search')
let cmd = l:Search(cli)
if !a:config.is_expr
let should_set_jumplist = (cli._flag !=# 'n')
call s:set_search_related_stuff(cli, cmd, should_set_jumplist)
if a:config.mode is# 'no'
call s:set_vimrepeat(cmd)
let input = s:get_input(cli)
if cli._does_exit_from_incsearch
" Outer incsearch-plugin handle it so do not something in paticular
return cli._return_cmd
else
" After getting input, generate command, take aftercare, and return
" command.
let l:F = function(cli._flag is# 'n' ? 's:stay' : 's:search')
let cmd = l:F(cli, input)
if !a:config.is_expr
let should_set_jumplist = (cli._flag !=# 'n')
call s:set_search_related_stuff(cli, cmd, should_set_jumplist)
if a:config.mode is# 'no'
call s:set_vimrepeat(cmd)
endif
endif
return cmd
endif
return cmd
endfunction

"" To handle recursive mapping, map command to <Plug>(_incsearch-dotrepeat)
Expand All @@ -157,16 +165,6 @@ function! s:set_vimrepeat(cmd) abort
silent! call repeat#set("\<Plug>(_incsearch-dotrepeat)")
endfunction

" similar to incsearch#forward() but do not move the cursor unless explicitly
" move the cursor while searching
" @expr but sometimes called by non-<expr>
" @return: command which is excutable with expr-mappings or `exec 'normal!'`
function! incsearch#stay(cli) abort
let input = s:get_input(a:cli)
let l:F = function(a:cli._flag is# 'n' ? 's:stay' : 's:search')
return l:F(a:cli, input)
endfunction

let g:incsearch#_view = get(g:, 'incsearch#_view', {})
noremap <silent> <Plug>(_incsearch-winrestview) <Nop>
noremap! <silent> <Plug>(_incsearch-winrestview) <Nop>
Expand All @@ -175,7 +173,7 @@ xnoremap <silent> <Plug>(_incsearch-winrestview) :<C-u>call winrestview(g:incsea
function! s:stay(cli, input) abort
let [raw_pattern, offset] = a:cli._parse_pattern()
let pattern = incsearch#convert(raw_pattern)
let pattern = a:cli._convert(raw_pattern)

" NOTE: do not move cursor but need to handle {offset} for n & N ...! {{{
" FIXME: cannot set {offset} if in operator-pending mode because this
Expand All @@ -202,10 +200,6 @@ function! s:stay(cli, input) abort
return s:U.is_visual(a:cli._mode) ? "\<ESC>gv" : "\<ESC>" " just exit
endfunction

function! incsearch#search(cli) abort
return s:search(a:cli, s:get_input(a:cli))
endfunction

function! s:search(cli, input) abort
call incsearch#autocmd#auto_nohlsearch(1) " NOTE: `.` repeat doesn't handle this
return a:cli._generate_command(a:input)
Expand Down Expand Up @@ -257,7 +251,7 @@ function! s:set_search_related_stuff(cli, cmd, ...) abort
else
" Add history if necessary
" Do not save converted pattern to history
let pattern = incsearch#convert(raw_pattern)
let pattern = a:cli._convert(raw_pattern)
let input = a:cli._combine_pattern(raw_pattern, offset)
call histadd(a:cli._base_key, input)
let @/ = pattern
Expand Down Expand Up @@ -310,16 +304,6 @@ function! incsearch#parse_pattern(expr, search_key) abort
return result
endfunction

" convert implementation. assume pattern is not empty
function! s:_convert(pattern) abort
return incsearch#magic() . a:pattern
endfunction

function! incsearch#convert(pattern) abort
" TODO: convert pattern if required in addition to appending magic flag
return a:pattern is# '' ? a:pattern : s:_convert(a:pattern)
endfunction

function! incsearch#detect_case(pattern) abort
" Ignore \%C, \%U, \%V for smartcase detection
let p = substitute(a:pattern, s:non_escaped_backslash . '%[CUV]', '', 'g')
Expand Down Expand Up @@ -391,7 +375,7 @@ function! s:emulate_search_error(direction, ...) abort
silent! call incsearch#execute_search(keyseq . "\<CR>")
call winrestview(from)
if g:incsearch#do_not_save_error_message_history
if v:errmsg != ''
if v:errmsg !=# ''
call s:Error(v:errmsg)
else
let v:errmsg = old_errmsg
Expand All @@ -405,13 +389,13 @@ function! s:emulate_search_error(direction, ...) abort
catch /^Vim\%((\a\+)\)\=:E/
let first_error = matchlist(v:exception, '\v^Vim%(\(\a+\))=:(E.*)$')[1]
call s:Error(first_error, 'echom')
if last_error != '' && last_error !=# first_error
if last_error !=# '' && last_error !=# first_error
call s:Error(last_error, 'echom')
endif
finally
call winrestview(from)
endtry
if v:errmsg == ''
if v:errmsg ==# ''
let v:errmsg = old_errmsg
endif
endif
Expand Down
3 changes: 2 additions & 1 deletion autoload/incsearch/cli.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function! incsearch#cli#set(cli, config) abort
let a:cli._pattern = a:config.pattern
let a:cli._prompt = a:config.prompt
let a:cli._keymap = a:config.keymap
let a:cli._converters = a:config.converters
let a:cli._flag = a:config.is_stay ? 'n'
\ : a:config.command is# '/' ? ''
\ : a:config.command is# '?' ? 'b'
Expand All @@ -54,7 +55,7 @@ function! incsearch#cli#set(cli, config) abort
return a:cli
endfunction

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

" Add modules
Expand Down
27 changes: 14 additions & 13 deletions autoload/incsearch/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let s:config = {
\ 'count1': 1,
\ 'prompt': '',
\ 'modules': [],
\ 'converters': [],
\ 'keymap': {}
\ }

Expand All @@ -43,7 +44,7 @@ endfunction

" @return config with default value
function! incsearch#config#make(additional) abort
let default = extend(copy(s:config), s:lazy_config())
let default = extend(deepcopy(s:config), s:lazy_config())
let c = s:U.deepextend(default, a:additional)
if c.prompt is# ''
let c.prompt = c.command
Expand All @@ -53,28 +54,28 @@ endfunction

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

Expand Down
34 changes: 25 additions & 9 deletions autoload/incsearch/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,30 @@ let s:U = incsearch#util#import()
" Management:

let s:V = vital#of('incsearch')
let s:hi = s:V.import("Coaster.Highlight").make()
let s:hi = s:V.import('Coaster.Highlight').make()
let g:incsearch#highlight#_hi = s:hi

function! incsearch#highlight#update() abort
" it's intuiive to call incsearch#highlight#on() & off() but there are no
" need to execute `:nohlsearch` when updating.
call s:hi.disable_all()
call s:hi.enable_all()
endfunction

function! incsearch#highlight#on() abort
call s:hi.enable_all()
if ! g:incsearch#no_inc_hlsearch
let &hlsearch = &hlsearch
endif
endfunction

function! incsearch#highlight#off() abort
call s:hi.disable_all()
if ! g:incsearch#no_inc_hlsearch
nohlsearch
endif
endfunction

function! s:init_hl() abort
hi link IncSearchMatch Search
hi link IncSearchMatchReverse IncSearch
Expand Down Expand Up @@ -168,13 +184,13 @@ function! incsearch#highlight#emulate_visual_highlight(...) abort
" Note: the default pos value assume visual selection is not cleared.
" It uses curswant to emulate visual-block
let v_start_pos = get(a:, 3,
\ (is_visual_now ? [line("v"),col("v")] : [line("'<"), col("'<")]))
\ (is_visual_now ? [line('v'),col('v')] : [line("'<"), col("'<")]))
" See: https://github.com/vim-jp/issues/issues/604
" getcurpos() could be negative value, so use winsaveview() instead
let end_curswant_pos =
\ (exists('*getcurpos') ? getcurpos()[4] : winsaveview().curswant + 1)
let v_end_pos = get(a:, 4, (is_visual_now
\ ? [line("."), end_curswant_pos < 0 ? s:INT.MAX : end_curswant_pos ]
\ ? [line('.'), end_curswant_pos < 0 ? s:INT.MAX : end_curswant_pos ]
\ : [line("'>"), col("'>")]))
let pattern = incsearch#highlight#get_visual_pattern(mode, v_start_pos, v_end_pos)
let hgm = incsearch#highlight#hgm()
Expand Down Expand Up @@ -214,15 +230,15 @@ function! incsearch#highlight#get_visual_pattern(mode, v_start_pos, v_end_pos) a
elseif a:mode ==# 'V'
return printf('\v%%%dl\_.*%%%dl', v_start[0], v_end[0])
elseif a:mode ==# "\<C-v>"
" @vimlint(EVL102, 1, l:min_c)
let [min_c, max_c] = s:U.sort_num([v_start[1], v_end[1]])
let max_c += 1 " increment needed
let max_c = max_c < 0 ? s:INT.MAX : max_c
return '\v'.join(map(range(v_start[0], v_end[0]), '
\ printf("%%%dl%%%dc.*%%%dc",
\ v:val,
\ min_c,
\ min([max_c, s:U.get_max_col(v:val)]))
\ '), "|")
let mapfunc = "
\ printf('%%%dl%%%dc.*%%%dc',
\ v:val, min_c, min([max_c, s:U.get_max_col(v:val)]))
\ "
return '\v'.join(map(range(v_start[0], v_end[0]), mapfunc), '|')
else
throw 'incsearch.vim: unexpected mode ' . a:mode
endif
Expand Down
Loading

0 comments on commit 5b79457

Please sign in to comment.