To: vim_dev@googlegroups.com Subject: Patch 8.0.0475 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0475 Problem: Not enough testing for the client-server feature. Solution: Add more tests. Add the remote_startserver() function. Fix that a locally evaluated expression uses function-local variables. Files: src/if_xcmdsrv.c, src/evalfunc.c, src/os_mswin.c, src/proto/main.pro, src/testdir/test_clientserver.vim, runtime/doc/eval.txt *** ../vim-8.0.0474/src/if_xcmdsrv.c 2017-03-16 17:23:26.823815869 +0100 --- src/if_xcmdsrv.c 2017-03-18 18:00:48.479701197 +0100 *************** *** 399,425 **** /* Execute locally if no display or target is ourselves */ if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) ! { ! if (asExpr) ! { ! char_u *ret; ! ! ret = eval_client_expr_to_string(cmd); ! if (result != NULL) ! { ! if (ret == NULL) ! *result = vim_strsave((char_u *)_(e_invexprmsg)); ! else ! *result = ret; ! } ! else ! vim_free(ret); ! return ret == NULL ? -1 : 0; ! } ! else ! server_to_input_buf(cmd); ! return 0; ! } /* * Bind the server name to a communication window. --- 399,405 ---- /* Execute locally if no display or target is ourselves */ if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) ! return sendToLocalVim(cmd, asExpr, result); /* * Bind the server name to a communication window. *************** *** 800,805 **** --- 780,786 ---- WaitForReply(void *p) { Window *w = (Window *) p; + return ServerReplyFind(*w, SROP_Find) != NULL; } *** ../vim-8.0.0474/src/evalfunc.c 2017-03-12 20:09:59.460468432 +0100 --- src/evalfunc.c 2017-03-18 17:19:11.629583419 +0100 *************** *** 307,312 **** --- 307,313 ---- static void f_remote_peek(typval_T *argvars, typval_T *rettv); static void f_remote_read(typval_T *argvars, typval_T *rettv); static void f_remote_send(typval_T *argvars, typval_T *rettv); + static void f_remote_startserver(typval_T *argvars, typval_T *rettv); static void f_remove(typval_T *argvars, typval_T *rettv); static void f_rename(typval_T *argvars, typval_T *rettv); static void f_repeat(typval_T *argvars, typval_T *rettv); *************** *** 741,746 **** --- 742,748 ---- {"remote_peek", 1, 2, f_remote_peek}, {"remote_read", 1, 1, f_remote_read}, {"remote_send", 2, 3, f_remote_send}, + {"remote_startserver", 1, 1, f_remote_startserver}, {"remove", 2, 3, f_remove}, {"rename", 2, 2, f_rename}, {"repeat", 2, 2, f_repeat}, *************** *** 8487,8493 **** make_connection(); if (X_DISPLAY == NULL) { ! EMSG(_("E240: No connection to Vim server")); return FAIL; } return OK; --- 8489,8495 ---- make_connection(); if (X_DISPLAY == NULL) { ! EMSG(_("E240: No connection to the X server")); return FAIL; } return OK; *************** *** 8689,8694 **** --- 8691,8723 ---- #endif } + /* + * "remote_startserver()" function + */ + static void + f_remote_startserver(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + #ifdef FEAT_CLIENTSERVER + char_u *server = get_tv_string_chk(&argvars[0]); + + if (server == NULL) + return; /* type error; errmsg already given */ + if (serverName != NULL) + EMSG(_("E941: already started a server")); + else + { + # ifdef FEAT_X11 + if (check_connection() == OK) + serverRegisterName(X_DISPLAY, server); + # else + serverSetName(server); + # endif + } + #else + EMSG(_("E942: +clientserver feature not available")); + #endif + } + /* * "remove()" function */ *** ../vim-8.0.0474/src/os_mswin.c 2017-03-18 16:18:25.103693785 +0100 --- src/os_mswin.c 2017-03-18 18:01:05.019583007 +0100 *************** *** 2409,2414 **** --- 2409,2418 ---- int retcode = 0; char_u altname_buf[MAX_PATH]; + /* Execute locally if no display or target is ourselves */ + if (serverName != NULL && STRICMP(name, serverName) == 0) + return sendToLocalVim(cmd, asExpr, result); + /* If the server name does not end in a digit then we look for an * alternate name. e.g. when "name" is GVIM the we may find GVIM2. */ if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) *** ../vim-8.0.0474/src/proto/main.pro 2016-09-12 13:04:10.000000000 +0200 --- src/proto/main.pro 2017-03-18 17:59:50.252117273 +0100 *************** *** 11,15 **** --- 11,16 ---- void time_msg(char *mesg, void *tv_start); void server_to_input_buf(char_u *str); char_u *eval_client_expr_to_string(char_u *expr); + int sendToLocalVim(char_u *cmd, int asExpr, char_u **result); char_u *serverConvert(char_u *client_enc, char_u *data, char_u **tofree); /* vim: set ft=c : */ *** ../vim-8.0.0474/src/testdir/test_clientserver.vim 2017-03-18 16:18:25.099693814 +0100 --- src/testdir/test_clientserver.vim 2017-03-18 17:45:24.702325840 +0100 *************** *** 30,35 **** --- 30,60 ---- call WaitFor('remote_expr("' . name . '", "testvar") == "yes"') call assert_equal('yes', remote_expr(name, "testvar")) + if has('unix') && has('gui') && !has('gui_running') + " Running in a terminal and the GUI is avaiable: Tell the server to open + " the GUI and check that the remote command still works. + " Need to wait for the GUI to start up, otherwise the send hangs in trying + " to send to the terminal window. + call remote_send(name, ":gui -f\") + sleep 500m + call remote_send(name, ":let testvar = 'maybe'\") + call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"') + call assert_equal('maybe', remote_expr(name, "testvar")) + endif + + call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\")', 'E241') + + " Expression evaluated locally. + if v:servername == '' + call remote_startserver('MYSELF') + call assert_equal('MYSELF', v:servername) + endif + let g:testvar = 'myself' + call assert_equal('myself', remote_expr(v:servername, 'testvar')) + + call remote_send(name, ":call server2client(expand(''), 'got it')\", 'g:myserverid') + call assert_equal('got it', remote_read(g:myserverid)) + call remote_send(name, ":qa!\") call WaitFor('job_status(g:job) == "dead"') if job_status(g:job) != 'dead' *** ../vim-8.0.0474/runtime/doc/eval.txt 2017-03-09 18:19:58.153107904 +0100 --- runtime/doc/eval.txt 2017-03-18 18:05:48.361558128 +0100 *************** *** 2259,2264 **** --- 2262,2269 ---- remote_read({serverid}) String read reply string remote_send({server}, {string} [, {idvar}]) String send key sequence + remote_startserver({name}) none become server {name} + String send key sequence remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list} remove({dict}, {key}) any remove entry {key} from {dict} rename({from}, {to}) Number rename (move) file from {from} to {to} *************** *** 6357,6362 **** --- 6377,6383 ---- See also |clientserver| |RemoteReply|. This function is not available in the |sandbox|. {only available when compiled with the |+clientserver| feature} + Note: Any errors will be reported in the server and may mess up the display. Examples: > *************** *** 6368,6373 **** --- 6389,6400 ---- :echo remote_send("gvim", ":sleep 10 | echo ". \ 'server2client(expand(""), "HELLO")') < + *remote_startserver()* *E941* *E942* + remote_startserver({name}) + Become the server {name}. This fails if already running as a + server, when |v:servername| is not empty. + {only available when compiled with the |+clientserver| feature} + remove({list}, {idx} [, {end}]) *remove()* Without {end}: Remove the item at {idx} from |List| {list} and return the item. *** ../vim-8.0.0474/src/version.c 2017-03-18 16:18:25.103693785 +0100 --- src/version.c 2017-03-18 17:01:15.061284034 +0100 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 475, /**/ -- hundred-and-one symptoms of being an internet addict: 146. You experience ACTUAL physical withdrawal symptoms when away from your 'puter and the net. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///