nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 3063dfb76631ecadde1b947d21b1422a3c8a53c4
parent a03a639390011a51358ec3460a3be58d6cd86e8a
Author: Jason Franklin <j_fra@fastmail.us>
Date:   Sat, 10 Jun 2017 15:59:56 -0400

Refactor the :OpenBookmark command

I altered the behavior of the ":OpenBookmark" command to match that of
the "NERDTree-o" mapping. This is acceptable for the following reasons:

 1. It was broken, so no one was using it.
 2. The name matches its behavior.

If a bookmark is to be opened in an explorer window, we should have a
command with a matching name for that behavior (":ExploreBookmark", for
example). This can be added later if there is enough demand for the
feature. Otherwise, this is a perfectly valid change.

Diffstat:
Mautoload/nerdtree/ui_glue.vim | 20+++++++++-----------
Mdoc/NERD_tree.txt | 11++++++-----
Mlib/nerdtree/creator.vim | 2+-
3 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -441,21 +441,19 @@ function! s:jumpToSibling(currentNode, forward)
 endfunction
 
 " FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1
-" put the cursor on the given bookmark and, if its a file, open it
+" Open the Bookmark that has the specified name. This function provides the
+" implementation for the ":OpenBookmark" command.
 function! nerdtree#ui_glue#openBookmark(name)
     try
-        let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0, b:NERDTree)
-        call targetNode.putCursorHere(0, 1)
-        redraw!
-    catch /^NERDTree.BookmarkedNodeNotFoundError/
-        call nerdtree#echo("note - target node is not cached")
-        let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
-        let targetNode = g:NERDTreeFileNode.New(bookmark.path, b:NERDTree)
+        let l:bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
+    catch /^NERDTree.BookmarkNotFoundError/
+        call nerdtree#echoError('bookmark "' . a:name . '" not found')
+        return
     endtry
-    if targetNode.path.isDirectory
-        call targetNode.openExplorer()
+    if l:bookmark.path.isDirectory
+        call l:bookmark.open(b:NERDTree)
     else
-        call targetNode.open({'where': 'p'})
+        call l:bookmark.open(b:NERDTree, {'where': 'p'})
     endif
 endfunction
 
diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt
@@ -158,7 +158,7 @@ click bookmarks or use the |NERDTree-o| mapping to activate them. See also,
 ------------------------------------------------------------------------------
 2.2.2. Bookmark commands                            *NERDTreeBookmarkCommands*
 
-Note that the following commands are only available in the NERD tree buffer.
+Note: The following commands are only available within the NERDTree buffer.
 
 :Bookmark [<name>]
     Bookmark the current node as <name>. If there is already a <name>
@@ -178,10 +178,11 @@ Note that the following commands are only available in the NERD tree buffer.
     (i.e. directory nodes above it will be opened) and the cursor will be
     placed on it.
 
-:OpenBookmark <bookmark>
-    <bookmark> must point to a file. The file is opened as though |NERDTree-o|
-    was applied. If the node is cached under the current root then it will be
-    revealed and the cursor will be placed on it.
+:OpenBookmark <name>
+    The Bookmark named <name> is opened as if |NERDTree-o| was applied to
+    its entry in the Bookmark table. If the Bookmark points to a directory,
+    it is made the new root of the current NERDTree. If the Bookmark points
+    to a file, that file is opened for editing in another window.
 
 :ClearBookmarks [<bookmarks>]
     Remove all the given bookmarks. If no bookmarks are given then remove all
diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim
@@ -14,7 +14,7 @@ function! s:Creator._bindMappings()
 
     command! -buffer -nargs=? Bookmark :call nerdtree#ui_glue#bookmarkNode('<args>')
     command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#ui_glue#revealBookmark('<args>')
-    command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#ui_glue#openBookmark('<args>')
+    command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark call nerdtree#ui_glue#openBookmark('<args>')
     command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#ui_glue#clearBookmarks('<args>')
     command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('<args>', b:NERDTree)
     command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() <bar> call b:NERDTree.render()