Skip to content

Commit ec1f7e3

Browse files
author
marty
committed
Merge branch 'api'
2 parents abfd4fe + 8535a90 commit ec1f7e3

File tree

6 files changed

+717
-327
lines changed

6 files changed

+717
-327
lines changed

Rakefile

-18
This file was deleted.

doc/NERD_tree.txt

+1-35
Original file line numberDiff line numberDiff line change
@@ -949,41 +949,7 @@ This option is used to change the size of the NERD tree when it is loaded.
949949
==============================================================================
950950
4. Hacking the NERD tree *NERDTreeHacking*
951951

952-
Public functions ~
953-
954-
The script provides 2 public functions for your hacking pleasure. Their
955-
signatures are: >
956-
function! NERDTreeGetCurrentNode()
957-
function! NERDTreeGetCurrentPath()
958-
<
959-
The first returns the node object that the cursor is currently on, while the
960-
second returns the corresponding path object.
961-
962-
This is probably a good time to mention that the script implements prototype
963-
style OO. To see the functions that each class provides you can read look at
964-
the code.
965-
966-
Use the node objects to manipulate the structure of the tree. Use the path
967-
objects to access the files/directories the tree nodes represent.
968-
969-
The NERD tree filetype ~
970-
971-
NERD tree buffers have a filetype of "nerdtree". You can use this to hack the
972-
NERD tree via autocommands (on |FileType|) or via an ftplugin.
973-
974-
For example, putting this code in ~/.vim/ftplugin/nerdtree.vim would override
975-
the o mapping, making it open the selected node in a new gvim instance. >
976-
977-
nnoremap <silent> <buffer> o :call <sid>openInNewVimInstance()<cr>
978-
function! s:openInNewVimInstance()
979-
let p = NERDTreeGetCurrentPath()
980-
if p != {}
981-
silent exec "!gvim " . p.strForOS(1) . "&"
982-
endif
983-
endfunction
984-
<
985-
This way you can add new mappings or :commands or override any existing
986-
mapping.
952+
TODO: fill in when new api is complete
987953

988954
==============================================================================
989955
5. About *NERDTreeAbout*

nerdtree_plugin/exec_menuitem.vim

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
" ============================================================================
2+
" File: nerdtree_fs_menu.vim
3+
" Description: plugin for NERD Tree that provides an execute file menu item
4+
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
5+
" Last Change: 22 July, 2009
6+
" License: This program is free software. It comes without any warranty,
7+
" to the extent permitted by applicable law. You can redistribute
8+
" it and/or modify it under the terms of the Do What The Fuck You
9+
" Want To Public License, Version 2, as published by Sam Hocevar.
10+
" See http://sam.zoy.org/wtfpl/COPYING for more details.
11+
"
12+
" ============================================================================
13+
if exists("g:loaded_nerdtree_exec_menuitem")
14+
finish
15+
endif
16+
let g:loaded_nerdtree_exec_menuitem = 1
17+
18+
call NERDTreeAddMenuItem({
19+
\ 'text': '(!) - Execute file',
20+
\ 'shortcut': '!',
21+
\ 'callback': 'NERDTreeExecFile',
22+
\ 'isActiveCallback': 'NERDTreeExecFileActive' })
23+
24+
function! NERDTreeExecFileActive()
25+
let node = g:NERDTreeFileNode.GetSelected()
26+
return !node.path.isDirectory && node.path.isExecutable
27+
endfunction
28+
29+
function! NERDTreeExecFile()
30+
let treenode = g:NERDTreeFileNode.GetSelected()
31+
echo "Complete the command to execute (add arguments etc): \n\n"
32+
let cmd = treenode.path.strForOS(1)
33+
let cmd = input(':!', cmd . ' ')
34+
35+
if cmd != ''
36+
exec ':!' . cmd
37+
else
38+
echo "Aborted"
39+
endif
40+
endfunction

nerdtree_plugin/fs_menu.vim

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
" ============================================================================
2+
" File: nerdtree_fs_menu.vim
3+
" Description: plugin for the NERD Tree that provides a file system menu
4+
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
5+
" Last Change: 17 July, 2009
6+
" License: This program is free software. It comes without any warranty,
7+
" to the extent permitted by applicable law. You can redistribute
8+
" it and/or modify it under the terms of the Do What The Fuck You
9+
" Want To Public License, Version 2, as published by Sam Hocevar.
10+
" See http://sam.zoy.org/wtfpl/COPYING for more details.
11+
"
12+
" ============================================================================
13+
if exists("g:loaded_nerdtree_fs_menu")
14+
finish
15+
endif
16+
let g:loaded_nerdtree_fs_menu = 1
17+
18+
call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callback': 'NERDTreeAddNode'})
19+
call NERDTreeAddMenuItem({'text': '(m)ove the curent node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'})
20+
call NERDTreeAddMenuItem({'text': '(d)elete the curent node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'})
21+
if g:NERDTreePath.CopyingSupported()
22+
call NERDTreeAddMenuItem({'text': '(c)copy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'})
23+
endif
24+
25+
"FUNCTION: s:echo(msg){{{1
26+
function! s:echo(msg)
27+
redraw
28+
echomsg "NERDTree: " . a:msg
29+
endfunction
30+
31+
"FUNCTION: s:echoWarning(msg){{{1
32+
function! s:echoWarning(msg)
33+
echohl warningmsg
34+
call s:echo(a:msg)
35+
echohl normal
36+
endfunction
37+
38+
"FUNCTION: s:promptToDelBuffer(bufnum, msg){{{1
39+
"prints out the given msg and, if the user responds by pushing 'y' then the
40+
"buffer with the given bufnum is deleted
41+
"
42+
"Args:
43+
"bufnum: the buffer that may be deleted
44+
"msg: a message that will be echoed to the user asking them if they wish to
45+
" del the buffer
46+
function! s:promptToDelBuffer(bufnum, msg)
47+
echo a:msg
48+
if nr2char(getchar()) ==# 'y'
49+
exec "silent bdelete! " . a:bufnum
50+
endif
51+
endfunction
52+
53+
"FUNCTION: NERDTreeAddNode(){{{1
54+
function! NERDTreeAddNode()
55+
let curDirNode = g:NERDTreeDirNode.GetSelected()
56+
57+
let newNodeName = input("Add a childnode\n".
58+
\ "==========================================================\n".
59+
\ "Enter the dir/file name to be created. Dirs end with a '/'\n" .
60+
\ "", curDirNode.path.strForGlob() . g:NERDTreePath.Slash())
61+
62+
if newNodeName ==# ''
63+
call s:echo("Node Creation Aborted.")
64+
return
65+
endif
66+
67+
try
68+
let newPath = g:NERDTreePath.Create(newNodeName)
69+
let parentNode = b:NERDTreeRoot.findNode(newPath.getParent())
70+
71+
let newTreeNode = g:NERDTreeFileNode.New(newPath)
72+
if parentNode.isOpen || !empty(parentNode.children)
73+
call parentNode.addChild(newTreeNode, 1)
74+
call NERDTreeRender()
75+
call newTreeNode.putCursorHere(1, 0)
76+
endif
77+
catch /^NERDTree/
78+
call s:echoWarning("Node Not Created.")
79+
endtry
80+
endfunction
81+
82+
"FUNCTION: NERDTreeMoveNode(){{{1
83+
function! NERDTreeMoveNode()
84+
let curNode = g:NERDTreeFileNode.GetSelected()
85+
if curNode ==# {}
86+
call s:echo("Put the cursor on a node first" )
87+
return
88+
endif
89+
90+
let newNodePath = input("Rename the current node\n" .
91+
\ "==========================================================\n" .
92+
\ "Enter the new path for the node: \n" .
93+
\ "", curNode.path.strForOS(0))
94+
95+
if newNodePath ==# ''
96+
call s:echo("Node Renaming Aborted.")
97+
return
98+
endif
99+
100+
try
101+
let bufnum = bufnr(curNode.path.str(0))
102+
103+
call curNode.rename(newNodePath)
104+
call NERDTreeRender()
105+
106+
"if the node is open in a buffer, ask the user if they want to
107+
"close that buffer
108+
if bufnum != -1
109+
let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
110+
call s:promptToDelBuffer(bufnum, prompt)
111+
endif
112+
113+
call curNode.putCursorHere(1, 0)
114+
115+
redraw
116+
catch /^NERDTree/
117+
call s:echoWarning("Node Not Renamed.")
118+
endtry
119+
endfunction
120+
121+
" FUNCTION: NERDTreeDeleteNode() {{{1
122+
function! NERDTreeDeleteNode()
123+
let currentNode = g:NERDTreeFileNode.GetSelected()
124+
if currentNode ==# {}
125+
call s:echo("Put the cursor on a node first")
126+
return
127+
endif
128+
129+
let confirmed = 0
130+
131+
if currentNode.path.isDirectory
132+
let choice =input("Delete the current node\n" .
133+
\ "==========================================================\n" .
134+
\ "STOP! To delete this entire directory, type 'yes'\n" .
135+
\ "" . currentNode.path.strForOS(0) . ": ")
136+
let confirmed = choice ==# 'yes'
137+
else
138+
echo "Delete the current node\n" .
139+
\ "==========================================================\n".
140+
\ "Are you sure you wish to delete the node:\n" .
141+
\ "" . currentNode.path.strForOS(0) . " (yN):"
142+
let choice = nr2char(getchar())
143+
let confirmed = choice ==# 'y'
144+
endif
145+
146+
147+
if confirmed
148+
try
149+
call currentNode.delete()
150+
call NERDTreeRender()
151+
152+
"if the node is open in a buffer, ask the user if they want to
153+
"close that buffer
154+
let bufnum = bufnr(currentNode.path.str(0))
155+
if buflisted(bufnum)
156+
let prompt = "\nNode deleted.\n\nThe file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
157+
call s:promptToDelBuffer(bufnum, prompt)
158+
endif
159+
160+
redraw
161+
catch /^NERDTree/
162+
call s:echoWarning("Could not remove node")
163+
endtry
164+
else
165+
call s:echo("delete aborted")
166+
endif
167+
168+
endfunction
169+
170+
" FUNCTION: NERDTreeCopyNode() {{{1
171+
function! NERDTreeCopyNode()
172+
let currentNode = g:NERDTreeFileNode.GetSelected()
173+
if currentNode ==# {}
174+
call s:echo("Put the cursor on a file node first")
175+
return
176+
endif
177+
178+
let newNodePath = input("Copy the current node\n" .
179+
\ "==========================================================\n" .
180+
\ "Enter the new path to copy the node to: \n" .
181+
\ "", currentNode.path.str(0))
182+
183+
if newNodePath != ""
184+
"strip trailing slash
185+
let newNodePath = substitute(newNodePath, '\/$', '', '')
186+
187+
let confirmed = 1
188+
if currentNode.path.copyingWillOverwrite(newNodePath)
189+
call s:echo("Warning: copying may overwrite files! Continue? (yN)")
190+
let choice = nr2char(getchar())
191+
let confirmed = choice ==# 'y'
192+
endif
193+
194+
if confirmed
195+
try
196+
let newNode = currentNode.copy(newNodePath)
197+
call NERDTreeRender()
198+
call newNode.putCursorHere(0, 0)
199+
catch /^NERDTree/
200+
call s:echoWarning("Could not copy node")
201+
endtry
202+
endif
203+
else
204+
call s:echo("Copy aborted.")
205+
endif
206+
redraw
207+
endfunction
208+
209+
" vim: set sw=4 sts=4 et fdm=marker:

0 commit comments

Comments
 (0)