Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created July 9, 2011 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osyo-manga/1073619 to your computer and use it in GitHub Desktop.
Save osyo-manga/1073619 to your computer and use it in GitHub Desktop.
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