Skip to content

Commit

Permalink
If g:clang_snippet is not set, use the dummy snippet engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierd committed Mar 10, 2013
1 parent 361aa8a commit 9ae8609
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 47 deletions.
4 changes: 2 additions & 2 deletions doc/clang_complete.txt
Expand Up @@ -121,8 +121,8 @@ Default: "clang_complete"
*clang_complete-conceal_snippets*
*g:clang_conceal_snippets*
Note: This option is specific to clang_complete snippets engine.
If equal to 1, clang_complete will use vim 7.3 conceal feature to hide <#
and #> which delimit snippet placeholders.
If equal to 1, clang_complete will use vim 7.3 conceal feature to hide the
snippet placeholders.

Example of conceal configuration (see |'concealcursor'| and |'conceallevel'|
for details): >
Expand Down
54 changes: 23 additions & 31 deletions plugin/clang_complete.vim
Expand Up @@ -53,8 +53,8 @@ function! s:ClangCompleteInit()
let g:clang_periodic_quickfix = 0
endif

if !exists('g:clang_snippets')
let g:clang_snippets = 0
if !exists('g:clang_snippets') || g:clang_snippets == 0
let g:clang_snippets_engine = 'dummy'
endif

if !exists('g:clang_snippets_engine')
Expand Down Expand Up @@ -134,9 +134,7 @@ function! s:ClangCompleteInit()
return
endif

if g:clang_snippets == 1
python snippetsInit()
endif
python snippetsInit()

inoremap <expr> <buffer> <C-X><C-U> <SID>LaunchCompletion()
inoremap <expr> <buffer> . <SID>CompleteDot()
Expand Down Expand Up @@ -257,20 +255,18 @@ function! s:initClangCompletePython()
exe 'python sys.path = ["' . s:plugin_path . '"] + sys.path'
exe 'pyfile ' . fnameescape(s:plugin_path) . '/libclang.py'

if g:clang_snippets == 1
"try
exe 'python from snippets.' . g:clang_snippets_engine . ' import *'
let l:snips_loaded = 1
"catch
" let l:snips_loaded = 0
"endtry
if l:snips_loaded == 0
" Oh yeah, vimscript rocks!
" Putting that echoe inside the catch, will throw an error, and
" display spurious unwanted errors…
echoe 'Snippets engine ' . g:clang_snippets_engine . ' not found'
return 0
endif
try
exe 'python from snippets.' . g:clang_snippets_engine . ' import *'
let l:snips_loaded = 1
catch
let l:snips_loaded = 0
endtry
if l:snips_loaded == 0
" Oh yeah, vimscript rocks!
" Putting that echoe inside the catch, will throw an error, and
" display spurious unwanted errors…
echoe 'Snippets engine ' . g:clang_snippets_engine . ' not found'
return 0
endif

py vim.command('let l:res = ' + str(initClangComplete(vim.eval('g:clang_complete_lib_flags'), vim.eval('g:clang_compilation_database'), vim.eval('g:clang_library_path'))))
Expand Down Expand Up @@ -352,9 +348,7 @@ function! ClangComplete(findstart, base)
let l:time_start = reltime()
endif

if g:clang_snippets == 1
python snippetsReset()
endif
python snippetsReset()

python completions, timer = getCurrentCompletions(vim.eval('a:base'))
python vim.command('let l:res = ' + completions)
Expand Down Expand Up @@ -396,16 +390,14 @@ function! s:TriggerSnippet()
return
endif

if g:clang_snippets == 1
" Stop monitoring as we'll trigger a snippet
silent! iunmap <buffer> <C-Y>
augroup ClangComplete
au! CursorMovedI <buffer>
augroup end
" Stop monitoring as we'll trigger a snippet
silent! iunmap <buffer> <C-Y>
augroup ClangComplete
au! CursorMovedI <buffer>
augroup end

" Trigger the snippet
python snippetsTrigger()
endif
" Trigger the snippet
python snippetsTrigger()

if g:clang_close_preview
pclose
Expand Down
4 changes: 2 additions & 2 deletions plugin/libclang.py
Expand Up @@ -381,7 +381,7 @@ def formatResult(result):
abbr = chunk_spelling

if chunk.isKindPlaceHolder():
word += snippetsFormatPlaceHolder(chunk.spelling)
word += snippetsFormatPlaceHolder(chunk_spelling)
else:
word += chunk_spelling

Expand All @@ -392,7 +392,7 @@ def formatResult(result):
if returnValue:
menu = returnValue.spelling + " " + menu

completion['word'] = snippetsAddSnippet(info, word)
completion['word'] = snippetsAddSnippet(info, word, abbr)
completion['abbr'] = abbr
completion['menu'] = menu
completion['info'] = info
Expand Down
2 changes: 1 addition & 1 deletion plugin/snippets/clang_complete.py
Expand Up @@ -15,7 +15,7 @@ def snippetsInit():
def snippetsFormatPlaceHolder(word):
return "$`%s`" % word

def snippetsAddSnippet(fullname, word):
def snippetsAddSnippet(fullname, word, abbr):
return word

r = re.compile('\$`[^`]*`')
Expand Down
14 changes: 6 additions & 8 deletions plugin/snippets/dummy.py
@@ -1,18 +1,16 @@
def snippetsInit():
print "Initializing stuffs"
pass

def snippetsFormatPlaceHolder(word):
print "Creating snippet for placeholder " + word
return word
return ''

def snippetsAddSnippet(fullname, word):
print "Adding snippet for " + fullname
return fullname
def snippetsAddSnippet(fullname, word, abbr):
return abbr

def snippetsTrigger():
print "Triggering snippets"
pass

def snippetsReset():
print "Resetting all snippets"
pass

# vim: set ts=2 sts=2 sw=2 expandtab :
8 changes: 5 additions & 3 deletions plugin/snippets/ultisnips.py
Expand Up @@ -2,9 +2,9 @@
import re
from UltiSnips import UltiSnips_Manager

ultisnips_idx = 0

def snippetsInit():
global ultisnips_idx
ultisnips_idx = 0
UltiSnips_Manager.add_buffer_filetypes('%s.clang_complete' % vim.eval('&filetype'))

def snippetsFormatPlaceHolder(word):
Expand All @@ -13,12 +13,14 @@ def snippetsFormatPlaceHolder(word):
ultisnips_idx += 1
return '${%d:%s}' % (ultisnips_idx, word)

def snippetsAddSnippet(fullname, word):
def snippetsAddSnippet(fullname, word, abbr):
global ultisnips_idx
ultisnips_idx = 0
UltiSnips_Manager.add_snippet(fullname, word, fullname, "i", "clang_complete")
return fullname

def snippetsTrigger():
print vim.current.line
UltiSnips_Manager.expand()

def snippetsReset():
Expand Down

0 comments on commit 9ae8609

Please sign in to comment.