Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim plugin with helper function(s) for --remote-wait |
| 2 | " Maintainer: Flemming Madsen <fma@cci.dk> |
| 3 | " Last Change: 2004 May 30 |
| 4 | |
| 5 | " Has this already been loaded? |
| 6 | if exists("loaded_rrhelper") |
| 7 | finish |
| 8 | endif |
| 9 | let loaded_rrhelper = 1 |
| 10 | |
| 11 | " Setup answers for a --remote-wait client who will assume |
| 12 | " a SetupRemoteReplies() function in the command server |
| 13 | |
| 14 | if 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. |
| 30 | let f = escape(substitute(argv(cnt), '\\', '/', "g"), ' *,?[{') |
| 31 | execute "augroup ".uniqueGroup |
| 32 | execute "autocmd ".uniqueGroup." BufUnload ". f ." call DoRemoteReply('".id."', '".cnt."', '".uniqueGroup."', '". f ."')" |
| 33 | let cnt = cnt + 1 |
| 34 | endwhile |
| 35 | augroup END |
| 36 | endfunc |
| 37 | |
| 38 | function DoRemoteReply(id, cnt, group, file) |
| 39 | call server2client(a:id, a:cnt) |
| 40 | execute 'autocmd! '.a:group.' BufUnload '.a:file |
| 41 | execute 'augroup! '.a:group |
| 42 | endfunc |
| 43 | |
| 44 | endif |
| 45 | |
| 46 | |
| 47 | " vim: set sw=2 sts=2 : |