]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.0501: on MS-Windows ":!start" does not work as expected v8.0.0501
authorBram Moolenaar <Bram@vim.org>
Tue, 21 Mar 2017 18:29:26 +0000 (19:29 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 21 Mar 2017 18:29:26 +0000 (19:29 +0100)
Problem:    On MS-Windows ":!start" does not work as expected.
Solution:   When creating a process fails try passing the argument to
            ShellExecute().  (Katsuya Hino, closes #1570)

runtime/doc/os_win32.txt
src/os_win32.c
src/version.c

index 7357542828d952ac3e78e6c54a845f463556ff39..663087b96c792bd2e23e90c26c91109615db06a8 100644 (file)
@@ -212,10 +212,19 @@ A. You can't!  This is a limitation of the NT console.  NT 5.0 is reported to
    be able to set the blink rate for all console windows at the same time.
 
                                                        *:!start*
-Q. How can I run an external command or program asynchronously?
-A. When using :! to run an external command, you can run it with "start": >
-       :!start winfile.exe<CR>
-<  Using "start" stops Vim switching to another screen, opening a new console,
+Q. How can I asynchronously run an external command or program, or open a
+   document or URL with its default program?
+A. When using :! to run an external command, you can run it with "start". For
+   example, to run notepad: >
+       :!start notepad
+<   To open "image.jpg" with the default image viewer: >
+        :!start image.jpg
+<   To open the folder of the current file in Windows Explorer: >
+        :!start %:h
+<   To open the Vim home page with the default browser: >
+        :!start http://www.vim.org/
+<
+   Using "start" stops Vim switching to another screen, opening a new console,
    or waiting for the program to complete; it indicates that you are running a
    program that does not affect the files you are editing.  Programs begun
    with :!start do not get passed Vim's open file handles, which means they do
index edd38e3a9ed4154f5def2fc57ddee0a915e4cff4..f2fd808e929867b7671099dcbdb24c9bf6f82da2 100644 (file)
@@ -4008,6 +4008,28 @@ vim_create_process(
 }
 
 
+    static HINSTANCE
+vim_shell_execute(
+    char *cmd,
+    INT         n_show_cmd)
+{
+#ifdef FEAT_MBYTE
+    if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+    {
+       WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL);
+       if (wcmd != NULL)
+       {
+           HINSTANCE ret;
+           ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd);
+           vim_free(wcmd);
+           return ret;
+       }
+    }
+#endif
+    return ShellExecute(NULL, NULL, cmd, NULL, NULL, n_show_cmd);
+}
+
+
 #if defined(FEAT_GUI_W32) || defined(PROTO)
 
 /*
@@ -4711,6 +4733,7 @@ mch_call_shell(
            STARTUPINFO         si;
            PROCESS_INFORMATION pi;
            DWORD               flags = CREATE_NEW_CONSOLE;
+           INT                 n_show_cmd = SW_SHOWNORMAL;
            char_u              *p;
 
            ZeroMemory(&si, sizeof(si));
@@ -4729,6 +4752,7 @@ mch_call_shell(
                cmdbase = skipwhite(cmdbase + 4);
                si.dwFlags = STARTF_USESHOWWINDOW;
                si.wShowWindow = SW_SHOWMINNOACTIVE;
+               n_show_cmd = SW_SHOWMINNOACTIVE;
            }
            else if ((STRNICMP(cmdbase, "/b", 2) == 0)
                    && VIM_ISWHITE(cmdbase[2]))
@@ -4800,6 +4824,9 @@ mch_call_shell(
             */
            if (vim_create_process((char *)newcmd, FALSE, flags, &si, &pi))
                x = 0;
+           else if (vim_shell_execute((char *)newcmd, n_show_cmd)
+                                                              > (HINSTANCE)32)
+               x = 0;
            else
            {
                x = -1;
index c3a4779d774cc8b6f77f9db50f906285c396853d..a1edd07d7b4728eec92d5acd44b697e5934115c0 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    501,
 /**/
     500,
 /**/