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> |
Bram Moolenaar | 864207d | 2008-06-24 22:14:38 +0000 | [diff] [blame] | 3 | " Last Change: 2008 May 29 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4 | |
| 5 | " Has this already been loaded? |
Bram Moolenaar | c5604bc | 2010-07-17 15:20:30 +0200 | [diff] [blame] | 6 | if exists("loaded_rrhelper") || !has("clientserver") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | c5604bc | 2010-07-17 15:20:30 +0200 | [diff] [blame] | 14 | function SetupRemoteReplies() |
| 15 | let cnt = 0 |
| 16 | let max = argc() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | |
Bram Moolenaar | c5604bc | 2010-07-17 15:20:30 +0200 | [diff] [blame] | 18 | let id = expand("<client>") |
| 19 | if id == 0 |
| 20 | return |
| 21 | endif |
| 22 | while cnt < max |
| 23 | " Handle same file from more clients and file being more than once |
| 24 | " on the command line by encoding this stuff in the group name |
| 25 | let uniqueGroup = "RemoteReply_".id."_".cnt |
| 26 | |
| 27 | " Path separators are always forward slashes for the autocommand pattern. |
| 28 | " Escape special characters with a backslash. |
| 29 | let f = substitute(argv(cnt), '\\', '/', "g") |
| 30 | if exists('*fnameescape') |
| 31 | let f = fnameescape(f) |
| 32 | else |
| 33 | let f = escape(f, " \t\n*?[{`$\\%#'\"|!<") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | endif |
Bram Moolenaar | c5604bc | 2010-07-17 15:20:30 +0200 | [diff] [blame] | 35 | execute "augroup ".uniqueGroup |
| 36 | execute "autocmd ".uniqueGroup." BufUnload ". f ." call DoRemoteReply('".id."', '".cnt."', '".uniqueGroup."', '". f ."')" |
| 37 | let cnt = cnt + 1 |
| 38 | endwhile |
| 39 | augroup END |
| 40 | endfunc |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | |
Bram Moolenaar | c5604bc | 2010-07-17 15:20:30 +0200 | [diff] [blame] | 42 | function DoRemoteReply(id, cnt, group, file) |
| 43 | call server2client(a:id, a:cnt) |
| 44 | execute 'autocmd! '.a:group.' BufUnload '.a:file |
| 45 | execute 'augroup! '.a:group |
| 46 | endfunc |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
| 48 | " vim: set sw=2 sts=2 : |