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