kamailio.vim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function! KamailioDictGrep(sbase, dfiles)
  2. try
  3. exe 'vimgrep /^\s*' . a:sbase . '.*/j ' . a:dfiles
  4. catch /.*/
  5. echo "no matches"
  6. endtry
  7. endfunction
  8. function! KamailioComplete(findstart, findbase)
  9. if a:findstart
  10. " start position to match till cursor
  11. " - first non-whitespace column:
  12. " return match(getline("."),'\S')
  13. " - last word starting from last whitespace, quote,
  14. " comma, equal or plus:
  15. return match(getline("."),"[^ \t\"',=+][^ \t\"',=+]*$")
  16. else
  17. " grep the dictionary files and build list of results:
  18. let dpath = "~/.vim/plugin/kamailio/kamailio-*.dictionary"
  19. call KamailioDictGrep( escape(a:findbase, '\\/.*$^~[]'), dpath )
  20. let lmatch = []
  21. if(a:findbase == '')
  22. call add(lmatch, {'word': 'a', 'menu': '-- kamailio completion start'})
  23. endif
  24. for matchline in getqflist()
  25. " trim leading whitespace
  26. let mtokens = split(matchline.text,'@@')
  27. if len(mtokens) > 0
  28. let mword = matchstr(mtokens[0],'\S.*\S')
  29. call add(lmatch, {'word': mword, 'menu': get(mtokens, 1, '-- kamailio completion')})
  30. endif
  31. endfor
  32. call setqflist([])
  33. return lmatch
  34. endif
  35. endfunction