Skip to content

Commit

Permalink
[vim] unite.vim update
Browse files Browse the repository at this point in the history
  • Loading branch information
guns committed Sep 13, 2013
1 parent d96786e commit b22e8b9
Show file tree
Hide file tree
Showing 41 changed files with 1,050 additions and 534 deletions.
5 changes: 4 additions & 1 deletion etc/vim/bundle/unite.vim/autoload/unite.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: unite.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 17 Jun 2013.
" Last Modified: 26 Aug 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -289,6 +289,9 @@ endfunction"}}}
function! unite#args_complete(sources, arglead, cmdline, cursorpos) "{{{
return unite#complete#args(a:sources, a:arglead, a:cmdline, a:cursorpos)
endfunction"}}}
function! unite#dummy_completefunc(findstart, base) "{{{
return a:findstart ? -1 : []
endfunction"}}}

function! unite#all_quit_session(...) "{{{
call unite#view#_quit(get(a:000, 0, 1), 1)
Expand Down
12 changes: 8 additions & 4 deletions etc/vim/bundle/unite.vim/autoload/unite/action.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: action.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 20 Jul 2013.
" Last Modified: 02 Sep 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -68,6 +68,10 @@ function! s:get_action_table(source_name, kind_name, self_func, is_parents_actio
call unite#print_error('[unite.vim] source "' . a:source_name . '" is not found.')
return {}
endif
if empty(kind)
call unite#print_error('[unite.vim] kind "' . a:kind_name . '" is not found.')
return {}
endif

let action_table = {}

Expand Down Expand Up @@ -373,12 +377,12 @@ function! unite#action#do(action_name, ...) "{{{
catch /^Vim\%((\a\+)\)\=:E325/
" Ignore catch.
call unite#print_error(v:exception)
call unite#print_error('Attenssion: Swap file is found in executing action!')
call unite#print_error('Warning: Swap file was found while executing action!')
call unite#print_error('Action name is ' . table.action.name)
catch
call unite#print_error(v:throwpoint)
call unite#print_error(v:exception)
call unite#print_error('Error occured in executing action!')
call unite#print_error('Error occured while executing action!')
call unite#print_error('Action name is ' . table.action.name)
endtry

Expand All @@ -397,7 +401,7 @@ function! unite#action#do(action_name, ...) "{{{
endif
endfor

if !is_quit && unite.context.keep_focus
if (!is_quit || unite.context.no_quit) && unite.context.keep_focus
let winnr = bufwinnr(unite.bufnr)

if winnr > 0
Expand Down
6 changes: 2 additions & 4 deletions etc/vim/bundle/unite.vim/autoload/unite/candidates.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: candidates.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 23 Jul 2013.
" Last Modified: 02 Sep 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -107,9 +107,7 @@ function! unite#candidates#gather(...) "{{{
if is_gather_all
let unite.candidates_pos = len(unite.candidates)
elseif unite.context.is_redraw || unite.candidates_pos == 0
let height = unite.context.no_split ?
\ winheight(0) : unite.context.winheight
let unite.candidates_pos = height
let unite.candidates_pos = line('.') + winheight(0)
endif

let candidates = unite#init#_candidates(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: converter_relative_abbr.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 22 Jul 2013.
" Last Modified: 30 Jul 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -58,6 +58,9 @@ function! s:converter.filter(candidates, context) "{{{
let candidate.abbr = get(candidate, 'action__path',
\ candidate.word)
endif
if isdirectory(candidate.abbr)
let candidate.abbr .= '/'
endif
endfor
finally
if has_key(a:context, 'source__directory')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"=============================================================================
" FILE: converter_smart_path.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 04 Aug 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================

let s:save_cpo = &cpo
set cpo&vim

function! unite#filters#converter_smart_path#define() "{{{
return s:converter
endfunction"}}}

let s:converter = {
\ 'name' : 'converter_smart_path',
\ 'description' : 'converts word to smart path of filename',
\}

function! s:converter.filter(candidates, context) "{{{
if a:context.input =~ '^\%(\a\+:/\|/\)'
return unite#filters#converter_full_path#define().filter(
\ a:candidates, a:context)
endif

return a:candidates
endfunction"}}}

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: foldmethod=marker
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: matcher_hide_hidden_files.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 23 Jul 2013.
" Last Modified: 04 Aug 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -38,12 +38,11 @@ let s:matcher = {

function! s:matcher.filter(candidates, context) "{{{
if stridx(a:context.input, '.') >= 0
\ || get(a:context, 'source__directory', '') =~ '/\.\|^\.'
return unite#filters#filter_matcher(
\ a:candidates, '', a:context)
endif

return filter(a:candidates, "v:val.action__path !~ '/\\.\\|^\\.'")
return filter(a:candidates, "v:val.action__path !~ '/\\.[^/]*$\\|^\\.[^/]*$'")
endfunction"}}}

let &cpo = s:save_cpo
Expand Down
50 changes: 50 additions & 0 deletions etc/vim/bundle/unite.vim/autoload/unite/filters/sorter_ftime.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"=============================================================================
" FILE: sorter_ftime.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 06 Aug 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================

let s:save_cpo = &cpo
set cpo&vim

function! unite#filters#sorter_ftime#define() "{{{
return s:sorter
endfunction"}}}

let s:sorter = {
\ 'name' : 'sorter_ftime',
\ 'description' : 'sort by getftime() order',
\}

function! s:sorter.filter(candidates, context) "{{{
return unite#util#sort_by(a:candidates, '
\ has_key(v:val, "action__path") ? getftime(v:val.action__path)
\ : has_key(v:val, "action__directory") ? getftime(v:val.action__directory)
\ : 0
\ ')
endfunction"}}}

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: foldmethod=marker
23 changes: 16 additions & 7 deletions etc/vim/bundle/unite.vim/autoload/unite/filters/sorter_rank.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: sorter_rank.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 05 Jul 2013.
" Last Modified: 08 Aug 2013.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -37,7 +37,7 @@ let s:sorter = {
\}

function! s:sorter.filter(candidates, context) "{{{
if a:context.input == '' || !has('float')
if a:context.input == '' || !has('float') || empty(a:candidates)
return a:candidates
endif

Expand All @@ -46,12 +46,22 @@ function! s:sorter.filter(candidates, context) "{{{
let candidate.filter__rank = 0
endfor

" let is_path = has_key(a:candidates[0], 'action__path')

for input in split(a:context.input, '\\\@<! ')
let input = substitute(substitute(input, '\\ ', ' ', 'g'),
\ '\*', '', 'g')

" Calc rank.
let l1 = len(input)

" for candidate in a:candidates
" let word = is_path ? fnamemodify(candidate.word, ':t') : candidate.word
" let index = stridx(word, input[0])
" let candidate.filter__rank +=
" \ len(word) + (index > 0 ? index * 2 : len(word))
" endfor

if unite#util#has_lua()
for candidate in a:candidates
let candidate.filter__rank +=
Expand All @@ -71,6 +81,8 @@ function! s:sorter.filter(candidates, context) "{{{
endfunction"}}}

function! s:calc_word_distance(str1, str2, l1) "{{{
return

let l2 = len(a:str2)
let p1 = range(l2+1)
let p2 = []
Expand Down Expand Up @@ -113,16 +125,12 @@ function! s:calc_word_distance_lua(str1, str2, l1) "{{{
for j = 0, l2 do
p2[j+1] = math.min(p1[j+1] + 1, p2[j]+1)
end

-- Swap.
local tmp = p1
p1 = p2
p2 = tmp
end

vim.command('let distance = ' .. p1[l2])
EOF

" echomsg string([a:str1, a:str2, distance])
return distance
endfunction"}}}

Expand All @@ -142,6 +150,7 @@ do
end
end
EOF
" echomsg string(map(copy(a:candidates), '[v:val.word, v:val.filter__rank]'))
return a:candidates
endfunction"}}}

Expand Down
Loading

0 comments on commit b22e8b9

Please sign in to comment.