From 7d9a3f0e8b1546c81e9a3591c416313f0dffd936 Mon Sep 17 00:00:00 2001 From: "Phil Runninger (mac)" Date: Tue, 7 Aug 2018 18:13:40 -0400 Subject: [PATCH 1/2] Make sure the path to the bookmarks file exists before writing it. --- lib/nerdtree/bookmark.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index dd69ad05..55abc8c0 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -343,6 +343,12 @@ function! s:Bookmark.Write() for j in s:Bookmark.InvalidBookmarks() call add(bookmarkStrings, j) endfor + + let path = fnamemodify(g:NERDTreeBookmarksFile, ':h') + if !isdirectory(path) + call mkdir(path, 'p') + endif + call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) endfunction From f78cf63627dbed66f01c4eaba37c2e5e86315d41 Mon Sep 17 00:00:00 2001 From: "Phil Runninger (mac)" Date: Sun, 9 Sep 2018 21:29:20 -0400 Subject: [PATCH 2/2] Instead of creating the bookmark file path, show error message. This change puts the burden on the user to make sure g:NERDTreeBookmarksFile is correctly set and the path it contains is present and has the proper permissions. If this is not the case, an error message is displayed. This is a better solution than to blindly create the path, when it may actually be impossible to do so. --- lib/nerdtree/bookmark.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index 55abc8c0..2e0aab02 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -344,12 +344,11 @@ function! s:Bookmark.Write() call add(bookmarkStrings, j) endfor - let path = fnamemodify(g:NERDTreeBookmarksFile, ':h') - if !isdirectory(path) - call mkdir(path, 'p') - endif - - call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) + try + call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) + catch + call nerdtree#echoError("Failed to write bookmarks file. Make sure g:NERDTreeBookmarksFile points to a valid location.") + endtry endfunction " vim: set sw=4 sts=4 et fdm=marker: