1 " clang_complete clang_complete's snippet generator
2 " Author: Xavier Deguillard, Philippe Vaucher
4 function! snippets#clang_complete#init()
5 noremap <expr> <silent> <buffer> <tab> UpdateSnips()
6 snoremap <expr> <silent> <buffer> <tab> UpdateSnips()
7 syntax match Conceal /<#/ conceal
8 syntax match Conceal /#>/ conceal
11 " fullname = strcat(char *dest, const char *src)
12 " args_pos = [ [8, 17], [20, 34] ]
13 function! snippets#clang_complete#add_snippet(fullname, args_pos)
17 let l:res .= a:fullname[l:prev_idx : elt[0] - 1] . '<#' . a:fullname[elt[0] : elt[1] - 1] . '#>'
18 let l:prev_idx = elt[1]
21 let l:res .= a:fullname[l:prev_idx : ]
26 function! snippets#clang_complete#trigger()
30 function! snippets#clang_complete#reset()
34 " ---------------- Helpers ----------------
36 function! UpdateSnips()
37 let l:line = getline('.')
38 let l:pattern = '<#[^#]*#>'
39 if match(l:line, l:pattern) == -1
45 let l:commands .= "\<esc>"
48 let l:commands .= ":call MoveToCCSnippetBegin()\<CR>"
49 let l:commands .= "m'"
50 let l:commands .= ":call MoveToCCSnippetEnd()\<CR>"
52 if &selection == "exclusive"
53 let l:commands .= "ll"
58 let l:commands .= "v`'o\<C-G>"
63 function! MoveToCCSnippetBegin()
65 let l:line = getline('.')
66 let l:startpos = col('.') + 1
67 let l:ind = match(l:line, l:pattern, l:startpos)
69 let l:ind = match(l:line, l:pattern, 0)
71 call cursor(line('.'), l:ind + 1)
74 function! MoveToCCSnippetEnd()
75 let l:line = getline('.')
77 let l:startpos = col('.') + 2
79 call cursor(line('.'), match(l:line, l:pattern, l:startpos) + 1)
82 function! s:BeginSnips()
87 " Do we need to launch UpdateSnippets()?
88 let l:line = getline('.')
89 let l:pattern = '<#[^#]*#>'
90 if match(l:line, l:pattern) == -1
93 call feedkeys("\<esc>^\<tab>")
96 " vim: set ts=2 sts=2 sw=2 expandtab :