" http://recursivedream.com/blog/2012/auto-completing-google-contacts-in-vim/ " Escape query and handle goobook errors function! mailcomplete#Complete(findstart, base) if a:findstart == 1 let line = getline('.') let idx = col('.') while idx > 0 let idx -= 1 let c = line[idx] " break on header and previous email if c == ':' || c == '>' return idx + 2 else continue endif endwhile return idx else if exists("g:goobookrc") let goobook="goobook -c " . g:goobookrc else let goobook="goobook" endif let res=system(goobook . ' query ' . shellescape(a:base)) if v:shell_error return [] else "return split(system(trim . '|' . fmt, res), '\n') return mailcomplete#Format(mailcomplete#Trim(res)) endif endif endfunc function! mailcomplete#Trim(res) "let trim="sed '/^$/d' | grep -v '(group)$' | cut -f1,2" let ret=[] for line in split(a:res, '\n') if line !~ '(group)$' call add(ret, split(line, '\t')[:1]) endif endfor return ret endfunc function! mailcomplete#Format(contacts) "let fmt='awk ''BEGIN{FS="\t"}{printf "%s <%s>\n", $2, $1}''' let ret=[] for [email, name] in a:contacts call add(ret, printf("%s <%s>", name, email)) endfor return ret endfunc