]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0600: clientserver method needs to be given as argument master v9.2.0600
authorFoxe Chen <chen.foxe@gmail.com>
Fri, 5 Jun 2026 17:41:26 +0000 (17:41 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 5 Jun 2026 17:46:31 +0000 (17:46 +0000)
Problem:  clientserver method needs to be given as argument
Solution: Add support for the $VIM_CLIENTSERVER environment variable,
          which defines which clientserver method Vim should use
          (Foxe Chen).

closes: #20409

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/remote.txt
runtime/doc/tags
runtime/doc/vim.1
runtime/doc/vim.man
src/clientserver.c
src/main.c
src/proto/clientserver.pro
src/testdir/test_clientserver.vim
src/version.c

index 260fc864f63974138f12782d73b2672c9f45b28e..d33c14eb5ffd3126ff42621f491ca5cedfae382e 100644 (file)
@@ -1,4 +1,4 @@
-*remote.txt*   For Vim version 9.2.  Last change: 2026 Feb 14
+*remote.txt*   For Vim version 9.2.  Last change: 2026 Jun 05
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -80,11 +80,17 @@ The following command line arguments are available:
    --clientserver {method}     Use the specified method {method} as the
                                backend for clientserver functionality.  Can
                                either be "socket", "x11", or "mswin".
+                                                           *$VIM_CLIENTSERVER*
+                               If the "$VIM_CLIENTSERVER" environment
+                               variable is set, then Vim will interpret the
+                               value just like the --clientserver argument.
+                               If it is set and --clientserver is provided in
+                               the command line, then --clientserver takes
+                               priority.
                                {only available when compiled with both |+X11|
                                and |+socketserver| features, or
                                |+socketserver| on MS-Windows}
 
-
 Examples ~
 
 Edit "file.txt" in an already running GVIM server: >
index 21ad16a14c7cab9815af20459881a60f49ccfbcc..33c6daa42b0fe1f1453295e9a7d10f554517bca4 100644 (file)
@@ -13,6 +13,7 @@ $NoDefaultCurrentDirectoryInExePath   builtin.txt     /*$NoDefaultCurrentDirectoryInEx
 $VIM   starting.txt    /*$VIM*
 $VIM-use       version5.txt    /*$VIM-use*
 $VIMRUNTIME    starting.txt    /*$VIMRUNTIME*
+$VIM_CLIENTSERVER      remote.txt      /*$VIM_CLIENTSERVER*
 $VIM_POSIX     vi_diff.txt     /*$VIM_POSIX*
 $XDG_CONFIG_HOME       starting.txt    /*$XDG_CONFIG_HOME*
 $quote eval.txt        /*$quote*
index fbc4252501504b50b2b72a2da50ce684982cf0cf..93c28d6ace8f3bece009c704221f1b10610e125d 100644 (file)
@@ -1,4 +1,4 @@
-.TH VIM 1 "2026 May 22"
+.TH VIM 1 "2026 Jun 05"
 .SH NAME
 vim \- Vi IMproved, a programmer's text editor
 .SH SYNOPSIS
@@ -518,7 +518,9 @@ it is taken as either an absolute, relative or relative path to the socket.
 Use {backend} as the backend for clientserver functionality, either "socket",
 "x11", or "mswin" respectively.  Only available when compiled with both
 socketserver and X11 features present, or if compiled with socketserver on
-MS-Windows.
+MS-Windows. The $VIM_CLIENTSERVER environment variable may also be set which
+will be interpreted in the same way, but the --clientserver argument will always
+take priority.
 .TP
 \-\-socketid {id}
 GTK GUI only: Use the GtkPlug mechanism to run gVim in another window.
index c3bc78c2f7a6420a75f2246720c15664e1cdf7d8..583d9d28fde04006fc79a58908eb7b7e5db9bb10 100644 (file)
@@ -390,11 +390,13 @@ OPTIONS
                    to the socket.
 
        --clientserver {backend}
-                   Use {backend} as the backend for  clientserver  functional‐
+                   Use  {backend}  as the backend for clientserver functional‐
                    ity, either "socket", "x11", or "mswin" respectively.  Only
                    available when compiled with both socketserver and X11 fea‐
-                   tures  present, or if compiled with socketserver on MS-Win‐
-                   dows.
+                   tures present, or if compiled with socketserver on  MS-Win‐
+                   dows.  The  $VIM_CLIENTSERVER environment variable may also
+                   be set which will be interpreted in the same way,  but  the
+                   --clientserver argument will always take priority.
 
        --socketid {id}
                    GTK  GUI only: Use the GtkPlug mechanism to run gVim in an‐
@@ -493,4 +495,4 @@ BUGS
        vi_diff.txt when in Vim).  Also have a look  at  the  'compatible'  and
        'cpoptions' options.
 
-                                  2026 May 22                           VIM(1)
+                                  2026 Jun 05                           VIM(1)
index ae72a694f10e0254687b35bcc4f9899b5a09e584..5b0d4a2df9f2759a345b28035f818d192f250a7a 100644 (file)
@@ -1276,3 +1276,28 @@ f_serverlist(typval_T *argvars UNUSED, typval_T *rettv)
     rettv->vval.v_string = r;
 }
 #endif
+
+#ifdef FEAT_CLIENTSERVER_BACKENDS
+/*
+ * Check the $VIM_CLIENTSERVER environment variable and set the method
+ */
+    void
+check_clientserver_method_env(void)
+{
+    char_u *env = mch_getenv("VIM_CLIENTSERVER");
+
+    if (env == NULL)
+       return;
+
+    if (STRICMP(env, "socket") == 0)
+       clientserver_method = CLIENTSERVER_METHOD_SOCKET;
+# ifdef FEAT_X11
+    else if (STRICMP(env, "x11") == 0)
+       clientserver_method = CLIENTSERVER_METHOD_X11;
+# endif
+# ifdef MSWIN
+    else if (STRICMP(env, "mswin") == 0)
+       clientserver_method = CLIENTSERVER_METHOD_MSWIN;
+# endif
+}
+#endif
index d2fe22ebe555942ba27a00ab4d0cb050307b0d54..e30012be40cfa3a293352c6c5605bd68e27e05bf 100644 (file)
@@ -1038,6 +1038,13 @@ common_init_2(mparm_T *paramp)
     gui.dofork = true;             // default is to use fork()
 #endif
 
+#ifdef FEAT_CLIENTSERVER_BACKENDS
+    /*
+     * Check the $VIM_CLIENTSERVER env before we handle the --clientserver arg
+     */
+    check_clientserver_method_env();
+#endif
+
     /*
      * Do a first scan of the arguments in "argv[]":
      *   -display or --display
index 3acd5e01e74905c57ab3eceed97da38df91d4a6c..2c71b130eeb803fee8ba74e0f6e9e54aa6a855c0 100644 (file)
@@ -13,4 +13,5 @@ void f_remote_send(typval_T *argvars, typval_T *rettv);
 void f_remote_startserver(typval_T *argvars, typval_T *rettv);
 void f_server2client(typval_T *argvars, typval_T *rettv);
 void f_serverlist(typval_T *argvars, typval_T *rettv);
+void check_clientserver_method_env(void);
 /* vim: set ft=c : */
index 15918f726795aeec1e1d0c01061391fce1b9d2ba..754aa77305355ba50b0f0a602e72f9d39f8f05f7 100644 (file)
@@ -498,6 +498,48 @@ func Test_clientserver_socketserver_invalid_msg()
   call StopVimInTerminal(buf)
 endfunc
 
+" Test that $VIM_CLIENTSERVER env var works properly
+func Test_clientserver_env_method()
+  CheckFeature socketserver
+
+  let g:test_is_flaky = 1
+  let cmd = GetVimCommand()
+
+  if cmd == ''
+    throw 'GetVimCommand() failed'
+  endif
+
+  " Don't use channel:2000, because previous tests use that and it may take a
+  " while for the channel to fully close.
+  let actual = cmd .. ' --servername channel:4000'
+  let $VIM_CLIENTSERVER = 'socket'
+
+  let job = job_start(actual, {'stoponexit': 'kill', 'out_io': 'null'})
+
+  call WaitForAssert({-> assert_equal("run", job_status(job))})
+
+  if !has('win32') || !has('gui_running')
+      call assert_match('channel:4000',
+            \ system(actual .. ' --remote-expr "v:servername"'))
+  endif
+
+  if has('win32')
+    call job_stop(job, 'kill')
+  else
+    call system(actual .. " --remote-expr 'execute(\"qa!\")'")
+  endif
+  unlet $VIM_CLIENTSERVER
+
+  try
+    call WaitForAssert({-> assert_equal("dead", job_status(job))})
+  finally
+    if job_status(job) != 'dead'
+      call assert_report('Server did not exit')
+      call job_stop(job, 'kill')
+    endif
+  endtry
+endfunc
+
 " Uncomment this line to get a debugging log
 " call ch_logfile('channellog', 'w')
 
index 669a5cf0334829abef503a4a8f7a8fedd9583b91..a58178aedb2e73ff8603ef7ea5e0f97fa7f02537 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    600,
 /**/
     599,
 /**/