summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/evalfunc.c31
-rw-r--r--src/if_xcmdsrv.c23
-rw-r--r--src/os_mswin.c4
-rw-r--r--src/proto/main.pro1
-rw-r--r--src/testdir/test_clientserver.vim25
-rw-r--r--src/version.c2
6 files changed, 64 insertions, 22 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 21b75c108..bee58eee1 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -307,6 +307,7 @@ static void f_remote_foreground(typval_T *argvars, typval_T *rettv);
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,6 +742,7 @@ static struct fst
{"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,7 +8489,7 @@ check_connection(void)
make_connection();
if (X_DISPLAY == NULL)
{
- EMSG(_("E240: No connection to Vim server"));
+ EMSG(_("E240: No connection to the X server"));
return FAIL;
}
return OK;
@@ -8690,6 +8692,33 @@ f_remote_send(typval_T *argvars UNUSED, typval_T *rettv)
}
/*
+ * "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
*/
static void
diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c
index fa91c3e8c..18c208b96 100644
--- a/src/if_xcmdsrv.c
+++ b/src/if_xcmdsrv.c
@@ -399,27 +399,7 @@ serverSendToVim(
/* 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;
- }
+ return sendToLocalVim(cmd, asExpr, result);
/*
* Bind the server name to a communication window.
@@ -800,6 +780,7 @@ serverSendReply(char_u *name, char_u *str)
WaitForReply(void *p)
{
Window *w = (Window *) p;
+
return ServerReplyFind(*w, SROP_Find) != NULL;
}
diff --git a/src/os_mswin.c b/src/os_mswin.c
index 166305298..cfa208493 100644
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -2409,6 +2409,10 @@ serverSendToVim(
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]))
diff --git a/src/proto/main.pro b/src/proto/main.pro
index 958e1f3bb..f8abb94b5 100644
--- a/src/proto/main.pro
+++ b/src/proto/main.pro
@@ -11,5 +11,6 @@ void time_pop(void *tp);
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 : */
diff --git a/src/testdir/test_clientserver.vim b/src/testdir/test_clientserver.vim
index 55cc98ec8..55f440ffc 100644
--- a/src/testdir/test_clientserver.vim
+++ b/src/testdir/test_clientserver.vim
@@ -30,6 +30,31 @@ func Test_client_server()
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\<CR>")
+ sleep 500m
+ call remote_send(name, ":let testvar = 'maybe'\<CR>")
+ 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''\<CR>")', '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('<client>'), 'got it')\<CR>", 'g:myserverid')
+ call assert_equal('got it', remote_read(g:myserverid))
+
call remote_send(name, ":qa!\<CR>")
call WaitFor('job_status(g:job) == "dead"')
if job_status(g:job) != 'dead'
diff --git a/src/version.c b/src/version.c
index 72c8e78dd..18ba30e87 100644
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 475,
+/**/
474,
/**/
473,