rrhelper.vim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. " Vim plugin with helper function(s) for --remote-wait
  2. " Maintainer: Flemming Madsen <fma@cci.dk>
  3. " Last Change: 2008 May 29
  4. " Has this already been loaded?
  5. if exists("loaded_rrhelper") || !has("clientserver")
  6. finish
  7. endif
  8. let loaded_rrhelper = 1
  9. " Setup answers for a --remote-wait client who will assume
  10. " a SetupRemoteReplies() function in the command server
  11. function SetupRemoteReplies()
  12. let cnt = 0
  13. let max = argc()
  14. let id = expand("<client>")
  15. if id == 0
  16. return
  17. endif
  18. while cnt < max
  19. " Handle same file from more clients and file being more than once
  20. " on the command line by encoding this stuff in the group name
  21. let uniqueGroup = "RemoteReply_".id."_".cnt
  22. " Path separators are always forward slashes for the autocommand pattern.
  23. " Escape special characters with a backslash.
  24. let f = substitute(argv(cnt), '\\', '/', "g")
  25. if exists('*fnameescape')
  26. let f = fnameescape(f)
  27. else
  28. let f = escape(f, " \t\n*?[{`$\\%#'\"|!<")
  29. endif
  30. execute "augroup ".uniqueGroup
  31. execute "autocmd ".uniqueGroup." BufUnload ". f ." call DoRemoteReply('".id."', '".cnt."', '".uniqueGroup."', '". f ."')"
  32. let cnt = cnt + 1
  33. endwhile
  34. augroup END
  35. endfunc
  36. function DoRemoteReply(id, cnt, group, file)
  37. call server2client(a:id, a:cnt)
  38. execute 'autocmd! '.a:group.' BufUnload '.a:file
  39. execute 'augroup! '.a:group
  40. endfunc
  41. " vim: set sw=2 sts=2 :