Include neocomplete (requires lua)

This commit is contained in:
Anthony Rose 2017-04-06 15:34:32 +01:00
parent 17cf45dfb6
commit 5fff31eec9
59 changed files with 10590 additions and 1 deletions

View file

@ -3,10 +3,11 @@
Git submodules are slow, so handle this manually.
* [opt/vim-pathogen](https://github.com/tpope/vim-pathogen)
* [start/TextFormat](https://github.com/vim-scripts/TextFormat)
* [start/jellybeans.vim](https://github.com/nanotech/jellybeans.vim)
* [start/mom.vim](https://github.com/vim-scripts/mom.vim)
* [start/neocomplete.vim](https://github.com/Shougo/neocomplete.vim)
* [start/rust.vim](https://github.com/rust-lang/rust.vim)
* [start/TextFormat](https://github.com/vim-scripts/TextFormat)
* [start/vim-airline](https://github.com/bling/vim-airline)
* [start/vim-ps1](https://github.com/PProvost/vim-ps1)
* [start/vim-surround](https://github.com/tpope/vim-surround)

View file

@ -0,0 +1,31 @@
# Problems summary
## Expected
## Environment Information
* OS:
* Vim version:
## Provide a minimal .vimrc with less than 50 lines (Required!)
```vim
" Your minimal .vimrc
set runtimepath+=~/path/to/neocomplete.nvim/
let g:neocomplete#enable_at_startup = 1
```
## The reproduce ways from Vim starting (Required!)
1. foo
2. bar
3. baz
## Screen shot (if possible)
## Upload the log messages by `:redir` and `:message`

View file

@ -0,0 +1 @@
doc/tags

View file

@ -0,0 +1,8 @@
sudo: false
before_script:
- git clone https://github.com/syngan/vim-vimlint /tmp/vim-vimlint
- git clone https://github.com/ynkdir/vim-vimlparser /tmp/vim-vimlparser
script:
- sh /tmp/vim-vimlint/bin/vimlint.sh -l /tmp/vim-vimlint -p /tmp/vim-vimlparser -e EVL103=1 -e EVL102.l:_=1 autoload

View file

@ -0,0 +1,27 @@
# Problems summary
## Expected
## Environment Information
* OS:
* Vim version:
## Minimal vimrc less than 50 lines
" Your vimrc
set nocompatible
set runtimepath+=~/path/to/neocomplete.vim/
set fo+=aw
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_auto_select = 0
set tw=10 " just for testing purposes
## Reproducable ways from Vim starting
1.
2.
3.
## Screen shot (if possible)

View file

@ -0,0 +1,197 @@
neocomplete
===========
neocomplete is the abbreviation of "neo-completion with cache". It provides
keyword completion system by maintaining a cache of keywords in the current
buffer. neocomplete can be customized easily and has many more features than
Vim's built-in completion.
Note: If you use neovim, you should use deoplete instead.
https://github.com/Shougo/deoplete.nvim
## Installation
**Note:** neocomplete requires Vim 7.3.885+ with Lua enabled.
See [requirements](#requirements) if you aren't sure whether you have this.
1. Extract the files and put them in your Vim directory
(usually `~/.vim/` or `Program Files/Vim/vimfiles` on Windows).
2. Execute the `:NeoCompleteEnable` command or set `let g:neocomplete#enable_at_startup = 1`
in your `.vimrc` (**not** in `.gvimrc` or `_gvimrc`!)
## Requirements
neocomplete requires Vim 7.3.885+ compiled with [if\_lua](http://vimdoc.sourceforge.net/htmldoc/if_lua.html).
If `:echo has("lua")` returns `1`, then you're done; otherwise, see below.
### Vim builds for Windows
[github release](https://github.com/vim/vim-win32-installer/releases)
* [Vim 32bit](http://files.kaoriya.net/goto/vim73w32)
* [Vim 64bit](http://files.kaoriya.net/goto/vim73w64)
* [Vim 32bit alternative](http://tuxproject.de/projects/vim/)
* [Another alternative](http://wyw.dcweb.cn/#download)
**Note:** the Vim build may not include the Lua DLL. In that case,
[download Lua](http://lua-users.org/wiki/LuaBinaries) and put the `lua52.dll`
file in the same directory as `gvim.exe`.
### Vim for Mac OS X:
[MacVim with `if\_lua`](https://github.com/zhaocai/macvim)
Or, you can install MacVim with homebrew:
brew install macvim --with-cscope --with-lua
brew linkapps macvim
To install Vim (as opposed to MacVim) with homebrew:
brew install vim --with-lua
### Vim for Linux:
#### Debian (or Ubuntu)
Make sure you have any of these packages:
* vim-nox
* vim-gtk
* vim-gnome
* vim-athena
Which package depends on your graphical environment (except vim-nox which is for vim with no GUI).
#### Fedora
The latest version of vim includes lua.
As of 2014-04-16 you need to [download the rpm](http://koji.fedoraproject.org/koji/packageinfo?packageID=216).
#### Misc
Be aware, your distribution's package manager may have a fairly outdated
Vim build (for example, Ubuntu 12.04 ships Vim 7.3.429).
However, [building Vim](http://vim.wikia.com/wiki/Building_Vim) on Linux is not difficult.
Remember to specify `--with-lua` (or `--with-features=huge`).
### Vim for Cygwin:
In a cygwin environment, the Lua interface is supported by default.
If you want to make manually, you also need gcc and make.
When everything is prepared, execute these commands.
cd /usr/src
tar jxf vim-7.4.tar.bz2
tar xvfz lua-5.1.5.tar.gz
cd vim74/
./configure --enable-luainterp --enable-gui=no \
--without-x --enable-multibyte --prefix=/usr
make && make install
To check if everything was successfull enter the following `vim --version`. You should see ` +lua` in the list of features.
## Snippets
The Snippets feature of neocomplete was split into a
[separate plugin](https://github.com/Shougo/neosnippet).
A migration guide for existing users of neocomplcache is available:
[Migration guide](https://github.com/Shougo/neocomplete.vim/wiki/neocomplete-migration-guide)
## Screenshots
### Original filename completion
![Original filename completion.](https://f.cloud.github.com/assets/41495/622454/f519f6b8-cf42-11e2-921e-6e34dba148a6.png)
![Include filename completion.](https://f.cloud.github.com/assets/214488/623151/284ad86e-cf5b-11e2-828e-257d31bf0572.png)
### Omni completion
![Omni completion.](https://f.cloud.github.com/assets/41495/622456/fb2cc0bc-cf42-11e2-94e8-403cdcf5427e.png)
### Completion with [vimshell](http://github.com/Shougo/vimshell)
![Completion with vimshell(http://github.com/Shougo/vimshell).](https://f.cloud.github.com/assets/41495/622458/01dbc660-cf43-11e2-85f1-326e7432b0a1.png)
### Vim completion (provided by [neco-vim](https://github.com/Shougo/neco-vim))
![Vim completion.](https://f.cloud.github.com/assets/41495/622457/fe90ad5e-cf42-11e2-8e03-8f189b5e26e5.png)
![Vim completion with animation.](https://f.cloud.github.com/assets/214488/623496/94ed19a2-cf68-11e2-8d33-3aad8a39d7c1.gif)
## Configuration Examples
```vim
"Note: This option must be set in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <expr><C-l> neocomplete#complete_common_string()
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
```

View file

@ -0,0 +1,329 @@
"=============================================================================
" FILE: neocomplete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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.
" }}}
"=============================================================================
if !exists('g:loaded_neocomplete')
runtime! plugin/neocomplete.vim
endif
let s:save_cpo = &cpo
set cpo&vim
" Global options definition. "{{{
let g:neocomplete#max_list =
\ get(g:, 'neocomplete#max_list', 100)
let g:neocomplete#max_keyword_width =
\ get(g:, 'neocomplete#max_keyword_width', 80)
let g:neocomplete#auto_completion_start_length =
\ get(g:, 'neocomplete#auto_completion_start_length', 2)
let g:neocomplete#manual_completion_start_length =
\ get(g:, 'neocomplete#manual_completion_start_length', 0)
let g:neocomplete#min_keyword_length =
\ get(g:, 'neocomplete#min_keyword_length', 4)
let g:neocomplete#enable_ignore_case =
\ get(g:, 'neocomplete#enable_ignore_case', &ignorecase)
let g:neocomplete#enable_smart_case =
\ get(g:, 'neocomplete#enable_smart_case', &infercase)
let g:neocomplete#enable_camel_case =
\ get(g:, 'neocomplete#enable_camel_case', 0)
let g:neocomplete#disable_auto_complete =
\ get(g:, 'neocomplete#disable_auto_complete', 0)
let g:neocomplete#enable_fuzzy_completion =
\ get(g:, 'neocomplete#enable_fuzzy_completion', 1)
let g:neocomplete#auto_complete_delay =
\ get(g:, 'neocomplete#auto_complete_delay', 50)
let g:neocomplete#enable_auto_select =
\ get(g:, 'neocomplete#enable_auto_select', 0)
let g:neocomplete#enable_auto_delimiter =
\ get(g:, 'neocomplete#enable_auto_delimiter', 0)
let g:neocomplete#lock_buffer_name_pattern =
\ get(g:, 'neocomplete#lock_buffer_name_pattern', '')
let g:neocomplete#lock_iminsert =
\ get(g:, 'neocomplete#lock_iminsert', 0)
let g:neocomplete#enable_multibyte_completion =
\ get(g:, 'neocomplete#enable_multibyte_completion', 0)
let g:neocomplete#release_cache_time =
\ get(g:, 'neocomplete#release_cache_time', 900)
let g:neocomplete#skip_auto_completion_time =
\ get(g:, 'neocomplete#skip_auto_completion_time', '0.3')
let g:neocomplete#enable_auto_close_preview =
\ get(g:, 'neocomplete#enable_auto_close_preview', 0)
let g:neocomplete#enable_refresh_always =
\ get(g:, 'neocomplete#enable_refresh_always', 0)
let g:neocomplete#fallback_mappings =
\ get(g:, 'neocomplete#fallback_mappings', [])
let g:neocomplete#sources =
\ get(g:, 'neocomplete#sources', {})
let g:neocomplete#keyword_patterns =
\ get(g:, 'neocomplete#keyword_patterns', {})
let g:neocomplete#delimiter_patterns =
\ get(g:, 'neocomplete#delimiter_patterns', {})
let g:neocomplete#text_mode_filetypes =
\ get(g:, 'neocomplete#text_mode_filetypes', {})
let g:neocomplete#tags_filter_patterns =
\ get(g:, 'neocomplete#tags_filter_patterns', {})
let g:neocomplete#force_omni_input_patterns =
\ get(g:, 'neocomplete#force_omni_input_patterns', {})
let g:neocomplete#ignore_source_files =
\ get(g:, 'neocomplete#ignore_source_files', [])
"}}}
function! neocomplete#initialize() abort "{{{
return neocomplete#init#enable()
endfunction"}}}
function! neocomplete#get_current_neocomplete() abort "{{{
if !exists('b:neocomplete')
call neocomplete#init#_current_neocomplete()
endif
return b:neocomplete
endfunction"}}}
function! neocomplete#get_context() abort "{{{
return neocomplete#get_current_neocomplete().context
endfunction"}}}
" Source helper. "{{{
function! neocomplete#define_source(source) abort "{{{
let sources = neocomplete#variables#get_sources()
for source in neocomplete#util#convert2list(a:source)
let source = neocomplete#init#_source(source)
if !source.disabled
let sources[source.name] = source
endif
endfor
endfunction"}}}
function! neocomplete#define_filter(filter) abort "{{{
let filters = neocomplete#variables#get_filters()
for filter in neocomplete#util#convert2list(a:filter)
let filters[filter.name] = neocomplete#init#_filter(filter)
endfor
endfunction"}}}
function! neocomplete#available_sources() abort "{{{
return copy(neocomplete#variables#get_sources())
endfunction"}}}
function! neocomplete#custom_source(source_name, option_name, value) abort "{{{
return neocomplete#custom#source(a:source_name, a:option_name, a:value)
endfunction"}}}
function! neocomplete#dup_filter(list) abort "{{{
return neocomplete#util#dup_filter(a:list)
endfunction"}}}
function! neocomplete#system(...) abort "{{{
return call('neocomplete#util#system', a:000)
endfunction"}}}
function! neocomplete#has_vimproc() abort "{{{
return neocomplete#util#has_vimproc()
endfunction"}}}
function! neocomplete#get_cur_text(...) abort "{{{
" Return cached text.
let neocomplete = neocomplete#get_current_neocomplete()
return (a:0 == 0 && mode() ==# 'i' &&
\ neocomplete.cur_text != '') ?
\ neocomplete.cur_text : neocomplete#helper#get_cur_text()
endfunction"}}}
function! neocomplete#get_keyword_pattern(...) abort "{{{
let filetype = a:0 != 0? a:1 : neocomplete#get_context_filetype()
if a:0 < 2
return neocomplete#helper#unite_patterns(
\ g:neocomplete#keyword_patterns, filetype)
endif
let source = neocomplete#variables#get_source(a:2)
if !has_key(source, 'neocomplete__keyword_patterns')
let source.neocomplete__keyword_patterns = {}
endif
if !has_key(source.neocomplete__keyword_patterns, filetype)
let source.neocomplete__keyword_patterns[filetype] =
\ neocomplete#helper#unite_patterns(
\ source.keyword_patterns, filetype)
endif
return source.neocomplete__keyword_patterns[filetype]
endfunction"}}}
function! neocomplete#get_keyword_pattern_end(...) abort "{{{
return '\%('.call('neocomplete#get_keyword_pattern', a:000).'\m\)$'
endfunction"}}}
function! neocomplete#match_word(...) abort "{{{
return call('neocomplete#helper#match_word', a:000)
endfunction"}}}
function! neocomplete#is_enabled() abort "{{{
return neocomplete#init#is_enabled()
endfunction"}}}
function! neocomplete#is_locked(...) abort "{{{
return neocomplete#is_cache_disabled() || &paste
\ || (&t_Co != '' && &t_Co < 8)
\ || g:neocomplete#disable_auto_complete
endfunction"}}}
function! neocomplete#is_cache_disabled() abort "{{{
let ignore_filetypes = ['fuf', 'ku']
let bufnr = a:0 > 0 ? a:1 : bufnr('%')
return !neocomplete#is_enabled()
\ || index(ignore_filetypes, &filetype) >= 0
\ || neocomplete#get_current_neocomplete().lock
\ || (g:neocomplete#lock_buffer_name_pattern != '' &&
\ bufname(bufnr) =~ g:neocomplete#lock_buffer_name_pattern)
endfunction"}}}
function! neocomplete#is_auto_select() abort "{{{
return g:neocomplete#enable_auto_select
endfunction"}}}
function! neocomplete#is_auto_complete() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
return neocomplete.is_auto_complete
endfunction"}}}
function! neocomplete#is_eskk_enabled() abort "{{{
return exists('*eskk#is_enabled') && eskk#is_enabled()
endfunction"}}}
function! neocomplete#is_multibyte_input(cur_text) abort "{{{
return (exists('b:skk_on') && b:skk_on)
\ || (!g:neocomplete#enable_multibyte_completion
\ && char2nr(split(a:cur_text, '\zs')[-1]) > 0x80)
endfunction"}}}
function! neocomplete#is_text_mode() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let filetypes = g:neocomplete#text_mode_filetypes
return get(filetypes, neocomplete.context_filetype, 0)
\ || get(filetypes, '_', 0)
endfunction"}}}
function! neocomplete#is_windows() abort "{{{
return neocomplete#util#is_windows()
endfunction"}}}
function! neocomplete#is_prefetch() abort "{{{
return 1
endfunction"}}}
function! neocomplete#exists_echodoc() abort "{{{
return exists('g:loaded_echodoc') && g:loaded_echodoc
endfunction"}}}
function! neocomplete#within_comment() abort "{{{
return neocomplete#get_current_neocomplete().within_comment
endfunction"}}}
function! neocomplete#print_error(string) abort "{{{
echohl Error | echomsg '[neocomplete] ' . a:string | echohl None
endfunction"}}}
function! neocomplete#print_warning(string) abort "{{{
echohl WarningMsg | echomsg '[neocomplete] ' . a:string | echohl None
endfunction"}}}
function! neocomplete#head_match(checkstr, headstr) abort "{{{
let checkstr = &ignorecase ?
\ tolower(a:checkstr) : a:checkstr
let headstr = &ignorecase ?
\ tolower(a:headstr) : a:headstr
return stridx(checkstr, headstr) == 0
endfunction"}}}
function! neocomplete#get_source_filetypes(filetype) abort "{{{
return neocomplete#helper#get_source_filetypes(a:filetype)
endfunction"}}}
function! neocomplete#escape_match(str) abort "{{{
return escape(a:str, '~"*\.^$[]')
endfunction"}}}
function! neocomplete#get_context_filetype(...) abort "{{{
let neocomplete = exists('b:neocomplete') ?
\ b:neocomplete : neocomplete#get_current_neocomplete()
if a:0 != 0 || mode() !=# 'i' ||
\ neocomplete.context_filetype == ''
call neocomplete#context_filetype#set()
endif
return neocomplete.context_filetype
endfunction"}}}
function! neocomplete#print_debug(expr) abort "{{{
if g:neocomplete#enable_debug
echomsg string(a:expr)
endif
endfunction"}}}
function! neocomplete#get_data_directory() abort "{{{
let g:neocomplete#data_directory =
\ get(g:, 'neocomplete#data_directory',
\ ($XDG_CACHE_HOME != '' ?
\ $XDG_CACHE_HOME . '/neocomplete' : '~/.cache/neocomplete'))
let directory = neocomplete#util#substitute_path_separator(
\ neocomplete#util#expand(g:neocomplete#data_directory))
if !isdirectory(directory)
if neocomplete#util#is_sudo()
call neocomplete#print_error(printf(
\ 'Cannot create Directory "%s" in sudo session.', directory))
else
call mkdir(directory, 'p')
endif
endif
return directory
endfunction"}}}
function! neocomplete#complete_check() abort "{{{
return neocomplete#helper#complete_check()
endfunction"}}}
function! neocomplete#skip_next_complete() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.skip_next_complete = 1
endfunction"}}}
function! neocomplete#get_default_matchers() abort "{{{
return map(copy(neocomplete#get_current_neocomplete().default_matchers),
\ 'v:val.name')
endfunction"}}}
function! neocomplete#set_default_matchers(matchers) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.default_matchers = neocomplete#init#_filters(
\ neocomplete#util#convert2list(a:matchers))
endfunction"}}}
function! neocomplete#set_dictionary_helper(variable, keys, value) abort "{{{
return neocomplete#util#set_dictionary_helper(
\ a:variable, a:keys, a:value)
endfunction"}}}
function! neocomplete#disable_default_dictionary(variable) abort "{{{
return neocomplete#util#disable_default_dictionary(a:variable)
endfunction"}}}
function! neocomplete#filetype_complete(arglead, cmdline, cursorpos) abort "{{{
return neocomplete#helper#filetype_complete(a:arglead, a:cmdline, a:cursorpos)
endfunction"}}}
"}}}
" Key mapping functions. "{{{
function! neocomplete#smart_close_popup() abort
return neocomplete#mappings#smart_close_popup()
endfunction
function! neocomplete#close_popup() abort
return neocomplete#mappings#close_popup()
endfunction
function! neocomplete#cancel_popup() abort
return neocomplete#mappings#cancel_popup()
endfunction
function! neocomplete#undo_completion() abort
return neocomplete#mappings#undo_completion()
endfunction
function! neocomplete#complete_common_string() abort
return neocomplete#mappings#complete_common_string()
endfunction
function! neocomplete#start_manual_complete(...) abort
return call('neocomplete#mappings#start_manual_complete', a:000)
endfunction
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,276 @@
"=============================================================================
" FILE: async_cache.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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 condition
"
" 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! s:main(argv) abort "{{{
" args: funcname, outputname filename pattern_file_name mark minlen fileencoding
let [funcname, outputname, filename, pattern_file_name, mark, minlen, fileencoding]
\ = a:argv
if funcname ==# 'load_from_file'
let keyword_list = s:load_from_file(
\ filename, pattern_file_name, mark, minlen, fileencoding, 1)
let string = '{' . escape(string(keyword_list)[1 : -2], '\\') . '}'
else
let keyword_list = s:load_from_tags(
\ filename, pattern_file_name, mark, minlen, fileencoding)
let string = string(keyword_list)
endif
if empty(keyword_list)
return
endif
" For neocomplete.
" Output cache.
call writefile([string], outputname)
endfunction"}}}
function! s:load_from_file(filename, pattern_file_name, mark, minlen, fileencoding, is_string) abort "{{{
if !filereadable(a:filename)
" File not found.
return []
endif
let lines = readfile(a:filename)
if a:fileencoding !=# &encoding
let lines = map(lines, 's:iconv(v:val, a:fileencoding, &encoding)')
endif
let pattern = get(readfile(a:pattern_file_name), 0, '\h\w*')
let pattern2 = '^\%('.pattern.'\m\)'
let keyword_list = []
let dup_check = {}
for line in lines "{{{
let match = match(line, pattern)
while match >= 0 "{{{
let match_str = matchstr(line, pattern2, match)
if !has_key(dup_check, match_str) && len(match_str) >= a:minlen
" Append list.
call add(keyword_list, match_str)
let dup_check[match_str] = 1
endif
if match_str == ''
break
endif
let match += len(match_str)
let match = match(line, pattern, match)
endwhile"}}}
endfor"}}}
if !a:is_string
call map(keyword_list, "{'word' : match_str}")
endif
return keyword_list
endfunction"}}}
function! s:load_from_tags(filename, pattern_file_name, mark, minlen, fileencoding) abort "{{{
let keyword_lists = []
let dup_check = {}
let [tags_file_name, filter_pattern] =
\ readfile(a:pattern_file_name)[1 : 2]
if tags_file_name !=# '$dummy$'
" Check output.
let tags_list = []
let i = 0
while i < 2
if filereadable(tags_file_name)
" Use filename.
let tags_list = map(readfile(tags_file_name),
\ 's:iconv(v:val, a:fileencoding, &encoding)')
break
endif
sleep 500m
let i += 1
endwhile
else
if !filereadable(a:filename)
return []
endif
" Use filename.
let tags_list = map(readfile(a:filename),
\ 's:iconv(v:val, a:fileencoding, &encoding)')
endif
if empty(tags_list)
return s:load_from_file(a:filename, a:pattern_file_name,
\ a:mark, a:minlen, a:fileencoding, 0)
endif
for line in tags_list
let tag = split(substitute(line, "\<CR>", '', 'g'), '\t', 1)
" Add keywords.
if line =~ '^!' || len(tag) < 3 || len(tag[0]) < a:minlen
\ || has_key(dup_check, tag[0])
continue
endif
let opt = join(tag[2:], "\<TAB>")
let cmd = matchstr(opt, '.*/;"')
let option = {
\ 'cmd' : substitute(substitute(substitute(cmd,
\'^\%([/?]\^\?\)\?\s*\|\%(\$\?[/?]\)\?;"$', '', 'g'),
\ '\\\\', '\\', 'g'), '\\/', '/', 'g'),
\ 'kind' : ''
\}
if option.cmd =~ '\d\+'
let option.cmd = tag[0]
endif
for opt in split(opt[len(cmd):], '\t', 1)
let key = matchstr(opt, '^\h\w*\ze:')
if key == ''
let option['kind'] = opt
else
let option[key] = matchstr(opt, '^\h\w*:\zs.*')
endif
endfor
if has_key(option, 'file')
\ || (has_key(option, 'access') && option.access != 'public')
continue
endif
let abbr = has_key(option, 'signature')? tag[0] . option.signature :
\ (option['kind'] == 'd' || option['cmd'] == '') ?
\ tag[0] : option['cmd']
let abbr = substitute(abbr, '\s\+', ' ', 'g')
" Substitute "namespace foobar" to "foobar <namespace>".
let abbr = substitute(abbr,
\'^\(namespace\|class\|struct\|enum\|union\)\s\+\(.*\)$',
\'\2 <\1>', '')
" Substitute typedef.
let abbr = substitute(abbr,
\'^typedef\s\+\(.*\)\s\+\(\h\w*\%(::\w*\)*\);\?$',
\'\2 <typedef \1>', 'g')
" Substitute extends and implements.
let abbr = substitute(abbr,
\'\<\%(extends\|implements\)\s\+\S\+\>', '', '')
" Substitute marker.
let abbr = substitute(abbr, '"\s*{{{', '', '')
let keyword = {
\ 'word' : tag[0], 'abbr' : abbr, 'menu' : '',
\ 'kind' : option['kind'],
\ }
if has_key(option, 'struct')
let keyword.menu = option.struct
elseif has_key(option, 'class')
let keyword.menu = option.class
elseif has_key(option, 'enum')
let keyword.menu = option.enum
elseif has_key(option, 'union')
let keyword.menu = option.union
endif
call add(keyword_lists, keyword)
let dup_check[tag[0]] = 1
endfor"}}}
if filter_pattern != ''
call filter(keyword_lists, filter_pattern)
endif
return keyword_lists
endfunction"}}}
function! s:truncate(str, width) abort "{{{
" Original function is from mattn.
" http://github.com/mattn/googlereader-vim/tree/master
if a:str =~# '^[\x00-\x7f]*$'
return len(a:str) < a:width ?
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
endif
let ret = a:str
let width = strdisplaywidth(a:str)
if width > a:width
let ret = s:strwidthpart(ret, a:width)
let width = strdisplaywidth(ret)
endif
if width < a:width
let ret .= repeat(' ', a:width - width)
endif
return ret
endfunction"}}}
function! s:strwidthpart(str, width) abort "{{{
let ret = a:str
let width = strdisplaywidth(a:str)
while width > a:width
let char = matchstr(ret, '.$')
let ret = ret[: -1 - len(char)]
let width -= strwidth(char)
endwhile
return ret
endfunction"}}}
function! s:iconv(expr, from, to) abort
if a:from == '' || a:to == '' || a:from ==? a:to
return a:expr
endif
let result = iconv(a:expr, a:from, a:to)
return result != '' ? result : a:expr
endfunction
if argc() == 7 &&
\ (argv(0) ==# 'load_from_file' || argv(0) ==# 'load_from_tags')
try
call s:main(argv())
catch
call writefile([v:throwpoint, v:exception],
\ fnamemodify(argv(1), ':h:h').'/async_error_log')
endtry
qall!
else
function! neocomplete#async_cache#main(argv) abort "{{{
call s:main(a:argv)
endfunction"}}}
endif
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,298 @@
"=============================================================================
" FILE: cache.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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 conditionneocomplete#cache#
"
" 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
let s:Cache = neocomplete#util#get_vital().import('System.Cache.Deprecated')
" Cache loader.
function! neocomplete#cache#load_from_cache(cache_dir, filename, ...) abort "{{{
let is_string = get(a:000, 0, 0)
try
" Note: For neocomplete.
let list = []
if is_string
lua << EOF
do
local ret = vim.eval('list')
local list = {}
for line in io.lines(vim.eval(
'neocomplete#cache#encode_name(a:cache_dir, a:filename)')) do
list = (loadstring) and loadstring('return ' .. line)()
or load('return ' .. line)()
end
for i = 1, #list do
ret:add(list[i])
end
end
EOF
else
let list = eval(get(neocomplete#cache#readfile(
\ a:cache_dir, a:filename), 0, '[]'))
endif
if !empty(list) && is_string && type(list[0]) != type('')
" Type check.
throw 'Type error'
endif
return list
catch
" echomsg string(v:errmsg)
" echomsg string(v:exception)
" Delete old cache file.
let cache_name =
\ neocomplete#cache#encode_name(a:cache_dir, a:filename)
if filereadable(cache_name)
call delete(cache_name)
endif
return []
endtry
endfunction"}}}
" New cache loader.
function! neocomplete#cache#check_cache(cache_dir, key, async_cache_dictionary, keyword_cache, is_string) abort "{{{
if !has_key(a:async_cache_dictionary, a:key)
return
endif
let cache_list = a:async_cache_dictionary[a:key]
if !has_key(a:keyword_cache, a:key)
let a:keyword_cache[a:key] = []
endif
for cache in filter(copy(cache_list), 'filereadable(v:val.cachename)')
let a:keyword_cache[a:key] += neocomplete#cache#load_from_cache(
\ a:cache_dir, cache.filename, a:is_string)
endfor
call filter(cache_list, '!filereadable(v:val.cachename)')
if empty(cache_list)
" Delete from dictionary.
call remove(a:async_cache_dictionary, a:key)
return
endif
endfunction"}}}
" For buffer source cache loader.
function! neocomplete#cache#get_cache_list(cache_dir, async_cache_list) abort "{{{
let cache_list = a:async_cache_list
let loaded_keywords = []
let loaded = 0
for cache in filter(copy(cache_list), 'filereadable(v:val.cachename)')
let loaded = 1
let loaded_keywords = neocomplete#cache#load_from_cache(
\ a:cache_dir, cache.filename, 1)
endfor
call filter(cache_list, '!filereadable(v:val.cachename)')
return [loaded, loaded_keywords]
endfunction"}}}
function! neocomplete#cache#save_cache(cache_dir, filename, keyword_list) abort "{{{
if neocomplete#util#is_sudo()
return
endif
" Output cache.
let string = substitute(substitute(substitute(
\ string(a:keyword_list), '^[', '{', ''),
\ ']$', '}', ''), '\\', '\\\\', 'g')
call neocomplete#cache#writefile(
\ a:cache_dir, a:filename, [string])
endfunction"}}}
" Cache helper.
function! neocomplete#cache#getfilename(cache_dir, filename) abort "{{{
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.getfilename(cache_dir, a:filename)
endfunction"}}}
function! neocomplete#cache#filereadable(cache_dir, filename) abort "{{{
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.filereadable(cache_dir, a:filename)
endfunction"}}}
function! neocomplete#cache#readfile(cache_dir, filename) abort "{{{
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.readfile(cache_dir, a:filename)
endfunction"}}}
function! neocomplete#cache#writefile(cache_dir, filename, list) abort "{{{
if neocomplete#util#is_sudo()
return
endif
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.writefile(cache_dir, a:filename, a:list)
endfunction"}}}
function! neocomplete#cache#encode_name(cache_dir, filename) abort
" Check cache directory.
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.getfilename(cache_dir, a:filename)
endfunction
function! neocomplete#cache#check_old_cache(cache_dir, filename) abort "{{{
let cache_dir = neocomplete#get_data_directory() . '/' . a:cache_dir
return s:Cache.check_old_cache(cache_dir, a:filename)
endfunction"}}}
function! neocomplete#cache#make_directory(directory) abort "{{{
let directory =
\ neocomplete#get_data_directory() .'/'.a:directory
if !isdirectory(directory)
if neocomplete#util#is_sudo()
call neocomplete#print_error(printf(
\ 'Cannot create Directory "%s" in sudo session.', directory))
else
call mkdir(directory, 'p')
endif
endif
endfunction"}}}
let s:sdir = neocomplete#util#substitute_path_separator(
\ fnamemodify(expand('<sfile>'), ':p:h'))
function! neocomplete#cache#async_load_from_file(cache_dir, filename, pattern, mark) abort "{{{
if !neocomplete#cache#check_old_cache(a:cache_dir, a:filename)
\ || neocomplete#util#is_sudo()
return neocomplete#cache#encode_name(a:cache_dir, a:filename)
endif
let pattern_file_name =
\ neocomplete#cache#encode_name('keyword_patterns', a:filename)
let cache_name =
\ neocomplete#cache#encode_name(a:cache_dir, a:filename)
" Create pattern file.
call neocomplete#cache#writefile(
\ 'keyword_patterns', a:filename, [a:pattern])
" args: funcname, outputname, filename pattern mark
" minlen maxlen encoding
let fileencoding =
\ &fileencoding == '' ? &encoding : &fileencoding
let argv = [
\ 'load_from_file', cache_name, a:filename, pattern_file_name, a:mark,
\ g:neocomplete#min_keyword_length, fileencoding
\ ]
return s:async_load(argv, a:cache_dir, a:filename)
endfunction"}}}
function! neocomplete#cache#async_load_from_tags(cache_dir, filename, filetype, pattern, mark) abort "{{{
if !neocomplete#cache#check_old_cache(a:cache_dir, a:filename)
\ || neocomplete#util#is_sudo()
return neocomplete#cache#encode_name(a:cache_dir, a:filename)
endif
let cache_name =
\ neocomplete#cache#encode_name(a:cache_dir, a:filename)
let pattern_file_name =
\ neocomplete#cache#encode_name('tags_patterns', a:filename)
let tags_file_name = '$dummy$'
let filter_pattern =
\ get(g:neocomplete#tags_filter_patterns, a:filetype, '')
call neocomplete#cache#writefile('tags_patterns', a:filename,
\ [a:pattern, tags_file_name, filter_pattern, a:filetype])
" args: funcname, outputname, filename
" pattern mark minlen encoding
let fileencoding = &fileencoding == '' ? &encoding : &fileencoding
let argv = [
\ 'load_from_tags', cache_name, a:filename, pattern_file_name, a:mark,
\ g:neocomplete#min_keyword_length, fileencoding
\ ]
return s:async_load(argv, a:cache_dir, a:filename)
endfunction"}}}
function! s:async_load(argv, cache_dir, filename) abort "{{{
let vim_path = s:search_vim_path()
if vim_path == '' || !executable(vim_path)
call neocomplete#async_cache#main(a:argv)
else
let args = [vim_path, '-u', 'NONE', '-i', 'NONE', '-n',
\ '-N', '-S', s:sdir.'/async_cache.vim']
\ + a:argv
call vimproc#system_bg(args)
" call vimproc#system(args)
" call system(join(args))
endif
return neocomplete#cache#encode_name(a:cache_dir, a:filename)
endfunction"}}}
function! s:search_vim_path() abort "{{{
if exists('s:vim_path')
return s:vim_path
endif
if !neocomplete#has_vimproc()
return ''
endif
let paths = vimproc#get_command_name(v:progname, $PATH, -1)
if empty(paths)
if has('gui_macvim')
" MacVim check.
if !executable('/Applications/MacVim.app/Contents/MacOS/Vim')
call neocomplete#print_error(
\ 'You installed MacVim in not default directory!'.
\ ' You must add MacVim installed path in $PATH.')
let g:neocomplete#use_vimproc = 0
return ''
endif
let s:vim_path = '/Applications/MacVim.app/Contents/MacOS/Vim'
else
call neocomplete#print_error(
\ printf('Vim path : "%s" is not found.'.
\ ' You must add "%s" installed path in $PATH.',
\ v:progname, v:progname))
let g:neocomplete#use_vimproc = 0
return ''
endif
else
let base_path = neocomplete#util#substitute_path_separator(
\ fnamemodify(paths[0], ':p:h'))
let s:vim_path = base_path . '/vim'
if !executable(s:vim_path) && neocomplete#util#is_mac()
" Note: Search "Vim" instead of vim.
let s:vim_path = base_path. '/Vim'
endif
endif
return s:vim_path
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,100 @@
"=============================================================================
" FILE: commands.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#commands#_initialize() abort "{{{
command! -nargs=1 NeoCompleteAutoCompletionLength
\ call s:set_auto_completion_length(<args>)
endfunction"}}}
function! neocomplete#commands#_toggle_lock() abort "{{{
if !neocomplete#is_enabled()
call neocomplete#init#enable()
return
endif
if neocomplete#get_current_neocomplete().lock
echo 'neocomplete is unlocked!'
call neocomplete#commands#_unlock()
else
echo 'neocomplete is locked!'
call neocomplete#commands#_lock()
endif
endfunction"}}}
function! neocomplete#commands#_lock() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.lock = 1
endfunction"}}}
function! neocomplete#commands#_unlock() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.lock = 0
endfunction"}}}
function! neocomplete#commands#_clean() abort "{{{
" Delete cache files.
let data_directory = neocomplete#get_data_directory()
for directory in filter(neocomplete#util#glob(
\ data_directory.'/*'), 'isdirectory(v:val)')
if has('patch-7.4.1120')
call delete(data_directory, 'rf')
else
for filename in filter(neocomplete#util#glob(directory.'/*'),
\ '!isdirectory(v:val)')
call delete(filename)
endfor
endif
endfor
echo 'Cleaned cache files in: ' . data_directory
endfunction"}}}
function! neocomplete#commands#_set_file_type(filetype) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.context_filetype = a:filetype
endfunction"}}}
function! s:rand(max) abort "{{{
if !has('reltime')
" Same value.
return 0
endif
let time = reltime()[1]
return (time < 0 ? -time : time)% (a:max + 1)
endfunction"}}}
function! s:set_auto_completion_length(len) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.completion_length = a:len
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,348 @@
"=============================================================================
" FILE: complete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#complete#_get_results(cur_text, ...) abort "{{{
call neocomplete#print_debug('start get_complete_sources')
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.start_time = reltime()
" Comment check.
let neocomplete.within_comment =
\ neocomplete#helper#get_syn_name(1) ==# 'Comment'
let complete_sources = call(
\ 'neocomplete#complete#_set_results_pos', [a:cur_text] + a:000)
if empty(complete_sources)
call neocomplete#print_debug('Skipped.')
return []
endif
if neocomplete#is_auto_complete()
let complete_pos =
\ neocomplete#complete#_get_complete_pos(complete_sources)
call neocomplete#complete#_set_previous_position(a:cur_text, complete_pos)
endif
call neocomplete#complete#_set_results_words(complete_sources)
return filter(copy(complete_sources),
\ '!empty(v:val.neocomplete__context.candidates)')
endfunction"}}}
function! neocomplete#complete#_get_complete_pos(sources) abort "{{{
if empty(a:sources)
return -1
endif
return min([col('.')] + map(copy(a:sources),
\ 'v:val.neocomplete__context.complete_pos'))
endfunction"}}}
function! neocomplete#complete#_get_words(sources, complete_pos, complete_str) abort "{{{
let frequencies = neocomplete#variables#get_frequencies()
if exists('*neocomplete#sources#buffer#get_frequencies')
let frequencies = extend(copy(
\ neocomplete#sources#buffer#get_frequencies()),
\ frequencies)
endif
" Append prefix.
let candidates = []
let len_words = 0
for source in sort(filter(deepcopy(a:sources),
\ '!empty(v:val.neocomplete__context.candidates)'),
\ 's:compare_source_rank')
let context = source.neocomplete__context
let words = type(context.candidates[0]) == type('') ?
\ map(copy(context.candidates), "{'word': v:val}") :
\ deepcopy(context.candidates)
let context.candidates = words
call neocomplete#helper#call_hook(
\ source, 'on_post_filter', {})
if context.complete_pos > a:complete_pos
let prefix = a:complete_str[: context.complete_pos
\ - a:complete_pos - 1]
" Fix complete position.
let context.complete_pos = a:complete_pos
let context.complete_str = prefix
for candidate in words
let candidate.word = prefix . candidate.word
endfor
endif
lua << EOF
do
local frequencies = vim.eval('frequencies')
local candidates = vim.eval('words')
for i = 0, #candidates-1 do
if frequencies[candidates[i].word] ~= nil then
candidates[i].rank = frequencies[candidates[i].word]
end
end
end
EOF
let words = neocomplete#helper#call_filters(
\ source.neocomplete__sorters, source, {})
if empty(words)
continue
endif
if source.max_candidates > 0
let words = words[: len(source.max_candidates)-1]
endif
let words = neocomplete#helper#call_filters(
\ source.neocomplete__converters, source, {})
if empty(words)
continue
endif
" Set default menu.
if get(words[0], 'menu', '') !~ '^\[.*\'
call s:set_default_menu(words, source)
endif
let candidates += words
let len_words += len(words)
if g:neocomplete#max_list > 0
\ && len_words > g:neocomplete#max_list
break
endif
if neocomplete#complete_check()
return []
endif
endfor
call filter(candidates, 'v:val.word !=# a:complete_str')
if g:neocomplete#max_list > 0
let candidates = candidates[: g:neocomplete#max_list]
endif
" Check dup and set icase.
let icase = g:neocomplete#enable_ignore_case &&
\ !((g:neocomplete#enable_smart_case
\ || g:neocomplete#enable_camel_case) && a:complete_str =~ '\u')
if icase
for candidate in candidates
let candidate.icase = 1
endfor
endif
if neocomplete#complete_check()
return []
endif
return candidates
endfunction"}}}
function! neocomplete#complete#_set_results_pos(cur_text, ...) abort "{{{
" Initialize sources.
let neocomplete = neocomplete#get_current_neocomplete()
let filetype = neocomplete#get_context_filetype()
let sources = (a:0 > 0) ? a:1 :
\ (filetype ==# neocomplete.sources_filetype) ?
\ neocomplete.sources : neocomplete#helper#get_sources_list()
let pos = winsaveview()
" Try source completion. "{{{
let complete_sources = []
for source in filter(values(sources),
\ 'neocomplete#helper#is_enabled_source(v:val, filetype)')
if !source.loaded
call neocomplete#helper#call_hook(source, 'on_init', {})
let source.loaded = 1
endif
let context = source.neocomplete__context
let context.input = a:cur_text
let context.filetype = filetype
let context.filetypes = neocomplete#context_filetype#filetypes()
try
let complete_pos = s:use_previous_result(source, context) ?
\ context.prev_complete_pos :
\ has_key(source, 'get_complete_position') ?
\ source.get_complete_position(context) :
\ neocomplete#helper#match_word(context.input,
\ neocomplete#get_keyword_pattern_end(filetype, source.name))[0]
catch
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
call neocomplete#print_error(
\ 'Error occurred in source''s get_complete_position()!')
call neocomplete#print_error(
\ 'Source name is ' . source.name)
return complete_sources
finally
if winsaveview() != pos
call winrestview(pos)
endif
endtry
if complete_pos < 0
let context.complete_pos = -1
let context.complete_str = ''
continue
endif
let complete_str = context.input[complete_pos :]
if neocomplete#is_auto_complete() &&
\ (source.input_pattern == '' ||
\ context.input !~# '\%(' . source.input_pattern.'\m\)$') &&
\ len(complete_str) < source.min_pattern_length
" Skip.
let context.complete_pos = -1
let context.complete_str = ''
continue
endif
let context.complete_pos = complete_pos
let context.complete_str = complete_str
call add(complete_sources, source)
endfor
"}}}
return complete_sources
endfunction"}}}
function! neocomplete#complete#_set_results_words(sources) abort "{{{
" Try source completion.
" Save options.
let ignorecase_save = &ignorecase
let pos = winsaveview()
try
for source in a:sources
if neocomplete#complete_check()
return
endif
let context = source.neocomplete__context
let &ignorecase = (g:neocomplete#enable_smart_case
\ || g:neocomplete#enable_camel_case) ?
\ context.complete_str !~ '\u'
\ : g:neocomplete#enable_ignore_case
if s:use_previous_result(source, context)
" Use previous candidates.
let context.candidates = deepcopy(context.prev_candidates)
else
try
let context.candidates = source.gather_candidates(context)
catch
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
call neocomplete#print_error(
\ 'Source name is ' . source.name)
call neocomplete#print_error(
\ 'Error occurred in source''s gather_candidates()!')
return
finally
if winsaveview() != pos
call winrestview(pos)
endif
endtry
let context.prev_line = context.input
let context.prev_candidates = copy(context.candidates)
let context.prev_complete_pos = context.complete_pos
endif
if !empty(context.candidates)
let matchers = empty(source.neocomplete__matchers) ?
\ neocomplete#get_current_neocomplete().default_matchers
\ : source.neocomplete__matchers
let context.candidates = neocomplete#helper#call_filters(
\ matchers, source, {})
endif
call neocomplete#print_debug(source.name)
endfor
finally
let &ignorecase = ignorecase_save
endtry
endfunction"}}}
function! neocomplete#complete#_check_previous_position(cur_text, complete_pos) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
return a:complete_pos == neocomplete.old_complete_pos
\ && line('.') == neocomplete.old_linenr
\ && a:cur_text ==# neocomplete.old_cur_text
endfunction"}}}
function! neocomplete#complete#_set_previous_position(cur_text, complete_pos) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.old_complete_pos = a:complete_pos
let neocomplete.old_linenr = line('.')
let neocomplete.old_cur_text = a:cur_text
endfunction"}}}
" Source rank order. "{{{
function! s:compare_source_rank(i1, i2) abort
return a:i2.rank - a:i1.rank
endfunction"}}}
function! s:set_default_menu(words, source) abort "{{{
lua << EOF
do
local candidates = vim.eval('a:words')
local mark = vim.eval('a:source.mark') .. ' '
for i = 0, #candidates-1 do
candidates[i].menu = mark .. (candidates[i].menu ~= nil and
candidates[i].menu or '')
end
end
EOF
endfunction"}}}
function! s:use_previous_result(source, context) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
return !a:source.is_volatile
\ && substitute(a:context.input, '\k\+$', '', '')
\ ==# substitute(a:context.prev_line, '\k\+$', '', '')
\ && stridx(a:context.input, a:context.prev_line) == 0
\ && !empty(a:context.prev_candidates)
\ && line('.') == neocomplete.old_linenr
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,67 @@
"=============================================================================
" FILE: context_filetype.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" context_filetype.vim installation check.
if !exists('s:exists_context_filetype')
silent! call context_filetype#version()
let s:exists_context_filetype = exists('*context_filetype#version')
endif
function! neocomplete#context_filetype#set() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let context_filetype =
\ s:exists_context_filetype ?
\ context_filetype#get_filetype() : &filetype
if context_filetype == ''
let context_filetype = 'nothing'
endif
let neocomplete.context_filetype = context_filetype
let neocomplete.context_filetypes = s:exists_context_filetype ?
\ context_filetype#get_filetypes(context_filetype) :
\ [context_filetype] + split(context_filetype, '\.')
return neocomplete.context_filetype
endfunction"}}}
function! neocomplete#context_filetype#get(filetype) abort "{{{
let context_filetype =
\ s:exists_context_filetype ?
\ context_filetype#get_filetype(a:filetype) : a:filetype
if context_filetype == ''
let context_filetype = 'nothing'
endif
return context_filetype
endfunction"}}}
function! neocomplete#context_filetype#filetypes() abort "{{{
return copy(neocomplete#get_current_neocomplete().context_filetypes)
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,54 @@
"=============================================================================
" FILE: custom.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#custom#get() abort "{{{
if !exists('s:custom')
let s:custom = {}
let s:custom.sources = {}
let s:custom.sources._ = {}
endif
return s:custom
endfunction"}}}
function! neocomplete#custom#source(source_name, option_name, value) abort "{{{
let custom_sources = neocomplete#custom#get().sources
for key in split(a:source_name, '\s*,\s*')
if !has_key(custom_sources, key)
let custom_sources[key] = {}
endif
let custom_sources[key][a:option_name] = a:value
endfor
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,48 @@
"=============================================================================
" FILE: filters.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#fuzzy_escape(string) abort "{{{
" Escape string for lua regexp.
let string = substitute(neocomplete#filters#escape(a:string),
\ '\w', '\0.*', 'g')
if g:neocomplete#enable_camel_case && string =~ '\u'
let string = substitute(string, '\l', '[\0\u\0\E]', 'g')
endif
return string
endfunction"}}}
function! neocomplete#filters#escape(string) abort "{{{
" Escape string for lua regexp.
return substitute(a:string,
\ '[%\[\]().*+?^$-]', '%\0', 'g')
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,66 @@
"=============================================================================
" FILE: converter_abbr.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_abbr#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_abbr',
\ 'description' : 'abbreviate abbr converter',
\}
function! s:converter.filter(context) abort "{{{
if g:neocomplete#max_keyword_width < 0
return a:context.candidates
endif
lua << EOF
do
local candidates = vim.eval('a:context.candidates')
local max = vim.eval('g:neocomplete#max_keyword_width')
for i = 0, #candidates-1 do
local abbr = candidates[i].abbr == nil and
candidates[i].word or candidates[i].abbr
if string.len(abbr) > max then
vim.command("let a:context.candidates[".. i .."].abbr = neocomplete#util#truncate_smart("..
"get(a:context.candidates[".. i .."], 'abbr', " ..
"a:context.candidates[".. i .."].word), g:neocomplete#max_keyword_width," ..
"g:neocomplete#max_keyword_width/2, '..')")
end
end
end
EOF
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,53 @@
"=============================================================================
" FILE: converter_add_paren.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_add_paren#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_add_paren',
\ 'description' : 'add parenthesis if needed',
\}
function! s:converter.filter(context) abort "{{{
for candidate in filter(copy(a:context.candidates), "
\ v:val.word !~ '()\\?$' &&
\ (get(v:val, 'abbr', '') =~ '(.*)'
\ || get(v:val, 'info', '') =~ '(.*)')
\ ")
let candidate.word .= '('
endfor
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,80 @@
"=============================================================================
" FILE: converter_case.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_case#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_case',
\ 'description' : 'case converter',
\}
function! s:converter.filter(context) abort "{{{
if !neocomplete#is_text_mode() && !neocomplete#within_comment()
return a:context.candidates
endif
if a:context.complete_str =~ '^\l\{3}$'
for candidate in s:get_convert_candidates(a:context.candidates)
let candidate.word = tolower(candidate.word)
if has_key(candidate, 'abbr')
let candidate.abbr = tolower(candidate.abbr)
endif
endfor
elseif a:context.complete_str =~ '^\u\{3}$'
for candidate in s:get_convert_candidates(a:context.candidates)
let candidate.word = toupper(candidate.word)
if has_key(candidate, 'abbr')
let candidate.abbr = toupper(candidate.abbr)
endif
endfor
elseif a:context.complete_str =~ '^\u\l\+$'
for candidate in s:get_convert_candidates(a:context.candidates)
let candidate.word = toupper(candidate.word[0]).
\ candidate.word[1:]
if has_key(candidate, 'abbr')
let candidate.abbr = toupper(candidate.abbr[0]).
\ tolower(candidate.abbr[1:])
endif
endfor
endif
return a:context.candidates
endfunction"}}}
function! s:get_convert_candidates(candidates) abort
return filter(copy(a:candidates),
\ "get(v:val, 'neocomplete__convertable', 1)
\ && v:val.word =~ '^[a-zA-Z0-9_''-]\\+$'")
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,114 @@
"=============================================================================
" FILE: converter_delimiter.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_delimiter#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_delimiter',
\ 'description' : 'delimiter converter',
\}
" @vimlint(EVL102, 1, l:delim_cnt)
function! s:converter.filter(context) abort "{{{
if g:neocomplete#max_keyword_width < 0
return a:context.candidates
endif
" Delimiter check.
for delimiter in get(g:neocomplete#delimiter_patterns,
\ a:context.filetype, [])
" Count match.
let delim_cnt = 0
let delimiter_vim = neocomplete#util#escape_pattern(delimiter)
let matchend = matchend(a:context.complete_str, delimiter_vim)
while matchend >= 0
let matchend = matchend(a:context.complete_str,
\ delimiter_vim, matchend)
let delim_cnt += 1
endwhile
lua << EOF
do
local candidates = vim.eval('a:context.candidates')
local pattern = vim.eval('neocomplete#filters#escape(delimiter)')..'.'
for i = 0, #candidates-1 do
if string.find(candidates[i].word, pattern, 1) ~= nil and (
not candidates[i].abbr or
string.gsub(candidates[i].word, '%([^)]*%)?', '()')
== string.gsub(candidates[i].abbr, '%([^)]*%)?', '()')) then
vim.command('call s:process_delimiter(a:context, '..
'a:context.candidates['.. i ..
'], delimiter_vim, delim_cnt)')
end
end
end
EOF
endfor
return a:context.candidates
endfunction"}}}
" @vimlint(EVL102, 0, l:delim_cnt)
function! s:process_delimiter(context, candidate, delimiter, delim_cnt) abort
let candidate = a:candidate
let split_list = split(candidate.word, a:delimiter.'\ze.', 1)
let delimiter_sub = substitute(
\ a:delimiter, '\\\(.\)', '\1', 'g')
let candidate.abbr = join(
\ split(get(candidate, 'abbr', candidate.word),
\ a:delimiter.'\ze.', 1)[ : a:delim_cnt],
\ delimiter_sub)
let candidate.word = join(split_list[ : a:delim_cnt], delimiter_sub)
if g:neocomplete#max_keyword_width >= 0
\ && len(candidate.abbr) > g:neocomplete#max_keyword_width
let candidate.abbr = substitute(candidate.abbr,
\ '\(\h\)\w*'.a:delimiter, '\1'.delimiter_sub, 'g')
endif
if a:delim_cnt+1 < len(split_list)
let candidate.abbr .= delimiter_sub . '~'
let candidate.dup = 0
if g:neocomplete#enable_auto_delimiter
let candidate.word .= delimiter_sub
endif
endif
" Clear previous result.
let a:context.prev_candidates = []
let a:context.prev_complete_pos = -1
let a:context.prev_line = ''
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,49 @@
"=============================================================================
" FILE: converter_disable_abbr.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_disable_abbr#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_disable_abbr',
\ 'description' : 'disable abbr converter',
\}
function! s:converter.filter(context) abort "{{{
for candidate in a:context.candidates
let candidate.abbr = candidate.word
endfor
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,50 @@
"=============================================================================
" FILE: converter_remove_last_paren.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_remove_last_paren#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_remove_last_paren',
\ 'description' : 'remove last parenthesis',
\}
function! s:converter.filter(context) abort "{{{
for candidate in a:context.candidates
let candidate.word =
\ substitute(candidate.word, '[\[<({]$', '', '')
endfor
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,122 @@
"=============================================================================
" FILE: converter_overlap.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#converter_remove_overlap#define() abort "{{{
return s:converter
endfunction"}}}
let s:converter = {
\ 'name' : 'converter_remove_overlap',
\ 'description' : 'remove overlapped characters',
\}
function! s:converter.filter(context) abort "{{{
let next = matchstr(getline('.')[
\ len(neocomplete#helper#get_cur_text()) :], '^\S\+')
if next == ''
return a:context.candidates
endif
let candidates = []
for candidate in a:context.candidates
let overlapped_len = neocomplete#filters#
\converter_remove_overlap#length(candidate.word, next)
if overlapped_len > 0
if !has_key(candidate, 'abbr')
let candidate.abbr = candidate.word
endif
let candidate.word = candidate.word[: -overlapped_len-1]
call add(candidates, candidate)
elseif !neocomplete#is_auto_complete()
call add(candidates, candidate)
endif
endfor
if empty(candidates)
return a:context.candidates
endif
let candidates = filter(candidates,
\ 'v:val.word !=# a:context.complete_str')
return candidates
endfunction"}}}
function! neocomplete#filters#converter_remove_overlap#length(left, right) abort "{{{
if a:left == '' || a:right == ''
return 0
endif
let ret = 0
lua << EOF
do
local ret = vim.eval('ret')
local left = vim.eval('a:left')
local right = vim.eval('a:right')
local left_len = string.len(left)
local right_len = string.len(right)
if left_len > right_len then
left = string.sub(left, left_len-right_len, left_len)
elseif left_len < right_len then
right = string.sub(right, 0, left_len)
end
if left == right then
ret = math.min(left_len, right_len)
else
local length = 1
left_len = string.len(left)
while 1 do
local pattern = string.sub(left, left_len-length+1, left_len)
local pos = string.find(right, pattern, 1, 1)
if pos == nil then
break
end
length = length + pos - 1
if string.sub(left, left_len-length+1, left_len) ==
string.sub(right, 1, length) then
ret = length
length = length + 1
end
end
end
vim.command('let ret = ' .. ret)
end
EOF
return ret
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,89 @@
"=============================================================================
" FILE: matcher_fuzzy.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#matcher_fuzzy#define() abort "{{{
return s:matcher
endfunction"}}}
let s:matcher = {
\ 'name' : 'matcher_fuzzy',
\ 'description' : 'fuzzy matcher',
\}
function! s:matcher.filter(context) abort "{{{
if len(a:context.complete_str) > 10
" Mix fuzzy mode.
let len = len(a:context.complete_str)
let fuzzy_len = len - len/(1 + len/10)
let pattern =
\ neocomplete#filters#escape(
\ a:context.complete_str[: fuzzy_len-1]) .
\ neocomplete#filters#fuzzy_escape(
\ a:context.complete_str[fuzzy_len :])
else
let pattern = neocomplete#filters#fuzzy_escape(
\ a:context.complete_str)
endif
" The first letter must be matched.
let pattern = '^' . pattern
lua << EOF
do
local pattern = vim.eval('pattern')
local input = vim.eval('a:context.complete_str')
local candidates = vim.eval('a:context.candidates')
if vim.eval('&ignorecase') ~= 0 then
pattern = string.lower(pattern)
input = string.lower(input)
for i = #candidates-1, 0, -1 do
local word = vim.type(candidates[i]) == 'dict' and
string.lower(candidates[i].word) or string.lower(candidates[i])
if string.find(word, pattern, 1) == nil then
candidates[i] = nil
end
end
else
for i = #candidates-1, 0, -1 do
local word = vim.type(candidates[i]) == 'dict' and
candidates[i].word or candidates[i]
if string.find(word, pattern, 1) == nil then
candidates[i] = nil
end
end
end
end
EOF
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,72 @@
"=============================================================================
" FILE: matcher_head.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#matcher_head#define() abort "{{{
return s:matcher
endfunction"}}}
let s:matcher = {
\ 'name' : 'matcher_head',
\ 'description' : 'head matcher',
\}
function! s:matcher.filter(context) abort "{{{
lua << EOF
do
local pattern = vim.eval(
"'^' . neocomplete#filters#escape(a:context.complete_str)")
local input = vim.eval('a:context.complete_str')
local candidates = vim.eval('a:context.candidates')
if vim.eval('&ignorecase') ~= 0 then
pattern = string.lower(pattern)
for i = #candidates-1, 0, -1 do
local word = vim.type(candidates[i]) == 'dict' and
string.lower(candidates[i].word) or string.lower(candidates[i])
if string.find(word, pattern, 1) == nil then
candidates[i] = nil
end
end
else
for i = #candidates-1, 0, -1 do
local word = vim.type(candidates[i]) == 'dict' and
candidates[i].word or candidates[i]
if string.find(word, pattern, 1) == nil then
candidates[i] = nil
end
end
end
end
EOF
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,63 @@
"=============================================================================
" FILE: matcher_length.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#matcher_length#define() abort "{{{
return s:matcher
endfunction"}}}
let s:matcher = {
\ 'name' : 'matcher_length',
\ 'description' : 'input length matcher',
\}
function! s:matcher.filter(context) abort "{{{
if empty(a:context.candidates)
return []
endif
lua << EOF
do
local candidates = vim.eval('a:context.candidates')
local len = string.len(vim.eval('a:context.complete_str'))
for i = #candidates-1, 0, -1 do
local word = vim.type(candidates[i]) == 'dict' and
candidates[i].word or candidates[i]
if string.len(word) <= len then
candidates[i] = nil
end
end
end
EOF
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,45 @@
"=============================================================================
" FILE: matcher_nothing.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#matcher_nothing#define() abort "{{{
return s:matcher
endfunction"}}}
let s:matcher = {
\ 'name' : 'matcher_nothing',
\ 'description' : 'input nothing matcher',
\}
function! s:matcher.filter(context) abort "{{{
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,50 @@
"=============================================================================
" FILE: sorter_filename.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#sorter_filename#define() abort "{{{
return s:sorter
endfunction"}}}
let s:sorter = {
\ 'name' : 'sorter_filename',
\ 'description' : 'sort by filename order',
\}
function! s:sorter.filter(context) abort "{{{
let dir_list = filter(copy(a:context.candidates),
\ 'v:val.action__is_directory')
let file_list = filter(copy(a:context.candidates),
\ '!v:val.action__is_directory')
return neocomplete#helper#sort_human(dir_list)
\ + neocomplete#helper#sort_human(file_list)
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,53 @@
"=============================================================================
" FILE: sorter_length.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#sorter_length#define() abort "{{{
return s:sorter
endfunction"}}}
let s:sorter = {
\ 'name' : 'sorter_length',
\ 'description' : 'sort by length order',
\}
function! s:sorter.filter(context) abort "{{{
return sort(a:context.candidates, 's:compare')
endfunction"}}}
function! s:compare(i1, i2) abort
let diff = len(a:i1.word) - len(a:i2.word)
if !diff
let diff = (a:i1.word ># a:i2.word) ? 1 : -1
endif
return diff
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,74 @@
"=============================================================================
" FILE: sorter_rank.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#sorter_rank#define() abort "{{{
return s:sorter
endfunction"}}}
let s:sorter = {
\ 'name' : 'sorter_rank',
\ 'description' : 'sort by matched rank order',
\}
function! s:sorter.filter(context) abort "{{{
lua << EOF
do
local candidates = vim.eval('a:context.candidates')
local t = {}
local input = string.lower(vim.eval('a:context.input'))
for i = 1, #candidates do
t[i] = candidates[i-1]
local ti = t[i]
-- Match position.
ti.neocomplete__match = select(1, string.find(
string.lower(ti.word), input, 1, true))
if ti.neocomplete__match == nil then
ti.neocomplete__match = string.len(ti.word)
end
if ti.rank == nil then
ti.rank = 0
end
end
table.sort(t, function(a, b)
return (a.rank == b.rank) and (a.neocomplete__match
< b.neocomplete__match) or (a.rank > b.rank)
end)
for i = 0, #candidates-1 do
candidates[i] = t[i+1]
end
end
EOF
return a:context.candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,49 @@
"=============================================================================
" FILE: sorter_word.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#filters#sorter_word#define() abort "{{{
return s:sorter
endfunction"}}}
let s:sorter = {
\ 'name' : 'sorter_word',
\ 'description' : 'sort by word order',
\}
function! s:sorter.filter(context) abort "{{{
return sort(a:context.candidates, 's:compare')
endfunction"}}}
function! s:compare(i1, i2) abort
return a:i1.word ># a:i2.word
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,367 @@
"=============================================================================
" FILE: handler.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#handler#_on_moved_i() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if neocomplete.linenr != line('.')
call neocomplete#helper#clear_result()
endif
let neocomplete.linenr = line('.')
call s:close_preview_window()
endfunction"}}}
function! neocomplete#handler#_on_insert_enter() abort "{{{
if !neocomplete#is_enabled()
return
endif
let neocomplete = neocomplete#get_current_neocomplete()
if neocomplete.linenr != line('.')
call neocomplete#helper#clear_result()
endif
let neocomplete.linenr = line('.')
if &l:foldmethod ==# 'expr' && foldlevel('.') != 0
foldopen
endif
endfunction"}}}
function! neocomplete#handler#_on_insert_leave() abort "{{{
call neocomplete#helper#clear_result()
call s:close_preview_window()
call s:make_cache_current_line()
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.cur_text = ''
endfunction"}}}
function! neocomplete#handler#_on_complete_done() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if neocomplete.event !=# 'mapping'
\ && !s:is_delimiter() && !get(neocomplete, 'refresh', 0)
call neocomplete#mappings#close_popup()
endif
" Use v:completed_item feature.
if !exists('v:completed_item') || empty(v:completed_item)
return
endif
let complete_str = v:completed_item.word
if complete_str == ''
return
endif
let frequencies = neocomplete#variables#get_frequencies()
if !has_key(frequencies, complete_str)
let frequencies[complete_str] = 20
else
let frequencies[complete_str] += 20
endif
endfunction"}}}
function! neocomplete#handler#_on_insert_char_pre() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.skip_next_complete = 0
if pumvisible() && g:neocomplete#enable_refresh_always
" Auto refresh
call feedkeys("\<Plug>(neocomplete_auto_refresh)")
endif
if neocomplete#is_cache_disabled()
return
endif
if neocomplete.old_char != ' ' && v:char == ' ' && v:count == 0
call s:make_cache_current_line()
endif
let neocomplete.old_char = v:char
endfunction"}}}
function! neocomplete#handler#_on_text_changed() abort "{{{
if neocomplete#is_cache_disabled()
return
endif
if getline('.') == ''
call s:make_cache_current_line()
endif
if !neocomplete#util#is_text_changed()
call s:indent_current_line()
endif
endfunction"}}}
function! s:complete_delay(timer) abort "{{{
let event = s:timer.event
unlet! s:timer
return s:do_auto_complete(event)
endfunction"}}}
function! neocomplete#handler#_do_auto_complete(event) abort "{{{
if s:check_in_do_auto_complete(a:event)
return
endif
if g:neocomplete#auto_complete_delay > 0 && has('timers')
\ && (!has('gui_macvim') || has('patch-8.0.95'))
if exists('s:timer')
call timer_stop(s:timer.id)
endif
if a:event !=# 'Manual'
let s:timer = { 'event': a:event }
let s:timer.id = timer_start(
\ g:neocomplete#auto_complete_delay,
\ function('s:complete_delay'))
return
endif
endif
return s:do_auto_complete(a:event)
endfunction"}}}
function! s:do_auto_complete(event) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if s:check_in_do_auto_complete(a:event)
return
endif
let neocomplete.skipped = 0
let neocomplete.event = a:event
call neocomplete#helper#clear_result()
" Set context filetype.
call neocomplete#context_filetype#set()
let cur_text = neocomplete#get_cur_text(1)
let complete_pos = -1
call neocomplete#print_debug('cur_text = ' . cur_text)
try
" Prevent infinity loop.
if s:is_skip_auto_complete(cur_text)
call neocomplete#print_debug('Skipped.')
return
endif
let complete_pos = s:check_force_omni(cur_text)
if complete_pos >= 0
return
endif
" Check multibyte input or eskk or spaces.
if cur_text =~ '^\s*$'
\ || (!neocomplete#is_eskk_enabled()
\ && neocomplete#is_multibyte_input(cur_text))
call neocomplete#print_debug('Skipped.')
return
endif
try
let neocomplete.is_auto_complete = 1
" Do prefetch.
let neocomplete.complete_sources =
\ neocomplete#complete#_get_results(cur_text)
finally
let neocomplete.is_auto_complete = 0
endtry
if empty(neocomplete.complete_sources)
call s:check_fallback(cur_text)
return
endif
" Start auto complete.
call s:complete_key(
\ "\<Plug>(neocomplete_start_auto_complete)")
finally
call neocomplete#complete#_set_previous_position(cur_text, complete_pos)
endtry
endfunction"}}}
function! s:check_in_do_auto_complete(event) abort "{{{
if neocomplete#is_locked()
\ || (a:event !=# 'InsertEnter' && mode() !=# 'i')
return 1
endif
" Detect completefunc.
if &l:completefunc != '' && &l:buftype =~ 'nofile'
return 1
endif
let neocomplete = neocomplete#get_current_neocomplete()
" Detect foldmethod.
if (&l:foldmethod ==# 'expr' || &l:foldmethod ==# 'syntax')
\ && !neocomplete.detected_foldmethod
\ && a:event !=# 'InsertEnter'
\ && line('.') > 1000
let neocomplete.detected_foldmethod = 1
call neocomplete#print_error(
\ printf('foldmethod = "%s" is detected.', &foldmethod))
redir => foldmethod
verbose setlocal foldmethod?
redir END
for msg in split(substitute(foldmethod, '\t', '', 'g'), "\n")
call neocomplete#print_error(msg)
endfor
call neocomplete#print_error(
\ 'You should disable it or install FastFold plugin.')
endif
endfunction"}}}
function! s:is_skip_auto_complete(cur_text) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if (g:neocomplete#lock_iminsert && &l:iminsert)
\ || (&l:formatoptions =~# '[tca]' && &l:textwidth > 0
\ && strdisplaywidth(a:cur_text) >= &l:textwidth)
let neocomplete.skip_next_complete = 0
return 1
endif
let skip = neocomplete.skip_next_complete
if !skip || s:is_delimiter()
return 0
endif
let neocomplete.skip_next_complete = 0
return skip
endfunction"}}}
function! s:close_preview_window() abort "{{{
if g:neocomplete#enable_auto_close_preview
\ && bufname('%') !=# '[Command Line]'
\ && winnr('$') != 1 && !&l:previewwindow
\ && !neocomplete#is_cache_disabled()
" Close preview window.
pclose!
endif
endfunction"}}}
function! s:make_cache_current_line() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if neocomplete#helper#is_enabled_source('buffer',
\ neocomplete.context_filetype)
" Caching current cache line.
call neocomplete#sources#buffer#make_cache_current_line()
endif
if neocomplete#helper#is_enabled_source('member',
\ neocomplete.context_filetype)
" Caching current cache line.
call neocomplete#sources#member#make_cache_current_line()
endif
endfunction"}}}
function! s:check_force_omni(cur_text) abort "{{{
let cur_text = a:cur_text
let complete_pos = neocomplete#helper#get_force_omni_complete_pos(cur_text)
if complete_pos >= 0
\ && !neocomplete#complete#_check_previous_position(
\ cur_text, complete_pos)
call s:complete_key("\<Plug>(neocomplete_start_omni_complete)")
endif
return complete_pos
endfunction"}}}
function! s:check_fallback(cur_text) abort "{{{
let cur_text = a:cur_text
let complete_pos = match(cur_text, '\h\w*$')
let neocomplete = neocomplete#get_current_neocomplete()
if empty(g:neocomplete#fallback_mappings)
\ || len(matchstr(cur_text, '\h\w*$'))
\ < g:neocomplete#auto_completion_start_length
\ || neocomplete.skip_next_complete
\ || neocomplete#complete#_check_previous_position(
\ cur_text, complete_pos)
return
endif
let key = ''
for i in range(0, len(g:neocomplete#fallback_mappings)-1)
let key .= '<C-r>=neocomplete#mappings#fallback(' . i . ')<CR>'
endfor
execute 'inoremap <silent> <Plug>(neocomplete_fallback)' key
" Fallback
call s:complete_key("\<Plug>(neocomplete_fallback)")
endfunction"}}}
function! s:complete_key(key) abort "{{{
call neocomplete#helper#complete_configure()
call feedkeys(a:key)
endfunction"}}}
function! s:indent_current_line() abort "{{{
" indent line matched by indentkeys
let neocomplete = neocomplete#get_current_neocomplete()
let cur_text = matchstr(getline('.'), '^.*\%'.col('.').'c')
if neocomplete.indent_text == matchstr(getline('.'), '\S.*$')
return
endif
for word in filter(map(split(&l:indentkeys, ','),
\ "v:val =~ '^<.*>$' ? matchstr(v:val, '^<\\zs.*\\ze>$')
\ : matchstr(v:val, ':\\|e\\|=\\zs.*')"),
\ "v:val != ''")
if word ==# 'e'
let word = 'else'
endif
let lastpos = len(cur_text)-len(word)
if lastpos >= 0 && strridx(cur_text, word) == lastpos
call neocomplete#helper#indent_current_line()
let neocomplete.indent_text = matchstr(getline('.'), '\S.*$')
break
endif
endfor
endfunction"}}}
function! s:is_delimiter() abort "{{{
" Check delimiter pattern.
let is_delimiter = 0
let cur_text = neocomplete#get_cur_text(1)
for delimiter in ['/']
if stridx(cur_text, delimiter,
\ len(cur_text) - len(delimiter)) >= 0
let is_delimiter = 1
break
endif
endfor
return is_delimiter
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,357 @@
"=============================================================================
" FILE: helper.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#helper#get_cur_text(...) abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let is_skip_char = get(a:000, 0, 0)
let mode = mode()
if neocomplete.event ==# 'InsertEnter'
let mode = 'i'
endif
let cur_text =
\ (mode ==# 'i' ?
\ (col('.')-1) : col('.')) >= len(getline('.')) ?
\ getline('.') :
\ matchstr(getline('.'),
\ '^.*\%' . (mode ==# 'i' && !is_skip_char ?
\ col('.') : col('.') - 1)
\ . 'c' . (mode ==# 'i' ? '' : '.'))
if cur_text =~ '^.\{-}\ze\S\+$'
let complete_str = matchstr(cur_text, '\S\+$')
let cur_text = matchstr(cur_text, '^.\{-}\ze\S\+$')
else
let complete_str = ''
endif
if neocomplete.event ==# 'InsertCharPre'
let complete_str .= v:char
endif
let neocomplete.cur_text = cur_text . complete_str
" Save cur_text.
return neocomplete.cur_text
endfunction"}}}
function! neocomplete#helper#get_force_omni_complete_pos(cur_text) abort "{{{
let filetype = neocomplete#get_context_filetype()
let omnifunc = &l:omnifunc
if neocomplete#helper#check_invalid_omnifunc(omnifunc)
return -1
endif
let pattern = ''
if has_key(g:neocomplete#force_omni_input_patterns, omnifunc)
let pattern = g:neocomplete#force_omni_input_patterns[omnifunc]
elseif filetype != '' &&
\ get(g:neocomplete#force_omni_input_patterns, filetype, '') != ''
let pattern = g:neocomplete#force_omni_input_patterns[filetype]
endif
if pattern == ''
return -1
endif
return match(a:cur_text, '\%(' . pattern . '\m\)$')
endfunction"}}}
function! neocomplete#helper#is_enabled_source(source, filetype) abort "{{{
let source = type(a:source) == type('') ?
\ get(neocomplete#variables#get_sources(), a:source, {})
\ : a:source
return !empty(source) && (empty(source.filetypes) ||
\ neocomplete#helper#check_filetype(source.filetypes))
\ && (!get(source.disabled_filetypes, '_', 0) &&
\ !neocomplete#helper#check_filetype(source.disabled_filetypes))
endfunction"}}}
function! neocomplete#helper#get_source_filetypes(filetype) abort "{{{
return neocomplete#context_filetype#filetypes()
endfunction"}}}
function! neocomplete#helper#complete_check() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
if g:neocomplete#enable_debug
echomsg split(reltimestr(reltime(neocomplete.start_time)))[0]
endif
let ret =
\ neocomplete#is_auto_complete()
\ && g:neocomplete#skip_auto_completion_time != ''
\ && split(reltimestr(reltime(neocomplete.start_time)))[0] >
\ g:neocomplete#skip_auto_completion_time
if ret
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.skipped = 1
call neocomplete#print_debug('Skipped.')
endif
return ret
endfunction"}}}
function! neocomplete#helper#get_syn_name(is_trans) abort "{{{
return len(getline('.')) < 200 ?
\ synIDattr(synIDtrans(synID(line('.'), mode() ==# 'i' ?
\ col('.')-1 : col('.'), a:is_trans)), 'name') : ''
endfunction"}}}
function! neocomplete#helper#match_word(cur_text, ...) abort "{{{
let pattern = a:0 >= 1 ? a:1 : neocomplete#get_keyword_pattern_end()
" Check wildcard.
let complete_pos = match(a:cur_text, pattern)
let complete_str = (complete_pos >=0) ?
\ a:cur_text[complete_pos :] : ''
return [complete_pos, complete_str]
endfunction"}}}
function! neocomplete#helper#filetype_complete(arglead, cmdline, cursorpos) abort "{{{
" Dup check.
let ret = {}
for item in map(
\ split(globpath(&runtimepath, 'syntax/*.vim'), '\n') +
\ split(globpath(&runtimepath, 'indent/*.vim'), '\n') +
\ split(globpath(&runtimepath, 'ftplugin/*.vim'), '\n')
\ , 'fnamemodify(v:val, ":t:r")')
if !has_key(ret, item) && item =~ '^'.a:arglead
let ret[item] = 1
endif
endfor
return sort(keys(ret))
endfunction"}}}
function! neocomplete#helper#unite_patterns(pattern_var, filetype) abort "{{{
let keyword_patterns = []
lua << EOF
do
local patterns = vim.eval('keyword_patterns')
local filetypes = vim.eval("split(a:filetype, '\\.')")
local pattern_var = vim.eval('a:pattern_var')
local dup_check = {}
for i = 0, #filetypes-1 do
local ft = filetypes[i]
-- Composite filetype.
if pattern_var[ft] ~= nil and dup_check[ft] == nil then
dup_check[ft] = 1
patterns:add(pattern_var[ft])
end
end
if #patterns == 0 then
local default = pattern_var['_']
if default == nil then
default = pattern_var['default']
end
if default ~= nil and default ~= '' then
patterns:add(default)
end
end
end
EOF
return join(keyword_patterns, '\m\|')
endfunction"}}}
function! neocomplete#helper#check_filetype(dictionary) abort "{{{
return !empty(filter(neocomplete#context_filetype#filetypes(),
\ 'get(a:dictionary, v:val, 0)'))
endfunction"}}}
function! neocomplete#helper#get_sources_list(...) abort "{{{
let filetype = neocomplete#get_context_filetype()
let source_names = exists('b:neocomplete_sources') ?
\ b:neocomplete_sources :
\ get(a:000, 0,
\ get(g:neocomplete#sources, filetype,
\ get(g:neocomplete#sources, '_', ['_'])))
call neocomplete#init#_sources(source_names)
let all_sources = neocomplete#available_sources()
let sources = {}
for source_name in source_names
if source_name ==# '_'
" All sources.
let sources = all_sources
break
endif
if !has_key(all_sources, source_name)
call neocomplete#print_warning(printf(
\ 'Invalid source name "%s" is given.', source_name))
continue
endif
let sources[source_name] = all_sources[source_name]
endfor
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.sources = filter(sources, "
\ empty(v:val.filetypes) ||
\ neocomplete#helper#check_filetype(v:val.filetypes)")
let neocomplete.sources_filetype = neocomplete.context_filetype
return neocomplete.sources
endfunction"}}}
function! neocomplete#helper#clear_result() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.complete_str = ''
let neocomplete.candidates = []
let neocomplete.complete_sources = []
let neocomplete.complete_pos = -1
" Restore completeopt.
if neocomplete.completeopt !=# &completeopt
" Restore completeopt.
let &completeopt = neocomplete.completeopt
endif
endfunction"}}}
function! neocomplete#helper#call_hook(sources, hook_name, context) abort "{{{
for source in neocomplete#util#convert2list(a:sources)
try
if has_key(source.hooks, a:hook_name)
call call(source.hooks[a:hook_name],
\ [extend(source.neocomplete__context, a:context)],
\ source.hooks)
endif
catch
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
call neocomplete#print_error(
\ 'Error occurred in calling hook "' . a:hook_name . '"!')
call neocomplete#print_error(
\ 'Source name is ' . source.name)
endtry
endfor
endfunction"}}}
function! neocomplete#helper#call_filters(filters, source, context) abort "{{{
let context = extend(a:source.neocomplete__context, a:context)
for filter in a:filters
try
let context.candidates = call(filter.filter, [context], filter)
catch
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
call neocomplete#print_error(
\ 'Error occurred in calling filter '
\ . filter.name . '!')
call neocomplete#print_error(
\ 'Source name is ' . a:source.name)
endtry
endfor
return context.candidates
endfunction"}}}
function! neocomplete#helper#sort_human(candidates) abort "{{{
" Use lua interface.
lua << EOF
do
local candidates = vim.eval('a:candidates')
local t = {}
for i = 1, #candidates do
t[i] = candidates[i-1]
end
table.sort(t, function(a, b) return a.word < b.word end)
for i = 0, #candidates-1 do
candidates[i] = t[i+1]
end
end
EOF
return a:candidates
endfunction"}}}
function! neocomplete#helper#check_invalid_omnifunc(omnifunc) abort "{{{
return a:omnifunc == '' || (a:omnifunc !~ '#' && !exists('*' . a:omnifunc))
endfunction"}}}
function! neocomplete#helper#indent_current_line() abort "{{{
let pos = getpos('.')
let len = len(getline('.'))
let equalprg = &l:equalprg
try
setlocal equalprg=
silent normal! ==
finally
let &l:equalprg = equalprg
let pos[2] += len(getline('.')) - len
call setpos('.', pos)
endtry
endfunction"}}}
function! neocomplete#helper#complete_configure() abort "{{{
set completeopt-=menu
set completeopt-=longest
set completeopt+=menuone
" Set options.
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.completeopt = &completeopt
if neocomplete#util#is_complete_select()
\ && &completeopt !~# 'noinsert\|noselect'
if g:neocomplete#enable_auto_select
set completeopt-=noselect
set completeopt+=noinsert
else
set completeopt-=noinsert
set completeopt+=noselect
endif
endif
endfunction"}}}
function! neocomplete#helper#clean(directory) abort "{{{
let directory = neocomplete#get_data_directory() .'/'.a:directory
for file in split(glob(directory . '/*'), '\n')
let orig = substitute(substitute(fnamemodify(file, ':t'),
\ '=-', ':', 'g'), '=+', '/', 'g')
if !filereadable(orig)
call delete(file)
endif
endfor
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,659 @@
"=============================================================================
" FILE: init.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
if !exists('s:is_enabled')
let s:is_enabled = 0
endif
function! neocomplete#init#enable() abort "{{{
if neocomplete#is_enabled()
return
endif
if !(has('lua') && (v:version > 703 || v:version == 703 && has('patch885')))
echomsg 'neocomplete does not work with this version of Vim.'
echomsg 'neocomplete requires Vim 7.3.885 or later with Lua support ("+lua").'
return
endif
if !exists('b:neocomplete')
call neocomplete#init#_current_neocomplete()
endif
call neocomplete#init#_autocmds()
call neocomplete#init#_others()
call neocomplete#init#_sources(get(g:neocomplete#sources,
\ neocomplete#get_context_filetype(), ['_']))
let s:is_enabled = 1
doautocmd <nomodeline> neocomplete InsertEnter
endfunction"}}}
function! neocomplete#init#disable() abort "{{{
if !neocomplete#is_enabled()
return
endif
let s:is_enabled = 0
augroup neocomplete
autocmd!
augroup END
silent! delcommand NeoCompleteDisable
call neocomplete#helper#call_hook(filter(values(
\ neocomplete#variables#get_sources()), 'v:val.loaded'),
\ 'on_final', {})
endfunction"}}}
function! neocomplete#init#is_enabled() abort "{{{
return s:is_enabled
endfunction"}}}
function! neocomplete#init#_autocmds() abort "{{{
augroup neocomplete
autocmd!
autocmd InsertEnter *
\ call neocomplete#handler#_on_insert_enter()
autocmd InsertLeave *
\ call neocomplete#handler#_on_insert_leave()
autocmd CursorMovedI *
\ call neocomplete#handler#_on_moved_i()
autocmd InsertCharPre *
\ call neocomplete#handler#_on_insert_char_pre()
autocmd TextChangedI *
\ call neocomplete#handler#_on_text_changed()
autocmd CompleteDone *
\ call neocomplete#handler#_on_complete_done()
augroup END
let event = neocomplete#util#is_text_changed() ?
\ 'TextChangedI' : 'CursorMovedI'
execute 'autocmd neocomplete' event '*'
\ 'call neocomplete#handler#_do_auto_complete("'.event.'")'
autocmd neocomplete InsertEnter *
\ call neocomplete#handler#_do_auto_complete('InsertEnter')
endfunction"}}}
function! neocomplete#init#_others() abort "{{{
call neocomplete#init#_variables()
call neocomplete#commands#_initialize()
" For auto complete keymappings.
call neocomplete#mappings#define_default_mappings()
" Detect set paste.
if &paste
redir => output
99verbose set paste
redir END
call neocomplete#print_error(output)
call neocomplete#print_error(
\ 'Detected set paste! Disabled neocomplete.')
endif
" Detect poor color
if &t_Co != '' && &t_Co < 8
call neocomplete#print_error(
\ 'Your terminal color is very limited. Disabled neocomplete.')
endif
command! -nargs=0 -bar NeoCompleteDisable
\ call neocomplete#init#disable()
endfunction"}}}
function! neocomplete#init#_variables() abort "{{{
" Initialize keyword patterns. "{{{
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'_',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#keyword_patterns',
\'filename',
\ neocomplete#util#is_windows() ?
\'\%(\a\+:/\)\?\%([/[:alnum:]()$+_~.{}\x80-\xff-]\|[^[:print:]]\|\\.\)\+' :
\'\%([/\[\][:alnum:]()$+_~.{}-]\|[^[:print:]]\|\\.\)\+')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'lisp,scheme,clojure,int-gosh,int-clisp,int-clj',
\'[[:alpha:]!$%&*+/:<=>?@\^_~\-][[:alnum:]!$%&*./:<=>?@\^_~\-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'ruby,int-irb',
\'^=\%(b\%[egin]\|e\%[nd]\)\|\%(@@\|[$@]\)\h\w*\|\h\w*\%(::\w*\)*[!?]\?')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'php,int-php',
\'</\?\%(\h[[:alnum:]_-]*\s*\)\?\%(/\?>\)\?'.
\'\|\$\h\w*\|\h\w*\%(\%(\\\|::\)\w*\)*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'perl,int-perlsh',
\'<\h\w*>\?\|[$@%&*]\h\w*\|\h\w*\%(::\w*\)*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'perl6,int-perl6',
\'<\h\w*>\?\|[$@%&][!.*?]\?\h[[:alnum:]_-]*'.
\'\|\h[[:alnum:]_-]*\%(::[[:alnum:]_-]*\)*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'pir',
\'[$@%.=]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'pasm',
\'[=]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'vim,help',
\'-\h[[:alnum:]-]*=\?\|\c\[:\%(\h\w*:\]\)\?\|&\h[[:alnum:]_:]*\|'.
\'<SID>\%(\h\w*\)\?\|<Plug>([^)]*)\?'.
\'\|<\h[[:alnum:]_-]*>\?\|\h[[:alnum:]_:#]*[!(]\?\|$\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'tex',
\'\\\a{\a\{1,2}}\|\\[[:alpha:]@][[:alnum:]@]*'.
\'\%({\%([[:alnum:]:_]\+\*\?}\?\)\?\)\?\|\a[[:alnum:]:_]*\*\?')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'sh,zsh,int-zsh,int-bash,int-sh',
\'[[:alpha:]_.-][[:alnum:]_.-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'vimshell',
\'\$\$\?\w*\|[[:alpha:]_.\\/~-][[:alnum:]_.\\/~-]*\|\d\+\%(\.\d\+\)\+')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'ps1,int-powershell',
\'\[\h\%([[:alnum:]_.]*\]::\)\?\|[$%@.]\?[[:alpha:]_.:-][[:alnum:]_.:-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'c',
\'^\s*#\s*\h\w*\|\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'cpp',
\'^\s*#\s*\h\w*\|\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'objc',
\'^\s*#\s*\h\w*\|\h\w*\|@\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'objcpp',
\'^\s*#\s*\h\w*\|\h\w*\|@\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'objj',
\'\h\w*\|@\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'d',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'python,int-python,int-ipython',
\'[@]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'cs',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'java',
\'[@]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'javascript,actionscript,int-js,int-kjs,int-rhino',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'coffee,int-coffee',
\'[@]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'awk',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'haskell,int-ghci',
\'\%(\u\w*\.\)\+[[:alnum:]_'']*\|[[:alpha:]_''][[:alnum:]_'']*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'ml,ocaml,int-ocaml,int-sml,int-smlsharp',
\'[''`#.]\?\h[[:alnum:]_'']*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'erlang,int-erl',
\'^\s*-\h\w*\|\%(\h\w*:\)*\h\w*\|\h[[:alnum:]_@]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'html,xhtml,xml,markdown,mkd,eruby',
\'</\?\%([[:alnum:]_:-]\+\s*\)\?\%(/\?>\)\?\|&\h\%(\w*;\)\?'.
\'\|\h[[:alnum:]_-]*="\%([^"]*"\?\)\?\|\h[[:alnum:]_:-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'css,stylus,scss,less',
\'[@#.]\?[[:alpha:]_:-][[:alnum:]_:-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'tags',
\'^[^!][^/[:blank:]]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'pic',
\'^\s*#\h\w*\|\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'arm',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'asmh8300',
\'[[:alpha:]_.][[:alnum:]_.]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'masm',
\'\.\h\w*\|[[:alpha:]_@?$][[:alnum:]_@?$]*\|\h\w*:\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'nasm',
\'^\s*\[\h\w*\|[%.]\?\h\w*\|\%(\.\.@\?\|%[%$!]\)\%(\h\w*\)\?\|\h\w*:\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'asm',
\'[%$.]\?\h\w*\%(\$\h\w*\)\?')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'gas',
\'[$.]\?\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'gdb,int-gdb',
\'$\h\w*\|[[:alnum:]:._-]\+')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'make',
\'[[:alpha:]_.-][[:alnum:]_.-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'scala,int-scala',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'int-termtter',
\'\h[[:alnum:]_/-]*\|\$\a\+\|#\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'int-earthquake',
\'[:#$]\h\w*\|\h[[:alnum:]_/-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'dosbatch,int-cmdproxy',
\'\$\w+\|[[:alpha:]_./-][[:alnum:]_.-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'vb',
\'\h\w*\|#\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'lua',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\ 'zimbu',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'konoha',
\'[*$@%]\h\w*\|\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'cobol',
\'\a[[:alnum:]-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'coq',
\'\h[[:alnum:]_'']*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'tcl',
\'[.-]\h\w*\|\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'nyaos,int-nyaos',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'go',
\'\h\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#keyword_patterns',
\'toml',
\'\h[[:alnum:]_.-]*')
"}}}
" Initialize delimiter patterns. "{{{
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'vim,help', ['#'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'erlang,lisp,int-clisp', [':'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'lisp,int-clisp', ['/', ':'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'clojure,int-clj', ['/', '.'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'perl,cpp', ['::'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'php', ['\', '::'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'java,d,javascript,actionscript,'.
\ 'ruby,eruby,haskell,int-ghci,coffee,zimbu,konoha',
\ ['.'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'lua', ['.', ':'])
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#delimiter_patterns',
\ 'perl6', ['.', '::'])
"}}}
" Initialize text mode filetypes. "{{{
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#text_mode_filetypes',
\ join(['hybrid', 'text', 'help', 'tex', 'gitcommit', 'gitrebase',
\ 'vcs-commit', 'markdown', 'mkd', 'textile', 'creole',
\ 'org', 'rdoc', 'mediawiki', 'rst', 'asciidoc', 'pod',
\ 'gita-commit', 'J6uil_say',
\ ], ','), 1)
"}}}
" Initialize tags filter patterns. "{{{
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#tags_filter_patterns', 'c,cpp',
\'v:val.word !~ ''^[~_]''')
"}}}
" Initialize force omni completion patterns. "{{{
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#force_omni_input_patterns', 'objc',
\'\h\w\+\|[^.[:digit:] *\t]\%(\.\|->\)')
"}}}
" Must g:neocomplete#auto_completion_start_length > 1.
if g:neocomplete#auto_completion_start_length < 1
let g:neocomplete#auto_completion_start_length = 1
endif
" Must g:neocomplete#min_keyword_length > 1.
if g:neocomplete#min_keyword_length < 1
let g:neocomplete#min_keyword_length = 1
endif
endfunction"}}}
function! neocomplete#init#_current_neocomplete() abort "{{{
let b:neocomplete = {
\ 'context' : {
\ 'input' : '',
\ 'complete_pos' : -1,
\ 'complete_str' : '',
\ 'candidates' : [],
\ },
\ 'lock' : 0,
\ 'skip_next_complete' : 0,
\ 'filetype' : '',
\ 'context_filetype' : '',
\ 'context_filetypes' : [],
\ 'completion_length' : -1,
\ 'foldinfo' : [],
\ 'skipped' : 0,
\ 'event' : '',
\ 'cur_text' : '',
\ 'old_cur_text' : '',
\ 'old_linenr' : line('.'),
\ 'old_complete_pos' : -1,
\ 'old_char' : '',
\ 'complete_str' : '',
\ 'complete_pos' : -1,
\ 'candidates' : [],
\ 'complete_sources' : [],
\ 'manual_sources' : [],
\ 'start_time' : reltime(),
\ 'linenr' : 0,
\ 'completeopt' : &completeopt,
\ 'sources' : [],
\ 'sources_filetype' : '',
\ 'within_comment' : 0,
\ 'is_auto_complete' : 0,
\ 'indent_text' : '',
\ 'detected_foldmethod' : 0,
\ 'default_matchers' : neocomplete#init#_filters(
\ (g:neocomplete#enable_fuzzy_completion ?
\ ['matcher_fuzzy'] : ['matcher_head'])
\ + ['matcher_length']),
\}
endfunction"}}}
function! neocomplete#init#_sources(names) abort "{{{
if !exists('s:loaded_source_files')
" Initialize.
let s:loaded_source_files = {}
let s:loaded_all_sources = 0
let s:runtimepath_save = ''
endif
" Initialize sources table.
if s:loaded_all_sources && &runtimepath ==# s:runtimepath_save
return
endif
let runtimepath_save = neocomplete#util#split_rtp(s:runtimepath_save)
let runtimepath = neocomplete#util#join_rtp(
\ filter(neocomplete#util#split_rtp(),
\ 'index(runtimepath_save, v:val) < 0'))
let sources = neocomplete#variables#get_sources()
for name in filter(copy(a:names), '!has_key(sources, v:val)')
" Search autoload.
for source_name in map(filter(split(globpath(runtimepath,
\ 'autoload/neocomplete/sources/*.vim'), '\n'),
\ "index(g:neocomplete#ignore_source_files,
\ fnamemodify(v:val, ':t')) < 0"),
\ "fnamemodify(v:val, ':t:r')")
if has_key(s:loaded_source_files, source_name)
continue
endif
let s:loaded_source_files[source_name] = 1
let source = neocomplete#sources#{source_name}#define()
if empty(source)
" Ignore.
continue
endif
call neocomplete#define_source(source)
endfor
if name == '_'
let s:loaded_all_sources = 1
let s:runtimepath_save = &runtimepath
endif
endfor
endfunction"}}}
function! neocomplete#init#_source(source) abort "{{{
let default = {
\ 'is_volatile' : 0,
\ 'max_candidates' : 0,
\ 'filetypes' : {},
\ 'disabled' : 0,
\ 'disabled_filetypes' : {},
\ 'hooks' : {},
\ 'matchers' : [],
\ 'sorters' : ['sorter_rank'],
\ 'converters' : [
\ 'converter_remove_overlap',
\ 'converter_delimiter',
\ 'converter_abbr',
\ ],
\ 'keyword_patterns' : g:neocomplete#keyword_patterns,
\ 'min_pattern_length' : g:neocomplete#auto_completion_start_length,
\ 'input_pattern' : '',
\ 'neocomplete__context' : neocomplete#init#_context({}),
\ }
let source = extend(copy(default), a:source)
" Overwritten by user custom.
let custom = neocomplete#custom#get().sources
let source = extend(source, get(custom, source.name,
\ get(custom, '_', {})))
let source.loaded = 0
" Source kind convertion.
if !has_key(source, 'kind')
let source.kind = 'manual'
elseif source.kind ==# 'plugin'
let source.kind = 'keyword'
elseif source.kind ==# 'ftplugin' || source.kind ==# 'complfunc'
" For compatibility.
let source.kind = 'manual'
endif
if !has_key(source, 'rank')
" Set default rank.
let source.rank = (source.kind ==# 'keyword') ? 5 :
\ empty(source.filetypes) ? 10 : 100
endif
if !has_key(source, 'mark')
" Set default mark.
let source.mark = '[' . source.name . ']'
endif
if !has_key(source.keyword_patterns, '_')
" Set default keyword pattern.
let source.keyword_patterns['_'] =
\ get(g:neocomplete#keyword_patterns, '_', '\h\w*')
endif
let source.neocomplete__matchers = neocomplete#init#_filters(
\ neocomplete#util#convert2list(source.matchers))
let source.neocomplete__sorters = neocomplete#init#_filters(
\ neocomplete#util#convert2list(source.sorters))
let source.neocomplete__converters = neocomplete#init#_filters(
\ neocomplete#util#convert2list(source.converters))
let source.neocomplete__context.source_name = source.name
return source
endfunction"}}}
function! neocomplete#init#_filters(names) abort "{{{
let _ = []
let filters = neocomplete#variables#get_filters()
for name in a:names
if !has_key(filters, name)
" Search autoload.
for filter_name in map(split(globpath(&runtimepath,
\ 'autoload/neocomplete/filters/'.
\ substitute(name,
\'^\%(matcher\|sorter\|converter\)_[^/_-]\+\zs[/_-].*$', '', '')
\ .'*.vim'), '\n'), "fnamemodify(v:val, ':t:r')")
let filter = neocomplete#filters#{filter_name}#define()
if empty(filter)
" Ignore.
continue
endif
call neocomplete#define_filter(filter)
endfor
if !has_key(filters, name)
" Not found.
call neocomplete#print_error(
\ printf('filter name : %s is not found.', string(name)))
continue
endif
endif
if has_key(filters, name)
call add(_, filters[name])
endif
endfor
return _
endfunction"}}}
function! neocomplete#init#_filter(filter) abort "{{{
let default = {
\ }
let filter = extend(default, a:filter)
if !has_key(filter, 'kind')
let filter.kind =
\ (filter.name =~# '^matcher_') ? 'matcher' :
\ (filter.name =~# '^sorter_') ? 'sorter' : 'converter'
endif
return filter
endfunction"}}}
function! neocomplete#init#_context(context) abort "{{{
let filetype = neocomplete#get_context_filetype()
return extend(a:context, {
\ 'input' : '',
\ 'prev_complete_pos' : -1,
\ 'prev_candidates' : [],
\ 'prev_line' : '',
\ 'complete_pos' : -1,
\ 'complete_str' : '',
\ 'candidates' : [],
\ 'filetype' : filetype,
\ 'filetypes' : neocomplete#context_filetype#filetypes(),
\ })
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,269 @@
"=============================================================================
" FILE: mappings.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#mappings#define_default_mappings() abort "{{{
inoremap <expr><silent> <Plug>(neocomplete_start_unite_complete)
\ unite#sources#neocomplete#start_complete()
inoremap <expr><silent> <Plug>(neocomplete_start_unite_quick_match)
\ unite#sources#neocomplete#start_quick_match()
if neocomplete#util#is_complete_select()
inoremap <silent> <Plug>(neocomplete_start_omni_complete)
\ <C-x><C-o>
else
inoremap <silent> <Plug>(neocomplete_start_omni_complete)
\ <C-x><C-o><C-p>
endif
if neocomplete#util#is_complete_select()
inoremap <silent> <Plug>(neocomplete_start_auto_complete)
\ <C-r>=neocomplete#mappings#auto_complete()<CR>
inoremap <silent> <Plug>(neocomplete_start_manual_complete)
\ <C-r>=neocomplete#mappings#manual_complete()<CR>
else
inoremap <silent> <Plug>(neocomplete_start_auto_complete)
\ <C-r>=neocomplete#mappings#auto_complete()<CR><C-r>=
\neocomplete#mappings#popup_post()<CR>
inoremap <silent> <Plug>(neocomplete_start_manual_complete)
\ <C-r>=neocomplete#mappings#manual_complete()<CR><C-r>=
\neocomplete#mappings#popup_post()<CR>
endif
if !has('patch-7.4.653')
" To prevent Vim's complete() bug.
if mapcheck('<C-h>', 'i') ==# ''
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
endif
if mapcheck('<BS>', 'i') ==# ''
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
endif
endif
inoremap <silent> <Plug>(neocomplete_auto_refresh)
\ <C-r>=neocomplete#mappings#refresh()<CR>
endfunction"}}}
function! neocomplete#mappings#auto_complete() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let cur_text = neocomplete#get_cur_text(1)
let complete_pos =
\ neocomplete#complete#_get_complete_pos(
\ neocomplete.complete_sources)
let base = cur_text[complete_pos :]
let neocomplete.candidates = neocomplete#complete#_get_words(
\ neocomplete.complete_sources, complete_pos, base)
let neocomplete.complete_str = base
let neocomplete.refresh = 0
if empty(neocomplete.candidates)
return ''
endif
" Start auto complete.
call complete(complete_pos+1, neocomplete.candidates)
return ''
endfunction"}}}
function! neocomplete#mappings#manual_complete() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let cur_text = neocomplete#get_cur_text(1)
let complete_sources = neocomplete#complete#_get_results(
\ cur_text, neocomplete.manual_sources)
let complete_pos =
\ neocomplete#complete#_get_complete_pos(
\ complete_sources)
let base = cur_text[complete_pos :]
let neocomplete.complete_pos = complete_pos
let neocomplete.candidates = neocomplete#complete#_get_words(
\ complete_sources, complete_pos, base)
let neocomplete.complete_str = base
if empty(neocomplete.candidates)
return ''
endif
" Start auto complete.
call complete(complete_pos+1, neocomplete.candidates)
return ''
endfunction"}}}
function! neocomplete#mappings#smart_close_popup() abort "{{{
return neocomplete#mappings#cancel_popup()
endfunction
"}}}
function! neocomplete#mappings#close_popup() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.complete_str = ''
let neocomplete.old_cur_text = neocomplete#get_cur_text(1)
let neocomplete.skip_next_complete = 1
return pumvisible() ? "\<C-y>" : ''
endfunction
"}}}
function! neocomplete#mappings#cancel_popup() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.complete_str = ''
let neocomplete.old_cur_text = neocomplete#get_cur_text(1)
let neocomplete.old_complete_pos = col('.')
if mode() !=# 'i'
let neocomplete.old_complete_pos += 1
endif
let neocomplete.old_linenr = line('.')
let neocomplete.skip_next_complete = 1
return pumvisible() ? "\<C-e>" : ''
endfunction
"}}}
function! neocomplete#mappings#popup_post() abort "{{{
return !pumvisible() ? "" :
\ g:neocomplete#enable_auto_select ? "\<C-p>\<Down>" : "\<C-p>"
endfunction"}}}
function! neocomplete#mappings#undo_completion() abort "{{{
if !neocomplete#is_enabled()
return ''
endif
let neocomplete = neocomplete#get_current_neocomplete()
" Get cursor word.
let complete_str =
\ (!exists('v:completed_item') || empty(v:completed_item)) ?
\ neocomplete#helper#match_word(neocomplete#get_cur_text(1))[1] :
\ v:completed_item.word
let old_keyword_str = neocomplete.complete_str
let neocomplete.complete_str = complete_str
return (!pumvisible() ? '' :
\ complete_str ==# old_keyword_str ? "\<C-e>" : "\<C-y>")
\. repeat("\<BS>", strchars(complete_str)) . old_keyword_str
endfunction"}}}
function! neocomplete#mappings#complete_common_string() abort "{{{
if !neocomplete#is_enabled()
return ''
endif
" Get cursor word.
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.event = 'mapping'
let complete_str =
\ neocomplete#helper#match_word(neocomplete#get_cur_text(1))[1]
if complete_str == ''
return ''
endif
" Save options.
let ignorecase_save = &ignorecase
try
if neocomplete#is_text_mode()
let &ignorecase = 1
elseif g:neocomplete#enable_smart_case
\ || g:neocomplete#enable_camel_case
let &ignorecase = complete_str !~ '\u'
else
let &ignorecase = g:neocomplete#enable_ignore_case
endif
let candidates = neocomplete#filters#matcher_head#define().filter(
\ { 'candidates' : copy(neocomplete.candidates),
\ 'complete_str' : complete_str})
if empty(candidates)
return ''
endif
let common_str = candidates[0].word
for keyword in candidates[1:]
while !neocomplete#head_match(keyword.word, common_str)
let common_str = common_str[: -2]
endwhile
endfor
finally
let &ignorecase = ignorecase_save
endtry
if common_str == ''
\ || complete_str ==? common_str
return ''
endif
return (pumvisible() ? "\<C-e>" : '')
\ . repeat("\<BS>", strchars(complete_str)) . common_str
endfunction"}}}
function! neocomplete#mappings#fallback(i) abort "{{{
let mapping = g:neocomplete#fallback_mappings[a:i]
return (pumvisible() || (mapping ==? "\<C-x>\<C-o>"
\ && &l:omnifunc == '')) ? "" :
\ (mapping . (neocomplete#util#is_complete_select() ?
\ "" : "\<C-p>"))
endfunction"}}}
function! neocomplete#mappings#refresh() abort "{{{
let neocomplete = neocomplete#get_current_neocomplete()
let neocomplete.refresh = 1
return pumvisible() ? "\<C-e>" : ''
endfunction"}}}
" Manual complete wrapper.
function! neocomplete#mappings#start_manual_complete(...) abort "{{{
if !neocomplete#is_enabled()
return ''
endif
if neocomplete#helper#get_force_omni_complete_pos(
\ neocomplete#get_cur_text(1)) >= 0
return "\<C-x>\<C-o>"
endif
" Set context filetype.
call neocomplete#context_filetype#set()
let neocomplete = neocomplete#get_current_neocomplete()
let sources = get(a:000, 0,
\ keys(neocomplete#available_sources()))
let neocomplete.manual_sources = neocomplete#helper#get_sources_list(
\ neocomplete#util#convert2list(sources))
let neocomplete.sources_filetype = ''
call neocomplete#helper#complete_configure()
" Start complete.
return "\<C-r>=neocomplete#mappings#manual_complete()\<CR>"
\ . (neocomplete#util#is_complete_select() ?
\ "" : "\<C-r>=neocomplete#mappings#popup_post()\<CR>")
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,400 @@
"=============================================================================
" FILE: buffer.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" Global options definition. "{{{
let g:neocomplete#sources#buffer#cache_limit_size =
\ get(g:, 'neocomplete#sources#buffer#cache_limit_size', 500000)
let g:neocomplete#sources#buffer#disabled_pattern =
\ get(g:, 'neocomplete#sources#buffer#disabled_pattern', '')
let g:neocomplete#sources#buffer#max_keyword_width =
\ get(g:, 'neocomplete#sources#buffer#max_keyword_width', 80)
"}}}
" Important variables.
if !exists('s:buffer_sources')
let s:buffer_sources = {}
let s:async_dictionary_list = {}
endif
let s:source = {
\ 'name' : 'buffer',
\ 'kind' : 'manual',
\ 'mark' : '[B]',
\ 'rank' : 5,
\ 'min_pattern_length' :
\ g:neocomplete#auto_completion_start_length,
\ 'hooks' : {},
\ 'is_volatile' : 1,
\}
function! s:source.hooks.on_init(context) abort "{{{
let s:buffer_sources = {}
augroup neocomplete "{{{
autocmd BufEnter,BufRead,BufWinEnter,BufWritePost *
\ call s:check_source()
autocmd InsertEnter,InsertLeave *
\ call neocomplete#sources#buffer#make_cache_current_line()
autocmd VimLeavePre * call s:clean()
augroup END"}}}
" Create cache directory.
call neocomplete#cache#make_directory('buffer_cache')
call neocomplete#cache#make_directory('buffer_temp')
" Initialize script variables. "{{{
let s:buffer_sources = {}
let s:async_dictionary_list = {}
"}}}
call s:make_cache_buffer(bufnr('%'))
call s:check_source()
endfunction
"}}}
function! s:source.hooks.on_final(context) abort "{{{
silent! delcommand NeoCompleteBufferMakeCache
let s:buffer_sources = {}
endfunction"}}}
function! s:source.hooks.on_post_filter(context) abort "{{{
" Filters too long word.
call filter(a:context.candidates,
\ 'len(v:val.word) < g:neocomplete#sources#buffer#max_keyword_width')
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
call s:check_async_cache(a:context)
let keyword_list = []
for source in s:get_sources_list(a:context)
let keyword_list += source.words
endfor
return keyword_list
endfunction"}}}
function! neocomplete#sources#buffer#define() abort "{{{
return s:source
endfunction"}}}
function! neocomplete#sources#buffer#get_frequencies() abort "{{{
return get(get(s:buffer_sources, bufnr('%'), {}), 'frequencies', {})
endfunction"}}}
function! neocomplete#sources#buffer#make_cache_current_line() abort "{{{
if neocomplete#is_locked()
return
endif
" let start = reltime()
call s:make_cache_current_buffer(
\ max([1, line('.') - winline()]),
\ min([line('$'), line('.') + winheight(0) - winline()]))
" echomsg reltimestr(reltime(start))
endfunction"}}}
function! s:should_create_cache(bufnr) " {{{
let filepath = fnamemodify(bufname(a:bufnr), ':p')
return getfsize(filepath) < g:neocomplete#sources#buffer#cache_limit_size
\ && getbufvar(a:bufnr, '&modifiable')
\ && !getwinvar(bufwinnr(a:bufnr), '&previewwindow')
\ && (g:neocomplete#sources#buffer#disabled_pattern == ''
\ || filepath !~# g:neocomplete#sources#buffer#disabled_pattern)
endfunction"}}}
function! s:get_sources_list(context) abort "{{{
let filetypes_dict = {}
for filetype in a:context.filetypes
let filetypes_dict[filetype] = 1
endfor
return values(filter(copy(s:buffer_sources),
\ "has_key(filetypes_dict, v:val.filetype)
\ || has_key(filetypes_dict, '_')
\ || bufnr('%') == v:key
\ || (bufname('%') ==# '[Command Line]' && bufwinnr('#') == v:key)"))
endfunction"}}}
function! s:initialize_source(srcname) abort "{{{
let path = fnamemodify(bufname(a:srcname), ':p')
let filename = fnamemodify(path, ':t')
if filename == ''
let filename = '[No Name]'
let path .= '/[No Name]'
endif
let ft = getbufvar(a:srcname, '&filetype')
if ft == ''
let ft = 'nothing'
endif
let keyword_pattern = neocomplete#get_keyword_pattern(ft, s:source.name)
let s:buffer_sources[a:srcname] = {
\ 'words' : [],
\ 'frequencies' : {},
\ 'name' : filename, 'filetype' : ft,
\ 'keyword_pattern' : keyword_pattern,
\ 'cached_time' : 0,
\ 'path' : path,
\ 'cache_name' : neocomplete#cache#encode_name('buffer_cache', path),
\}
endfunction"}}}
function! s:make_cache_file(srcname) abort "{{{
" Initialize source.
if !has_key(s:buffer_sources, a:srcname)
call s:initialize_source(a:srcname)
endif
let source = s:buffer_sources[a:srcname]
if !filereadable(source.path)
\ || getbufvar(a:srcname, '&modified')
\ || getbufvar(a:srcname, '&buftype') =~ 'nofile\|acwrite'
call s:make_cache_buffer(a:srcname)
return
endif
call neocomplete#print_debug('make_cache_buffer: ' . source.path)
let source.cache_name =
\ neocomplete#cache#async_load_from_file(
\ 'buffer_cache', source.path,
\ source.keyword_pattern, 'B')
let source.cached_time = localtime()
let source.filetype = getbufvar(a:srcname, '&filetype')
let s:async_dictionary_list[source.path] = [{
\ 'filename' : source.path,
\ 'cachename' : source.cache_name,
\ }]
endfunction"}}}
function! s:make_cache_buffer(srcname) abort "{{{
if !s:should_create_cache(a:srcname)
return
endif
call neocomplete#print_debug('make_cache_buffer: ' . a:srcname)
if !s:exists_current_source()
call s:initialize_source(a:srcname)
if a:srcname ==# bufnr('%')
" Force sync cache
call s:make_cache_current_buffer(1, 1000)
return
endif
endif
let source = s:buffer_sources[a:srcname]
let temp = neocomplete#cache#getfilename(
\ 'buffer_temp', getpid() . '_' . a:srcname)
let lines = getbufline(a:srcname, 1, '$')
call writefile(lines, temp)
" Create temporary file
let source.cache_name =
\ neocomplete#cache#async_load_from_file(
\ 'buffer_cache', temp,
\ source.keyword_pattern, 'B')
let source.cached_time = localtime()
let source.filetype = getbufvar(a:srcname, '&filetype')
if source.filetype == ''
let source.filetype = 'nothing'
endif
let s:async_dictionary_list[source.path] = [{
\ 'filename' : temp,
\ 'cachename' : source.cache_name,
\ }]
endfunction"}}}
function! s:check_changed_buffer(bufnr) abort "{{{
let source = s:buffer_sources[a:bufnr]
let ft = getbufvar(a:bufnr, '&filetype')
if ft == ''
let ft = 'nothing'
endif
let filename = fnamemodify(bufname(a:bufnr), ':t')
if filename == ''
let filename = '[No Name]'
endif
return source.name != filename || source.filetype != ft
endfunction"}}}
function! s:check_source() abort "{{{
" Check new buffer.
call map(filter(range(1, bufnr('$')), "
\ (v:val != bufnr('%') || neocomplete#has_vimproc())
\ && (!has_key(s:buffer_sources, v:val) && buflisted(v:val)
\ || (has_key(s:buffer_sources, v:val) &&
\ s:buffer_sources[v:val].cached_time
\ < getftime(s:buffer_sources[v:val].path)))
\ && (!neocomplete#is_locked(v:val) ||
\ g:neocomplete#disable_auto_complete)
\ && s:should_create_cache(v:val)
\ "), 's:make_cache_file(v:val)')
" Remove unlisted buffers.
call filter(s:buffer_sources,
\ "v:key == bufnr('%') || buflisted(str2nr(v:key))")
endfunction"}}}
function! s:exists_current_source() abort "{{{
return has_key(s:buffer_sources, bufnr('%')) &&
\ !s:check_changed_buffer(bufnr('%'))
endfunction"}}}
function! s:make_cache_current_buffer(start, end) abort "{{{
let srcname = bufnr('%')
" Make cache from current buffer.
if !s:should_create_cache(srcname)
return
endif
if !s:exists_current_source()
call s:initialize_source(srcname)
endif
let source = s:buffer_sources[srcname]
let keyword_pattern = source.keyword_pattern
if keyword_pattern == ''
return
endif
let words = []
lua << EOF
do
local words = vim.eval('words')
local dup = {}
local min_length = vim.eval('g:neocomplete#min_keyword_length')
for linenr = vim.eval('a:start'), vim.eval('a:end') do
local match = 0
while 1 do
local match_str = vim.eval('matchstr(getline('..linenr..
'), keyword_pattern, ' .. match .. ')')
if match_str == '' then
break
end
if dup[match_str] == nil
and string.len(match_str) >= min_length then
dup[match_str] = 1
words:add(match_str)
end
-- Next match.
match = vim.eval('matchend(getline(' .. linenr ..
'), keyword_pattern, ' .. match .. ')')
end
end
end
EOF
let source.words = neocomplete#util#uniq(source.words + words)
endfunction"}}}
function! s:check_async_cache(context) abort "{{{
for source in s:get_sources_list(a:context)
if !has_key(s:async_dictionary_list, source.path)
continue
endif
" Load from cache.
let [loaded, file_cache] = neocomplete#cache#get_cache_list(
\ 'buffer_cache', s:async_dictionary_list[source.path])
if loaded
let source.words = file_cache
endif
if empty(s:async_dictionary_list[source.path])
call remove(s:async_dictionary_list, source.path)
endif
endfor
endfunction"}}}
function! s:clean() abort "{{{
" Remove temporary files
for file in glob(printf('%s/%d_*',
\ neocomplete#get_data_directory() . '/buffer_temp',
\ getpid()), 1, 1)
call delete(file)
let cachefile = neocomplete#get_data_directory() . '/buffer_cache/'
\ . substitute(substitute(file, ':', '=-', 'g'), '[/\\]', '=+', 'g')
if filereadable(cachefile)
call delete(cachefile)
endif
endfor
endfunction"}}}
" Command functions. "{{{
function! neocomplete#sources#buffer#make_cache(name) abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
if a:name == ''
let number = bufnr('%')
else
let number = bufnr(a:name)
if number < 0
let bufnr = bufnr('%')
" No swap warning.
let save_shm = &shortmess
set shortmess+=A
" Open new buffer.
execute 'silent! edit' fnameescape(a:name)
let &shortmess = save_shm
if bufnr('%') != bufnr
setlocal nobuflisted
execute 'buffer' bufnr
endif
endif
let number = bufnr(a:name)
endif
call s:make_cache_file(number)
endfunction"}}}
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,150 @@
"=============================================================================
" FILE: dictionary.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" Global options definition. "{{{
let g:neocomplete#sources#dictionary#dictionaries =
\ get(g:, 'neocomplete#sources#dictionary#dictionaries', {})
"}}}
" Important variables.
if !exists('s:dictionary_cache')
let s:dictionary_cache = {}
let s:async_dictionary_list = {}
endif
function! neocomplete#sources#dictionary#define() abort "{{{
return s:source
endfunction"}}}
let s:source = {
\ 'name' : 'dictionary',
\ 'kind' : 'keyword',
\ 'mark' : '[D]',
\ 'rank' : 4,
\ 'hooks' : {},
\}
function! s:source.hooks.on_init(context) abort "{{{
augroup neocomplete "{{{
autocmd FileType * call s:make_cache(&l:filetype)
augroup END"}}}
" Create cache directory.
call neocomplete#cache#make_directory('dictionary_cache')
" Initialize check.
call s:make_cache(&l:filetype)
endfunction"}}}
function! s:source.hooks.on_final(context) abort "{{{
silent! delcommand NeoCompleteDictionaryMakeCache
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
let list = []
for ft in a:context.filetypes
if !has_key(s:dictionary_cache, ft)
call s:make_cache(ft)
endif
call neocomplete#cache#check_cache(
\ 'dictionary_cache', ft,
\ s:async_dictionary_list, s:dictionary_cache, 1)
let list += get(s:dictionary_cache, ft, [])
endfor
return list
endfunction"}}}
function! s:make_cache(filetype) abort "{{{
if !has_key(s:dictionary_cache, a:filetype)
\ && !has_key(s:async_dictionary_list, a:filetype)
call neocomplete#sources#dictionary#remake_cache(a:filetype)
endif
endfunction"}}}
function! neocomplete#sources#dictionary#remake_cache(filetype) abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
let filetype = a:filetype
if filetype == ''
let filetype = neocomplete#get_context_filetype(1)
endif
if !has_key(s:async_dictionary_list, filetype)
let s:async_dictionary_list[filetype] = []
endif
let pattern = neocomplete#get_keyword_pattern(filetype, s:source.name)
for dictionary in neocomplete#sources#dictionary#get_dictionaries(filetype)
let dictionary = neocomplete#util#substitute_path_separator(
\ fnamemodify(dictionary, ':p'))
if filereadable(dictionary)
call neocomplete#print_debug('Make cache dictionary: ' . dictionary)
call add(s:async_dictionary_list[filetype], {
\ 'filename' : dictionary,
\ 'cachename' : neocomplete#cache#async_load_from_file(
\ 'dictionary_cache', dictionary, pattern, 'D')
\ })
endif
endfor
endfunction"}}}
function! neocomplete#sources#dictionary#get_dictionaries(filetype) abort "{{{
let filetype = a:filetype
if filetype == ''
let filetype = neocomplete#get_context_filetype(1)
endif
" Make cache.
let dictionaries = get(
\ g:neocomplete#sources#dictionary#dictionaries, filetype, '')
if has_key(g:neocomplete#sources#dictionary#dictionaries, '_')
" Load global dictionaries.
let dictionaries .= ',' .
\ g:neocomplete#sources#dictionary#dictionaries['_']
endif
if dictionaries == '' && &l:dictionary != ''
if ((filetype ==# 'nothing' && &filetype == '')
\ || filetype ==# &filetype)
\ && &l:dictionary !=# &g:dictionary
let dictionaries = &l:dictionary
endif
endif
return split(dictionaries, ',')
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,159 @@
"=============================================================================
" FILE: file.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
let s:source = {
\ 'name' : 'file',
\ 'kind' : 'manual',
\ 'mark' : '[F]',
\ 'rank' : 10,
\ 'sorters' : 'sorter_filename',
\ 'converters' : ['converter_remove_overlap', 'converter_abbr'],
\ 'is_volatile' : 1,
\ 'input_pattern': '/',
\}
function! s:source.get_complete_position(context) abort "{{{
let filetype = a:context.filetype
if filetype ==# 'vimshell' || filetype ==# 'unite' || filetype ==# 'int-ssh'
return -1
endif
" Filename pattern.
let pattern = neocomplete#get_keyword_pattern_end('filename', self.name)
let [complete_pos, complete_str] =
\ neocomplete#helper#match_word(a:context.input, pattern)
if complete_str =~ '//' || complete_str == '/' ||
\ (neocomplete#is_auto_complete() &&
\ complete_str !~ '/' ||
\ complete_str =~#
\ '\\[^ ;*?[]"={}'']\|\.\.\+$\|/c\%[ygdrive/]$\|\${')
" Not filename pattern.
return -1
endif
if complete_str =~ '/'
let complete_pos += strridx(complete_str, '/') + 1
endif
return complete_pos
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
let pattern = neocomplete#get_keyword_pattern_end('filename', self.name)
let complete_str =
\ neocomplete#helper#match_word(a:context.input, pattern)[1]
if neocomplete#is_windows() && complete_str =~ '^[\\/]'
return []
endif
let cwd = getcwd()
try
let buffer_dir = fnamemodify(bufname('%'), ':h')
if isdirectory(buffer_dir)
" cd to buffer directory.
execute 'lcd' fnameescape(buffer_dir)
endif
let files = s:get_glob_files(complete_str, '')
finally
execute 'lcd' fnameescape(cwd)
endtry
return files
endfunction"}}}
let s:cached_files = {}
function! s:get_glob_files(complete_str, path) abort "{{{
let path = ',,' . substitute(a:path, '\.\%(,\|$\)\|,,', '', 'g')
let complete_str = neocomplete#util#substitute_path_separator(
\ substitute(a:complete_str, '\\\(.\)', '\1', 'g'))
let complete_str = substitute(complete_str, '[^/.]\+$', '', '')
" Note: Support ${env}
let complete_str = substitute(complete_str, '\${\(\w\+\)}', '$\1', 'g')
let glob = (complete_str !~ '\*$')?
\ complete_str . '*' : complete_str
let ftype = getftype(glob)
if ftype != '' && ftype !=# 'dir'
" Note: If glob() device files, Vim may freeze!
return []
endif
if a:path == ''
let files = neocomplete#util#glob(glob)
else
try
let globs = globpath(path, glob)
catch
return []
endtry
let files = split(substitute(globs, '\\', '/', 'g'), '\n')
endif
call filter(files, 'v:val !~ "/\\.\\.\\?$"')
let files = map(
\ files, "{
\ 'word' : fnamemodify(v:val, ':t'),
\ 'action__is_directory' : isdirectory(v:val),
\ 'kind' : (isdirectory(v:val) ? 'dir' : 'file'),
\ }")
let candidates = []
for dict in files
let abbr = dict.word
if dict.action__is_directory && dict.word !~ '/$'
let abbr .= '/'
if g:neocomplete#enable_auto_delimiter
let dict.word .= '/'
endif
endif
let dict.abbr = abbr
" Escape word.
let dict.word = escape(dict.word, ' ;*?[]"={}''')
call add(candidates, dict)
endfor
return candidates
endfunction"}}}
function! neocomplete#sources#file#define() abort "{{{
return s:source
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,277 @@
"=============================================================================
" FILE: member.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" Global options definition. "{{{
let g:neocomplete#sources#member#prefix_patterns =
\ get(g:, 'neocomplete#sources#member#prefix_patterns', {})
let g:neocomplete#sources#member#input_patterns =
\ get(g:, 'neocomplete#sources#member#input_patterns', {})
"}}}
" Important variables.
if !exists('s:member_sources')
let s:member_sources = {}
endif
let s:source = {
\ 'name' : 'member',
\ 'kind' : 'manual',
\ 'mark' : '[M]',
\ 'rank' : 5,
\ 'min_pattern_length' : 0,
\ 'hooks' : {},
\ 'is_volatile' : 1,
\}
function! s:source.hooks.on_init(context) abort "{{{
augroup neocomplete "{{{
" Make cache events
autocmd CursorHold * call s:make_cache_current_buffer(
\ line('.')-10, line('.')+10)
autocmd InsertEnter,InsertLeave *
\ call neocomplete#sources#member#make_cache_current_line()
autocmd FileType *
\ call neocomplete#sources#member#remake_cache(&l:filetype)
augroup END"}}}
" Initialize member prefix patterns. "{{{
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ '_', '\.')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ 'c,objc', '\.\|->')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ 'cpp,objcpp', '\.\|->\|::')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ 'perl,php', '->')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ 'ruby', '\.\|::')
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#prefix_patterns',
\ 'lua', '\.\|:')
"}}}
" Initialize member patterns. "{{{
call neocomplete#util#set_default_dictionary(
\ 'g:neocomplete#sources#member#input_patterns',
\ '_', '\h\w*\%(()\?\|\[\h\w*\]\)\?')
"}}}
" Initialize script variables. "{{{
let s:member_sources = {}
"}}}
endfunction
"}}}
function! s:source.get_complete_position(context) abort "{{{
" Check member prefix pattern.
let filetype = a:context.filetype
let prefix = get(g:neocomplete#sources#member#prefix_patterns, filetype,
\ get(g:neocomplete#sources#member#prefix_patterns, '_', ''))
if prefix == ''
return -1
endif
let member = s:get_member_pattern(filetype)
let complete_pos = matchend(a:context.input,
\ member . '\m\%(' . prefix . '\m\)\ze\w*$')
return complete_pos
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
" Check member prefix pattern.
let filetype = a:context.filetype
let prefix = get(g:neocomplete#sources#member#prefix_patterns, filetype,
\ get(g:neocomplete#sources#member#prefix_patterns, '_', ''))
if prefix == ''
return []
endif
call neocomplete#sources#member#remake_cache(filetype)
let var_name = matchstr(a:context.input,
\ s:get_member_pattern(filetype) . '\m\%(' .
\ prefix . '\m\)\ze\w*$')
if var_name == ''
return []
endif
return s:get_member_list(a:context, a:context.input, var_name)
endfunction"}}}
function! neocomplete#sources#member#define() abort "{{{
return s:source
endfunction"}}}
function! neocomplete#sources#member#make_cache_current_line() abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
" Make cache from current line.
return s:make_cache_current_buffer(line('.')-1, line('.')+1)
endfunction"}}}
function! neocomplete#sources#member#make_cache_current_buffer() abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
" Make cache from current buffer.
return s:make_cache_current_buffer(1, line('$'))
endfunction"}}}
function! s:make_cache_current_buffer(start, end) abort "{{{
let filetype = neocomplete#get_context_filetype(1)
if !has_key(s:member_sources, bufnr('%'))
call s:initialize_source(bufnr('%'), filetype)
endif
call s:make_cache_lines(bufnr('%'), filetype, getline(a:start, a:end))
endfunction"}}}
function! s:make_cache_lines(srcname, filetype, lines) abort "{{{
let filetype = a:filetype
if !has_key(s:member_sources, a:srcname)
call s:initialize_source(a:srcname, filetype)
endif
let prefix = get(g:neocomplete#sources#member#prefix_patterns, filetype,
\ get(g:neocomplete#sources#member#prefix_patterns, '_', ''))
if prefix == ''
return
endif
let source = s:member_sources[a:srcname]
let member_pattern = s:get_member_pattern(filetype)
let prefix_pattern = member_pattern . '\m\%(' . prefix . '\m\)'
let keyword_pattern =
\ prefix_pattern . member_pattern
" Cache member pattern.
for line in a:lines
let match = match(line, keyword_pattern)
while match >= 0 "{{{
let match_str = matchstr(line, '^'.keyword_pattern, match)
" Next match.
let match = matchend(line, prefix_pattern, match)
let member_name = matchstr(match_str, member_pattern . '$')
if member_name == ''
continue
endif
let var_name = match_str[ : -len(member_name)-1]
if !has_key(source.member_cache, var_name)
let source.member_cache[var_name] = {}
endif
if !has_key(source.member_cache[var_name], member_name)
let source.member_cache[var_name][member_name] = 1
endif
let match_str = matchstr(var_name, '^'.keyword_pattern)
endwhile"}}}
endfor
endfunction"}}}
function! s:get_member_list(context, cur_text, var_name) abort "{{{
let keyword_list = []
for source in filter(s:get_sources_list(a:context),
\ 'has_key(v:val.member_cache, a:var_name)')
let keyword_list +=
\ keys(source.member_cache[a:var_name])
endfor
return keyword_list
endfunction"}}}
function! s:get_sources_list(context) abort "{{{
let filetypes_dict = {}
for filetype in a:context.filetypes
let filetypes_dict[filetype] = 1
endfor
return values(filter(copy(s:member_sources),
\ "has_key(filetypes_dict, v:val.filetype)
\ || has_key(filetypes_dict, '_')
\ || bufnr('%') == v:key
\ || (bufname('%') ==# '[Command Line]' && bufwinnr('#') == v:key)"))
endfunction"}}}
function! s:initialize_source(srcname, filetype) abort "{{{
let path = (a:srcname=~ '^\d\+$') ?
\ fnamemodify(bufname(a:srcname), ':p') : a:srcname
let filename = fnamemodify(path, ':t')
if filename == ''
let filename = '[No Name]'
let path .= '/[No Name]'
endif
let ft = a:filetype
if ft == ''
let ft = 'nothing'
endif
let s:member_sources[a:srcname] = {
\ 'member_cache' : {}, 'filetype' : ft,
\ 'time' : getftime(path),
\ 'keyword_pattern' : neocomplete#get_keyword_pattern(ft, s:source.name),
\}
endfunction"}}}
function! s:get_member_pattern(filetype) abort "{{{
return get(g:neocomplete#sources#member#input_patterns, a:filetype,
\ get(g:neocomplete#sources#member#input_patterns, '_', ''))
endfunction"}}}
function! neocomplete#sources#member#remake_cache(filetype) abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
if get(g:neocomplete#sources#member#prefix_patterns, a:filetype, '') == ''
return
endif
for dictionary in
\ filter(map(neocomplete#sources#dictionary#get_dictionaries(a:filetype),
\ "neocomplete#util#substitute_path_separator(
\ fnamemodify(v:val, ':p'))"),
\ "filereadable(v:val) && (!has_key(s:member_sources, v:val)
\ || getftime(v:val) > s:member_sources[v:val].time)")
call s:make_cache_lines(dictionary, a:filetype, readfile(dictionary))
endfor
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,294 @@
"=============================================================================
" FILE: omni.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" Global options definition. "{{{
let g:neocomplete#sources#omni#functions =
\ get(g:, 'neocomplete#sources#omni#functions', {})
let g:neocomplete#sources#omni#input_patterns =
\ get(g:, 'neocomplete#sources#omni#input_patterns', {})
"}}}
let s:source = {
\ 'name' : 'omni',
\ 'kind' : 'manual',
\ 'mark' : '[O]',
\ 'rank' : 50,
\ 'min_pattern_length' : 0,
\ 'hooks' : {},
\}
let s:List = neocomplete#util#get_vital().import('Data.List')
function! s:source.hooks.on_init(context) abort "{{{
" Initialize omni completion pattern. "{{{
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'html,xhtml,xml,markdown,mkd',
\'<\|\s[[:alnum:]-]*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'css,scss,sass',
\'\w\+\|\w\+[):;]\?\s\+\w*\|[@!]')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'javascript',
\'[^. \t]\.\%(\h\w*\)\?')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'actionscript',
\'[^. \t][.:]\h\w*')
"call neocomplete#util#set_default_dictionary(
"\'g:neocomplete#sources#omni#input_patterns',
"\'php',
"\'[^. \t]->\h\w*\|\h\w*::\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'java',
\'\%(\h\w*\|)\)\.\w*')
"call neocomplete#util#set_default_dictionary(
"\'g:neocomplete#sources#omni#input_patterns',
"\'perl',
"\'\h\w*->\h\w*\|\h\w*::\w*')
"call neocomplete#util#set_default_dictionary(
"\'g:neocomplete#sources#omni#input_patterns',
"\'c',
"\'[^.[:digit:] *\t]\%(\.\|->\)\w*'
"call neocomplete#util#set_default_dictionary(
"\'g:neocomplete#sources#omni#input_patterns',
"\'cpp',
"\'[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'objc',
\'[^.[:digit:] *\t]\%(\.\|->\)\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'objj',
\'[\[ \.]\w\+$\|:\w*$')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'go',
\'[^.[:digit:] *\t]\.\w*')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'clojure',
\'\%(([^)]\+\)\|\*[[:alnum:]_-]\+')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'rust',
\'[^.[:digit:] *\t]\%(\.\|\::\)\%(\h\w*\)\?')
" External language interface check.
if has('ruby')
" call neocomplete#util#set_default_dictionary(
"\'g:neocomplete#sources#omni#input_patterns', 'ruby',
"\'[^. *\t]\.\h\w*\|\h\w*::\w*')
endif
if has('python') || has('python3')
call neocomplete#util#set_default_dictionary(
\'g:neocomplete#sources#omni#input_patterns',
\'python', '[^. \t]\.\w*')
endif
"}}}
endfunction"}}}
function! s:source.get_complete_position(context) abort "{{{
let a:context.source__complete_results =
\ s:set_complete_results_pos(
\ s:get_omni_funcs(a:context.filetype), a:context.input)
return s:get_complete_pos(a:context.source__complete_results)
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
return s:get_candidates(
\ s:set_complete_results_words(
\ a:context.source__complete_results),
\ a:context.complete_pos, a:context.complete_str)
endfunction"}}}
function! neocomplete#sources#omni#define() abort "{{{
return s:source
endfunction"}}}
function! s:get_omni_funcs(filetype) abort "{{{
let funcs = []
for ft in insert(split(a:filetype, '\.'), '_')
let omnifuncs = neocomplete#util#convert2list(
\ get(g:neocomplete#sources#omni#functions, ft, &l:omnifunc))
for omnifunc in omnifuncs
if neocomplete#helper#check_invalid_omnifunc(omnifunc)
" omnifunc is irregal.
continue
endif
if get(g:neocomplete#sources#omni#input_patterns, omnifunc, '') != ''
let pattern = g:neocomplete#sources#omni#input_patterns[omnifunc]
elseif get(g:neocomplete#sources#omni#input_patterns, ft, '') != ''
let pattern = g:neocomplete#sources#omni#input_patterns[ft]
else
let pattern = ''
endif
if pattern == ''
continue
endif
call add(funcs, [omnifunc, pattern])
endfor
endfor
return s:List.uniq(funcs)
endfunction"}}}
function! s:get_omni_list(list) abort "{{{
let omni_list = []
" Convert string list.
for val in deepcopy(a:list)
let dict = (type(val) == type('') ?
\ { 'word' : val } : val)
call add(omni_list, dict)
unlet val
endfor
return omni_list
endfunction"}}}
function! s:set_complete_results_pos(funcs, cur_text) abort "{{{
" Try omnifunc completion. "{{{
let complete_results = {}
for [omnifunc, pattern] in a:funcs
if neocomplete#is_auto_complete()
\ && (pattern == ''
\ || a:cur_text !~# '\%(' . pattern . '\m\)$')
continue
endif
" Save pos.
let pos = getpos('.')
try
let complete_pos = call(omnifunc, [1, ''])
catch
call neocomplete#print_error(
\ 'Error occurred calling omnifunction: ' . omnifunc)
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
let complete_pos = -1
finally
if getpos('.') != pos
call setpos('.', pos)
endif
endtry
if complete_pos < 0
continue
endif
let complete_str = a:cur_text[complete_pos :]
let complete_results[omnifunc] = {
\ 'candidates' : [],
\ 'complete_pos' : complete_pos,
\ 'complete_str' : complete_str,
\ 'omnifunc' : omnifunc,
\}
endfor
"}}}
return complete_results
endfunction"}}}
function! s:set_complete_results_words(complete_results) abort "{{{
" Try source completion.
for [omnifunc, result] in items(a:complete_results)
if neocomplete#complete_check()
return a:complete_results
endif
let pos = getpos('.')
try
let ret = call(omnifunc, [0, result.complete_str])
let list = type(ret) == type(0) ? [] :
\ type(ret) == type([]) ? ret : ret.words
catch
call neocomplete#print_error(
\ 'Error occurred calling omnifunction: ' . omnifunc)
call neocomplete#print_error(v:throwpoint)
call neocomplete#print_error(v:exception)
let list = []
finally
call setpos('.', pos)
endtry
let list = s:get_omni_list(list)
let result.candidates = list
endfor
return a:complete_results
endfunction"}}}
function! s:get_complete_pos(complete_results) abort "{{{
if empty(a:complete_results)
return -1
endif
let complete_pos = col('.')
for result in values(a:complete_results)
if complete_pos > result.complete_pos
let complete_pos = result.complete_pos
endif
endfor
return complete_pos
endfunction"}}}
function! s:get_candidates(complete_results, complete_pos, complete_str) abort "{{{
" Append prefix.
let candidates = []
for result in values(a:complete_results)
if result.complete_pos > a:complete_pos
let prefix = a:complete_str[: result.complete_pos
\ - a:complete_pos - 1]
for keyword in result.candidates
let keyword.word = prefix . keyword.word
endfor
endif
let candidates += result.candidates
endfor
return candidates
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,120 @@
"=============================================================================
" FILE: tag.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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
" Important variables.
if !exists('s:tags_list')
let s:tags_list = {}
let s:async_tags_list = {}
endif
let s:source = {
\ 'name' : 'tag',
\ 'kind' : 'keyword',
\ 'mark' : '[T]',
\ 'hooks' : {},
\}
function! s:source.hooks.on_init(context) abort "{{{
let g:neocomplete#sources#tags#cache_limit_size =
\ get(g:, 'neocomplete#sources#tags#cache_limit_size', 500000)
augroup neocomplete "{{{
autocmd BufWritePost * call neocomplete#sources#tag#make_cache(0)
augroup END"}}}
" Create cache directory.
call neocomplete#cache#make_directory('tags_cache')
endfunction"}}}
function! s:source.hooks.on_final(context) abort "{{{
silent! delcommand NeoCompleteTagMakeCache
endfunction"}}}
function! neocomplete#sources#tag#define() abort "{{{
return s:source
endfunction"}}}
function! s:source.gather_candidates(context) abort "{{{
if !has_key(s:async_tags_list, bufnr('%'))
\ && !has_key(s:tags_list, bufnr('%'))
call neocomplete#sources#tag#make_cache(0)
endif
if neocomplete#within_comment()
return []
endif
call neocomplete#cache#check_cache(
\ 'tags_cache', bufnr('%'), s:async_tags_list, s:tags_list, 0)
return copy(get(s:tags_list, bufnr('%'), []))
endfunction"}}}
function! s:initialize_tags(filename) abort "{{{
" Initialize tags list.
let ft = &filetype
if ft == ''
let ft = 'nothing'
endif
return {
\ 'filename' : a:filename,
\ 'cachename' : neocomplete#cache#async_load_from_tags(
\ 'tags_cache', a:filename,
\ neocomplete#get_keyword_pattern(ft, s:source.name),
\ ft, s:source.mark)
\ }
endfunction"}}}
function! neocomplete#sources#tag#make_cache(force) abort "{{{
if !neocomplete#is_enabled()
call neocomplete#initialize()
endif
let bufnumber = bufnr('%')
let s:async_tags_list[bufnumber] = []
let tagfiles = tagfiles()
if get(g:, 'loaded_neoinclude', 0)
let tagfiles += neoinclude#include#get_tag_files()
endif
for tags in map(filter(tagfiles, 'getfsize(v:val) > 0'),
\ "neocomplete#util#substitute_path_separator(
\ fnamemodify(v:val, ':p'))")
if tags !~? '/doc/tags\%(-\w\+\)\?$' &&
\ (a:force || getfsize(tags)
\ < g:neocomplete#sources#tags#cache_limit_size)
call add(s:async_tags_list[bufnumber],
\ s:initialize_tags(tags))
endif
endfor
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,264 @@
"=============================================================================
" FILE: util.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#util#get_vital() abort "{{{
if !exists('s:V')
let s:V = vital#neocomplete#new()
endif
return s:V
endfunction"}}}
function! s:get_prelude() abort "{{{
if !exists('s:Prelude')
let s:Prelude = neocomplete#util#get_vital().import('Prelude')
endif
return s:Prelude
endfunction"}}}
function! s:get_list() abort "{{{
if !exists('s:List')
let s:List = neocomplete#util#get_vital().import('Data.List')
endif
return s:List
endfunction"}}}
function! s:get_string() abort "{{{
if !exists('s:String')
let s:String = neocomplete#util#get_vital().import('Data.String')
endif
return s:String
endfunction"}}}
function! s:get_process() abort "{{{
if !exists('s:Process')
let s:Process = neocomplete#util#get_vital().import('Process')
endif
return s:Process
endfunction"}}}
function! neocomplete#util#truncate_smart(...) abort "{{{
return call(s:get_string().truncate_skipping, a:000)
endfunction"}}}
function! neocomplete#util#truncate(...) abort "{{{
return call(s:get_string().truncate, a:000)
endfunction"}}}
function! neocomplete#util#strchars(...) abort "{{{
return call(s:get_string().strchars, a:000)
endfunction"}}}
function! neocomplete#util#wcswidth(string) abort "{{{
return strwidth(a:string)
endfunction"}}}
function! neocomplete#util#strwidthpart(...) abort "{{{
return call(s:get_string().strwidthpart, a:000)
endfunction"}}}
function! neocomplete#util#strwidthpart_reverse(...) abort "{{{
return call(s:get_string().strwidthpart_reverse, a:000)
endfunction"}}}
function! neocomplete#util#substitute_path_separator(...) abort "{{{
return call(s:get_prelude().substitute_path_separator, a:000)
endfunction"}}}
function! neocomplete#util#mb_strlen(...) abort "{{{
return call(s:get_string().strchars, a:000)
endfunction"}}}
function! neocomplete#util#uniq(list) abort "{{{
let dict = {}
for item in a:list
if !has_key(dict, item)
let dict[item] = item
endif
endfor
return values(dict)
endfunction"}}}
function! neocomplete#util#system(...) abort "{{{
return call(s:get_process().system, a:000)
endfunction"}}}
function! neocomplete#util#is_windows(...) abort "{{{
return call(s:get_prelude().is_windows, a:000)
endfunction"}}}
function! neocomplete#util#is_mac(...) abort "{{{
return call(s:get_prelude().is_mac, a:000)
endfunction"}}}
function! neocomplete#util#is_complete_select() abort "{{{
return has('patch-7.4.775')
endfunction"}}}
function! neocomplete#util#get_last_status(...) abort "{{{
return call(s:get_process().get_last_status, a:000)
endfunction"}}}
function! neocomplete#util#escape_pattern(...) abort "{{{
return call(s:get_string().escape_pattern, a:000)
endfunction"}}}
function! neocomplete#util#iconv(...) abort "{{{
return call(s:get_process().iconv, a:000)
endfunction"}}}
function! neocomplete#util#uniq(...) abort "{{{
return call(s:get_list().uniq, a:000)
endfunction"}}}
function! neocomplete#util#sort_by(...) abort "{{{
return call(s:get_list().sort_by, a:000)
endfunction"}}}
" Sudo check.
function! neocomplete#util#is_sudo() abort "{{{
return $SUDO_USER != '' && $USER !=# $SUDO_USER
\ && $HOME !=# expand('~'.$USER)
\ && $HOME ==# expand('~'.$SUDO_USER)
endfunction"}}}
function! neocomplete#util#glob(pattern, ...) abort "{{{
if a:pattern =~ "'"
" Use glob('*').
let cwd = getcwd()
let base = neocomplete#util#substitute_path_separator(
\ fnamemodify(a:pattern, ':h'))
execute 'lcd' fnameescape(base)
let files = map(split(neocomplete#util#substitute_path_separator(
\ glob('*')), '\n'), "base . '/' . v:val")
execute 'lcd' fnameescape(cwd)
return files
endif
" let is_force_glob = get(a:000, 0, 0)
let is_force_glob = get(a:000, 0, 1)
if !is_force_glob && a:pattern =~ '^[^\\*]\+/\*'
\ && neocomplete#util#has_vimproc() && exists('*vimproc#readdir')
return filter(vimproc#readdir(a:pattern[: -2]), 'v:val !~ "/\\.\\.\\?$"')
else
" Escape [.
if neocomplete#util#is_windows()
let glob = substitute(a:pattern, '\[', '\\[[]', 'g')
else
let glob = escape(a:pattern, '[')
endif
return split(neocomplete#util#substitute_path_separator(glob(glob)), '\n')
endif
endfunction"}}}
function! neocomplete#util#expand(path) abort "{{{
return expand(escape(a:path, '*?[]"={}'), 1)
endfunction"}}}
function! neocomplete#util#set_default(var, val, ...) abort "{{{
if !exists(a:var) || type({a:var}) != type(a:val)
let alternate_var = get(a:000, 0, '')
let {a:var} = exists(alternate_var) ?
\ {alternate_var} : a:val
endif
endfunction"}}}
function! neocomplete#util#set_dictionary_helper(variable, keys, pattern) abort "{{{
for key in split(a:keys, '\s*,\s*')
if !has_key(a:variable, key)
let a:variable[key] = a:pattern
endif
endfor
endfunction"}}}
function! neocomplete#util#set_default_dictionary(variable, keys, value) abort "{{{
if !exists('s:disable_dictionaries')
let s:disable_dictionaries = {}
endif
if has_key(s:disable_dictionaries, a:variable)
return
endif
call neocomplete#util#set_dictionary_helper({a:variable}, a:keys, a:value)
endfunction"}}}
function! neocomplete#util#disable_default_dictionary(variable) abort "{{{
if !exists('s:disable_dictionaries')
let s:disable_dictionaries = {}
endif
let s:disable_dictionaries[a:variable] = 1
endfunction"}}}
function! neocomplete#util#split_rtp(...) abort "{{{
let rtp = a:0 ? a:1 : &runtimepath
if type(rtp) == type([])
return rtp
endif
if rtp !~ '\\'
return split(rtp, ',')
endif
let split = split(rtp, '\\\@<!\%(\\\\\)*\zs,')
return map(split,'substitute(v:val, ''\\\([\\,]\)'', "\\1", "g")')
endfunction"}}}
function! neocomplete#util#join_rtp(list) abort "{{{
return join(map(copy(a:list), 's:escape(v:val)'), ',')
endfunction"}}}
" Escape a path for runtimepath.
function! s:escape(path) abort"{{{
return substitute(a:path, ',\|\\,\@=', '\\\0', 'g')
endfunction"}}}
function! neocomplete#util#has_vimproc() abort "{{{
" Initialize.
if !exists('g:neocomplete#use_vimproc')
" Check vimproc.
try
call vimproc#version()
let exists_vimproc = 1
catch
let exists_vimproc = 0
endtry
let g:neocomplete#use_vimproc = exists_vimproc
endif
return g:neocomplete#use_vimproc
endfunction"}}}
function! neocomplete#util#dup_filter(list) abort "{{{
let dict = {}
for keyword in a:list
if !has_key(dict, keyword.word)
let dict[keyword.word] = keyword
endif
endfor
return values(dict)
endfunction"}}}
function! neocomplete#util#convert2list(expr) abort "{{{
return type(a:expr) ==# type([]) ? a:expr : [a:expr]
endfunction"}}}
function! neocomplete#util#is_text_changed() abort "{{{
" Note: Vim 7.4.143 fixed TextChangedI bug.
return v:version > 704 || v:version == 704 && has('patch143')
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,67 @@
"=============================================================================
" FILE: variables.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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! neocomplete#variables#get_frequencies() abort "{{{
if !exists('s:filetype_frequencies')
let s:filetype_frequencies = {}
endif
let filetype = neocomplete#get_context_filetype()
if !has_key(s:filetype_frequencies, filetype)
let s:filetype_frequencies[filetype] = {}
endif
let frequencies = s:filetype_frequencies[filetype]
return frequencies
endfunction"}}}
function! neocomplete#variables#get_sources() abort "{{{
if !exists('s:sources')
let s:sources = {}
endif
return s:sources
endfunction"}}}
function! neocomplete#variables#get_source(name) abort "{{{
if !exists('s:sources')
let s:sources = {}
endif
return get(s:sources, a:name, {})
endfunction"}}}
function! neocomplete#variables#get_filters() abort "{{{
if !exists('s:filters')
let s:filters = {}
endif
return s:filters
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,144 @@
"=============================================================================
" FILE: neocomplete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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#sources#neocomplete#define() abort "{{{
return s:neocomplete_source
endfunction "}}}
" neocomplete unite source.
let s:neocomplete_source = {
\ 'name': 'neocomplete',
\ 'hooks' : {},
\ }
function! s:neocomplete_source.hooks.on_init(args, context) abort "{{{
if !neocomplete#is_enabled()
let a:context.source__complete_pos = -1
let a:context.source__candidates = []
return
endif
" Save options.
let max_list_save = g:neocomplete#max_list
let max_keyword_width_save = g:neocomplete#max_keyword_width
let manual_start_length = g:neocomplete#manual_completion_start_length
let neocomplete = neocomplete#get_current_neocomplete()
let sources_save = get(neocomplete, 'sources', {})
try
let g:neocomplete#max_list = -1
let g:neocomplete#max_keyword_width = -1
let g:neocomplete#manual_completion_start_length = 0
let cur_text = neocomplete#get_cur_text(1)
let sources = get(a:context, 'source__sources', [])
let args = [cur_text]
if !empty(sources)
call add(args, neocomplete#helper#get_sources_list(sources))
endif
let complete_sources = call('neocomplete#complete#_get_results', args)
let a:context.source__complete_pos =
\ neocomplete#complete#_get_complete_pos(complete_sources)
let a:context.source__candidates = neocomplete#complete#_get_words(
\ complete_sources, a:context.source__complete_pos,
\ cur_text[a:context.source__complete_pos :])
finally
" Restore options.
let g:neocomplete#max_list = max_list_save
let g:neocomplete#max_keyword_width = max_keyword_width_save
let g:neocomplete#manual_completion_start_length = manual_start_length
let neocomplete.sources = empty(sources_save) ?
\ neocomplete#helper#get_sources_list() : sources_save
endtry
endfunction"}}}
function! s:neocomplete_source.gather_candidates(args, context) abort "{{{
let keyword_pos = a:context.source__complete_pos
let candidates = []
for keyword in a:context.source__candidates
let dict = {
\ 'word' : keyword.word,
\ 'abbr' : printf('%-50s', get(keyword, 'abbr', keyword.word)),
\ 'kind': 'completion',
\ 'action__complete_word' : keyword.word,
\ 'action__complete_pos' : keyword_pos,
\ }
if has_key(keyword, 'kind')
let dict.abbr .= ' ' . keyword.kind
endif
if has_key(keyword, 'menu')
let dict.abbr .= ' ' . keyword.menu
endif
if has_key(keyword, 'description')
if type(keyword.description) ==# type(function('tr'))
let dict.action__complete_info_lazy = keyword.description
else
let dict.action__complete_info = keyword.description
endif
endif
call add(candidates, dict)
endfor
return candidates
endfunction "}}}
function! unite#sources#neocomplete#start_complete() abort "{{{
return s:start_complete(0)
endfunction "}}}
function! unite#sources#neocomplete#start_quick_match() abort "{{{
return s:start_complete(1)
endfunction "}}}
function! s:start_complete(is_quick_match) abort "{{{
if !neocomplete#is_enabled()
return ''
endif
if !exists(':Unite')
echoerr 'unite.vim is not installed.'
return ''
endif
let cur_text = neocomplete#get_cur_text(1)
let complete_sources = neocomplete#complete#_set_results_pos(cur_text)
if empty(complete_sources)
return ''
endif
return unite#start_complete(['neocomplete'], {
\ 'auto_preview' : 1, 'quick_match' : a:is_quick_match,
\ 'input' : cur_text[neocomplete#complete#_get_complete_pos(
\ complete_sources) :],
\ })
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,12 @@
function! vital#of(name) abort
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital', 1)
let file = split(files, "\n")
if empty(file)
throw 'vital: version file not found: ' . a:name
endif
let ver = readfile(file[0], 'b')
if empty(ver)
throw 'vital: invalid version file: ' . a:name
endif
return vital#_{substitute(ver[0], '\W', '', 'g')}#new()
endfunction

View file

@ -0,0 +1,5 @@
let s:_plugin_name = expand('<sfile>:t:r')
function! vital#{s:_plugin_name}#new() abort
return vital#{s:_plugin_name[1:]}#new()
endfunction

View file

@ -0,0 +1,457 @@
" ___vital___
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_neocomplete#Data#List#import() abort
return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'map_accum': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'shift': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, 'function("s:" . v:key)')
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_neocomplete#Data#List#import() abort', printf("return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'map_accum': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'shift': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
" Utilities for list.
let s:save_cpo = &cpo
set cpo&vim
function! s:pop(list) abort
return remove(a:list, -1)
endfunction
function! s:push(list, val) abort
call add(a:list, a:val)
return a:list
endfunction
function! s:shift(list) abort
return remove(a:list, 0)
endfunction
function! s:unshift(list, val) abort
return insert(a:list, a:val)
endfunction
function! s:cons(x, xs) abort
return [a:x] + a:xs
endfunction
function! s:conj(xs, x) abort
return a:xs + [a:x]
endfunction
" Removes duplicates from a list.
function! s:uniq(list) abort
return s:uniq_by(a:list, 'v:val')
endfunction
" Removes duplicates from a list.
function! s:uniq_by(list, f) abort
let list = map(copy(a:list), printf('[v:val, %s]', a:f))
let i = 0
let seen = {}
while i < len(list)
let key = string(list[i][1])
if has_key(seen, key)
call remove(list, i)
else
let seen[key] = 1
let i += 1
endif
endwhile
return map(list, 'v:val[0]')
endfunction
function! s:clear(list) abort
if !empty(a:list)
unlet! a:list[0 : len(a:list) - 1]
endif
return a:list
endfunction
" Concatenates a list of lists.
" XXX: Should we verify the input?
function! s:concat(list) abort
let memo = []
for Value in a:list
let memo += Value
endfor
return memo
endfunction
" Take each elements from lists to a new list.
function! s:flatten(list, ...) abort
let limit = a:0 > 0 ? a:1 : -1
let memo = []
if limit == 0
return a:list
endif
let limit -= 1
for Value in a:list
let memo +=
\ type(Value) == type([]) ?
\ s:flatten(Value, limit) :
\ [Value]
unlet! Value
endfor
return memo
endfunction
" Sorts a list with expression to compare each two values.
" a:a and a:b can be used in {expr}.
function! s:sort(list, expr) abort
if type(a:expr) == type(function('function'))
return sort(a:list, a:expr)
endif
let s:expr = a:expr
return sort(a:list, 's:_compare')
endfunction
function! s:_compare(a, b) abort
return eval(s:expr)
endfunction
" Sorts a list using a set of keys generated by mapping the values in the list
" through the given expr.
" v:val is used in {expr}
function! s:sort_by(list, expr) abort
let pairs = map(a:list, printf('[v:val, %s]', a:expr))
return map(s:sort(pairs,
\ 'a:a[1] ==# a:b[1] ? 0 : a:a[1] ># a:b[1] ? 1 : -1'), 'v:val[0]')
endfunction
" Returns a maximum value in {list} through given {expr}.
" Returns 0 if {list} is empty.
" v:val is used in {expr}
function! s:max_by(list, expr) abort
if empty(a:list)
return 0
endif
let list = map(copy(a:list), a:expr)
return a:list[index(list, max(list))]
endfunction
" Returns a minimum value in {list} through given {expr}.
" Returns 0 if {list} is empty.
" v:val is used in {expr}
" FIXME: -0x80000000 == 0x80000000
function! s:min_by(list, expr) abort
return s:max_by(a:list, '-(' . a:expr . ')')
endfunction
" Returns List of character sequence between [a:from, a:to]
" e.g.: s:char_range('a', 'c') returns ['a', 'b', 'c']
function! s:char_range(from, to) abort
return map(
\ range(char2nr(a:from), char2nr(a:to)),
\ 'nr2char(v:val)'
\)
endfunction
" Returns true if a:list has a:value.
" Returns false otherwise.
function! s:has(list, value) abort
return index(a:list, a:value) isnot -1
endfunction
" Returns true if a:list[a:index] exists.
" Returns false otherwise.
" NOTE: Returns false when a:index is negative number.
function! s:has_index(list, index) abort
" Return true when negative index?
" let index = a:index >= 0 ? a:index : len(a:list) + a:index
return 0 <= a:index && a:index < len(a:list)
endfunction
" similar to Haskell's Data.List.span
function! s:span(f, xs) abort
let border = len(a:xs)
for i in range(len(a:xs))
if !eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
let border = i
break
endif
endfor
return border == 0 ? [[], copy(a:xs)] : [a:xs[: border - 1], a:xs[border :]]
endfunction
" similar to Haskell's Data.List.break
function! s:break(f, xs) abort
return s:span(printf('!(%s)', a:f), a:xs)
endfunction
" similar to Haskell's Data.List.takeWhile
function! s:take_while(f, xs) abort
return s:span(a:f, a:xs)[0]
endfunction
" similar to Haskell's Data.List.partition
function! s:partition(f, xs) abort
return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')]
endfunction
" similar to Haskell's Prelude.all
function! s:all(f, xs) abort
return !s:any(printf('!(%s)', a:f), a:xs)
endfunction
" similar to Haskell's Prelude.any
function! s:any(f, xs) abort
return !empty(filter(map(copy(a:xs), a:f), 'v:val'))
endfunction
" similar to Haskell's Prelude.and
function! s:and(xs) abort
return s:all('v:val', a:xs)
endfunction
" similar to Haskell's Prelude.or
function! s:or(xs) abort
return s:any('v:val', a:xs)
endfunction
function! s:map_accum(expr, xs, init) abort
let memo = []
let init = a:init
for x in a:xs
let expr = substitute(a:expr, 'v:memo', init, 'g')
let expr = substitute(expr, 'v:val', x, 'g')
let [tmp, init] = eval(expr)
call add(memo, tmp)
endfor
return memo
endfunction
" similar to Haskell's Prelude.foldl
function! s:foldl(f, init, xs) abort
let memo = a:init
for x in a:xs
let expr = substitute(a:f, 'v:val', string(x), 'g')
let expr = substitute(expr, 'v:memo', string(memo), 'g')
unlet memo
let memo = eval(expr)
endfor
return memo
endfunction
" similar to Haskell's Prelude.foldl1
function! s:foldl1(f, xs) abort
if len(a:xs) == 0
throw 'vital: Data.List: foldl1'
endif
return s:foldl(a:f, a:xs[0], a:xs[1:])
endfunction
" similar to Haskell's Prelude.foldr
function! s:foldr(f, init, xs) abort
return s:foldl(a:f, a:init, reverse(copy(a:xs)))
endfunction
" similar to Haskell's Prelude.fold11
function! s:foldr1(f, xs) abort
if len(a:xs) == 0
throw 'vital: Data.List: foldr1'
endif
return s:foldr(a:f, a:xs[-1], a:xs[0:-2])
endfunction
" similar to python's zip()
function! s:zip(...) abort
return map(range(min(map(copy(a:000), 'len(v:val)'))), "map(copy(a:000), 'v:val['.v:val.']')")
endfunction
" similar to zip(), but goes until the longer one.
function! s:zip_fill(xs, ys, filler) abort
if empty(a:xs) && empty(a:ys)
return []
elseif empty(a:ys)
return s:cons([a:xs[0], a:filler], s:zip_fill(a:xs[1 :], [], a:filler))
elseif empty(a:xs)
return s:cons([a:filler, a:ys[0]], s:zip_fill([], a:ys[1 :], a:filler))
else
return s:cons([a:xs[0], a:ys[0]], s:zip_fill(a:xs[1 :], a:ys[1: ], a:filler))
endif
endfunction
" Inspired by Ruby's with_index method.
function! s:with_index(list, ...) abort
let base = a:0 > 0 ? a:1 : 0
return map(copy(a:list), '[v:val, v:key + base]')
endfunction
" similar to Ruby's detect or Haskell's find.
function! s:find(list, default, f) abort
for x in a:list
if eval(substitute(a:f, 'v:val', string(x), 'g'))
return x
endif
endfor
return a:default
endfunction
" Returns the index of the first element which satisfies the given expr.
function! s:find_index(xs, f, ...) abort
let len = len(a:xs)
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0
let default = a:0 > 1 ? a:2 : -1
if start >=# len || start < 0
return default
endif
for i in range(start, len - 1)
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
return i
endif
endfor
return default
endfunction
" Returns the index of the last element which satisfies the given expr.
function! s:find_last_index(xs, f, ...) abort
let len = len(a:xs)
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : len - 1
let default = a:0 > 1 ? a:2 : -1
if start >=# len || start < 0
return default
endif
for i in range(start, 0, -1)
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
return i
endif
endfor
return default
endfunction
" Similar to find_index but returns the list of indices satisfying the given expr.
function! s:find_indices(xs, f, ...) abort
let len = len(a:xs)
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0
let result = []
if start >=# len || start < 0
return result
endif
for i in range(start, len - 1)
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
call add(result, i)
endif
endfor
return result
endfunction
" Return non-zero if a:list1 and a:list2 have any common item(s).
" Return zero otherwise.
function! s:has_common_items(list1, list2) abort
return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1'))
endfunction
function! s:intersect(list1, list2) abort
let items = []
" for funcref
for X in a:list1
if index(a:list2, X) != -1 && index(items, X) == -1
let items += [X]
endif
endfor
return items
endfunction
" similar to Ruby's group_by.
function! s:group_by(xs, f) abort
let result = {}
let list = map(copy(a:xs), printf('[v:val, %s]', a:f))
for x in list
let Val = x[0]
let key = type(x[1]) !=# type('') ? string(x[1]) : x[1]
if has_key(result, key)
call add(result[key], Val)
else
let result[key] = [Val]
endif
unlet Val
endfor
return result
endfunction
function! s:_default_compare(a, b) abort
return a:a <# a:b ? -1 : a:a ># a:b ? 1 : 0
endfunction
function! s:binary_search(list, value, ...) abort
let Predicate = a:0 >= 1 ? a:1 : 's:_default_compare'
let dic = a:0 >= 2 ? a:2 : {}
let start = 0
let end = len(a:list) - 1
while 1
if start > end
return -1
endif
let middle = (start + end) / 2
let compared = call(Predicate, [a:value, a:list[middle]], dic)
if compared < 0
let end = middle - 1
elseif compared > 0
let start = middle + 1
else
return middle
endif
endwhile
endfunction
function! s:product(lists) abort
let result = [[]]
for pool in a:lists
let tmp = []
for x in result
let tmp += map(copy(pool), 'x + [v:val]')
endfor
let result = tmp
endfor
return result
endfunction
function! s:permutations(list, ...) abort
if a:0 > 1
throw 'vital: Data.List: too many arguments'
endif
let r = a:0 == 1 ? a:1 : len(a:list)
if r > len(a:list)
return []
elseif r < 0
throw 'vital: Data.List: {r} must be non-negative integer'
endif
let n = len(a:list)
let result = []
for indices in s:product(map(range(r), 'range(n)'))
if len(s:uniq(indices)) == r
call add(result, map(indices, 'a:list[v:val]'))
endif
endfor
return result
endfunction
function! s:combinations(list, r) abort
if a:r > len(a:list)
return []
elseif a:r < 0
throw 'vital: Data:List: {r} must be non-negative integer'
endif
let n = len(a:list)
let result = []
for indices in s:permutations(range(n), a:r)
if s:sort(copy(indices), 'a:a - a:b') == indices
call add(result, map(indices, 'a:list[v:val]'))
endif
endfor
return result
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View file

@ -0,0 +1,633 @@
" ___vital___
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_neocomplete#Data#String#import() abort
return map({'starts_with': '', 'split3': '', 'replace_first': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'justify_equal_spacing': '', 'nr2hex': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', '_vital_created': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'dstring': '', 'pad_both_sides': '', 'substitute_last': '', 'pad_right': '', 'remove_ansi_sequences': '', '_vital_loaded': ''}, 'function("s:" . v:key)')
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_neocomplete#Data#String#import() abort', printf("return map({'starts_with': '', 'split3': '', 'replace_first': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'justify_equal_spacing': '', 'nr2hex': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', '_vital_created': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'dstring': '', 'pad_both_sides': '', 'substitute_last': '', 'pad_right': '', 'remove_ansi_sequences': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
" Utilities for string.
let s:save_cpo = &cpo
set cpo&vim
function! s:_vital_loaded(V) abort
let s:V = a:V
let s:L = s:V.import('Data.List')
endfunction
function! s:_vital_depends() abort
return ['Data.List']
endfunction
function! s:_vital_created(module) abort
" Expose script-local funcref
if exists('s:strchars')
let a:module.strchars = s:strchars
endif
if exists('s:wcswidth')
let a:module.wcswidth = s:wcswidth
endif
endfunction
" Substitute a:from => a:to by string.
" To substitute by pattern, use substitute() instead.
function! s:replace(str, from, to) abort
return s:_replace(a:str, a:from, a:to, 'g')
endfunction
" Substitute a:from => a:to only once.
" cf. s:replace()
function! s:replace_first(str, from, to) abort
return s:_replace(a:str, a:from, a:to, '')
endfunction
" implement of replace() and replace_first()
function! s:_replace(str, from, to, flags) abort
return substitute(a:str, '\V'.escape(a:from, '\'), escape(a:to, '\'), a:flags)
endfunction
function! s:scan(str, pattern) abort
let list = []
call substitute(a:str, a:pattern, '\=add(list, submatch(0)) == [] ? "" : ""', 'g')
return list
endfunction
function! s:reverse(str) abort
return join(reverse(split(a:str, '.\zs')), '')
endfunction
function! s:starts_with(str, prefix) abort
return stridx(a:str, a:prefix) == 0
endfunction
function! s:ends_with(str, suffix) abort
let idx = strridx(a:str, a:suffix)
return 0 <= idx && idx + len(a:suffix) == len(a:str)
endfunction
function! s:common_head(strs) abort
if empty(a:strs)
return ''
endif
let len = len(a:strs)
if len == 1
return a:strs[0]
endif
let strs = len == 2 ? a:strs : sort(copy(a:strs))
let pat = substitute(strs[0], '.', '\="[" . escape(submatch(0), "^\\") . "]"', 'g')
return pat ==# '' ? '' : matchstr(strs[-1], '\C^\%[' . pat . ']')
endfunction
" Split to two elements of List. ([left, right])
" e.g.: s:split3('neocomplcache', 'compl') returns ['neo', 'compl', 'cache']
function! s:split_leftright(expr, pattern) abort
let [left, _, right] = s:split3(a:expr, a:pattern)
return [left, right]
endfunction
function! s:split3(expr, pattern) abort
let ERROR = ['', '', '']
if a:expr ==# '' || a:pattern ==# ''
return ERROR
endif
let begin = match(a:expr, a:pattern)
if begin is -1
return ERROR
endif
let end = matchend(a:expr, a:pattern)
let left = begin <=# 0 ? '' : a:expr[: begin - 1]
let right = a:expr[end :]
return [left, a:expr[begin : end-1], right]
endfunction
" Slices into strings determines the number of substrings.
" e.g.: s:nsplit("neo compl cache", 2, '\s') returns ['neo', 'compl cache']
function! s:nsplit(expr, n, ...) abort
let pattern = get(a:000, 0, '\s')
let keepempty = get(a:000, 1, 1)
let ret = []
let expr = a:expr
if a:n <= 1
return [expr]
endif
while 1
let pos = match(expr, pattern)
if pos == -1
if expr !~ pattern || keepempty
call add(ret, expr)
endif
break
elseif pos >= 0
let left = pos > 0 ? expr[:pos-1] : ''
if pos > 0 || keepempty
call add(ret, left)
endif
let ml = len(matchstr(expr, pattern))
if pos == 0 && ml == 0
let pos = 1
endif
let expr = expr[pos+ml :]
endif
if len(expr) == 0
break
endif
if len(ret) == a:n - 1
call add(ret, expr)
break
endif
endwhile
return ret
endfunction
" Returns the number of character in a:str.
" NOTE: This returns proper value
" even if a:str contains multibyte character(s).
" s:strchars(str) {{{
if exists('*strchars')
let s:strchars = function('strchars')
else
function! s:strchars(str) abort
return strlen(substitute(copy(a:str), '.', 'x', 'g'))
endfunction
endif "}}}
" Returns the bool of contains any multibyte character in s:str
function! s:contains_multibyte(str) abort "{{{
return strlen(a:str) != s:strchars(a:str)
endfunction "}}}
" Remove last character from a:str.
" NOTE: This returns proper value
" even if a:str contains multibyte character(s).
function! s:chop(str) abort "{{{
return substitute(a:str, '.$', '', '')
endfunction "}}}
" Remove last \r,\n,\r\n from a:str.
function! s:chomp(str) abort "{{{
return substitute(a:str, '\%(\r\n\|[\r\n]\)$', '', '')
endfunction "}}}
" wrap() and its internal functions
" * _split_by_wcswidth_once()
" * _split_by_wcswidth()
" * _concat()
" * wrap()
"
" NOTE _concat() is just a copy of Data.List.concat().
" FIXME don't repeat yourself
function! s:_split_by_wcswidth_once(body, x) abort
let fst = s:strwidthpart(a:body, a:x)
let snd = s:strwidthpart_reverse(a:body, s:wcswidth(a:body) - s:wcswidth(fst))
return [fst, snd]
endfunction
function! s:_split_by_wcswidth(body, x) abort
let memo = []
let body = a:body
while s:wcswidth(body) > a:x
let [tmp, body] = s:_split_by_wcswidth_once(body, a:x)
call add(memo, tmp)
endwhile
call add(memo, body)
return memo
endfunction
function! s:trim(str) abort
return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$')
endfunction
function! s:trim_start(str) abort
return matchstr(a:str,'^\s*\zs.\{-}$')
endfunction
function! s:trim_end(str) abort
return matchstr(a:str,'^.\{-}\ze\s*$')
endfunction
function! s:wrap(str,...) abort
let _columns = a:0 > 0 ? a:1 : &columns
return s:L.concat(
\ map(split(a:str, '\r\n\|[\r\n]'), 's:_split_by_wcswidth(v:val, _columns - 1)'))
endfunction
function! s:nr2byte(nr) abort
if a:nr < 0x80
return nr2char(a:nr)
elseif a:nr < 0x800
return nr2char(a:nr/64+192).nr2char(a:nr%64+128)
else
return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128)
endif
endfunction
function! s:nr2enc_char(charcode) abort
if &encoding ==# 'utf-8'
return nr2char(a:charcode)
endif
let char = s:nr2byte(a:charcode)
if strlen(char) > 1
let char = strtrans(iconv(char, 'utf-8', &encoding))
endif
return char
endfunction
function! s:nr2hex(nr) abort
let n = a:nr
let r = ''
while n
let r = '0123456789ABCDEF'[n % 16] . r
let n = n / 16
endwhile
return r
endfunction
" If a ==# b, returns -1.
" If a !=# b, returns first index of different character.
function! s:diffidx(a, b) abort
return a:a ==# a:b ? -1 : strlen(s:common_head([a:a, a:b]))
endfunction
function! s:substitute_last(expr, pat, sub) abort
return substitute(a:expr, printf('.*\zs%s', a:pat), a:sub, '')
endfunction
function! s:dstring(expr) abort
let x = substitute(string(a:expr), "^'\\|'$", '', 'g')
let x = substitute(x, "''", "'", 'g')
return printf('"%s"', escape(x, '"'))
endfunction
function! s:lines(str) abort
return split(a:str, '\r\?\n')
endfunction
function! s:_pad_with_char(str, left, right, char) abort
return repeat(a:char, a:left). a:str. repeat(a:char, a:right)
endfunction
function! s:pad_left(str, width, ...) abort
let char = get(a:, 1, ' ')
if strdisplaywidth(char) != 1
throw "vital: Data.String: Can't use non-half-width characters for padding."
endif
let left = max([0, a:width - strdisplaywidth(a:str)])
return s:_pad_with_char(a:str, left, 0, char)
endfunction
function! s:pad_right(str, width, ...) abort
let char = get(a:, 1, ' ')
if strdisplaywidth(char) != 1
throw "vital: Data.String: Can't use non-half-width characters for padding."
endif
let right = max([0, a:width - strdisplaywidth(a:str)])
return s:_pad_with_char(a:str, 0, right, char)
endfunction
function! s:pad_both_sides(str, width, ...) abort
let char = get(a:, 1, ' ')
if strdisplaywidth(char) != 1
throw "vital: Data.String: Can't use non-half-width characters for padding."
endif
let space = max([0, a:width - strdisplaywidth(a:str)])
let left = space / 2
let right = space - left
return s:_pad_with_char(a:str, left, right, char)
endfunction
function! s:pad_between_letters(str, width, ...) abort
let char = get(a:, 1, ' ')
if strdisplaywidth(char) != 1
throw "vital: Data.String: Can't use non-half-width characters for padding."
endif
let letters = split(a:str, '\zs')
let each_width = a:width / len(letters)
let str = join(map(letters, 's:pad_both_sides(v:val, each_width, char)'), '')
if a:width - strdisplaywidth(str) > 0
return char. s:pad_both_sides(str, a:width - 1, char)
endif
return str
endfunction
function! s:justify_equal_spacing(str, width, ...) abort
let char = get(a:, 1, ' ')
if strdisplaywidth(char) != 1
throw "vital: Data.String: Can't use non-half-width characters for padding."
endif
let letters = split(a:str, '\zs')
let first_letter = letters[0]
" {width w/o the first letter} / {length w/o the first letter}
let each_width = (a:width - strdisplaywidth(first_letter)) / (len(letters) - 1)
let remainder = (a:width - strdisplaywidth(first_letter)) % (len(letters) - 1)
return first_letter. join(s:L.concat([
\ map(letters[1:remainder], 's:pad_left(v:val, each_width + 1, char)'),
\ map(letters[remainder + 1:], 's:pad_left(v:val, each_width, char)')
\ ]), '')
endfunction
function! s:levenshtein_distance(str1, str2) abort
let letters1 = split(a:str1, '\zs')
let letters2 = split(a:str2, '\zs')
let length1 = len(letters1)
let length2 = len(letters2)
let distances = map(range(1, length1 + 1), 'map(range(1, length2 + 1), ''0'')')
for i1 in range(0, length1)
let distances[i1][0] = i1
endfor
for i2 in range(0, length2)
let distances[0][i2] = i2
endfor
for i1 in range(1, length1)
for i2 in range(1, length2)
let cost = (letters1[i1 - 1] ==# letters2[i2 - 1]) ? 0 : 1
let distances[i1][i2] = min([
\ distances[i1 - 1][i2 ] + 1,
\ distances[i1 ][i2 - 1] + 1,
\ distances[i1 - 1][i2 - 1] + cost,
\])
endfor
endfor
return distances[length1][length2]
endfunction
function! s:padding_by_displaywidth(expr, width, float) abort
let padding_char = ' '
let n = a:width - strdisplaywidth(a:expr)
if n <= 0
let n = 0
endif
if a:float < 0
return a:expr . repeat(padding_char, n)
elseif 0 < a:float
return repeat(padding_char, n) . a:expr
else
if n % 2 is 0
return repeat(padding_char, n / 2) . a:expr . repeat(padding_char, n / 2)
else
return repeat(padding_char, (n - 1) / 2) . a:expr . repeat(padding_char, (n - 1) / 2) . padding_char
endif
endif
endfunction
function! s:split_by_displaywidth(expr, width, float, is_wrap) abort
if a:width is 0
return ['']
endif
let lines = []
let cs = split(a:expr, '\zs')
let cs_index = 0
let text = ''
while cs_index < len(cs)
if cs[cs_index] is# "\n"
let text = s:padding_by_displaywidth(text, a:width, a:float)
let lines += [text]
let text = ''
else
let w = strdisplaywidth(text . cs[cs_index])
if w < a:width
let text .= cs[cs_index]
elseif a:width < w
let text = s:padding_by_displaywidth(text, a:width, a:float)
else
let text .= cs[cs_index]
endif
if a:width <= w
let lines += [text]
let text = ''
if a:is_wrap
if a:width < w
if a:width < strdisplaywidth(cs[cs_index])
while get(cs, cs_index, "\n") isnot# "\n"
let cs_index += 1
endwhile
continue
else
let text = cs[cs_index]
endif
endif
else
while get(cs, cs_index, "\n") isnot# "\n"
let cs_index += 1
endwhile
continue
endif
endif
endif
let cs_index += 1
endwhile
if !empty(text)
let lines += [ s:padding_by_displaywidth(text, a:width, a:float) ]
endif
return lines
endfunction
function! s:hash(str) abort
if exists('*sha256')
return sha256(a:str)
else
" This gives up sha256ing but just adds up char with index.
let sum = 0
for i in range(len(a:str))
let sum += char2nr(a:str[i]) * (i + 1)
endfor
return printf('%x', sum)
endif
endfunction
function! s:truncate(str, width) abort
" Original function is from mattn.
" http://github.com/mattn/googlereader-vim/tree/master
if a:str =~# '^[\x00-\x7f]*$'
return len(a:str) < a:width
\ ? printf('%-' . a:width . 's', a:str)
\ : strpart(a:str, 0, a:width)
endif
let ret = a:str
let width = s:wcswidth(a:str)
if width > a:width
let ret = s:strwidthpart(ret, a:width)
let width = s:wcswidth(ret)
endif
if width < a:width
let ret .= repeat(' ', a:width - width)
endif
return ret
endfunction
function! s:truncate_skipping(str, max, footer_width, separator) abort
let width = s:wcswidth(a:str)
if width <= a:max
let ret = a:str
else
let header_width = a:max - s:wcswidth(a:separator) - a:footer_width
let ret = s:strwidthpart(a:str, header_width) . a:separator
\ . s:strwidthpart_reverse(a:str, a:footer_width)
endif
return s:truncate(ret, a:max)
endfunction
function! s:strwidthpart(str, width) abort
let str = tr(a:str, "\t", ' ')
let vcol = a:width + 2
return matchstr(str, '.*\%<' . (vcol < 0 ? 0 : vcol) . 'v')
endfunction
function! s:strwidthpart_reverse(str, width) abort
let str = tr(a:str, "\t", ' ')
let vcol = s:wcswidth(str) - a:width
return matchstr(str, '\%>' . (vcol < 0 ? 0 : vcol) . 'v.*')
endfunction
if v:version >= 703
" Use builtin function.
let s:wcswidth = function('strwidth')
else
function! s:wcswidth(str) abort
if a:str =~# '^[\x00-\x7f]*$'
return strlen(a:str)
endif
let mx_first = '^\(.\)'
let str = a:str
let width = 0
while 1
let ucs = char2nr(substitute(str, mx_first, '\1', ''))
if ucs == 0
break
endif
let width += s:_wcwidth(ucs)
let str = substitute(str, mx_first, '', '')
endwhile
return width
endfunction
" UTF-8 only.
function! s:_wcwidth(ucs) abort
let ucs = a:ucs
if (ucs >= 0x1100
\ && (ucs <= 0x115f
\ || ucs == 0x2329
\ || ucs == 0x232a
\ || (ucs >= 0x2e80 && ucs <= 0xa4cf
\ && ucs != 0x303f)
\ || (ucs >= 0xac00 && ucs <= 0xd7a3)
\ || (ucs >= 0xf900 && ucs <= 0xfaff)
\ || (ucs >= 0xfe30 && ucs <= 0xfe6f)
\ || (ucs >= 0xff00 && ucs <= 0xff60)
\ || (ucs >= 0xffe0 && ucs <= 0xffe6)
\ || (ucs >= 0x20000 && ucs <= 0x2fffd)
\ || (ucs >= 0x30000 && ucs <= 0x3fffd)
\ ))
return 2
endif
return 1
endfunction
endif
function! s:remove_ansi_sequences(text) abort
return substitute(a:text, '\e\[\%(\%(\d\+;\)*\d\+\)\?[mK]', '', 'g')
endfunction
function! s:escape_pattern(str) abort
" escape characters for no-magic
return escape(a:str, '^$~.*[]\')
endfunction
function! s:unescape_pattern(str) abort
" unescape characters for no-magic
return s:unescape(a:str, '^$~.*[]\')
endfunction
function! s:unescape(str, chars) abort
let chars = map(split(a:chars, '\zs'), 'escape(v:val, ''^$~.*[]\'')')
return substitute(a:str, '\\\(' . join(chars, '\|') . '\)', '\1', 'g')
endfunction
function! s:iconv(expr, from, to) abort
if a:from ==# '' || a:to ==# '' || a:from ==? a:to
return a:expr
endif
let result = iconv(a:expr, a:from, a:to)
return empty(result) ? a:expr : result
endfunction
" NOTE:
" A definition of a TEXT file is "A file that contains characters organized
" into one or more lines."
" A definition of a LINE is "A sequence of zero or more non- <newline>s
" plus a terminating <newline>"
" That's why {stdin} always ends with <newline> ideally. However, there are
" some programs which does not follow the POSIX rule and a Vim's way to join
" List into TEXT; join({text}, "\n"); does not add <newline> to the end of
" the last line.
" That's why add a trailing <newline> if it does not exist.
" REF:
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
" :help split()
" NOTE:
" it does nothing if the text is a correct POSIX text
function! s:repair_posix_text(text, ...) abort
let newline = get(a:000, 0, "\n")
return a:text =~# '\n$' ? a:text : a:text . newline
endfunction
" NOTE:
" A definition of a TEXT file is "A file that contains characters organized
" into one or more lines."
" A definition of a LINE is "A sequence of zero or more non- <newline>s
" plus a terminating <newline>"
" REF:
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
function! s:join_posix_lines(lines, ...) abort
let newline = get(a:000, 0, "\n")
return join(a:lines, newline) . newline
endfunction
" NOTE:
" A definition of a TEXT file is "A file that contains characters organized
" into one or more lines."
" A definition of a LINE is "A sequence of zero or more non- <newline>s
" plus a terminating <newline>"
" TEXT into List; split({text}, '\r\?\n', 1); add an extra empty line at the
" end of List because the end of TEXT ends with <newline> and keepempty=1 is
" specified. (btw. keepempty=0 cannot be used because it will remove
" emptylines in the head and the tail).
" That's why removing a trailing <newline> before proceeding to 'split' is required
" REF:
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
function! s:split_posix_text(text, ...) abort
let newline = get(a:000, 0, '\r\?\n')
let text = substitute(a:text, newline . '$', '', '')
return split(text, newline, 1)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View file

@ -0,0 +1,430 @@
" ___vital___
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_neocomplete#Prelude#import() abort
return map({'escape_pattern': '', 'is_funcref': '', 'path2directory': '', 'wcswidth': '', 'is_string': '', 'input_helper': '', 'is_number': '', 'is_cygwin': '', 'path2project_directory': '', 'strwidthpart_reverse': '', 'input_safe': '', 'is_list': '', 'truncate_skipping': '', 'glob': '', 'truncate': '', 'is_dict': '', 'set_default': '', 'is_numeric': '', 'getchar_safe': '', 'substitute_path_separator': '', 'is_mac': '', 'strwidthpart': '', 'getchar': '', 'is_unix': '', 'is_windows': '', 'globpath': '', 'escape_file_searching': '', 'is_float': '', 'smart_execute_command': ''}, 'function("s:" . v:key)')
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_neocomplete#Prelude#import() abort', printf("return map({'escape_pattern': '', 'is_funcref': '', 'path2directory': '', 'wcswidth': '', 'is_string': '', 'input_helper': '', 'is_number': '', 'is_cygwin': '', 'path2project_directory': '', 'strwidthpart_reverse': '', 'input_safe': '', 'is_list': '', 'truncate_skipping': '', 'glob': '', 'truncate': '', 'is_dict': '', 'set_default': '', 'is_numeric': '', 'getchar_safe': '', 'substitute_path_separator': '', 'is_mac': '', 'strwidthpart': '', 'getchar': '', 'is_unix': '', 'is_windows': '', 'globpath': '', 'escape_file_searching': '', 'is_float': '', 'smart_execute_command': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
let s:save_cpo = &cpo
set cpo&vim
if v:version > 703 ||
\ (v:version == 703 && has('patch465'))
function! s:glob(expr) abort
return glob(a:expr, 1, 1)
endfunction
else
function! s:glob(expr) abort
return split(glob(a:expr, 1), '\n')
endfunction
endif
if v:version > 704 ||
\ (v:version == 704 && has('patch279'))
function! s:globpath(path, expr) abort
return globpath(a:path, a:expr, 1, 1)
endfunction
else
function! s:globpath(path, expr) abort
return split(globpath(a:path, a:expr, 1), '\n')
endfunction
endif
" Wrapper functions for type().
" NOTE: __TYPE_FLOAT = -1 when -float.
" this doesn't match to anything.
if has('patch-7.4.2071')
let [
\ s:__TYPE_NUMBER,
\ s:__TYPE_STRING,
\ s:__TYPE_FUNCREF,
\ s:__TYPE_LIST,
\ s:__TYPE_DICT,
\ s:__TYPE_FLOAT] = [
\ v:t_number,
\ v:t_string,
\ v:t_func,
\ v:t_list,
\ v:t_dict,
\ v:t_float]
else
let [
\ s:__TYPE_NUMBER,
\ s:__TYPE_STRING,
\ s:__TYPE_FUNCREF,
\ s:__TYPE_LIST,
\ s:__TYPE_DICT,
\ s:__TYPE_FLOAT] = [
\ type(3),
\ type(''),
\ type(function('tr')),
\ type([]),
\ type({}),
\ has('float') ? type(str2float('0')) : -1]
endif
" Number or Float
function! s:is_numeric(Value) abort
let _ = type(a:Value)
return _ ==# s:__TYPE_NUMBER
\ || _ ==# s:__TYPE_FLOAT
endfunction
" Number
function! s:is_number(Value) abort
return type(a:Value) ==# s:__TYPE_NUMBER
endfunction
" String
function! s:is_string(Value) abort
return type(a:Value) ==# s:__TYPE_STRING
endfunction
" Funcref
function! s:is_funcref(Value) abort
return type(a:Value) ==# s:__TYPE_FUNCREF
endfunction
" List
function! s:is_list(Value) abort
return type(a:Value) ==# s:__TYPE_LIST
endfunction
" Dictionary
function! s:is_dict(Value) abort
return type(a:Value) ==# s:__TYPE_DICT
endfunction
" Float
function! s:is_float(Value) abort
return type(a:Value) ==# s:__TYPE_FLOAT
endfunction
function! s:truncate_skipping(str, max, footer_width, separator) abort
call s:_warn_deprecated('truncate_skipping', 'Data.String.truncate_skipping')
let width = s:wcswidth(a:str)
if width <= a:max
let ret = a:str
else
let header_width = a:max - s:wcswidth(a:separator) - a:footer_width
let ret = s:strwidthpart(a:str, header_width) . a:separator
\ . s:strwidthpart_reverse(a:str, a:footer_width)
endif
return s:truncate(ret, a:max)
endfunction
function! s:truncate(str, width) abort
" Original function is from mattn.
" http://github.com/mattn/googlereader-vim/tree/master
call s:_warn_deprecated('truncate', 'Data.String.truncate')
if a:str =~# '^[\x00-\x7f]*$'
return len(a:str) < a:width ?
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
endif
let ret = a:str
let width = s:wcswidth(a:str)
if width > a:width
let ret = s:strwidthpart(ret, a:width)
let width = s:wcswidth(ret)
endif
if width < a:width
let ret .= repeat(' ', a:width - width)
endif
return ret
endfunction
function! s:strwidthpart(str, width) abort
call s:_warn_deprecated('strwidthpart', 'Data.String.strwidthpart')
if a:width <= 0
return ''
endif
let ret = a:str
let width = s:wcswidth(a:str)
while width > a:width
let char = matchstr(ret, '.$')
let ret = ret[: -1 - len(char)]
let width -= s:wcswidth(char)
endwhile
return ret
endfunction
function! s:strwidthpart_reverse(str, width) abort
call s:_warn_deprecated('strwidthpart_reverse', 'Data.String.strwidthpart_reverse')
if a:width <= 0
return ''
endif
let ret = a:str
let width = s:wcswidth(a:str)
while width > a:width
let char = matchstr(ret, '^.')
let ret = ret[len(char) :]
let width -= s:wcswidth(char)
endwhile
return ret
endfunction
if v:version >= 703
" Use builtin function.
function! s:wcswidth(str) abort
call s:_warn_deprecated('wcswidth', 'Data.String.wcswidth')
return strwidth(a:str)
endfunction
else
function! s:wcswidth(str) abort
call s:_warn_deprecated('wcswidth', 'Data.String.wcswidth')
if a:str =~# '^[\x00-\x7f]*$'
return strlen(a:str)
end
let mx_first = '^\(.\)'
let str = a:str
let width = 0
while 1
let ucs = char2nr(substitute(str, mx_first, '\1', ''))
if ucs == 0
break
endif
let width += s:_wcwidth(ucs)
let str = substitute(str, mx_first, '', '')
endwhile
return width
endfunction
" UTF-8 only.
function! s:_wcwidth(ucs) abort
let ucs = a:ucs
if (ucs >= 0x1100
\ && (ucs <= 0x115f
\ || ucs == 0x2329
\ || ucs == 0x232a
\ || (ucs >= 0x2e80 && ucs <= 0xa4cf
\ && ucs != 0x303f)
\ || (ucs >= 0xac00 && ucs <= 0xd7a3)
\ || (ucs >= 0xf900 && ucs <= 0xfaff)
\ || (ucs >= 0xfe30 && ucs <= 0xfe6f)
\ || (ucs >= 0xff00 && ucs <= 0xff60)
\ || (ucs >= 0xffe0 && ucs <= 0xffe6)
\ || (ucs >= 0x20000 && ucs <= 0x2fffd)
\ || (ucs >= 0x30000 && ucs <= 0x3fffd)
\ ))
return 2
endif
return 1
endfunction
endif
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
let s:is_cygwin = has('win32unix')
let s:is_mac = !s:is_windows && !s:is_cygwin
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
\ (!isdirectory('/proc') && executable('sw_vers')))
let s:is_unix = has('unix')
function! s:is_windows() abort
return s:is_windows
endfunction
function! s:is_cygwin() abort
return s:is_cygwin
endfunction
function! s:is_mac() abort
return s:is_mac
endfunction
function! s:is_unix() abort
return s:is_unix
endfunction
function! s:_warn_deprecated(name, alternative) abort
try
echohl Error
echomsg 'Prelude.' . a:name . ' is deprecated! Please use ' . a:alternative . ' instead.'
finally
echohl None
endtry
endfunction
function! s:smart_execute_command(action, word) abort
execute a:action . ' ' . (a:word ==# '' ? '' : '`=a:word`')
endfunction
function! s:escape_file_searching(buffer_name) abort
return escape(a:buffer_name, '*[]?{}, ')
endfunction
function! s:escape_pattern(str) abort
call s:_warn_deprecated(
\ 'escape_pattern',
\ 'Data.String.escape_pattern',
\)
return escape(a:str, '~"\.^$[]*')
endfunction
function! s:getchar(...) abort
let c = call('getchar', a:000)
return type(c) == type(0) ? nr2char(c) : c
endfunction
function! s:getchar_safe(...) abort
let c = s:input_helper('getchar', a:000)
return type(c) == type('') ? c : nr2char(c)
endfunction
function! s:input_safe(...) abort
return s:input_helper('input', a:000)
endfunction
function! s:input_helper(funcname, args) abort
let success = 0
if inputsave() !=# success
throw 'vital: Prelude: inputsave() failed'
endif
try
return call(a:funcname, a:args)
finally
if inputrestore() !=# success
throw 'vital: Prelude: inputrestore() failed'
endif
endtry
endfunction
function! s:set_default(var, val) abort
if !exists(a:var) || type({a:var}) != type(a:val)
let {a:var} = a:val
endif
endfunction
function! s:substitute_path_separator(path) abort
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
endfunction
function! s:path2directory(path) abort
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
endfunction
function! s:_path2project_directory_git(path) abort
let parent = a:path
while 1
let path = parent . '/.git'
if isdirectory(path) || filereadable(path)
return parent
endif
let next = fnamemodify(parent, ':h')
if next == parent
return ''
endif
let parent = next
endwhile
endfunction
function! s:_path2project_directory_svn(path) abort
let search_directory = a:path
let directory = ''
let find_directory = s:escape_file_searching(search_directory)
let d = finddir('.svn', find_directory . ';')
if d ==# ''
return ''
endif
let directory = fnamemodify(d, ':p:h:h')
" Search parent directories.
let parent_directory = s:path2directory(
\ fnamemodify(directory, ':h'))
if parent_directory !=# ''
let d = finddir('.svn', parent_directory . ';')
if d !=# ''
let directory = s:_path2project_directory_svn(parent_directory)
endif
endif
return directory
endfunction
function! s:_path2project_directory_others(vcs, path) abort
let vcs = a:vcs
let search_directory = a:path
let find_directory = s:escape_file_searching(search_directory)
let d = finddir(vcs, find_directory . ';')
if d ==# ''
return ''
endif
return fnamemodify(d, ':p:h:h')
endfunction
function! s:path2project_directory(path, ...) abort
let is_allow_empty = get(a:000, 0, 0)
let search_directory = s:path2directory(a:path)
let directory = ''
" Search VCS directory.
for vcs in ['.git', '.bzr', '.hg', '.svn']
if vcs ==# '.git'
let directory = s:_path2project_directory_git(search_directory)
elseif vcs ==# '.svn'
let directory = s:_path2project_directory_svn(search_directory)
else
let directory = s:_path2project_directory_others(vcs, search_directory)
endif
if directory !=# ''
break
endif
endfor
" Search project file.
if directory ==# ''
for d in ['build.xml', 'prj.el', '.project', 'pom.xml', 'package.json',
\ 'Makefile', 'configure', 'Rakefile', 'NAnt.build',
\ 'P4CONFIG', 'tags', 'gtags']
let d = findfile(d, s:escape_file_searching(search_directory) . ';')
if d !=# ''
let directory = fnamemodify(d, ':p:h')
break
endif
endfor
endif
if directory ==# ''
" Search /src/ directory.
let base = s:substitute_path_separator(search_directory)
if base =~# '/src/'
let directory = base[: strridx(base, '/src/') + 3]
endif
endif
if directory ==# '' && !is_allow_empty
" Use original path.
let directory = search_directory
endif
return s:substitute_path_separator(directory)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View file

@ -0,0 +1,181 @@
" ___vital___
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_neocomplete#Process#import() abort
return map({'shellescape': '', 'has_vimproc': '', 'system': '', 'iconv': '', 'spawn': '', 'get_last_status': ''}, 'function("s:" . v:key)')
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_neocomplete#Process#import() abort', printf("return map({'shellescape': '', 'has_vimproc': '', 'system': '', 'iconv': '', 'spawn': '', 'get_last_status': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
" TODO: move all comments to doc file.
"
"
" FIXME: This module name should be Vital.System ?
" But the name has been already taken.
let s:save_cpo = &cpo
set cpo&vim
" FIXME: Unfortunately, can't use s:_vital_loaded() for this purpose.
" Because these variables are used when this script file is loaded.
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
let s:is_unix = has('unix')
" As of 7.4.122, the system()'s 1st argument is converted internally by Vim.
" Note that Patch 7.4.122 does not convert system()'s 2nd argument and
" return-value. We must convert them manually.
let s:need_trans = v:version < 704 || (v:version == 704 && !has('patch122'))
let s:TYPE_DICT = type({})
let s:TYPE_LIST = type([])
let s:TYPE_STRING = type('')
function! s:spawn(expr, ...) abort
let shellslash = 0
if s:is_windows
let shellslash = &l:shellslash
setlocal noshellslash
endif
try
if type(a:expr) is s:TYPE_LIST
let special = 1
let cmdline = join(map(a:expr, 'shellescape(v:val, special)'), ' ')
elseif type(a:expr) is s:TYPE_STRING
let cmdline = a:expr
if a:0 && a:1
" for :! command
let cmdline = substitute(cmdline, '\([!%#]\|<[^<>]\+>\)', '\\\1', 'g')
endif
else
throw 'Process.spawn(): invalid argument (value type:'.type(a:expr).')'
endif
if s:is_windows
silent execute '!start' cmdline
else
silent execute '!' cmdline '&'
endif
finally
if s:is_windows
let &l:shellslash = shellslash
endif
endtry
return ''
endfunction
" iconv() wrapper for safety.
function! s:iconv(expr, from, to) abort
if a:from ==# '' || a:to ==# '' || a:from ==? a:to
return a:expr
endif
let result = iconv(a:expr, a:from, a:to)
return result !=# '' ? result : a:expr
endfunction
" Check vimproc.
function! s:has_vimproc() abort
if !exists('s:exists_vimproc')
try
call vimproc#version()
let s:exists_vimproc = 1
catch
let s:exists_vimproc = 0
endtry
endif
return s:exists_vimproc
endfunction
" * {command} [, {input} [, {timeout}]]
" * {command} [, {dict}]
" {dict} = {
" use_vimproc: bool,
" input: string,
" timeout: bool,
" background: bool,
" }
function! s:system(str, ...) abort
" Process optional arguments at first
" because use_vimproc is required later
" for a:str argument.
let input = ''
let use_vimproc = s:has_vimproc()
let background = 0
let args = []
if a:0 ==# 1
" {command} [, {dict}]
" a:1 = {dict}
if type(a:1) is s:TYPE_DICT
if has_key(a:1, 'use_vimproc')
let use_vimproc = a:1.use_vimproc
endif
if has_key(a:1, 'input')
let args += [s:iconv(a:1.input, &encoding, 'char')]
endif
if use_vimproc && has_key(a:1, 'timeout')
" ignores timeout unless you have vimproc.
let args += [a:1.timeout]
endif
if has_key(a:1, 'background')
let background = a:1.background
endif
elseif type(a:1) is s:TYPE_STRING
let args += [s:iconv(a:1, &encoding, 'char')]
else
throw 'Process.system(): invalid argument (value type:'.type(a:1).')'
endif
elseif a:0 >= 2
" {command} [, {input} [, {timeout}]]
" a:000 = [{input} [, {timeout}]]
let [input; rest] = a:000
let input = s:iconv(input, &encoding, 'char')
let args += [input] + rest
endif
" Process a:str argument.
if type(a:str) is s:TYPE_LIST
let expr = use_vimproc ? '"''" . v:val . "''"' : 's:shellescape(v:val)'
let command = join(map(copy(a:str), expr), ' ')
elseif type(a:str) is s:TYPE_STRING
let command = a:str
else
throw 'Process.system(): invalid argument (value type:'.type(a:str).')'
endif
if s:need_trans
let command = s:iconv(command, &encoding, 'char')
endif
let args = [command] + args
if background && (use_vimproc || !s:is_windows)
let args[0] = args[0] . ' &'
endif
let funcname = use_vimproc ? 'vimproc#system' : 'system'
let output = call(funcname, args)
let output = s:iconv(output, 'char', &encoding)
return output
endfunction
function! s:get_last_status() abort
return s:has_vimproc() ?
\ vimproc#get_last_status() : v:shell_error
endfunction
if s:is_windows
function! s:shellescape(command) abort
return substitute(a:command, '[&()[\]{}^=;!''+,`~]', '^\0', 'g')
endfunction
else
function! s:shellescape(...) abort
return call('shellescape', a:000)
endfunction
endif
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View file

@ -0,0 +1,101 @@
" ___vital___
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_neocomplete#System#Cache#Deprecated#import() abort
return map({'filereadable': '', '_vital_depends': '', 'delete': '', 'readfile': '', 'getfilename': '', 'deletefile': '', 'check_old_cache': '', 'writefile': '', '_vital_loaded': ''}, 'function("s:" . v:key)')
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_neocomplete#System#Cache#Deprecated#import() abort', printf("return map({'filereadable': '', '_vital_depends': '', 'delete': '', 'readfile': '', 'getfilename': '', 'deletefile': '', 'check_old_cache': '', 'writefile': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
" Note:
" This module is deprecated. Use a new `Syste.Cache` instead.
let s:save_cpo = &cpo
set cpo&vim
function! s:_vital_loaded(V) abort
let s:V = a:V
let s:S = s:V.import('Data.String')
endfunction
function! s:_vital_depends() abort
return ['Data.String']
endfunction
function! s:getfilename(cache_dir, filename) abort
return s:_encode_name(a:cache_dir, a:filename)
endfunction
function! s:filereadable(cache_dir, filename) abort
let cache_name = s:_encode_name(a:cache_dir, a:filename)
return filereadable(cache_name)
endfunction
function! s:readfile(cache_dir, filename) abort
let cache_name = s:_encode_name(a:cache_dir, a:filename)
return filereadable(cache_name) ? readfile(cache_name) : []
endfunction
function! s:writefile(cache_dir, filename, list) abort
let cache_name = s:_encode_name(a:cache_dir, a:filename)
call writefile(a:list, cache_name)
endfunction
function! s:delete(cache_dir, filename) abort
echoerr 'System.Cache.delete() is obsolete. Use its deletefile() instead.'
return call('s:deletefile', a:cache_dir, a:filename)
endfunction
function! s:deletefile(cache_dir, filename) abort
let cache_name = s:_encode_name(a:cache_dir, a:filename)
return delete(cache_name)
endfunction
function! s:_encode_name(cache_dir, filename) abort
" Check cache directory.
if !isdirectory(a:cache_dir)
call mkdir(a:cache_dir, 'p')
endif
let cache_dir = a:cache_dir
if cache_dir !~# '/$'
let cache_dir .= '/'
endif
return cache_dir . s:_create_hash(cache_dir, a:filename)
endfunction
function! s:check_old_cache(cache_dir, filename) abort
" Check old cache file.
let cache_name = s:_encode_name(a:cache_dir, a:filename)
let ret = getftime(cache_name) == -1
\ || getftime(cache_name) <= getftime(a:filename)
if ret && filereadable(cache_name)
" Delete old cache.
call delete(cache_name)
endif
return ret
endfunction
function! s:_create_hash(dir, str) abort
if len(a:dir) + len(a:str) < 150
let hash = substitute(substitute(
\ a:str, ':', '=-', 'g'), '[/\\]', '=+', 'g')
else
let hash = s:S.hash(a:str)
endif
return hash
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View file

@ -0,0 +1,339 @@
let s:plugin_name = expand('<sfile>:t:r')
let s:vital_base_dir = expand('<sfile>:h')
let s:project_root = expand('<sfile>:h:h:h')
let s:is_vital_vim = s:plugin_name is# 'vital'
let s:loaded = {}
let s:cache_sid = {}
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort
return function(a:fstr)
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . s:_SID() . '_'
function! s:_function(fstr) abort
return function(substitute(a:fstr, 's:', s:_s, 'g'))
endfunction
endif
function! vital#{s:plugin_name}#new() abort
return s:new(s:plugin_name)
endfunction
function! vital#{s:plugin_name}#import(...) abort
if !exists('s:V')
let s:V = s:new(s:plugin_name)
endif
return call(s:V.import, a:000, s:V)
endfunction
let s:Vital = {}
function! s:new(plugin_name) abort
let base = deepcopy(s:Vital)
let base._plugin_name = a:plugin_name
return base
endfunction
function! s:vital_files() abort
if !exists('s:vital_files')
let s:vital_files = map(
\ s:is_vital_vim ? s:_global_vital_files() : s:_self_vital_files(),
\ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")')
endif
return copy(s:vital_files)
endfunction
let s:Vital.vital_files = s:_function('s:vital_files')
function! s:import(name, ...) abort dict
let target = {}
let functions = []
for a in a:000
if type(a) == type({})
let target = a
elseif type(a) == type([])
let functions = a
endif
unlet a
endfor
let module = self._import(a:name)
if empty(functions)
call extend(target, module, 'keep')
else
for f in functions
if has_key(module, f) && !has_key(target, f)
let target[f] = module[f]
endif
endfor
endif
return target
endfunction
let s:Vital.import = s:_function('s:import')
function! s:load(...) abort dict
for arg in a:000
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
let target = split(join(as, ''), '\W\+')
let dict = self
let dict_type = type({})
while !empty(target)
let ns = remove(target, 0)
if !has_key(dict, ns)
let dict[ns] = {}
endif
if type(dict[ns]) == dict_type
let dict = dict[ns]
else
unlet dict
break
endif
endwhile
if exists('dict')
call extend(dict, self._import(name))
endif
unlet arg
endfor
return self
endfunction
let s:Vital.load = s:_function('s:load')
function! s:unload() abort dict
let s:loaded = {}
let s:cache_sid = {}
unlet! s:vital_files
endfunction
let s:Vital.unload = s:_function('s:unload')
function! s:exists(name) abort dict
if a:name !~# '\v^\u\w*%(\.\u\w*)*$'
throw 'vital: Invalid module name: ' . a:name
endif
return s:_module_path(a:name) isnot# ''
endfunction
let s:Vital.exists = s:_function('s:exists')
function! s:search(pattern) abort dict
let paths = s:_extract_files(a:pattern, self.vital_files())
let modules = sort(map(paths, 's:_file2module(v:val)'))
return s:_uniq(modules)
endfunction
let s:Vital.search = s:_function('s:search')
function! s:plugin_name() abort dict
return self._plugin_name
endfunction
let s:Vital.plugin_name = s:_function('s:plugin_name')
function! s:_self_vital_files() abort
let builtin = printf('%s/__%s__/', s:vital_base_dir, s:plugin_name)
let installed = printf('%s/_%s/', s:vital_base_dir, s:plugin_name)
let base = builtin . ',' . installed
return split(globpath(base, '**/*.vim', 1), "\n")
endfunction
function! s:_global_vital_files() abort
let pattern = 'autoload/vital/__*__/**/*.vim'
return split(globpath(&runtimepath, pattern, 1), "\n")
endfunction
function! s:_extract_files(pattern, files) abort
let tr = {'.': '/', '*': '[^/]*', '**': '.*'}
let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g')
let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target)
return filter(a:files, 'v:val =~# regexp')
endfunction
function! s:_file2module(file) abort
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
return join(split(tail, '[\\/]\+'), '.')
endfunction
" @param {string} name e.g. Data.List
function! s:_import(name) abort dict
if has_key(s:loaded, a:name)
return copy(s:loaded[a:name])
endif
let module = self._get_module(a:name)
if has_key(module, '_vital_created')
call module._vital_created(module)
endif
let export_module = filter(copy(module), 'v:key =~# "^\\a"')
" Cache module before calling module.vital_loaded() to avoid cyclic
" dependences but remove the cache if module._vital_loaded() fails.
" let s:loaded[a:name] = export_module
let s:loaded[a:name] = export_module
if has_key(module, '_vital_loaded')
try
call module._vital_loaded(vital#{s:plugin_name}#new())
catch
unlet s:loaded[a:name]
throw 'vital: fail to call ._vital_loaded(): ' . v:exception
endtry
endif
return copy(s:loaded[a:name])
endfunction
let s:Vital._import = s:_function('s:_import')
" s:_get_module() returns module object wihch has all script local functions.
function! s:_get_module(name) abort dict
let funcname = s:_import_func_name(self.plugin_name(), a:name)
if s:_exists_autoload_func_with_source(funcname)
return call(funcname, [])
else
return s:_get_builtin_module(a:name)
endif
endfunction
function! s:_get_builtin_module(name) abort
return s:sid2sfuncs(s:_module_sid(a:name))
endfunction
if s:is_vital_vim
" For vital.vim, we can use s:_get_builtin_module directly
let s:Vital._get_module = s:_function('s:_get_builtin_module')
else
let s:Vital._get_module = s:_function('s:_get_module')
endif
function! s:_import_func_name(plugin_name, module_name) abort
return printf('vital#_%s#%s#import', a:plugin_name, s:_dot_to_sharp(a:module_name))
endfunction
function! s:_module_sid(name) abort
let path = s:_module_path(a:name)
if !filereadable(path)
throw 'vital: module not found: ' . a:name
endif
let vital_dir = s:is_vital_vim ? '__\w\+__' : printf('_\{1,2}%s\%%(__\)\?', s:plugin_name)
let base = join([vital_dir, ''], '[/\\]\+')
let p = base . substitute('' . a:name, '\.', '[/\\\\]\\+', 'g')
let sid = s:_sid(path, p)
if !sid
call s:_source(path)
let sid = s:_sid(path, p)
if !sid
throw printf('vital: cannot get <SID> from path: %s', path)
endif
endif
return sid
endfunction
function! s:_module_path(name) abort
return get(s:_extract_files(a:name, s:vital_files()), 0, '')
endfunction
function! s:_module_sid_base_dir() abort
return s:is_vital_vim ? &rtp : s:project_root
endfunction
function! s:_dot_to_sharp(name) abort
return substitute(a:name, '\.', '#', 'g')
endfunction
" It will sources autoload file if a given func is not already defined.
function! s:_exists_autoload_func_with_source(funcname) abort
if exists('*' . a:funcname)
" Return true if a given func is already defined
return 1
endif
" source a file which may include a given func definition and try again.
let path = 'autoload/' . substitute(substitute(a:funcname, '#[^#]*$', '.vim', ''), '#', '/', 'g')
call s:_runtime(path)
return exists('*' . a:funcname)
endfunction
function! s:_runtime(path) abort
execute 'runtime' fnameescape(a:path)
endfunction
function! s:_source(path) abort
execute 'source' fnameescape(a:path)
endfunction
" @vimlint(EVL102, 1, l:_)
" @vimlint(EVL102, 1, l:__)
function! s:_sid(path, filter_pattern) abort
let unified_path = s:_unify_path(a:path)
if has_key(s:cache_sid, unified_path)
return s:cache_sid[unified_path]
endif
for line in filter(split(s:_redir(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern')
let [_, sid, path; __] = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
if s:_unify_path(path) is# unified_path
let s:cache_sid[unified_path] = sid
return s:cache_sid[unified_path]
endif
endfor
return 0
endfunction
function! s:_redir(cmd) abort
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
set verbose=0 verbosefile=
redir => res
silent! execute a:cmd
redir END
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
return res
endfunction
if filereadable(expand('<sfile>:r') . '.VIM') " is case-insensitive or not
let s:_unify_path_cache = {}
" resolve() is slow, so we cache results.
" Note: On windows, vim can't expand path names from 8.3 formats.
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
" vital load duplicated scripts. Below's :~ avoid this issue.
function! s:_unify_path(path) abort
if has_key(s:_unify_path_cache, a:path)
return s:_unify_path_cache[a:path]
endif
let value = tolower(fnamemodify(resolve(fnamemodify(
\ a:path, ':p')), ':~:gs?[\\/]?/?'))
let s:_unify_path_cache[a:path] = value
return value
endfunction
else
function! s:_unify_path(path) abort
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
endfunction
endif
" copied and modified from Vim.ScriptLocal
let s:SNR = join(map(range(len("\<SNR>")), '"[\\x" . printf("%0x", char2nr("\<SNR>"[v:val])) . "]"'), '')
function! s:sid2sfuncs(sid) abort
let fs = split(s:_redir(printf(':function /^%s%s_', s:SNR, a:sid)), "\n")
let r = {}
let pattern = printf('\m^function\s<SNR>%d_\zs\w\{-}\ze(', a:sid)
for fname in map(fs, 'matchstr(v:val, pattern)')
let r[fname] = function(s:_sfuncname(a:sid, fname))
endfor
return r
endfunction
"" Return funcname of script local functions with SID
function! s:_sfuncname(sid, funcname) abort
return printf('<SNR>%s_%s', a:sid, a:funcname)
endfunction
if exists('*uniq')
function! s:_uniq(list) abort
return uniq(a:list)
endfunction
else
function! s:_uniq(list) abort
let i = len(a:list) - 1
while 0 < i
if a:list[i] ==# a:list[i - 1]
call remove(a:list, i)
endif
let i -= 1
endwhile
return a:list
endfunction
endif

View file

@ -0,0 +1,8 @@
neocomplete
645fe7142afdf5ef90e07cd275a15657c3328f53
Prelude
Data.List
Data.String
Process
System.Cache.Deprecated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,63 @@
"=============================================================================
" FILE: neocomplete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" 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.
" }}}
"=============================================================================
if exists('g:loaded_neocomplete')
finish
endif
let g:loaded_neocomplete = 1
let s:save_cpo = &cpo
set cpo&vim
command! -nargs=0 -bar NeoCompleteEnable
\ call neocomplete#init#enable()
command! -nargs=0 -bar NeoCompleteDisable
\ call neocomplete#init#disable()
command! -nargs=0 -bar NeoCompleteLock
\ call neocomplete#commands#_lock()
command! -nargs=0 -bar NeoCompleteUnlock
\ call neocomplete#commands#_unlock()
command! -nargs=0 -bar NeoCompleteToggle
\ call neocomplete#commands#_toggle_lock()
command! -nargs=1 -bar -complete=filetype NeoCompleteSetFileType
\ call neocomplete#commands#_set_file_type(<q-args>)
command! -nargs=0 -bar NeoCompleteClean
\ call neocomplete#commands#_clean()
" Global options definition. "{{{
let g:neocomplete#enable_debug =
\ get(g:, 'neocomplete#enable_debug', 0)
if get(g:, 'neocomplete#enable_at_startup', 0)
augroup neocomplete
" Enable startup.
autocmd CursorHold,InsertEnter
\ * call neocomplete#init#enable()
augroup END
endif"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View file

@ -0,0 +1,24 @@
"=============================================================================
" FILE: buffer.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
"=============================================================================
if exists('g:loaded_neocomplete_buffer')
finish
endif
let s:save_cpo = &cpo
set cpo&vim
" Add commands. "{{{
command! -nargs=? -complete=file -bar
\ NeoCompleteBufferMakeCache
\ call neocomplete#sources#buffer#make_cache(<q-args>)
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
let g:loaded_neocomplete_buffer = 1
" vim: foldmethod=marker

View file

@ -0,0 +1,24 @@
"=============================================================================
" FILE: dictionary.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
"=============================================================================
if exists('g:loaded_neocomplete_dictionary')
finish
endif
let s:save_cpo = &cpo
set cpo&vim
" Add commands. "{{{
command! -nargs=? -complete=customlist,neocomplete#filetype_complete
\ NeoCompleteDictionaryMakeCache
\ call neocomplete#sources#dictionary#remake_cache(<q-args>)
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
let g:loaded_neocomplete_dictionary = 1
" vim: foldmethod=marker

View file

@ -0,0 +1,24 @@
"=============================================================================
" FILE: member.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
"=============================================================================
if exists('g:loaded_neocomplete_member')
finish
endif
let s:save_cpo = &cpo
set cpo&vim
" Add commands. "{{{
command! -nargs=? -complete=file -bar
\ NeoCompleteMemberMakeCache
\ call neocomplete#sources#member#remake_cache(&l:filetype)
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
let g:loaded_neocomplete_member = 1
" vim: foldmethod=marker

View file

@ -0,0 +1,24 @@
"=============================================================================
" FILE: tag.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
"=============================================================================
if exists('g:loaded_neocomplete_tag')
finish
endif
let s:save_cpo = &cpo
set cpo&vim
" Add commands. "{{{
command! -nargs=0 -bar
\ NeoCompleteTagMakeCache
\ call neocomplete#sources#tag#make_cache(1)
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
let g:loaded_neocomplete_tag = 1
" vim: foldmethod=marker

View file

@ -0,0 +1,58 @@
let s:suite = themis#suite('parser')
let s:assert = themis#helper('assert')
function! s:suite.escape() abort
call s:assert.equals(
\ neocomplete#filters#fuzzy_escape('abc'), 'a.*b.*c.*')
call s:assert.equals(
\ neocomplete#filters#fuzzy_escape('%a%b%c'), '%%a.*%%b.*%%c.*')
call s:assert.equals(
\ neocomplete#filters#fuzzy_escape('%[ab]c'), '%%%[a.*b.*%]c.*')
call s:assert.equals(
\ neocomplete#filters#fuzzy_escape('.abc'), '%.a.*b.*c.*')
endfunction
function! s:suite.sort() abort
let candidates = []
for i in range(1, 1000)
call add(candidates, { 'word' : i, 'rank' : i })
endfor
function! CompareRank(i1, i2) abort
let diff = (get(a:i2, 'rank', 0) - get(a:i1, 'rank', 0))
return (diff != 0) ? diff : (len(a:i1.word) < len(a:i2.word)) ? 1 : -1
endfunction"
" Benchmark.
let start = reltime()
call sort(copy(candidates), 'CompareRank')
echomsg reltimestr(reltime(start))
let start = reltime()
call neocomplete#filters#sorter_rank#define().filter(
\ {'candidates' : copy(candidates), 'input' : '' })
echomsg reltimestr(reltime(start))
call s:assert.equals(sort(copy(candidates), 'CompareRank'),
\ neocomplete#filters#sorter_rank#define().filter(
\ {'candidates' : copy(candidates), 'input' : '' }))
endfunction
function! s:suite.fuzzy() abort
call s:assert.equals(neocomplete#filters#matcher_fuzzy#define().filter(
\ {'complete_str' : 'ae', 'candidates' : ['~/~']}), [])
endfunction
function! s:suite.overlap() abort
call s:assert.equals(neocomplete#filters#converter_remove_overlap#
\length('foo bar', 'bar baz'), 3)
call s:assert.equals(neocomplete#filters#converter_remove_overlap#
\length('foobar', 'barbaz'), 3)
call s:assert.equals(neocomplete#filters#converter_remove_overlap#
\length('foob', 'baz'), 1)
call s:assert.equals(neocomplete#filters#converter_remove_overlap#
\length('foobar', 'foobar'), 6)
call s:assert.equals(neocomplete#filters#converter_remove_overlap#
\length('тест', 'ст'), len('ст'))
endfunction
" vim:foldmethod=marker:fen:

4
vimrc
View file

@ -90,6 +90,10 @@ else
set listchars=eol,tab:→ ,trail:~,extends:>,precedes:<
endif
if has("lua")
let g:neocomplete#enable_at_startup=1
endif
if !empty(&viminfo)
set viminfo^=!
endif