diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/eval.c | 14 | ||||
| -rw-r--r-- | src/nvim/eval.lua | 1 | ||||
| -rw-r--r-- | src/nvim/testdir/test_swap.vim | 33 | 
3 files changed, 44 insertions, 4 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e9da1f2f2b..52b0f6cd8a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -16430,6 +16430,20 @@ static void f_swapinfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)    get_b0_dict(tv_get_string(argvars), rettv->vval.v_dict);  } +/// "swapname(expr)" function +static void f_swapname(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ +  rettv->v_type = VAR_STRING; +  buf_T *buf = tv_get_buf(&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 f_synID(typval_T *argvars, typval_T *rettv, FunPtr fptr)  { diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 02990fb102..b3f5ef2935 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -302,6 +302,7 @@ return {      submatch={args={1, 2}},      substitute={args=4},      swapinfo={args={1}}, +    swapname={args={1}},      synID={args=3},      synIDattr={args={2, 3}},      synIDtrans={args=1}, diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 789f14aa8d..1bd73707a8 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -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,7 +21,7 @@ func Test_swap_directory()    " 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] +  let swfname = s:swapname()    call assert_equal([swfname], glob(swfname, 1, 1, 1))    " './dir', swap file in a directory relative to the file @@ -27,7 +31,7 @@ func Test_swap_directory()    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, s:swapname())    call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))    " 'dir', swap file in directory relative to the current dir @@ -38,7 +42,7 @@ func Test_swap_directory()    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, s:swapname())    call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))    set dir& @@ -66,7 +70,7 @@ func Test_swapinfo()    new Xswapinfo    call setline(1, ['one', 'two', 'three'])    w -  let fname = trim(execute('swapname')) +  let fname = s:swapname()    call assert_match('Xswapinfo', fname)    let info = swapinfo(fname) @@ -100,3 +104,24 @@ func Test_swapinfo()    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  | 
