Patch 8.1.0401
Problem:    Can't get swap name of another buffer.
Solution:   Add swapname(). (Ozaki Kiichi, closes #3441)
Files:      runtime/doc/eval.txt, src/evalfunc.c, src/testdir/test_swap.vim


*** ../vim-8.1.0400/runtime/doc/eval.txt        2018-09-14 21:27:02.771741354 
+0200
--- runtime/doc/eval.txt        2018-09-16 18:41:36.931933772 +0200
***************
*** 2410,2415 ****
--- 2417,2423 ----
  substitute({expr}, {pat}, {sub}, {flags})
                                String  all {pat} in {expr} replaced with {sub}
  swapinfo({fname})             Dict    information about swap file {fname}
+ swapname({expr})              String  swap file of buffer {expr}
  synID({lnum}, {col}, {trans}) Number  syntax ID at {lnum} and {col}
  synIDattr({synID}, {what} [, {mode}])
                                String  attribute {what} of syntax ID {synID}
***************
*** 8011,8017 ****
                |submatch()| returns.  Example: >
                   :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
  
! swapinfo({fname})                                     swapinfo()
                The result is a dictionary, which holds information about the
                swapfile {fname}. The available fields are:
                        version VIM version
--- 8024,8030 ----
                |submatch()| returns.  Example: >
                   :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
  
! swapinfo({fname})                                     *swapinfo()*
                The result is a dictionary, which holds information about the
                swapfile {fname}. The available fields are:
                        version VIM version
***************
*** 8023,8034 ****
--- 8036,8055 ----
                        mtime   last modification time in seconds
                        inode   Optional: INODE number of the file
                        dirty   1 if file was modified, 0 if not
+               Note that "user" and "host" are truncated to at most 39 bytes.
                In case of failure an "error" item is added with the reason:
                        Cannot open file: file not found or in accessible
                        Cannot read file: cannot read first block
                        Not a swap file: does not contain correct block ID
                        Magic number mismatch: Info in first block is invalid
  
+ swapname({expr})                                      *swapname()*
+               The result is the swap file path of the buffer {expr}.
+               For the use of {expr}, see |bufname()| above.
+               If buffer {expr} is the current buffer, the result is equal to
+               |:swapname| (unless no swap file).
+               If buffer {expr} has no swap file, returns an empty string.
+ 
  synID({lnum}, {col}, {trans})                         *synID()*
                The result is a Number, which is the syntax ID at the position
                {lnum} and {col} in the current window.
*** ../vim-8.1.0400/src/evalfunc.c      2018-09-14 21:27:02.775741320 +0200
--- src/evalfunc.c      2018-09-16 18:41:36.935933733 +0200
***************
*** 399,404 ****
--- 399,405 ----
  static void f_submatch(typval_T *argvars, typval_T *rettv);
  static void f_substitute(typval_T *argvars, typval_T *rettv);
  static void f_swapinfo(typval_T *argvars, typval_T *rettv);
+ static void f_swapname(typval_T *argvars, typval_T *rettv);
  static void f_synID(typval_T *argvars, typval_T *rettv);
  static void f_synIDattr(typval_T *argvars, typval_T *rettv);
  static void f_synIDtrans(typval_T *argvars, typval_T *rettv);
***************
*** 865,870 ****
--- 866,872 ----
      {"submatch",      1, 2, f_submatch},
      {"substitute",    4, 4, f_substitute},
      {"swapinfo",      1, 1, f_swapinfo},
+     {"swapname",      1, 1, f_swapname},
      {"synID",         3, 3, f_synID},
      {"synIDattr",     2, 3, f_synIDattr},
      {"synIDtrans",    1, 1, f_synIDtrans},
***************
*** 12342,12347 ****
--- 12344,12366 ----
  }
  
  /*
+  * "swapname(expr)" function
+  */
+     static void
+ f_swapname(typval_T *argvars, typval_T *rettv)
+ {
+     buf_T     *buf;
+ 
+     rettv->v_type = VAR_STRING;
+     buf = get_buf_tv(&argvars[0], FALSE);
+     if (buf == NULL || buf->b_ml.ml_mfp == NULL
+                                       || buf->b_ml.ml_mfp->mf_fname == NULL)
+       rettv->vval.v_string = NULL;
+     else
+       rettv->vval.v_string = vim_strsave(buf->b_ml.ml_mfp->mf_fname);
+ }
+ 
+ /*
   * "synID(lnum, col, trans)" function
   */
      static void
*** ../vim-8.1.0400/src/testdir/test_swap.vim   2018-08-22 11:27:57.118946770 
+0200
--- src/testdir/test_swap.vim   2018-09-16 18:41:36.935933733 +0200
***************
*** 1,5 ****
--- 1,9 ----
  " Tests for the swap feature
  
+ func s:swapname()
+   return trim(execute('swapname'))
+ endfunc
+ 
  " Tests for 'directory' option.
  func Test_swap_directory()
    if !has("unix")
***************
*** 17,23 ****
    " Verify that the swap file doesn't exist in the current directory
    call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
    edit Xtest1
!   let swfname = split(execute("swapname"))[0]
    call assert_equal([swfname], glob(swfname, 1, 1, 1))
  
    " './dir', swap file in a directory relative to the file
--- 21,27 ----
    " Verify that the swap file doesn't exist in the current directory
    call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
    edit Xtest1
!   let swfname = s:swapname()
    call assert_equal([swfname], glob(swfname, 1, 1, 1))
  
    " './dir', swap file in a directory relative to the file
***************
*** 27,33 ****
    edit Xtest1
    call assert_equal([], glob(swfname, 1, 1, 1))
    let swfname = "Xtest2/Xtest1.swp"
!   call assert_equal(swfname, split(execute("swapname"))[0])
    call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
  
    " 'dir', swap file in directory relative to the current dir
--- 31,37 ----
    edit Xtest1
    call assert_equal([], glob(swfname, 1, 1, 1))
    let swfname = "Xtest2/Xtest1.swp"
!   call assert_equal(swfname, s:swapname())
    call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
  
    " 'dir', swap file in directory relative to the current dir
***************
*** 38,44 ****
    edit Xtest2/Xtest3
    call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
    let swfname = "Xtest.je/Xtest3.swp"
!   call assert_equal(swfname, split(execute("swapname"))[0])
    call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
  
    set dir&
--- 42,48 ----
    edit Xtest2/Xtest3
    call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
    let swfname = "Xtest.je/Xtest3.swp"
!   call assert_equal(swfname, s:swapname())
    call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
  
    set dir&
***************
*** 70,76 ****
        throw 'Skipped: cannot set second group on test file'
        else
        split Xtest
!       let swapname = substitute(execute('swapname'), '[[:space:]]', '', 'g')
        call assert_match('Xtest', swapname)
        " Group of swapfile must now match original file.
        call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname))
--- 74,80 ----
        throw 'Skipped: cannot set second group on test file'
        else
        split Xtest
!       let swapname = s:swapname()
        call assert_match('Xtest', swapname)
        " Group of swapfile must now match original file.
        call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname))
***************
*** 102,108 ****
    new Xswapinfo
    call setline(1, ['one', 'two', 'three'])
    w
!   let fname = trim(execute('swapname'))
    call assert_match('Xswapinfo', fname)
    let info = swapinfo(fname)
  
--- 106,112 ----
    new Xswapinfo
    call setline(1, ['one', 'two', 'three'])
    w
!   let fname = s:swapname()
    call assert_match('Xswapinfo', fname)
    let info = swapinfo(fname)
  
***************
*** 136,138 ****
--- 140,163 ----
    call assert_equal('Not a swap file', info.error)
    call delete('Xnotaswapfile')
  endfunc
+ 
+ func Test_swapname()
+   edit Xtest1
+   let expected = s:swapname()
+   call assert_equal(expected, swapname('%'))
+ 
+   new Xtest2
+   let buf = bufnr('%')
+   let expected = s:swapname()
+   wincmd p
+   call assert_equal(expected, swapname(buf))
+ 
+   new Xtest3
+   setlocal noswapfile
+   call assert_equal('', swapname('%'))
+ 
+   bwipe!
+   call delete('Xtest1')
+   call delete('Xtest2')
+   call delete('Xtest3')
+ endfunc
*** ../vim-8.1.0400/src/version.c       2018-09-16 18:10:45.246181729 +0200
--- src/version.c       2018-09-16 18:42:35.483369791 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     401,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
77. The phone company asks you to test drive their new PBX system

 /// 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