Advertisement
jfreak53

VIM GooBook (GMAIL) Popup Addressbook

Jul 14th, 2012
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 1.35 KB | None | 0 0
  1. fun! MailcompleteC(findstart, base)
  2.     if a:findstart == 1
  3.         let line = getline('.')
  4.         let idx = col('.')
  5.         while idx > 0
  6.             let idx -= 1
  7.             let c = line[idx]
  8.             " break on header and previous email
  9.             if c == ':' || c == '>'
  10.                 return idx + 2
  11.             else
  12.                 continue
  13.             endif
  14.         endwhile
  15.         return idx
  16.     else
  17.         if exists("g:goobookrc")
  18.             let goobook="goobook -c " . g:goobookrc
  19.         else
  20.             let goobook="goobook"
  21.         endif
  22.         let res=system(goobook . ' query ' . shellescape(a:base))
  23.         if v:shell_error
  24.             return []
  25.         else
  26.             "return split(system(trim . '|' . fmt, res), '\n')
  27.             return MailcompleteF(MailcompleteT(res))
  28.         endif
  29.     endif
  30. endfun
  31.  
  32. fun! MailcompleteT(res)
  33.     " next up: port this to vimscript!
  34.     let trim="sed '/^$/d' | grep -v '(group)$' | cut -f1,2"
  35.     return split(system(trim, a:res), '\n')
  36. endfun
  37.  
  38. fun! MailcompleteF(contacts)
  39.     "let fmt='awk ''BEGIN{FS="\t"}{printf "%s <%s>\n", $2, $1}'''
  40.     let contacts=map(copy(a:contacts), "split(v:val, '\t')")
  41.     let ret=[]
  42.     for [email, name] in contacts
  43.         call add(ret, printf("%s <%s>", name, email))
  44.     endfor
  45.     return ret
  46. endfun
  47.  
  48.  
  49. set completefunc=MailcompleteC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement