On 07/08/2012 07:49 PM, Brian D. Burns wrote: > On 07/07/2012 09:57 AM, Bram Moolenaar wrote: >> >> Brian Burns wrote: >> >>> Recently, I have been looking into different methods for using Vim >>> to syntax highlight small blocks of code. In the process, I found >>> runtime/tools/xcmdsrv_client.c, which worked but seemed a little >>> outdated. So, after working with this a bit, I decided to create a >>> Ruby extension from src/if_xcmdsrv.c. >>> https://github.com/burns/vim_client-ruby >>> This is the most I've ever done in C, so it was quite the learning >>> experience. So, comments/suggestions are certainly welcome :) >>> >>> While working with this, I found a few things I wanted to submit >>> for changes in if_xcmdsrv.c. I've attached 3 patches, which include >>> my comments. >>> >>> if_xcmdsrv.patch.1 was a duplicate call to ga_init2. >>> >>> if_xcmdsrv.patch.2 deals with the fact that the server is actually >>> sending a response to clients making input key requests (--remote-send), >>> even though they don't expect one, and some other thoughts. >>> >>> if_xcmdsrv.patch.3 suggests some changes to the ServerWait() function, >>> which speeds up response time, handles an issue where the XEvent queue >>> is not being checked when 'localLoop' is true, and a few other thoughts. >>> >>> I appreciate your time - and Vim! :) >> >> It looks like you know what you are doing. I appreciate taking the time >> to improve this code, it hasn't been worked on for a while. I'll look >> into the details later. >> >> While you are digging into this, could you find some way to test this >> code? This might be complicated, since it requires starting two Vim >> instances talking to each other, but it would be very useful to have at >> least basic testing for this code. >> >> > > Hey, > > I've attached some basic tests. > I'm not sure if what I'm doing here would work on all systems, > but it's a start. Let me know what you think. > > - Brian >
Small change. I meant to keep remote_read() from being called if remote_peek() didn't see a message, so it won't block. -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
Tests for the +clientserver feature. STARTTEST :" :" Set register 'a' to our expected result of 'ok'. :" Any error messages will be appended. :" :call setreg('a', 'ok', 'l') :" :" Start the server and verify it's available. :" :silent !../vim -nes -u NONE --servername vim_test_server <&- 2>&1 >/dev/null & :sleep 200m :if index(split(serverlist(), "\n"), 'VIM_TEST_SERVER') < 0 : if empty(system("../vim --serverlist | grep -i vim_test_server")) : call setreg('a', 'Server failed to start.', 'al') : else : call setreg('a', 'serverlist() failed.', 'al') : endif :endif :" :" Make sure remote_expr() works. :" :let r = remote_expr('vim_test_server', '2+2') :if r != "4" : call setreg('a', 'remote_expr() failed.', 'al') : call setreg('a', 'Expected: ''4'' Got: '. r, 'al') :endif :" :" Set a line in server's buffer. :" Give this a chance to process, since remote_send() returns immediately. :" Ask the server for the line to verify it was set. :" :call remote_send('vim_test_server', 'call setline(1,"test")<cr>') :sleep 200m :let r = remote_expr('vim_test_server', 'getline(1)') :if r != 'test' : call setreg('a', 'remote_send() failed to set server''s buffer.', 'al') : call setreg('a', 'Expected: ''test'' Got: '. r, 'al') :endif :" :" Lists should be returned as a newline joined string. :" :call remote_expr('vim_test_server', 'setline(1,["one","two"])') :let r = remote_expr('vim_test_server', 'getline(1,"$")') :if r != "one\ntwo\n" : call setreg('a', 'remote_expr() failed to return a newline joined string.', 'al') : call setreg('a', 'Expected: ''one\ntwo\n'' Got: '. r, 'al') :endif :" :" Ask the server to send us a message. :" Verify the message is waiting. :" Read the message. :" :let sid = '' :call remote_send('vim_test_server', 'call server2client(expand("<client>"), "message")<cr>', 'sid') :sleep 200m :if empty(sid) : call setreg('a', 'remote_send() failed to set the server id.', 'al') :else : let r = '' : let a = remote_peek(sid, 'r') : if a < 1 : call setreg('a', 'remote_peek() failed to report a message is waiting.', 'al') : else : if r != 'message' : call setreg('a', 'remote_peek() failed to return the waiting message.', 'al') : call setreg('a', 'Expected: ''message'' Got: '. r, 'al') : endif : let r = remote_read(sid) : if r != 'message' : call setreg('a', 'remote_read() failed to return the waiting message.', 'al') : call setreg('a', 'Expected: ''message'' Got: '. r, 'al') : endif : endif :endif :" :" Stop the server :" :let pid = system("ps -eo pid,cmd | grep vim_test_server | grep -v grep | awk '{print $1}'") :if !empty(pid) | exe("silent !kill ".pid) | endif :" :" Store results and exit :" G"ap :?RESULTS?1,$w! test.out :qa! ENDTEST RESULTS