Skip to content

Commit

Permalink
- Improved C syntax.
Browse files Browse the repository at this point in the history
- Added g:NeoComplCache_MaxTryKeywordLength option.
- Improved prev rank.
- Optimized if keyword is empty.
  • Loading branch information
Shougo committed Mar 31, 2009
1 parent 29fec9c commit 98e6fae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
14 changes: 9 additions & 5 deletions autoload/neocomplcache.vim
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: neocomplcache.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 28 Mar 2009
" Last Modified: 30 Mar 2009
" Usage: Just source this file.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -23,7 +23,7 @@
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
" Version: 2.14, for Vim 7.0
" Version: 2.15, for Vim 7.0
"=============================================================================

let s:disable_neocomplcache = 1
Expand Down Expand Up @@ -76,7 +76,7 @@ function! neocomplcache#complete()"{{{
let [l:cur_keyword_pos, l:cur_keyword_str] = s:check_wildcard(l:cur_text, l:pattern, l:cur_keyword_pos, l:cur_keyword_str)
endif

if l:cur_keyword_pos < 0 || len(cur_keyword_str) < g:NeoComplCache_KeywordCompletionStartLength
if l:cur_keyword_pos < 0 || len(l:cur_keyword_str) < g:NeoComplCache_KeywordCompletionStartLength
" Try filename completion.
"
if s:check_filename_completion(l:cur_text)
Expand Down Expand Up @@ -108,6 +108,7 @@ function! neocomplcache#complete()"{{{
" Prevent filcker.
if empty(s:complete_words) && !s:skipped
if g:NeoComplCache_TryKeywordCompletion
\&& len(l:cur_keyword_str) <= g:NeoComplCache_MaxTryKeywordLength
\&& l:cur_keyword_str =~ '\h\w*$' && l:cur_keyword_str !~ '\h\w*[*-]\w*$'
if &filetype == 'perl'
" Perl has a lot of included files.
Expand Down Expand Up @@ -294,7 +295,10 @@ function! neocomplcache#get_complete_words(cur_keyword_str)"{{{
endif"}}}

" Get keyword list.
let l:cache_keyword_buffer_list = filter(neocomplcache#keyword_complete#get_keyword_list(), l:pattern)
let l:cache_keyword_buffer_list = neocomplcache#keyword_complete#get_keyword_list()
if !empty(a:cur_keyword_str)
call filter(l:cache_keyword_buffer_list, l:pattern)
endif

" Similar filter."{{{
if &l:completefunc != 'neocomplcache#auto_complete' && g:NeoComplCache_SimilarMatch
Expand Down Expand Up @@ -602,7 +606,7 @@ function! neocomplcache#enable() "{{{
call s:set_keyword_pattern('ps1',
\'\($\w\+\|[[:alpha:]_.-][[:alnum:]_.-]*\(\s*(\)\=\)')
call s:set_keyword_pattern('c',
\'\(->\(\h\w*\(\s*(\)\=\)\=\|[.#]\=\h\w*\(\s*(\)\=\)')
\'\(->\(\h\w*\(\s*(\)\=\)\=\|^\s*#\s*\h\w*\|.\=\h\w*\(\s*(\)\=\)')
call s:set_keyword_pattern('cpp',
\'\(->\(\h\w*\(\s*(\|<\)\=\)\=\|::\(\h\w*\)\=\|[.#]\=\h\w*\(\s*(\|<\)\=\)')
call s:set_keyword_pattern('d',
Expand Down
10 changes: 6 additions & 4 deletions autoload/neocomplcache/keyword_complete.vim
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: keyword_complete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 28 Mar 2009
" Last Modified: 30 Mar 2009
" Usage: Just source this file.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -23,7 +23,7 @@
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
" Version: 2.14, for Vim 7.0
" Version: 2.15, for Vim 7.0
"=============================================================================

function! neocomplcache#keyword_complete#get_keyword_list()"{{{
Expand Down Expand Up @@ -201,7 +201,7 @@ function! neocomplcache#keyword_complete#calc_prev_rank(cache_keyword_buffer_lis
let keyword.prev_rank += keyword_lines[keyword.word].prev_rank[a:prev_word]
endif
endfor
let keyword.prev_rank = keyword.prev_rank * 4
let keyword.prev_rank = keyword.prev_rank * 12
endif
if has_key(l:source_next_next, keyword.srcname)
\&& has_key(l:source_next_next[keyword.srcname], keyword.word)
Expand All @@ -212,7 +212,9 @@ function! neocomplcache#keyword_complete#calc_prev_rank(cache_keyword_buffer_lis
let keyword.prepre_rank += keyword_lines[keyword.word].prepre_rank[a:prepre_word]
endif
endfor
let keyword.prepre_rank = keyword.prepre_rank
if a:prepre_word != '^'
let keyword.prepre_rank = keyword.prepre_rank * 3
endif
endif
endfor
endfunction"}}}
Expand Down
12 changes: 10 additions & 2 deletions plugin/neocomplcache.vim
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: neocomplcache.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 28 Mar 2009
" Last Modified: 30 Mar 2009
" Usage: Just source this file.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -23,10 +23,15 @@
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
" Version: 2.14, for Vim 7.0
" Version: 2.15, for Vim 7.0
"-----------------------------------------------------------------------------
" ChangeLog: "{{{
" ChangeLog NeoCompleCache2: "{{{
" 2.15:
" - Improved C syntax.
" - Added g:NeoComplCache_MaxTryKeywordLength option.
" - Improved prev rank.
" - Optimized if keyword is empty.
" 2.14:
" - Optimized calc rank.
" 2.13:
Expand Down Expand Up @@ -409,6 +414,9 @@ endif
if !exists('g:NeoComplCache_TryKeywordCompletion')
let g:NeoComplCache_TryKeywordCompletion = 0
endif
if !exists('g:NeoComplCache_MaxTryKeywordLength')
let g:NeoComplCache_MaxTryKeywordLength = 5
endif
if !exists('g:NeoComplCache_EnableInfo')
let g:NeoComplCache_EnableInfo = 0
endif
Expand Down
7 changes: 6 additions & 1 deletion presen/neocomplcache.txt
Expand Up @@ -220,7 +220,7 @@ autocomplpopで便利だったので、移植しました。
|にカーソルがあるとします。
|e
ここでhogeを補完すると、hogのみが補完され、結果はhog|eとなります。
ソースの修正時に便利
初めはそこまで便利だとは思っていませんでしたが、使ってみるとソースの修正時に便利
この機能はViViにインスパイアされました。

--------------------------------
Expand Down Expand Up @@ -321,6 +321,10 @@ thincaさんの要望により、試験的に実装。
追記:
januswelさんのエントリを参考に、
Perl以外ではインクルード補完を試してみることにしました。
追記2:
Ver.2.15より、g:NeoComplCache_MaxTryKeywordLengthを導入し、
入力されたキーワード文字がこれより多かったら、キーワード補完をしないようにしました。
これで補完時のちらつきが軽減されます。

この機能を使用するには、
let g:NeoComplCache_TryKeywordCompletion = 1
Expand Down Expand Up @@ -505,4 +509,5 @@ syntaxcompleteの実装など、まだまだやることがありそうです。
2009/03/26 neocomplcache Ver.2.02に対応。
2009/03/27 neocomplcache Ver.2.10に対応。
2009/03/27 neocomplcache Ver.2.11に対応。
2009/03/30 neocomplcache Ver.2.14に対応。
--------------------------------

0 comments on commit 98e6fae

Please sign in to comment.