vim-patch:8.2.4566: check for existing buffer in session file may not work

Problem:    Check for existing buffer in session file does not work for files
            in the home directory.
Solution:   Use fnamemodify(). (James Cherti, closes vim/vim#9945)  Add a test.
7d42840033
This commit is contained in:
zeertzjq
2022-03-15 08:03:18 +08:00
parent 61126fcc69
commit 2ea16f7354
2 changed files with 6 additions and 1 deletions

View File

@@ -365,7 +365,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr
// edit that buffer, to not lose folding information (:edit resets // edit that buffer, to not lose folding information (:edit resets
// folds in other buffers) // folds in other buffers)
if (fprintf(fd, if (fprintf(fd,
"if bufexists(\"%s\") | buffer %s | else | edit %s | endif\n" "if bufexists(fnamemodify(\"%s\", \":p\")) | buffer %s | else | edit %s | endif\n"
// Fixup :terminal buffer name. #7836 // Fixup :terminal buffer name. #7836
"if &buftype ==# 'terminal'\n" "if &buftype ==# 'terminal'\n"
" silent file %s\n" " silent file %s\n"

View File

@@ -219,6 +219,7 @@ func Test_mksession_one_buffer_two_windows()
let count1 = 0 let count1 = 0
let count2 = 0 let count2 = 0
let count2buf = 0 let count2buf = 0
let bufexists = 0
for line in lines for line in lines
if line =~ 'edit \f*Xtest1$' if line =~ 'edit \f*Xtest1$'
let count1 += 1 let count1 += 1
@@ -229,10 +230,14 @@ func Test_mksession_one_buffer_two_windows()
if line =~ 'buffer \f\{-}Xtest2' if line =~ 'buffer \f\{-}Xtest2'
let count2buf += 1 let count2buf += 1
endif endif
if line =~ 'bufexists(fnamemodify(.*, ":p")'
let bufexists += 1
endif
endfor endfor
call assert_equal(1, count1, 'Xtest1 count') call assert_equal(1, count1, 'Xtest1 count')
call assert_equal(2, count2, 'Xtest2 count') call assert_equal(2, count2, 'Xtest2 count')
call assert_equal(2, count2buf, 'Xtest2 buffer count') call assert_equal(2, count2buf, 'Xtest2 buffer count')
call assert_equal(2, bufexists)
close close
bwipe! bwipe!