Patch 8.2.3530
Problem:    ":buf \{a}" fails while ":edit \{a}" works.
Solution:   Unescape "\{". (closes #8917)
Files:      src/vim.h, src/cmdexpand.c, src/evalfunc.c, src/ex_getln.c,
            src/proto/ex_getln.pro, src/normal.c, src/session.c,
            src/terminal.c, src/vim9execute.c, src/testdir/test_cmdline.vim


*** ../vim-8.2.3529/src/vim.h   2021-09-12 12:39:04.323467415 +0100
--- src/vim.h   2021-10-17 17:01:30.538149382 +0100
***************
*** 291,296 ****
--- 291,297 ----
  #endif
  #ifdef BACKSLASH_IN_FILENAME
  # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
+ # define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`%#'\"|!<")
  #else
  # ifdef VMS
      // VMS allows a lot of characters in the file name
***************
*** 300,305 ****
--- 301,307 ----
  #  define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
  #  define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
  # endif
+ #  define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`$\\%#'\"|!<")
  #endif
  
  // length of a buffer to store a number in ASCII (64 bits binary + NUL)
***************
*** 2766,2770 ****
--- 2768,2776 ----
  #define UC_BUFFER     1       // -buffer: local to current buffer
  #define UC_VIM9               2       // {} argument: Vim9 syntax.
  
+ // flags used by vim_strsave_escaped()
+ #define VSE_NONE      0
+ #define VSE_SHELL     1       // escape for a shell command
+ #define VSE_BUFFER    2       // escape for a ":buffer" command
  
  #endif // VIM__H
*** ../vim-8.2.3529/src/cmdexpand.c     2021-09-12 14:45:06.686219399 +0100
--- src/cmdexpand.c     2021-10-17 17:18:56.860648984 +0100
***************
*** 48,53 ****
--- 48,55 ----
  {
      int               i;
      char_u    *p;
+     int               vse_what = xp->xp_context == EXPAND_BUFFERS
+                                                      ? VSE_BUFFER : VSE_NONE;
  
      // May change home directory back to "~"
      if (options & WILD_HOME_REPLACE)
***************
*** 84,92 ****
                    }
                }
  #ifdef BACKSLASH_IN_FILENAME
!               p = vim_strsave_fnameescape(files[i], FALSE);
  #else
!               p = vim_strsave_fnameescape(files[i], xp->xp_shell);
  #endif
                if (p != NULL)
                {
--- 86,95 ----
                    }
                }
  #ifdef BACKSLASH_IN_FILENAME
!               p = vim_strsave_fnameescape(files[i], vse_what);
  #else
!               p = vim_strsave_fnameescape(files[i],
!                                         xp->xp_shell ? VSE_SHELL : vse_what);
  #endif
                if (p != NULL)
                {
*** ../vim-8.2.3529/src/evalfunc.c      2021-10-14 21:27:50.646253845 +0100
--- src/evalfunc.c      2021-10-17 17:04:26.715837272 +0100
***************
*** 3886,3892 ****
        return;
  
      rettv->vval.v_string = vim_strsave_fnameescape(
!                                          tv_get_string(&argvars[0]), FALSE);
      rettv->v_type = VAR_STRING;
  }
  
--- 3886,3892 ----
        return;
  
      rettv->vval.v_string = vim_strsave_fnameescape(
!                                        tv_get_string(&argvars[0]), VSE_NONE);
      rettv->v_type = VAR_STRING;
  }
  
*** ../vim-8.2.3529/src/ex_getln.c      2021-10-04 19:47:31.940220521 +0100
--- src/ex_getln.c      2021-10-17 17:19:15.465361612 +0100
***************
*** 3894,3920 ****
  }
  
  /*
!  * Escape special characters in "fname" for when used as a file name argument
!  * after a Vim command, or, when "shell" is non-zero, a shell command.
   * Returns the result in allocated memory.
   */
      char_u *
! vim_strsave_fnameescape(char_u *fname, int shell UNUSED)
  {
      char_u    *p;
  #ifdef BACKSLASH_IN_FILENAME
      char_u    buf[20];
      int               j = 0;
  
!     // Don't escape '[', '{' and '!' if they are in 'isfname'.
!     for (p = PATH_ESC_CHARS; *p != NUL; ++p)
        if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p))
            buf[j++] = *p;
      buf[j] = NUL;
      p = vim_strsave_escaped(fname, buf);
  #else
!     p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
!     if (shell && csh_like_shell() && p != NULL)
      {
        char_u      *s;
  
--- 3894,3925 ----
  }
  
  /*
!  * Escape special characters in "fname", depending on "what":
!  * VSE_NONE: for when used as a file name argument after a Vim command.
!  * VSE_SHELL: for a shell command.
!  * VSE_BUFFER: for the ":buffer" command.
   * Returns the result in allocated memory.
   */
      char_u *
! vim_strsave_fnameescape(char_u *fname, int what)
  {
      char_u    *p;
  #ifdef BACKSLASH_IN_FILENAME
      char_u    buf[20];
      int               j = 0;
  
!     // Don't escape '[', '{' and '!' if they are in 'isfname' and for the
!     // ":buffer" command.
!     for (p = what == VSE_BUFFER ? BUFFER_ESC_CHARS : PATH_ESC_CHARS;
!                                                               *p != NUL; ++p)
        if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p))
            buf[j++] = *p;
      buf[j] = NUL;
      p = vim_strsave_escaped(fname, buf);
  #else
!     p = vim_strsave_escaped(fname, what == VSE_SHELL ? SHELL_ESC_CHARS
!                   : what == VSE_BUFFER ? BUFFER_ESC_CHARS : PATH_ESC_CHARS);
!     if (what == VSE_SHELL && csh_like_shell() && p != NULL)
      {
        char_u      *s;
  
*** ../vim-8.2.3529/src/proto/ex_getln.pro      2020-08-20 14:02:38.536534973 
+0100
--- src/proto/ex_getln.pro      2021-10-17 17:19:56.846898768 +0100
***************
*** 26,32 ****
  void compute_cmdrow(void);
  void cursorcmd(void);
  void gotocmdline(int clr);
! char_u *vim_strsave_fnameescape(char_u *fname, int shell);
  void escape_fname(char_u **pp);
  void tilde_replace(char_u *orig_pat, int num_files, char_u **files);
  cmdline_info_T *get_cmdline_info(void);
--- 26,32 ----
  void compute_cmdrow(void);
  void cursorcmd(void);
  void gotocmdline(int clr);
! char_u *vim_strsave_fnameescape(char_u *fname, int what);
  void escape_fname(char_u **pp);
  void tilde_replace(char_u *orig_pat, int num_files, char_u **files);
  cmdline_info_T *get_cmdline_info(void);
*** ../vim-8.2.3529/src/normal.c        2021-10-11 15:40:36.476538476 +0100
--- src/normal.c        2021-10-17 17:04:45.012012678 +0100
***************
*** 3741,3747 ****
        ptr = vim_strnsave(ptr, n);
        if (kp_ex)
            // Escape the argument properly for an Ex command
!           p = vim_strsave_fnameescape(ptr, FALSE);
        else
            // Escape the argument properly for a shell command
            p = vim_strsave_shellescape(ptr, TRUE, TRUE);
--- 3741,3747 ----
        ptr = vim_strnsave(ptr, n);
        if (kp_ex)
            // Escape the argument properly for an Ex command
!           p = vim_strsave_fnameescape(ptr, VSE_NONE);
        else
            // Escape the argument properly for a shell command
            p = vim_strsave_shellescape(ptr, TRUE, TRUE);
*** ../vim-8.2.3529/src/session.c       2021-07-20 20:07:32.968058851 +0100
--- src/session.c       2021-10-17 17:06:07.992808450 +0100
***************
*** 43,49 ****
      }
  
      // escape special characters
!     p = vim_strsave_fnameescape(sname, FALSE);
      vim_free(sname);
      if (p == NULL)
        return FAIL;
--- 43,49 ----
      }
  
      // escape special characters
!     p = vim_strsave_fnameescape(sname, VSE_NONE);
      vim_free(sname);
      if (p == NULL)
        return FAIL;
*** ../vim-8.2.3529/src/terminal.c      2021-10-15 22:25:37.785385044 +0100
--- src/terminal.c      2021-10-17 17:06:11.832845283 +0100
***************
*** 667,673 ****
  
            if (s == NULL)
                break;
!           p = vim_strsave_fnameescape(s, FALSE);
            if (p == NULL)
                break;
            ga_concat(&ga, p);
--- 667,673 ----
  
            if (s == NULL)
                break;
!           p = vim_strsave_fnameescape(s, VSE_NONE);
            if (p == NULL)
                break;
            ga_concat(&ga, p);
*** ../vim-8.2.3529/src/vim9execute.c   2021-09-16 15:15:00.204224417 +0100
--- src/vim9execute.c   2021-10-17 17:19:34.214066041 +0100
***************
*** 1147,1153 ****
                                    while ((e = vim_strchr(s, '\n')) != NULL)
                                    {
                                        *e = NUL;
!                                       p = vim_strsave_fnameescape(s, FALSE);
                                        if (p != NULL)
                                        {
                                            ga_concat(&ga, p);
--- 1147,1154 ----
                                    while ((e = vim_strchr(s, '\n')) != NULL)
                                    {
                                        *e = NUL;
!                                       p = vim_strsave_fnameescape(s,
!                                                                    VSE_NONE);
                                        if (p != NULL)
                                        {
                                            ga_concat(&ga, p);
*** ../vim-8.2.3529/src/testdir/test_cmdline.vim        2021-09-12 
14:45:06.690219391 +0100
--- src/testdir/test_cmdline.vim        2021-10-17 17:15:48.804560070 +0100
***************
*** 900,905 ****
--- 900,911 ----
    call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
    call assert_equal("\"unlet one two", @:)
  
+   " completion for the :buffer command with curlies
+   edit \{someFile}
+   call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
+   call assert_equal("\"buf {someFile}", @:)
+   bwipe {someFile}
+ 
    " completion for the :bdelete command
    call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
    call assert_equal("\"bdel a b c", @:)
*** ../vim-8.2.3529/src/version.c       2021-10-17 16:09:05.286073690 +0100
--- src/version.c       2021-10-17 16:31:03.313330781 +0100
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3530,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
177. You log off of your system because it's time to go to work.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211017162114.44AFDC80053%40moolenaar.net.

Raspunde prin e-mail lui