Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from Shougo/master

neocomplcache-clang_completeを修正しました
  • Loading branch information...
commit c880773823a8ec63a3d9ccc0e97b79ee067759e3 2 parents 65bc720 + 71a707f
@osyo-manga authored
Showing with 50 additions and 34 deletions.
  1. +50 −34 ftplugin/cpp.vim
View
84 ftplugin/cpp.vim
@@ -1,64 +1,80 @@
+let s:save_cpo = &cpo
+set cpo&vim
-function! s:ShouldComplete()
- if (getline('.') =~ '#\s*\(include\|import\)')
+function! s:should_complete()
+ 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
+ endif
+
+ if col('.') == 1
return 1
endif
+
+ for id in synstack(line('.'), col('.') - 1)
+ if synIDattr(id, 'name') =~ '\CComment\|String\|Number'
+ return 0
+ endif
+ endfor
+
+ return 1
endfunction
-function! s:LaunchCompletion()
- let l:result = ""
- if s:ShouldComplete()
- let l:result = "\<C-X>\<C-O>"
+function! s:launch_completion()
+ let result = ''
+
+ if s:should_complete()
+ let result = "\<C-x>\<C-o>"
if g:clang_auto_select != 2
- let l:result .= "\<C-P>"
+ let result .= "\<C-p>"
endif
if g:clang_auto_select == 1
- let l:result .= "\<C-R>=(pumvisible() ? \"\\<Down>\" : '')\<CR>"
+ let result .= "\<C-r>=(pumvisible() ? \"\\<Down>\" : '')\<CR>"
endif
endif
- return l:result
+
+ return result
endfunction
-function! s:CompleteDot()
- if g:clang_complete_auto == 1
- return '.' . s:LaunchCompletion()
+function! s:complete_dot()
+ if g:clang_complete_auto
+ return '.' . s:launch_completion()
endif
+
return '.'
endfunction
-function! s:CompleteArrow()
- if g:clang_complete_auto != 1 || getline('.')[col('.') - 2] != '-'
+function! s:complete_arrow()
+ if !g:clang_complete_auto || s:get_cur_text() !~ '-$'
return '>'
endif
- return '>' . s:LaunchCompletion()
+
+ return '>' . s:launch_completion()
endfunction
-function! s:CompleteColon()
- if g:clang_complete_auto != 1 || getline('.')[col('.') - 2] != ':'
+function! s:complete_colon()
+ if !g:clang_complete_auto || s:get_cur_text() !~ ':$'
return ':'
endif
- return ':' . s:LaunchCompletion()
+
+ return ':' . s:launch_completion()
endfunction
function! s:init_clang_complete()
- if exists("g:clang_complete_auto") && g:clang_complete_auto
- inoremap <expr> <buffer> . <SID>CompleteDot()
- inoremap <expr> <buffer> > <SID>CompleteArrow()
- inoremap <expr> <buffer> : <SID>CompleteColon()
- endif
+ if exists('g:clang_complete_auto') && g:clang_complete_auto
+ inoremap <expr> <buffer> . <SID>complete_dot()
+ inoremap <expr> <buffer> > <SID>complete_arrow()
+ inoremap <expr> <buffer> : <SID>complete_colon()
+ endif
+endfunction
+
+function! s:get_cur_text()
+ return matchstr(getline('.'),
+ \ '^.*\%' . col('.') . 'c' . (mode() ==# 'i' ? '' : '.'))
endfunction
-autocmd InsertEnter <buffer> call s:init_clang_complete()
+autocmd InsertEnter <buffer> call s:init_clang_complete()
+let &cpo = s:save_cpo
+unlet s:save_cpo
+" vim: sw=2 sts=2
Please sign in to comment.
Something went wrong with that request. Please try again.