>Bram Moolenaar wrote:
>
>>Tim Chase wrote:
>>
>>>>>I don't see this problem, ":e foo\ ~\ foo" works just fine for me.
>>>>>What version of Vim do you use?
>>>>>        
>>>>>
>>>Replicated here on both Vim7.0 (patches 1-122) and Vim7.1
>>>(patches 1-22) under Debian:
>>>
>>>  bash$ touch "foo ~ foo"
>>>  bash$ vi -u NONE
>>>  :set nocp
>>>  :e foo<tab>
>>>(expands to ":e foo\ ~\ foo")
>>>hit <enter>
>>>
>>>Get the same E77 that the OP got.
>>>    
>>
>>Still it works OK for me...  Ah, it's the value for 'shell' that
>>matters.  It fails when set to "sh", it works OK when set to "tcsh".
>>
>>
>It also fails for me with shell=/bin/ksh (using vim7.1.112, huge, fedora 
>core 5).
>

The following patch (based on the cvs version) should fix this problem
for shells other than *csh:

Index: os_unix.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/os_unix.c,v
retrieving revision 1.73
diff -u -p -r1.73 os_unix.c
--- os_unix.c   30 Aug 2007 09:47:13 -0000      1.73
+++ os_unix.c   22 Sep 2007 04:59:29 -0000
@@ -5061,11 +5061,22 @@ mch_expand_wildcards(num_pat, pat, num_f
     char_u     *command;
     FILE       *fd;
     char_u     *buffer;
-#define STYLE_ECHO  0      /* use "echo" to expand */
-#define STYLE_GLOB  1      /* use "glob" to expand, for csh */
-#define STYLE_PRINT 2      /* use "print -N" to expand, for zsh */
-#define STYLE_BT    3      /* `cmd` expansion, execute the pattern directly */
-    int                shell_style = STYLE_ECHO;
+#define STYLE_PSH_GLOB  0    /* use "glob" function for POSIX shells */
+#define STYLE_CSH_GLOB  1    /* use "glob" to expand, for csh */
+#define STYLE_BT    2     /* `cmd` expansion, execute the pattern directly */
+
+/* Simulate csh's builtin "glob" command (with nonomatch) for POSIX compatible
+ * shells. Tested with sh, ksh(5.2.14), bash-3.2.0(1) and zsh-4.2.6 on obsd
+ * v4.1
+ */
+#if 0
+#define CSH_GLOB "glob() { while [ $# -ge 1 ]; do echo -En \"$1\"; if [ ! $# 
-eq 1 ]; then echo -en \"\\000\"; fi;  shift; done };"
+#endif
+
+#define PSH_GLOB "glob() { while [ $# -ge 1 ]; do echo -En \"$1\"; echo -en 
\"\\000\"; shift; done };"
+    
+
+    int                shell_style = STYLE_PSH_GLOB;
     int                check_spaces;
     static int did_find_nul = FALSE;
     int                ampersent = FALSE;
@@ -5107,8 +5118,9 @@ mch_expand_wildcards(num_pat, pat, num_f
     /*
      * Let the shell expand the patterns and write the result into the temp
      * file.  if expanding `cmd` execute it directly.
-     * If we use csh, glob will work better than echo.
-     * If we use zsh, print -N will work better than glob.
+     *
+     * If we use csh, builtin command glob will be used.
+     * If we use other posix compatible shells, PSH_GLOB will be used.
      */
     if (num_pat == 1 && *pat[0] == '`'
            && (len = STRLEN(pat[0])) > 2
@@ -5117,13 +5129,11 @@ mch_expand_wildcards(num_pat, pat, num_f
     else if ((len = STRLEN(p_sh)) >= 3)
     {
        if (STRCMP(p_sh + len - 3, "csh") == 0)
-           shell_style = STYLE_GLOB;
-       else if (STRCMP(p_sh + len - 3, "zsh") == 0)
-           shell_style = STYLE_PRINT;
+           shell_style = STYLE_CSH_GLOB;
     }
 
-    /* "unset nonomatch; print -N >" plus two is 29 */
-    len = STRLEN(tempname) + 29;
+    len = STRLEN(tempname) + STRLEN(PSH_GLOB) + 2;
+
     for (i = 0; i < num_pat; ++i)
     {
        /* Count the length of the patterns in the same way as they are put in
@@ -5150,8 +5160,7 @@ mch_expand_wildcards(num_pat, pat, num_f
 
     /*
      * Build the shell command:
-     * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell
-     *  recognizes this).
+     * - Set $nonomatch depending on EW_NOTFOUND (for csh).
      * - Add the shell command to print the expanded names.
      * - Add the temp file name.
      * - Add the file name patterns.
@@ -5174,17 +5183,28 @@ mch_expand_wildcards(num_pat, pat, num_f
     }
     else
     {
-       if (flags & EW_NOTFOUND)
-           STRCPY(command, "set nonomatch; ");
-       else
-           STRCPY(command, "unset nonomatch; ");
-       if (shell_style == STYLE_GLOB)
-           STRCAT(command, "glob >");
-       else if (shell_style == STYLE_PRINT)
-           STRCAT(command, "print -N >");
-       else
-           STRCAT(command, "echo >");
+       if (shell_style == STYLE_CSH_GLOB) 
+       {
+           /* nonomatch is csh specific */
+           if (flags & EW_NOTFOUND)
+               STRCPY(command, "set nonomatch; ");
+           else
+               STRCPY(command, "unset nonomatch; ");
+       }
+       else if (shell_style == STYLE_PSH_GLOB)
+           STRCPY(command, PSH_GLOB);
+       else 
+       {
+           /* for other kinds of shells may be supported in future,
+            * should not be used now.
+            */
+#define SH_GLOB "glob() { bla;bla; };"
+           STRCPY(command, SH_GLOB);
+       }
+
+       STRCAT(command, "glob >");
     }
+
     STRCAT(command, tempname);
     if (shell_style != STYLE_BT)
        for (i = 0; i < num_pat; ++i)
@@ -5235,19 +5255,11 @@ mch_expand_wildcards(num_pat, pat, num_f
                                           redirection */
 
     /*
-     * Using zsh -G: If a pattern has no matches, it is just deleted from
-     * the argument list, otherwise zsh gives an error message and doesn't
-     * expand any other pattern.
-     */
-    if (shell_style == STYLE_PRINT)
-       extra_shell_arg = (char_u *)"-G";   /* Use zsh NULL_GLOB option */
-
-    /*
      * If we use -f then shell variables set in .cshrc won't get expanded.
      * vi can do it, so we will too, but it is only necessary if there is a "$"
      * in one of the patterns, otherwise we can still use the fast option.
      */
-    else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat))
+    else if (shell_style == STYLE_CSH_GLOB && !have_dollars(num_pat, pat))
        extra_shell_arg = (char_u *)"-f";       /* Use csh fast option */
 
     /*
@@ -5344,21 +5356,8 @@ mch_expand_wildcards(num_pat, pat, num_f
     len = p - buffer;
 # endif
 
-
-    /* file names are separated with Space */
-    if (shell_style == STYLE_ECHO)
-    {
-       buffer[len] = '\n';             /* make sure the buffer ends in NL */
-       p = buffer;
-       for (i = 0; *p != '\n'; ++i)    /* count number of entries */
-       {
-           while (*p != ' ' && *p != '\n')
-               ++p;
-           p = skipwhite(p);           /* skip to next entry */
-       }
-    }
     /* file names are separated with NL */
-    else if (shell_style == STYLE_BT)
+    if (shell_style == STYLE_BT)
     {
        buffer[len] = NUL;              /* make sure the buffer ends in NUL */
        p = buffer;
@@ -5375,26 +5374,8 @@ mch_expand_wildcards(num_pat, pat, num_f
     else
     {
        /*
-        * Some versions of zsh use spaces instead of NULs to separate
-        * results.  Only do this when there is no NUL before the end of the
-        * buffer, otherwise we would never be able to use file names with
-        * embedded spaces when zsh does use NULs.
-        * When we found a NUL once, we know zsh is OK, set did_find_nul and
-        * don't check for spaces again.
-        */
-       check_spaces = FALSE;
-       if (shell_style == STYLE_PRINT && !did_find_nul)
-       {
-           /* If there is a NUL, set did_find_nul, else set check_spaces */
-           if (len && (int)STRLEN(buffer) < len - 1)
-               did_find_nul = TRUE;
-           else
-               check_spaces = TRUE;
-       }
-
-       /*
-        * Make sure the buffer ends with a NUL.  For STYLE_PRINT there
-        * already is one, for STYLE_GLOB it needs to be added.
+        * Make sure the buffer ends with a NUL. For STYLE_PSH_GLOB there
+        * already is one, for STYLE_CSH_GLOB it needs to be added.
         */
        if (len && buffer[len - 1] == NUL)
            --len;
@@ -5402,7 +5383,7 @@ mch_expand_wildcards(num_pat, pat, num_f
            buffer[len] = NUL;
        i = 0;
        for (p = buffer; p < buffer + len; ++p)
-           if (*p == NUL || (*p == ' ' && check_spaces))   /* count entry */
+           if (*p == NUL )   /* count entry */
            {
                ++i;
                *p = NUL;
@@ -5436,11 +5417,13 @@ mch_expand_wildcards(num_pat, pat, num_f
     for (i = 0; i < *num_file; ++i)
     {
        (*file)[i] = p;
-       /* Space or NL separates */
-       if (shell_style == STYLE_ECHO || shell_style == STYLE_BT)
+
+       /* STYLE_BT assuming valid file names are separated with NL, and
+        * without leading white spaces. 
+        */
+       if (shell_style == STYLE_BT)
        {
-           while (!(shell_style == STYLE_ECHO && *p == ' ')
-                                                  && *p != '\n' && *p != NUL)
+           while ( *p != '\n' && *p != NUL)
                ++p;
            if (p == buffer + len)              /* last entry */
                *p = NUL;
-- 
Dasn


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui