Patch 8.0.1763
Problem:    :argedit does not reuse an empty unnamed buffer.
Solution:   Add the BLN_CURBUF flag and fix all the side effects. (Christian
            Brabandt, closes #2713)
Files:      src/buffer.c, src/ex_cmds2.c, src/proto/buffer.pro,
            src/testdir/test_arglist.vim, src/testdir/test_command_count.vim


*** ../vim-8.0.1762/src/buffer.c        2018-04-17 23:24:02.350755880 +0200
--- src/buffer.c        2018-04-24 21:51:37.382438994 +0200
***************
*** 1842,1847 ****
--- 1842,1861 ----
  static int  top_file_num = 1;         /* highest file number */
  
  /*
+  * Return TRUE if the current buffer is empty, unnamed, unmodified and used in
+  * only one window.  That means it can be re-used.
+  */
+     int
+ curbuf_reusable(void)
+ {
+     return (curbuf != NULL
+       && curbuf->b_ffname == NULL
+       && curbuf->b_nwindows <= 1
+       && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())
+       && !curbufIsChanged());
+ }
+ 
+ /*
   * Add a file name to the buffer list.  Return a pointer to the buffer.
   * If the same file name already exists return a pointer to that buffer.
   * If it does not exist, or if fname == NULL, a new entry is created.
***************
*** 1921,1931 ****
       * buffer.)
       */
      buf = NULL;
!     if ((flags & BLN_CURBUF)
!           && curbuf != NULL
!           && curbuf->b_ffname == NULL
!           && curbuf->b_nwindows <= 1
!           && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY()))
      {
        buf = curbuf;
        /* It's like this buffer is deleted.  Watch out for autocommands that
--- 1935,1941 ----
       * buffer.)
       */
      buf = NULL;
!     if ((flags & BLN_CURBUF) && curbuf_reusable())
      {
        buf = curbuf;
        /* It's like this buffer is deleted.  Watch out for autocommands that
*** ../vim-8.0.1762/src/ex_cmds2.c      2018-04-24 15:19:00.499068802 +0200
--- src/ex_cmds2.c      2018-04-24 21:58:20.220485397 +0200
***************
*** 2941,2946 ****
--- 2941,2948 ----
  ex_argedit(exarg_T *eap)
  {
      int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1;
+     // Whether curbuf will be reused, curbuf->b_ffname will be set.
+     int curbuf_is_reusable = curbuf_reusable();
  
      if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
        return;
***************
*** 2948,2955 ****
      maketitle();
  #endif
  
!     if (curwin->w_arg_idx == 0 && (curbuf->b_ml.ml_flags & ML_EMPTY)
!           && curbuf->b_ffname == NULL)
        i = 0;
      /* Edit the argument. */
      if (i < ARGCOUNT)
--- 2950,2958 ----
      maketitle();
  #endif
  
!     if (curwin->w_arg_idx == 0
!           && (curbuf->b_ml.ml_flags & ML_EMPTY)
!           && (curbuf->b_ffname == NULL || curbuf_is_reusable))
        i = 0;
      /* Edit the argument. */
      if (i < ARGCOUNT)
***************
*** 3281,3287 ****
        for (i = 0; i < count; ++i)
        {
            ARGLIST[after + i].ae_fname = files[i];
!           ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
        }
        ALIST(curwin)->al_ga.ga_len += count;
        if (old_argcount > 0 && curwin->w_arg_idx >= after)
--- 3284,3291 ----
        for (i = 0; i < count; ++i)
        {
            ARGLIST[after + i].ae_fname = files[i];
!           ARGLIST[after + i].ae_fnum =
!                               buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
        }
        ALIST(curwin)->al_ga.ga_len += count;
        if (old_argcount > 0 && curwin->w_arg_idx >= after)
*** ../vim-8.0.1762/src/proto/buffer.pro        2018-02-19 23:09:57.385619337 
+0100
--- src/proto/buffer.pro        2018-04-24 21:52:54.038035773 +0200
***************
*** 15,20 ****
--- 15,21 ----
  void do_autochdir(void);
  void no_write_message(void);
  void no_write_message_nobang(buf_T *buf);
+ int curbuf_reusable(void);
  buf_T *buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags);
  void free_buf_options(buf_T *buf, int free_p_ff);
  int buflist_getfile(int n, linenr_T lnum, int options, int forceit);
*** ../vim-8.0.1762/src/testdir/test_arglist.vim        2018-04-20 
21:58:16.446318499 +0200
--- src/testdir/test_arglist.vim        2018-04-24 21:54:38.513513422 +0200
***************
*** 308,313 ****
--- 308,325 ----
    %argd
    bwipe! C
    bwipe! D
+ 
+   " :argedit reuses the current buffer if it is empty
+   %argd
+   " make sure to use a new buffer number for x when it is loaded
+   bw! x
+   new
+   let a = bufnr('')
+   argedit x
+   call assert_equal(a, bufnr(''))
+   call assert_equal('x', bufname(''))
+   %argd
+   bw! x
  endfunc
  
  " Test for the :argdelete command
*** ../vim-8.0.1762/src/testdir/test_command_count.vim  2017-10-27 
00:54:59.142125127 +0200
--- src/testdir/test_command_count.vim  2018-04-24 21:47:12.804005629 +0200
***************
*** 173,179 ****
    only!
  
    exe bufnr . 'buf'
-   bnext
    let bufnr = bufnr('%')
    let buffers = []
    .,$-bufdo call add(buffers, bufnr('%'))
--- 173,178 ----
*** ../vim-8.0.1762/src/version.c       2018-04-24 21:40:06.095502611 +0200
--- src/version.c       2018-04-24 21:49:33.839132248 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     1763,
  /**/

-- 
GOD: That is your purpose Arthur ... the Quest for the Holy Grail ...
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui