Created
October 28, 2010 06:35
-
-
Save sgur/650773 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
" everything source for unite.vim | |
" Version: 0.0.1 | |
" Last Change: 01 Dec 2010 | |
" Author: sgur <sgurrr at gmail.com> | |
" Licence: The 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. | |
" }}} | |
" Variables "{{{ | |
call unite#set_default('g:unite_source_everything_limit', 50) | |
" search entire path | |
call unite#set_default('g:unite_source_everything_full_path_search', 1) | |
" use POSIX regexp | |
call unite#set_default('g:unite_source_everything_posix_regexp_search', 0) | |
" sort result by full path string | |
call unite#set_default('g:unite_source_everything_sort_by_full_path', 0) | |
"}}} | |
function! unite#sources#everything#define()"{{{ | |
return s:source | |
endfunction"}}} | |
let s:source = { | |
\ 'name' : 'everything', | |
\ 'is_volatile' : 1, | |
\ 'max_candidates': g:unite_source_everything_limit, | |
\} | |
let s:available_vimproc = globpath(&runtimepath, 'autoload/vimproc.vim') != '' | |
let s:available_es = unite#is_win() && executable('es.exe') | |
function! s:source.gather_candidates(args, context)"{{{ | |
" Win32環境でなおかつ es.exe がなかったら空リストを返す | |
if !(s:available_es && s:available_vimproc && vimproc#version() >0) | |
return [] | |
endif | |
" 引数文字列がない場合 es.exe は全エントリを表示しようとするので却下 | |
if len(a:context.input) == 0 | |
return [] | |
endif | |
let l:input = substitute(a:context.input, '^\a\+:\zs\*/', '/', '') | |
" vimproc | |
let l:res = vimproc#system('es' | |
\ . ' -n ' . g:unite_source_everything_limit | |
\ . (g:unite_source_everything_full_path_search > 0 ? ' -p' : '') | |
\ . (g:unite_source_everything_posix_regexp_search > 0 ? ' -r' : '') | |
\ . (g:unite_source_everything_sort_by_full_path > 0 ? ' -s' : '') | |
\ . ' ' . l:input) | |
if &shellslash | |
let l:res = substitute(l:res, '\\', '/', 'g') | |
endif | |
let l:candidates = split(l:res, '\r\n\|\r\|\n') | |
let l:candidates_dir = [] | |
let l:candidates_file = [] | |
for l:entry in l:candidates | |
let l:dict = { 'word' : l:entry, 'abbr' : l:entry, 'source' : 'everything', | |
\ 'action__path' : l:entry, | |
\ 'action__directory' : unite#path2directory(l:entry), | |
\ } | |
if isdirectory(l:entry) | |
if l:entry !~ '^\%(/\|\a\+:/\)$' | |
let l:dict.abbr .= '/' | |
endif | |
let l:dict.kind = 'directory' | |
call add(l:candidates_dir, l:dict) | |
else | |
let l:dict.kind = 'file' | |
call add(l:candidates_file, l:dict) | |
endif | |
endfor | |
return l:candidates_dir + l:candidates_file | |
endfunction"}}} | |
" vim: foldmethod=marker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あと、この程度ならvimproc#system()を使うべきですね。