Created
July 9, 2011 14:33
-
-
Save osyo-manga/1073619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let b:inited=0 | |
autocmd InsertEnter * call s:init_clang_complete() | |
function! s:init_clang_complete() | |
if( &filetype == 'c' || &filetype == 'cpp' | |
\|| &filetype == 'objc' || &filetype == 'objcpp' ) | |
if &cp || (exists('g:inited') && g:inited) | |
return | |
endif | |
let b:inited=1 | |
if( &completefunc=='ClangComplete' ) | |
setlocal completefunc= | |
endif | |
call <SID>ClangCompleteInit() | |
endif | |
endfunction | |
" clang_complete 側からコピペ | |
function! s:ClangCompleteInit() | |
inoremap <expr> <buffer> <C-X><C-O> <SID>LaunchCompletion() | |
inoremap <expr> <buffer> . <SID>CompleteDot() | |
inoremap <expr> <buffer> > <SID>CompleteArrow() | |
inoremap <expr> <buffer> : <SID>CompleteColon() | |
endfunction | |
function! s:ShouldComplete() | |
if (getline('.') =~ '#\s*\(include\|import\)') | |
return 0 | |
else | |
if col('.') == 1 | |
return 1 | |
endif | |
for l:id in synstack(line('.'), col('.') - 1) | |
if match(synIDattr(l:id, 'name'), '\CComment\|String\|Number') | |
\ != -1 | |
return 0 | |
endif | |
endfor | |
return 1 | |
endif | |
endfunction | |
function! s:LaunchCompletion() | |
let l:result = "" | |
if s:ShouldComplete() | |
if match(&completeopt, 'longest') != -1 | |
" 呼び出しを <C-x><C-u> → <C-x><C-o> に変更 | |
let l:result = "\<C-X>\<C-O>" | |
else | |
let l:result = "\<C-X>\<C-O>\<C-P>" | |
endif | |
if g:clang_auto_select == 1 | |
let l:result .= "\<C-R>=(pumvisible() ? \"\\<Down>\" : '')\<CR>" | |
endif | |
endif | |
return l:result | |
endfunction | |
function! s:CompleteDot() | |
if g:clang_complete_auto == 1 | |
return '.' . s:LaunchCompletion() | |
endif | |
return '.' | |
endfunction | |
function! s:CompleteArrow() | |
if g:clang_complete_auto != 1 || getline('.')[col('.') - 2] != '-' | |
return '>' | |
endif | |
return '>' . s:LaunchCompletion() | |
endfunction | |
function! s:CompleteColon() | |
if g:clang_complete_auto != 1 || getline('.')[col('.') - 2] != ':' | |
return ':' | |
endif | |
return ':' . s:LaunchCompletion() | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment