commit 82b1649f2e1c79ff17730fe0a3750bbec203dd29
parent 8d9b8dae67c5a6affbfd0304e0949ce9e79065ea
Author: William Findlay <william.findlay@carleton.ca>
Date: Fri, 22 Nov 2019 11:26:25 -0500
Add a NERDTreeToggleVCS command to the vcs plugin (#1060)
* NERDTreeToggleVCS
* nerdtree toggle vcs documentation
* fix function documentation
* changelog
* Update CHANGELOG.md
* Update CHANGELOG.md
* simplify toggletreevcs
* Update CHANGELOG.md
Diffstat:
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -7,7 +7,8 @@
in an unordered list. The format is:
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->
-
+#### 6.3
+- **.0**: Add new command that behaves like NERDTreeToggle but defaults to the root of a VCS repository. (willfindlay) [#1060](https://github.com/scrooloose/nerdtree/pull/1060)
#### 6.2
- **.1**: Menu option, 'copy path to clipboard' is aware of VIM clipboard option (jhzn) [#1056](https://github.com/scrooloose/nerdtree/pull/1056)
- **.0**: Support tab-specific CWDs (PhilRunninger) [#1032](https://github.com/scrooloose/nerdtree/pull/1032)
diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt
@@ -125,6 +125,14 @@ The following features and functionality are provided by the NERDTree:
again. If no NERDTree exists for this tab then this command acts the
same as the |:NERDTree| command.
+:NERDTreeToggleVCS [<start-directory> | <bookmark>] *:NERDTreeToggleVCS*
+ Like |:NERDTreeToggle|, but searches up the directory tree to find the top of
+ the version control system repository, and roots the NERDTree there. It
+ works with Git, Subversion, Mercurial, Bazaar, and Darcs repositories. A
+ couple of examples: >
+ :NERDTreeToggleVCS /home/marty/nerdtree/doc (opens /home/marty/nerdtree)
+ :NERDTreeToggleVCS (opens root of repository containing CWD)
+
:NERDTreeFocus *:NERDTreeFocus*
Opens (or reopens) the NERDTree if it is not currently visible;
otherwise, the cursor is moved to the already-open NERDTree.
diff --git a/nerdtree_plugin/vcs.vim b/nerdtree_plugin/vcs.vim
@@ -11,6 +11,7 @@
"
" ============================================================================
command! -n=? -complete=dir -bar NERDTreeVCS :call <SID>CreateTabTreeVCS('<args>')
+command! -n=? -complete=dir -bar NERDTreeToggleVCS :call <SID>ToggleTabTreeVCS('<args>')
" FUNCTION: s:CreateTabTreeVCS(a:name) {{{1
function! s:CreateTabTreeVCS(name)
@@ -19,6 +20,14 @@ function! s:CreateTabTreeVCS(name)
call g:NERDTreeCreator.createTabTree(empty(l:path) ? "" : l:path._str())
endfunction
+" FUNCTION: s:ToggleTabTreeVCS(a:name) {{{1
+" Behaves the same as ToggleTabTree except roots directory at VCS root
+function! s:ToggleTabTreeVCS(name)
+ let l:path = g:NERDTreeCreator._pathForString(a:name)
+ let l:path = s:FindParentVCSRoot(l:path)
+ call g:NERDTreeCreator.toggleTabTree(empty(l:path) ? "" : l:path._str())
+endfunction
+
" FUNCTION: s:FindParentVCSRoot(a:path) {{{1
" Finds the root version control system folder of the given path. If a:path is
" not part of a repository, return the original path.