diff --git a/runtime/pack/dist/opt/netrw/autoload/netrw.vim b/runtime/pack/dist/opt/netrw/autoload/netrw.vim index cabcd0c925..90bc4aee02 100644 --- a/runtime/pack/dist/opt/netrw/autoload/netrw.vim +++ b/runtime/pack/dist/opt/netrw/autoload/netrw.vim @@ -1,7 +1,7 @@ " Creator: Charles E Campbell " Previous Maintainer: Luca Saccarola " Maintainer: This runtime file is looking for a new maintainer. -" Last Change: 2026 Jul 23 +" Last Change: 2026 Aug 21 " Copyright: Copyright (C) 2016 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright @@ -4494,7 +4494,7 @@ function s:NetrwHome() if exists("g:netrw_mkdir") call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home))) else - call mkdir(home) + call mkdir(home, 'p') endif endif diff --git a/test/old/testdir/test_plugin_netrw.vim b/test/old/testdir/test_plugin_netrw.vim index b6a18ff418..431cec8c67 100644 --- a/test/old/testdir/test_plugin_netrw.vim +++ b/test/old/testdir/test_plugin_netrw.vim @@ -196,6 +196,11 @@ function Test_NetrwMarkFile_match_pattern_rebuild() bw endfunction + +" Test the "home" directory used for bookmarks and history +function Test_NetrwHome() abort + return s:NetrwHome() +endfunction " }}} END @@ -921,4 +926,55 @@ func Test_netrw_open_no_dir_arg() bw! endfunc +func Test_netrw_home_setting() + let save_home = get(g:, 'netrw_home', '') + let dir = fnamemodify('XnetrwHome', ':p') + let vimdir = fnamemodify('XvimDir', ':p') + let subdir = fnamemodify('XnetrwHomeParent/XnetrwHome', ':p') + if has('win32') + let dir = substitute(dir, '/', '\\', 'g') + let vimdir = substitute(vimdir, '/', '\\', 'g') + let subdir = substitute(subdir, '/', '\\', 'g') + endif + let save_myvimdir = getenv('MYVIMDIR') + let $MYVIMDIR = vimdir + + unlet! g:netrw_home + if has('nvim') + let expected = netrw#fs#PathJoin(stdpath('state'), 'netrw') + if has('win32') + let expected = substitute(expected, '/', '\\', 'g') + endif + call assert_equal(expected, Test_NetrwHome()) + else + " without the setting $MYVIMDIR is used + call assert_equal(vimdir, Test_NetrwHome()) + endif + + let g:netrw_home = dir + call assert_equal(dir, Test_NetrwHome()) + call assert_true(isdirectory(dir)) + + let g:netrw_home = subdir + call assert_equal(subdir, Test_NetrwHome()) + call assert_true(isdirectory(subdir)) + + " the value is expanded + let $NETRW_TEST_HOME = dir + let g:netrw_home = '$NETRW_TEST_HOME' + call assert_equal(dir, Test_NetrwHome()) + + call delete(dir, 'd') + call delete(vimdir, 'd') + call delete(subdir, 'd') + call delete(fnamemodify(subdir, ':h'), 'd') + unlet $NETRW_TEST_HOME + call setenv('MYVIMDIR', save_myvimdir) + if empty(save_home) + unlet! g:netrw_home + else + let g:netrw_home = save_home + endif +endfunc + " vim:ts=8 sts=2 sw=2 et