mirror of
https://github.com/preservim/nerdtree.git
synced 2025-03-04 07:35:26 +08:00
ensure bookmarks exist before opening them
This commit is contained in:
parent
e8aadb77b8
commit
332a1baedd
@ -275,6 +275,17 @@ function! s:oBookmark.GetNodeForName(name, searchFromAbsoluteRoot) dict
|
|||||||
endif
|
endif
|
||||||
return bookmark.GetNode(a:searchFromAbsoluteRoot)
|
return bookmark.GetNode(a:searchFromAbsoluteRoot)
|
||||||
endfunction
|
endfunction
|
||||||
|
" FUNCTION: oBookmark.MustExist() {{{3
|
||||||
|
" if this bookmark points to a nonexisting path, delete the bookmark and raise
|
||||||
|
" an exception
|
||||||
|
function! s:oBookmark.MustExist() dict
|
||||||
|
if !self.path.Exists()
|
||||||
|
call self.Delete()
|
||||||
|
throw "NERDTree.BookmarkPointsToInvalidLocation exception: the bookmark \"".
|
||||||
|
\ self.name ."\" points to a non existing location: \"".
|
||||||
|
\ self.path.StrForOS(0) ."\" and has been deleted"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
" FUNCTION: oBookmark.New(name, path) {{{3
|
" FUNCTION: oBookmark.New(name, path) {{{3
|
||||||
" Create a new bookmark object with the given name and path object
|
" Create a new bookmark object with the given name and path object
|
||||||
function! s:oBookmark.New(name, path) dict
|
function! s:oBookmark.New(name, path) dict
|
||||||
@ -1222,6 +1233,11 @@ function! s:oPath.ExtractDriveLetter(fullpath) dict
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
"FUNCTION: oPath.Exists() {{{3
|
||||||
|
"return 1 if this path points to a location that is readable or is a directory
|
||||||
|
function! s:oPath.Exists() dict
|
||||||
|
return filereadable(self.StrForOS(0)) || isdirectory(self.StrForOS(0))
|
||||||
|
endfunction
|
||||||
"FUNCTION: oPath.GetDir() {{{3
|
"FUNCTION: oPath.GetDir() {{{3
|
||||||
"
|
"
|
||||||
"Returns this path if it is a directory, else this paths parent.
|
"Returns this path if it is a directory, else this paths parent.
|
||||||
@ -1719,6 +1735,8 @@ endfunction
|
|||||||
" FUNCTION: s:BookmarkToRoot(name) {{{2
|
" FUNCTION: s:BookmarkToRoot(name) {{{2
|
||||||
" Make the node for the given bookmark the new tree root
|
" Make the node for the given bookmark the new tree root
|
||||||
function! s:BookmarkToRoot(name)
|
function! s:BookmarkToRoot(name)
|
||||||
|
let bookmark = s:oBookmark.BookmarkFor(a:name)
|
||||||
|
call bookmark.MustExist()
|
||||||
try
|
try
|
||||||
let targetNode = s:oBookmark.GetNodeForName(a:name, 1)
|
let targetNode = s:oBookmark.GetNodeForName(a:name, 1)
|
||||||
catch /NERDTree.BookmarkNotFound/
|
catch /NERDTree.BookmarkNotFound/
|
||||||
@ -2784,6 +2802,7 @@ function! s:ActivateNode(forceKeepWindowOpen)
|
|||||||
if bookmark.path.isDirectory
|
if bookmark.path.isDirectory
|
||||||
call s:BookmarkToRoot(bookmark.name)
|
call s:BookmarkToRoot(bookmark.name)
|
||||||
else
|
else
|
||||||
|
call bookmark.MustExist()
|
||||||
call s:OpenFileNode(s:oTreeFileNode.New(bookmark.path))
|
call s:OpenFileNode(s:oTreeFileNode.New(bookmark.path))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user