Compare commits

...

26 Commits
2.8.0 ... 2.9.0

Author SHA1 Message Date
Martin Grenfell
80e0bca4dc change version to 2.9.0 2008-05-17 16:24:48 +12:00
Martin Grenfell
04ea2eb0f7 apply Cory Echols' patch
adds :NERDTreeClose command and sets the filetype for the tree buffer to
"nerdtree"
2008-05-17 14:40:27 +12:00
Martin Grenfell
25aaaaae42 gitignore tags file 2008-05-17 14:36:02 +12:00
Martin Grenfell
8a32f5851f update changelog and credits 2008-05-17 14:12:23 +12:00
Martin Grenfell
6018625170 bugfix: use #StrForOS when refreshing a path 2008-05-16 12:35:11 +12:00
Martin Grenfell
c36aaf55f8 bugfix: process files with single letter extension
dont ignore files like foo.c !
2008-05-16 12:22:23 +12:00
Martin Grenfell
6e7960ba94 convert tabs to spaces
not sure how those tabs got in there!
2008-05-16 11:51:39 +12:00
Martin Grenfell
f1a9bd3c89 couple of fixes to the doc 2008-05-10 19:14:29 +12:00
Martin Grenfell
191dcc4068 remove a now unneeded not to windows users
dont warn windows users about setting NERDTreeChDirMode as drives are
handled properly now
2008-05-10 18:52:35 +12:00
Martin Grenfell
0d62ffd5db bugfix for paths on windows
delete oPath.NewMinimal cos it sucks and there is no need for it. It
was causing a bug with oPath.Equals on account of it wasnt correctly
determining whether a path found with s:GetSelectedPath() was a dir or a
file.
2008-05-10 18:29:20 +12:00
Martin Grenfell
510f890ee1 change to version 2.8.0.1 2008-05-10 16:28:01 +12:00
Martin Grenfell
06db1cdf2c fix some formatting 2008-05-10 16:27:50 +12:00
Martin Grenfell
0eaaf6842c improve path handling for windows 2008-05-10 16:26:32 +12:00
Martin Grenfell
2ed6524b9d use oPath#StrForCd where appropriate 2008-05-10 15:55:50 +12:00
Martin Grenfell
fb7f66dc47 update oPath#Equals 2008-05-10 15:49:08 +12:00
Martin Grenfell
dcf9e956a7 minor bugfix 2008-05-10 15:45:05 +12:00
Martin Grenfell
8aafa66eac handle trailing slashes inside oPath#Rename
previously the RenameCurrent() view function was removing trailing
slashes from the destination path before passing it to oPath, now oPath
handles the slashes
2008-05-10 15:33:11 +12:00
Martin Grenfell
f2ce7390b8 add oPath#StrForCd 2008-05-10 15:25:33 +12:00
Martin Grenfell
7275d89a35 add oPath#ExtractDriveLetter
If running windows, extract and cache the drive letter
2008-05-10 12:40:26 +12:00
Martin Grenfell
e6479c36f3 bugfix to prevent double escaping when refreshing a node 2008-05-04 21:37:36 +12:00
Martin Grenfell
da76bafaef add oPath#StrForGlob() to return a string that can be used to call globpath with
note: the main motivation behind this is to encapsulate differences in OSs
2008-05-04 21:33:52 +12:00
Martin Grenfell
ec76876a74 added a comment note to clarify something 2008-05-04 21:31:38 +12:00
Martin Grenfell
ef1a466342 make the script able to handle strange filenames with random chars in them (eg {'$%^&) 2008-05-04 16:48:32 +12:00
Martin Grenfell
56dd5f05ab fix the output of the rename prompt when it asks you to delete an old buffer 2008-05-04 14:22:59 +12:00
Martin Grenfell
92a006f51c some handy utils 2008-05-04 12:01:43 +12:00
Martin Grenfell
7d1cc4ecec bugfix: the script failed when being initialized on a dir containing spaces 2008-04-17 23:39:23 +12:00
4 changed files with 149 additions and 83 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
*~ *~
*.swp *.swp
tags

18
Rakefile Normal file
View File

@@ -0,0 +1,18 @@
desc "Copy the vim/doc files into ~/.vim"
task :deploy_local do
run "cp plugin/NERD_tree.vim ~/.vim/plugin"
run "cp doc/NERD_tree.txt ~/.vim/doc"
end
desc "Create a zip archive for release to vim.org"
task :zip do
abort "NERD_tree.zip already exists, aborting" if File.exist?("NERD_tree.zip")
run "zip NERD_tree.zip plugin/NERD_tree.vim doc/NERD_tree.txt"
end
def run(cmd)
puts "Executing: #{cmd}"
system cmd
end

View File

@@ -63,7 +63,8 @@ The following features and functionality are provided by the NERD tree:
* optional displaying of hidden files (. files) * optional displaying of hidden files (. files)
* files can be "turned off" so that only directories are displayed * files can be "turned off" so that only directories are displayed
* A textual filesystem menu is provided which allows you to * A textual filesystem menu is provided which allows you to
create/delete/rename file and directory nodes create/delete/rename file and directory nodes as well as copy (for
supported OSs)
* The position and size of the NERD tree window can be customised * The position and size of the NERD tree window can be customised
* The order in which the nodes in the tree are listed can be customised. * The order in which the nodes in the tree are listed can be customised.
* A model of your filesystem is created/maintained as you explore it. This * A model of your filesystem is created/maintained as you explore it. This
@@ -95,6 +96,9 @@ The following features and functionality are provided by the NERD tree:
rendered again. If no NERD tree exists for this tab then this rendered again. If no NERD tree exists for this tab then this
command acts the same as the |:NERDTree| command. command acts the same as the |:NERDTree| command.
:NERDTreeClose
Close the NERD tree in this tab.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2. NERD tree Mappings *NERDTreeMappings* 2.2. NERD tree Mappings *NERDTreeMappings*
@@ -581,10 +585,6 @@ the CWD is changed whenever the tree root is changed. For example, if the CWD
is /home/marty/foobar and you make the node for /home/marty/foobar/baz the new is /home/marty/foobar and you make the node for /home/marty/foobar/baz the new
root then the CWD will become /home/marty/foobar/baz. root then the CWD will become /home/marty/foobar/baz.
Note to windows users: it is highly recommended that you have this option set
to either 1 or 2 or else the script wont function properly if you attempt to
open a NERD tree on a different drive to the one vim is currently in.
Authors note: at work i have this option set to 1 because i have a giant ctags Authors note: at work i have this option set to 1 because i have a giant ctags
file in the root dir of my project. This way i can initialise the NERD tree file in the root dir of my project. This way i can initialise the NERD tree
with the root dir of my project and always have ctags available to me --- no with the root dir of my project and always have ctags available to me --- no
@@ -702,7 +702,7 @@ Other examples: >
(3) ['\/$', '\.rb$', '\.php$', '*', '\.swp$', '\.bak$', '\~$'] (3) ['\/$', '\.rb$', '\.php$', '*', '\.swp$', '\.bak$', '\~$']
< <
1. Directories will appear last, everything else will appear above. 1. Directories will appear last, everything else will appear above.
2. Every will simply appear in alphabetical order. 2. Everything will simply appear in alphabetical order.
3. Dirs will appear first, then ruby and php. Swap files, bak files and vim 3. Dirs will appear first, then ruby and php. Swap files, bak files and vim
backup files will appear last with everything else preceding them. backup files will appear last with everything else preceding them.
@@ -784,6 +784,18 @@ fridge for later ;)
============================================================================== ==============================================================================
7. Changelog *NERDTreeChangelog* 7. Changelog *NERDTreeChangelog*
2.9.0
- path handling improvements, thanks to Zhang Shuhan for heaps of
testing/bug reports
* improved how paths are stored, now the script will no longer get
confused about drives on MF Windows
* made the script way better at handling paths with strange characters
in them (eg '$@; etc)
- applied a patch from Cory Echols
* add the command :NERDTreeClose to close the tree for the current tab
* set the filetype for the NERD tree buffer to "nerdtree"
2.8.0 2.8.0
- added an option to enable/disable line numbers in the NERD tree window, - added an option to enable/disable line numbers in the NERD tree window,
thanks to Olivier Yiptong for the email. thanks to Olivier Yiptong for the email.
@@ -999,3 +1011,6 @@ the &hidden option is set.
Thanks to Olivier Yiptong for prompting me to make line numbers in the Thanks to Olivier Yiptong for prompting me to make line numbers in the
NERD tree window optional. NERD tree window optional.
Thanks to Zhang Shuhan for all of his emails and testing to help improve the
NERD tree path handling.

View File

@@ -1,7 +1,7 @@
" vim global plugin that provides a nice tree explorer " vim global plugin that provides a nice tree explorer
" Last Change: 31 March 2008 " Last Change: 17 May 2008
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com> " Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
let s:NERD_tree_version = '2.8.0' let s:NERD_tree_version = '2.9.0'
" SECTION: Script init stuff {{{1 " SECTION: Script init stuff {{{1
"============================================================ "============================================================
@@ -110,7 +110,7 @@ call s:InitVariable("g:NERDTreeMapUpdir", "u")
call s:InitVariable("g:NERDTreeMapUpdirKeepOpen", "U") call s:InitVariable("g:NERDTreeMapUpdirKeepOpen", "U")
"SECTION: Script level variable declaration{{{2 "SECTION: Script level variable declaration{{{2
let s:escape_chars = " `|\"~'#" let s:escape_chars = " \\`\|\"#%&,?()\*^<>"
let s:NERDTreeWinName = '_NERD_tree_' let s:NERDTreeWinName = '_NERD_tree_'
"init all the nerd tree markup "init all the nerd tree markup
@@ -139,6 +139,7 @@ endif
"init the command that users start the nerd tree with "init the command that users start the nerd tree with
command! -n=? -complete=dir NERDTree :call s:InitNerdTree('<args>') command! -n=? -complete=dir NERDTree :call s:InitNerdTree('<args>')
command! -n=? -complete=dir NERDTreeToggle :call s:Toggle('<args>') command! -n=? -complete=dir NERDTreeToggle :call s:Toggle('<args>')
command! -n=0 NERDTreeClose :call s:CloseTreeIfOpen()
" SECTION: Auto commands {{{1 " SECTION: Auto commands {{{1
"============================================================ "============================================================
"Save the cursor position whenever we close the nerd tree "Save the cursor position whenever we close the nerd tree
@@ -308,7 +309,8 @@ endfunction
"FUNCTION: oTreeFileNode.Rename {{{3 "FUNCTION: oTreeFileNode.Rename {{{3
"Calls the rename method for this nodes path obj "Calls the rename method for this nodes path obj
function! s:oTreeFileNode.Rename(newName) dict function! s:oTreeFileNode.Rename(newName) dict
call self.path.Rename(a:newName) let newName = substitute(a:newName, '\(\\\|\/\)$', '', '')
call self.path.Rename(newName)
call self.parent.RemoveChild(self) call self.parent.RemoveChild(self)
let parentPath = self.path.GetPathTrunk() let parentPath = self.path.GetPathTrunk()
@@ -318,7 +320,6 @@ function! s:oTreeFileNode.Rename(newName) dict
call newParent.CreateChild(self.path, 1) call newParent.CreateChild(self.path, 1)
endif endif
endfunction endfunction
"FUNCTION: oTreeFileNode.StrDisplay() {{{3 "FUNCTION: oTreeFileNode.StrDisplay() {{{3
" "
"Returns a string that specifies how the node should be represented as a "Returns a string that specifies how the node should be represented as a
@@ -553,7 +554,7 @@ function! s:oTreeDirNode.InitChildren(silent) dict
"get an array of all the files in the nodes dir "get an array of all the files in the nodes dir
let dir = self.path let dir = self.path
let filesStr = globpath(dir.StrForOS(0), '*') . "\n" . globpath(dir.StrForOS(0), '.*') let filesStr = globpath(dir.StrForGlob(), '*') . "\n" . globpath(dir.StrForGlob(), '.*')
let files = split(filesStr, "\n") let files = split(filesStr, "\n")
if !a:silent && len(files) > g:NERDTreeNotificationThreshold if !a:silent && len(files) > g:NERDTreeNotificationThreshold
@@ -564,7 +565,9 @@ function! s:oTreeDirNode.InitChildren(silent) dict
for i in files for i in files
"filter out the .. and . directories "filter out the .. and . directories
if i !~ '\.\.$' && i !~ '\.$' "Note: we must match .. AND ../ cos sometimes the globpath returns
"../ for path with strange chars (eg $)
if i !~ '\.\.\/\?$' && i !~ '\.\/\?$'
"put the next file in a new node and attach it "put the next file in a new node and attach it
try try
@@ -662,7 +665,7 @@ function! s:oTreeDirNode.Refresh() dict
"go thru all the files/dirs under this node "go thru all the files/dirs under this node
let dir = self.path let dir = self.path
let filesStr = globpath(dir.StrForOS(0), '*') . "\n" . globpath(dir.StrForOS(0), '.*') let filesStr = globpath(dir.StrForGlob(), '*') . "\n" . globpath(dir.StrForGlob(), '.*')
let files = split(filesStr, "\n") let files = split(filesStr, "\n")
for i in files for i in files
if i !~ '\.\.$' && i !~ '\.$' if i !~ '\.\.$' && i !~ '\.$'
@@ -770,9 +773,9 @@ let s:oPath = {}
let oPath = s:oPath let oPath = s:oPath
"FUNCTION: oPath.ChangeToDir() {{{3 "FUNCTION: oPath.ChangeToDir() {{{3
function! s:oPath.ChangeToDir() dict function! s:oPath.ChangeToDir() dict
let dir = self.Str(1) let dir = self.StrForCd()
if self.isDirectory == 0 if self.isDirectory == 0
let dir = self.GetPathTrunk().Str(1) let dir = self.GetPathTrunk().StrForCd()
endif endif
try try
@@ -848,27 +851,24 @@ function! s:oPath.Create(fullpath) dict
throw "NERDTree.Path.Exists Exception: Directory Exists: '" . a:fullpath . "'" throw "NERDTree.Path.Exists Exception: Directory Exists: '" . a:fullpath . "'"
endif endif
"get the unix version of the input path
let fullpath = s:oPath.WinToUnixPath(a:fullpath)
try try
"if it ends with a slash, assume its a dir create it "if it ends with a slash, assume its a dir create it
if fullpath =~ '\/$' if a:fullpath =~ '\(\\\|\/\)$'
"whack the trailing slash off the end if it exists "whack the trailing slash off the end if it exists
let fullpath = substitute(fullpath, '\/$', '', '') let fullpath = substitute(a:fullpath, '\(\\\|\/\)$', '', '')
call mkdir(fullpath, 'p') call mkdir(fullpath, 'p')
"assume its a file and create "assume its a file and create
else else
call writefile([], fullpath) call writefile([], a:fullpath)
endif endif
catch /.*/ catch /.*/
throw "NERDTree.Path Exception: Could not create path: '" . a:fullpath . "'" throw "NERDTree.Path Exception: Could not create path: '" . a:fullpath . "'"
endtry endtry
return s:oPath.New(fullpath) return s:oPath.New(a:fullpath)
endfunction endfunction
"FUNCTION: oPath.Copy(dest) {{{3 "FUNCTION: oPath.Copy(dest) {{{3
@@ -887,7 +887,7 @@ function! s:oPath.Copy(dest) dict
let cmd = g:NERDTreeCopyCmd . " " . self.StrForOS(0) . " " . dest let cmd = g:NERDTreeCopyCmd . " " . self.StrForOS(0) . " " . dest
let success = system(cmd) let success = system(cmd)
if success != 0 if success != 0
throw "NERDTree.Path Exception: Could not copy ''". self.StrForOS() ."'' to: '" . a:dest . "'" throw "NERDTree.Path Exception: Could not copy ''". self.StrForOS(0) ."'' to: '" . a:dest . "'"
endif endif
endfunction endfunction
@@ -933,7 +933,7 @@ function! s:oPath.Delete() dict
"if we are runnnig windows then put quotes around the pathstring "if we are runnnig windows then put quotes around the pathstring
let cmd = g:NERDTreeRemoveDirCmd . self.StrForOS(1) let cmd = g:NERDTreeRemoveDirCmd . self.StrForOS(1)
else else
let cmd = g:NERDTreeRemoveDirCmd . self.StrForOS(0) let cmd = g:NERDTreeRemoveDirCmd . self.StrForOS(1)
endif endif
let success = system(cmd) let success = system(cmd)
@@ -941,13 +941,24 @@ function! s:oPath.Delete() dict
throw "NERDTree.Path.Deletion Exception: Could not delete directory: '" . self.StrForOS(0) . "'" throw "NERDTree.Path.Deletion Exception: Could not delete directory: '" . self.StrForOS(0) . "'"
endif endif
else else
let success = delete(self.Str(0)) let success = delete(self.StrForOS(!s:running_windows))
if success != 0 if success != 0
throw "NERDTree.Path.Deletion Exception: Could not delete file: '" . self.Str(0) . "'" throw "NERDTree.Path.Deletion Exception: Could not delete file: '" . self.Str(0) . "'"
endif endif
endif endif
endfunction endfunction
"FUNCTION: oPath.ExtractDriveLetter(fullpath) {{{3
"
"If running windows, cache the drive letter for this path
function! s:oPath.ExtractDriveLetter(fullpath) dict
if s:running_windows
let self.drive = substitute(a:fullpath, '\(^[a-zA-Z]:\).*', '\1', '')
else
let self.drive = ''
endif
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.
@@ -973,8 +984,6 @@ function! s:oPath.GetParent() dict
let path = '/'. join(self.pathSegments[0:-2], '/') let path = '/'. join(self.pathSegments[0:-2], '/')
return s:oPath.New(path) return s:oPath.New(path)
endfunction endfunction
"FUNCTION: oPath.GetLastPathComponent(dirSlash) {{{3 "FUNCTION: oPath.GetLastPathComponent(dirSlash) {{{3
" "
"Gets the last part of this path. "Gets the last part of this path.
@@ -996,7 +1005,7 @@ endfunction
"FUNCTION: oPath.GetPathTrunk() {{{3 "FUNCTION: oPath.GetPathTrunk() {{{3
"Gets the path without the last segment on the end. "Gets the path without the last segment on the end.
function! s:oPath.GetPathTrunk() dict function! s:oPath.GetPathTrunk() dict
return s:oPath.New('/' . join(self.pathSegments[0:-2], '/')) return s:oPath.New(self.StrTrunk())
endfunction endfunction
"FUNCTION: oPath.GetSortOrderIndex() {{{3 "FUNCTION: oPath.GetSortOrderIndex() {{{3
@@ -1049,15 +1058,13 @@ endfunction
"FUNCTION: oPath.Equals() {{{3 "FUNCTION: oPath.Equals() {{{3
" "
"Determines whether 2 path objecs are "equal". "Determines whether 2 path objects are "equal".
"They are equal if the paths they represent are the same "They are equal if the paths they represent are the same
" "
"Args: "Args:
"path: the other path obj to compare this with "path: the other path obj to compare this with
function! s:oPath.Equals(path) dict function! s:oPath.Equals(path) dict
let this = self.ChopTrailingSlash(self.Str(1)) return self.Str(0) == a:path.Str(0)
let that = self.ChopTrailingSlash(a:path.Str(1))
return this == that
endfunction endfunction
"FUNCTION: oPath.New() {{{3 "FUNCTION: oPath.New() {{{3
@@ -1072,35 +1079,25 @@ function! s:oPath.New(fullpath) dict
return newPath return newPath
endfunction endfunction
"FUNCTION: oPath.NewMinimal() {{{3
function! s:oPath.NewMinimal(fullpath) dict
let newPath = copy(self)
let fullpath = s:oPath.WinToUnixPath(a:fullpath)
let newPath.pathSegments = split(fullpath, '/')
let newPath.isDirectory = isdirectory(fullpath)
return newPath
endfunction
"FUNCTION: oPath.ReadInfoFromDisk(fullpath) {{{3 "FUNCTION: oPath.ReadInfoFromDisk(fullpath) {{{3
" "
" "
"Throws NERDTree.Path.InvalidArguments exception. "Throws NERDTree.Path.InvalidArguments exception.
function! s:oPath.ReadInfoFromDisk(fullpath) dict function! s:oPath.ReadInfoFromDisk(fullpath) dict
call self.ExtractDriveLetter(a:fullpath)
let fullpath = s:oPath.WinToUnixPath(a:fullpath) let fullpath = s:oPath.WinToUnixPath(a:fullpath)
let self.pathSegments = split(fullpath, '/') let self.pathSegments = split(fullpath, '/')
let self.isReadOnly = 0 let self.isReadOnly = 0
if isdirectory(fullpath) if isdirectory(a:fullpath)
let self.isDirectory = 1 let self.isDirectory = 1
elseif filereadable(fullpath) elseif filereadable(a:fullpath)
let self.isDirectory = 0 let self.isDirectory = 0
let self.isReadOnly = filewritable(fullpath) == 0 let self.isReadOnly = filewritable(a:fullpath) == 0
else else
throw "NERDTree.Path.InvalidArguments Exception: Invalid path = " . fullpath throw "NERDTree.Path.InvalidArguments Exception: Invalid path = " . a:fullpath
endif endif
"grab the last part of the path (minus the trailing slash) "grab the last part of the path (minus the trailing slash)
@@ -1129,7 +1126,7 @@ endfunction
"FUNCTION: oPath.Refresh() {{{3 "FUNCTION: oPath.Refresh() {{{3
function! s:oPath.Refresh() dict function! s:oPath.Refresh() dict
call self.ReadInfoFromDisk(self.Str(0)) call self.ReadInfoFromDisk(self.StrForOS(0))
endfunction endfunction
"FUNCTION: oPath.Rename() {{{3 "FUNCTION: oPath.Rename() {{{3
@@ -1140,11 +1137,11 @@ function! s:oPath.Rename(newPath) dict
throw "NERDTree.Path.InvalidArguments exception. Invalid newPath for renaming = ". a:newPath throw "NERDTree.Path.InvalidArguments exception. Invalid newPath for renaming = ". a:newPath
endif endif
let success = rename(self.Str(0), a:newPath) let success = rename(self.StrForOS(!s:running_windows), a:newPath)
if success != 0 if success != 0
throw "NERDTree.Path.Rename Exception: Could not rename: '" . self.Str(0) . "'" . 'to:' . a:newPath throw "NERDTree.Path.Rename Exception: Could not rename: '" . self.StrForOS(0) . "'" . 'to:' . a:newPath
endif endif
let self.pathSegments = split(a:newPath, '/') call self.ReadInfoFromDisk(a:newPath)
endfunction endfunction
"FUNCTION: oPath.Str(esc) {{{3 "FUNCTION: oPath.Str(esc) {{{3
@@ -1175,6 +1172,19 @@ function! s:oPath.StrAbs() dict
return resolve(self.Str(1)) return resolve(self.Str(1))
endfunction endfunction
"FUNCTION: oPath.StrForCd() {{{3
"
" returns a string that can be used with :cd
"
"Return:
"a string that can be used in the view to represent this path
function! s:oPath.StrForCd() dict
if s:running_windows
return self.StrForOS(0)
else
return self.StrForOS(1)
endif
endfunction
"FUNCTION: oPath.StrDisplay() {{{3 "FUNCTION: oPath.StrDisplay() {{{3
" "
"Returns a string that specifies how the path should be represented as a "Returns a string that specifies how the path should be represented as a
@@ -1208,6 +1218,22 @@ function! s:oPath.StrForEditCmd() dict
endif endif
endfunction endfunction
"FUNCTION: oPath.StrForGlob() {{{3
function! s:oPath.StrForGlob() dict
let lead = s:os_slash
"if we are running windows then slap a drive letter on the front
if s:running_windows
let lead = self.drive . '\'
endif
let toReturn = lead . join(self.pathSegments, s:os_slash)
if !s:running_windows
let toReturn = escape(toReturn, s:escape_chars)
endif
return toReturn
endfunction
"FUNCTION: oPath.StrForOS(esc) {{{3 "FUNCTION: oPath.StrForOS(esc) {{{3
" "
"Gets the string path for this path object that is appropriate for the OS. "Gets the string path for this path object that is appropriate for the OS.
@@ -1222,7 +1248,7 @@ function! s:oPath.StrForOS(esc) dict
"if we are running windows then slap a drive letter on the front "if we are running windows then slap a drive letter on the front
if s:running_windows if s:running_windows
let lead = strpart(getcwd(), 0, 2) . s:os_slash let lead = self.drive . '\'
endif endif
let toReturn = lead . join(self.pathSegments, s:os_slash) let toReturn = lead . join(self.pathSegments, s:os_slash)
@@ -1240,7 +1266,7 @@ endfunction
"FUNCTION: oPath.StrTrunk() {{{3 "FUNCTION: oPath.StrTrunk() {{{3
"Gets the path without the last segment on the end. "Gets the path without the last segment on the end.
function! s:oPath.StrTrunk() dict function! s:oPath.StrTrunk() dict
return '/' . join(self.pathSegments[0:-2], '/') return self.drive . '/' . join(self.pathSegments[0:-2], '/')
endfunction endfunction
"FUNCTION: oPath.WinToUnixPath(pathstr){{{3 "FUNCTION: oPath.WinToUnixPath(pathstr){{{3
@@ -1312,7 +1338,9 @@ function! s:InitNerdTree(dir)
let dir = a:dir == '' ? expand('%:p:h') : a:dir let dir = a:dir == '' ? expand('%:p:h') : a:dir
let dir = resolve(dir) let dir = resolve(dir)
if !isdirectory(dir) let path = s:oPath.New(dir)
if !path.isDirectory
call s:EchoWarning("Error reading: " . dir) call s:EchoWarning("Error reading: " . dir)
return return
endif endif
@@ -1320,7 +1348,7 @@ function! s:InitNerdTree(dir)
"if instructed to, then change the vim CWD to the dir the NERDTree is "if instructed to, then change the vim CWD to the dir the NERDTree is
"inited in "inited in
if g:NERDTreeChDirMode != 0 if g:NERDTreeChDirMode != 0
exec "cd " . dir exec 'cd ' . path.StrForCd()
endif endif
let t:treeShowHelp = 0 let t:treeShowHelp = 0
@@ -1333,7 +1361,6 @@ function! s:InitNerdTree(dir)
unlet t:NERDTreeRoot unlet t:NERDTreeRoot
endif endif
let path = s:oPath.New(dir)
let t:NERDTreeRoot = s:oTreeDirNode.New(path) let t:NERDTreeRoot = s:oTreeDirNode.New(path)
call t:NERDTreeRoot.Open() call t:NERDTreeRoot.Open()
@@ -1404,7 +1431,13 @@ function! s:CenterView()
endif endif
endif endif
endfunction endfunction
"FUNCTION: s:CloseTreeIfOpen() {{{2
"Closes the NERD tree window if it is open
function! s:CloseTreeIfOpen()
if s:IsTreeOpen()
call s:CloseTree()
endif
endfunction
"FUNCTION: s:CloseTree() {{{2 "FUNCTION: s:CloseTree() {{{2
"Closes the NERD tree window "Closes the NERD tree window
function! s:CloseTree() function! s:CloseTree()
@@ -1455,16 +1488,17 @@ function! s:CreateTreeWin()
setlocal cursorline setlocal cursorline
endif endif
" syntax highlighting
if has("syntax") && exists("g:syntax_on") && !has("syntax_items")
call s:SetupSyntaxHighlighting()
endif
" for line continuation " for line continuation
let cpo_save1 = &cpo let cpo_save1 = &cpo
set cpo&vim set cpo&vim
call s:BindMappings() call s:BindMappings()
setfiletype nerdtree
" syntax highlighting
if has("syntax") && exists("g:syntax_on") && !has("syntax_items")
call s:SetupSyntaxHighlighting()
endif
endfunction endfunction
"FUNCTION: s:DrawTree {{{2 "FUNCTION: s:DrawTree {{{2
@@ -1772,8 +1806,9 @@ function! s:GetPath(ln)
endif endif
endif endif
endwhile endwhile
let curFile = dir . curFile let curFile = t:NERDTreeRoot.path.drive . dir . curFile
return s:oPath.NewMinimal(curFile) let toReturn = s:oPath.New(curFile)
return toReturn
endfunction endfunction
"FUNCTION: s:GetSelectedDir() {{{2 "FUNCTION: s:GetSelectedDir() {{{2
@@ -2585,7 +2620,7 @@ function! s:InsertNewNode()
let newNodeName = input("Add a childnode\n". let newNodeName = input("Add a childnode\n".
\ "==========================================================\n". \ "==========================================================\n".
\ "Enter the dir/file name to be created. Dirs end with a '/'\n" . \ "Enter the dir/file name to be created. Dirs end with a '/'\n" .
\ "", curDirNode.path.Str(0)) \ "", curDirNode.path.StrForGlob() . s:os_slash)
if newNodeName == '' if newNodeName == ''
call s:Echo("Node Creation Aborted.") call s:Echo("Node Creation Aborted.")
@@ -2594,7 +2629,6 @@ function! s:InsertNewNode()
try try
let newPath = s:oPath.Create(newNodeName) let newPath = s:oPath.Create(newNodeName)
let parentNode = t:NERDTreeRoot.FindNode(newPath.GetPathTrunk()) let parentNode = t:NERDTreeRoot.FindNode(newPath.GetPathTrunk())
let newTreeNode = s:oTreeFileNode.New(newPath) let newTreeNode = s:oTreeFileNode.New(newPath)
@@ -2793,15 +2827,13 @@ function! s:RenameCurrent()
let newNodePath = input("Rename the current node\n" . let newNodePath = input("Rename the current node\n" .
\ "==========================================================\n" . \ "==========================================================\n" .
\ "Enter the new path for the node: \n" . \ "Enter the new path for the node: \n" .
\ "", curNode.path.Str(0)) \ "", curNode.path.StrForOS(0))
if newNodePath == '' if newNodePath == ''
call s:Echo("Node Renaming Aborted.") call s:Echo("Node Renaming Aborted.")
return return
endif endif
let newNodePath = substitute(newNodePath, '\/$', '', '')
try try
let bufnum = bufnr(curNode.path.Str(0)) let bufnum = bufnr(curNode.path.Str(0))
@@ -2811,7 +2843,7 @@ function! s:RenameCurrent()
"if the node is open in a buffer, ask the user if they want to "if the node is open in a buffer, ask the user if they want to
"close that buffer "close that buffer
if bufnum != -1 if bufnum != -1
let prompt = "|\n|Node renamed.\n|\n|The old file is open in buffer ". bufnum . (bufwinnr(bufnum) == -1 ? " (hidden)" : "") .". Delete this buffer? (yN)" let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) == -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
call s:PromptToDelBuffer(bufnum, prompt) call s:PromptToDelBuffer(bufnum, prompt)
endif endif