mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 03:43:50 -05:00
make "OS" the default format for Path#str()
remove the old "OS" format option and introduce "UI" (which is the old default)
This commit is contained in:
@@ -30,7 +30,7 @@ function! NERDTreeExecFile()
|
|||||||
let treenode = g:NERDTreeFileNode.GetSelected()
|
let treenode = g:NERDTreeFileNode.GetSelected()
|
||||||
echo "==========================================================\n"
|
echo "==========================================================\n"
|
||||||
echo "Complete the command to execute (add arguments etc):\n"
|
echo "Complete the command to execute (add arguments etc):\n"
|
||||||
let cmd = treenode.path.str({'format': 'OS', 'escape': 1})
|
let cmd = treenode.path.str({'escape': 1})
|
||||||
let cmd = input(':!', cmd . ' ')
|
let cmd = input(':!', cmd . ' ')
|
||||||
|
|
||||||
if cmd != ''
|
if cmd != ''
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ function! NERDTreeMoveNode()
|
|||||||
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({'format': 'OS'})
|
\ "", curNode.path.str()
|
||||||
|
|
||||||
if newNodePath ==# ''
|
if newNodePath ==# ''
|
||||||
call s:echo("Node Renaming Aborted.")
|
call s:echo("Node Renaming Aborted.")
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ endfunction
|
|||||||
function! NERDTreeGitMove()
|
function! NERDTreeGitMove()
|
||||||
let node = g:NERDTreeFileNode.GetSelected()
|
let node = g:NERDTreeFileNode.GetSelected()
|
||||||
let path = node.path
|
let path = node.path
|
||||||
let p = path.str({'format': 'OS', 'escape': 1})
|
let p = path.str({'escape': 1})
|
||||||
|
|
||||||
let newPath = input("==========================================================\n" .
|
let newPath = input("==========================================================\n" .
|
||||||
\ "Enter the new path for the file: \n" .
|
\ "Enter the new path for the file: \n" .
|
||||||
\ "", node.path.str({'format': 'OS'}))
|
\ "", node.path.str())
|
||||||
if newPath ==# ''
|
if newPath ==# ''
|
||||||
call s:echo("git mv aborted.")
|
call s:echo("git mv aborted.")
|
||||||
return
|
return
|
||||||
@@ -82,19 +82,19 @@ endfunction
|
|||||||
function! NERDTreeGitAdd()
|
function! NERDTreeGitAdd()
|
||||||
let node = g:NERDTreeFileNode.GetSelected()
|
let node = g:NERDTreeFileNode.GetSelected()
|
||||||
let path = node.path
|
let path = node.path
|
||||||
call s:execGitCmd('add ' . path.str({'format': 'OS', 'escape': 1}))
|
call s:execGitCmd('add ' . path.str({'escape': 1}))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! NERDTreeGitRemove()
|
function! NERDTreeGitRemove()
|
||||||
let node = g:NERDTreeFileNode.GetSelected()
|
let node = g:NERDTreeFileNode.GetSelected()
|
||||||
let path = node.path
|
let path = node.path
|
||||||
call s:execGitCmd('rm ' . path.str({'format': 'OS', 'escape': 1}))
|
call s:execGitCmd('rm ' . path.str({'escape': 1}))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! NERDTreeGitCheckout()
|
function! NERDTreeGitCheckout()
|
||||||
let node = g:NERDTreeFileNode.GetSelected()
|
let node = g:NERDTreeFileNode.GetSelected()
|
||||||
let path = node.path
|
let path = node.path
|
||||||
call s:execGitCmd('checkout ' . path.str({'format': 'OS', 'escape': 1}))
|
call s:execGitCmd('checkout ' . path.str({'escape': 1}))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execGitCmd(sub_cmd)
|
function! s:execGitCmd(sub_cmd)
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ endif
|
|||||||
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
||||||
|
|
||||||
if !exists('g:NERDTreeStatusline')
|
if !exists('g:NERDTreeStatusline')
|
||||||
let g:NERDTreeStatusline = "%{b:NERDTreeRoot.path._strForOS()}"
|
let g:NERDTreeStatusline = "%{b:NERDTreeRoot.path.str()}"
|
||||||
endif
|
endif
|
||||||
call s:initVariable("g:NERDTreeWinPos", "left")
|
call s:initVariable("g:NERDTreeWinPos", "left")
|
||||||
call s:initVariable("g:NERDTreeWinSize", 31)
|
call s:initVariable("g:NERDTreeWinSize", 31)
|
||||||
@@ -342,7 +342,7 @@ function! s:Bookmark.mustExist()
|
|||||||
if !self.path.exists()
|
if !self.path.exists()
|
||||||
call s:Bookmark.CacheBookmarks(1)
|
call s:Bookmark.CacheBookmarks(1)
|
||||||
throw "NERDTree.BookmarkPointsToInvalidLocationError: the bookmark \"".
|
throw "NERDTree.BookmarkPointsToInvalidLocationError: the bookmark \"".
|
||||||
\ self.name ."\" points to a non existing location: \"". self.path.str({'format': 'OS'})
|
\ self.name ."\" points to a non existing location: \"". self.path.str()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" FUNCTION: Bookmark.New(name, path) {{{3
|
" FUNCTION: Bookmark.New(name, path) {{{3
|
||||||
@@ -376,7 +376,7 @@ function! s:Bookmark.str()
|
|||||||
let pathStrMaxLen = pathStrMaxLen - &numberwidth
|
let pathStrMaxLen = pathStrMaxLen - &numberwidth
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let pathStr = self.path.str({'format': 'OS'})
|
let pathStr = self.path.str({'format': 'UI'})
|
||||||
if len(pathStr) > pathStrMaxLen
|
if len(pathStr) > pathStrMaxLen
|
||||||
let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen)
|
let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen)
|
||||||
endif
|
endif
|
||||||
@@ -421,7 +421,7 @@ endfunction
|
|||||||
function! s:Bookmark.Write()
|
function! s:Bookmark.Write()
|
||||||
let bookmarkStrings = []
|
let bookmarkStrings = []
|
||||||
for i in s:Bookmark.Bookmarks()
|
for i in s:Bookmark.Bookmarks()
|
||||||
call add(bookmarkStrings, i.name . ' ' . i.path.str({'format': 'OS'}))
|
call add(bookmarkStrings, i.name . ' ' . i.path.str())
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
"add a blank line before the invalid ones
|
"add a blank line before the invalid ones
|
||||||
@@ -938,11 +938,11 @@ function! s:TreeFileNode.getLineNum()
|
|||||||
let totalLines = line("$")
|
let totalLines = line("$")
|
||||||
|
|
||||||
"the path components we have matched so far
|
"the path components we have matched so far
|
||||||
let pathcomponents = [substitute(b:NERDTreeRoot.path.str(), '/ *$', '', '')]
|
let pathcomponents = [substitute(b:NERDTreeRoot.path.str({'format': 'UI'}), '/ *$', '', '')]
|
||||||
"the index of the component we are searching for
|
"the index of the component we are searching for
|
||||||
let curPathComponent = 1
|
let curPathComponent = 1
|
||||||
|
|
||||||
let fullpath = self.path.str()
|
let fullpath = self.path.str({'format': 'UI'})
|
||||||
|
|
||||||
|
|
||||||
let lnum = s:TreeFileNode.GetRootLineNum()
|
let lnum = s:TreeFileNode.GetRootLineNum()
|
||||||
@@ -1062,7 +1062,7 @@ function! s:TreeFileNode.open()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
"if the file is already open in this tab then just stick the cursor in it
|
"if the file is already open in this tab then just stick the cursor in it
|
||||||
let winnr = bufwinnr('^' . self.path.str({'format': 'OS'}) . '$')
|
let winnr = bufwinnr('^' . self.path.str() . '$')
|
||||||
if winnr != -1
|
if winnr != -1
|
||||||
call s:exec(winnr . "wincmd w")
|
call s:exec(winnr . "wincmd w")
|
||||||
|
|
||||||
@@ -1898,10 +1898,10 @@ function! s:Path.copy(dest)
|
|||||||
|
|
||||||
let dest = s:Path.WinToUnixPath(a:dest)
|
let dest = s:Path.WinToUnixPath(a:dest)
|
||||||
|
|
||||||
let cmd = g:NERDTreeCopyCmd . " " . self.str({'format': 'OS'}) . " " . dest
|
let cmd = g:NERDTreeCopyCmd . " " . self.str() . " " . dest
|
||||||
let success = system(cmd)
|
let success = system(cmd)
|
||||||
if success != 0
|
if success != 0
|
||||||
throw "NERDTree.CopyError: Could not copy ''". self.str({'format': 'OS'}) ."'' to: '" . a:dest . "'"
|
throw "NERDTree.CopyError: Could not copy ''". self.str() ."'' to: '" . a:dest . "'"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -1942,14 +1942,14 @@ endfunction
|
|||||||
function! s:Path.delete()
|
function! s:Path.delete()
|
||||||
if self.isDirectory
|
if self.isDirectory
|
||||||
|
|
||||||
let cmd = g:NERDTreeRemoveDirCmd . self.str({'format': 'OS', 'escape': 1})
|
let cmd = g:NERDTreeRemoveDirCmd . self.str('escape': 1})
|
||||||
let success = system(cmd)
|
let success = system(cmd)
|
||||||
|
|
||||||
if v:shell_error != 0
|
if v:shell_error != 0
|
||||||
throw "NERDTree.PathDeletionError: Could not delete directory: '" . self.str({'format': 'OS'}) . "'"
|
throw "NERDTree.PathDeletionError: Could not delete directory: '" . self.str() . "'"
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let success = delete(self.str({'format': 'OS'}))
|
let success = delete(self.str())
|
||||||
if success != 0
|
if success != 0
|
||||||
throw "NERDTree.PathDeletionError: Could not delete file: '" . self.str() . "'"
|
throw "NERDTree.PathDeletionError: Could not delete file: '" . self.str() . "'"
|
||||||
endif
|
endif
|
||||||
@@ -1987,7 +1987,7 @@ endfunction
|
|||||||
"FUNCTION: Path.exists() {{{3
|
"FUNCTION: Path.exists() {{{3
|
||||||
"return 1 if this path points to a location that is readable or is a directory
|
"return 1 if this path points to a location that is readable or is a directory
|
||||||
function! s:Path.exists()
|
function! s:Path.exists()
|
||||||
let p = self.str({'format': 'OS'})
|
let p = self.str()
|
||||||
return filereadable(p) || isdirectory(p)
|
return filereadable(p) || isdirectory(p)
|
||||||
endfunction
|
endfunction
|
||||||
"FUNCTION: Path.getDir() {{{3
|
"FUNCTION: Path.getDir() {{{3
|
||||||
@@ -2164,7 +2164,7 @@ endfunction
|
|||||||
|
|
||||||
"FUNCTION: Path.refresh() {{{3
|
"FUNCTION: Path.refresh() {{{3
|
||||||
function! s:Path.refresh()
|
function! s:Path.refresh()
|
||||||
call self.readInfoFromDisk(self.str({'format': 'OS'}))
|
call self.readInfoFromDisk(self.str())
|
||||||
call self.cacheDisplayString()
|
call self.cacheDisplayString()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -2176,9 +2176,9 @@ function! s:Path.rename(newPath)
|
|||||||
throw "NERDTree.InvalidArgumentsError: Invalid newPath for renaming = ". a:newPath
|
throw "NERDTree.InvalidArgumentsError: Invalid newPath for renaming = ". a:newPath
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let success = rename(self.str({'format': 'OS'}), a:newPath)
|
let success = rename(self.str(), a:newPath)
|
||||||
if success != 0
|
if success != 0
|
||||||
throw "NERDTree.PathRenameError: Could not rename: '" . self.str({'format': 'OS'}) . "'" . 'to:' . a:newPath
|
throw "NERDTree.PathRenameError: Could not rename: '" . self.str() . "'" . 'to:' . a:newPath
|
||||||
endif
|
endif
|
||||||
call self.readInfoFromDisk(a:newPath)
|
call self.readInfoFromDisk(a:newPath)
|
||||||
|
|
||||||
@@ -2203,7 +2203,7 @@ endfunction
|
|||||||
"The 'format' key may have a value of:
|
"The 'format' key may have a value of:
|
||||||
" 'Cd' - a string to be used with the :cd command
|
" 'Cd' - a string to be used with the :cd command
|
||||||
" 'Edit' - a string to be used with :e :sp :new :tabedit etc
|
" 'Edit' - a string to be used with :e :sp :new :tabedit etc
|
||||||
" 'OS' - a string to be used with shell commands
|
" 'UI' - a string used in the NERD tree UI
|
||||||
"
|
"
|
||||||
"If not specified, a generic unix style path string will be returned
|
"If not specified, a generic unix style path string will be returned
|
||||||
"
|
"
|
||||||
@@ -2231,8 +2231,8 @@ function! s:Path.str(...)
|
|||||||
return toReturn
|
return toReturn
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: Path._str() {{{3
|
"FUNCTION: Path._strForUI() {{{3
|
||||||
function! s:Path._str()
|
function! s:Path._strForUI()
|
||||||
let toReturn = '/' . join(self.pathSegments, '/')
|
let toReturn = '/' . join(self.pathSegments, '/')
|
||||||
if self.isDirectory && toReturn != '/'
|
if self.isDirectory && toReturn != '/'
|
||||||
let toReturn = toReturn . '/'
|
let toReturn = toReturn . '/'
|
||||||
@@ -2245,9 +2245,9 @@ endfunction
|
|||||||
" returns a string that can be used with :cd
|
" returns a string that can be used with :cd
|
||||||
function! s:Path._strForCd()
|
function! s:Path._strForCd()
|
||||||
if s:running_windows
|
if s:running_windows
|
||||||
return self.str({'format': 'OS'})
|
return self.str()
|
||||||
else
|
else
|
||||||
return self.str({'format': 'OS', 'escape': 1})
|
return self.str({'escape': 1})
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
"FUNCTION: Path._strForEdit() {{{3
|
"FUNCTION: Path._strForEdit() {{{3
|
||||||
@@ -2255,11 +2255,11 @@ endfunction
|
|||||||
"Return: the string for this path that is suitable to be used with the :edit
|
"Return: the string for this path that is suitable to be used with the :edit
|
||||||
"command
|
"command
|
||||||
function! s:Path._strForEdit()
|
function! s:Path._strForEdit()
|
||||||
let p = self.str()
|
let p = self.str({'format': 'UI'})
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
|
|
||||||
if s:running_windows
|
if s:running_windows
|
||||||
let p = tolower(self.str({'format': 'OS'}))
|
let p = tolower(self.str())
|
||||||
let cwd = tolower(getcwd())
|
let cwd = tolower(getcwd())
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -2293,12 +2293,12 @@ function! s:Path._strForGlob()
|
|||||||
endif
|
endif
|
||||||
return toReturn
|
return toReturn
|
||||||
endfunction
|
endfunction
|
||||||
"FUNCTION: Path._strForOS() {{{3
|
"FUNCTION: Path._str() {{{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.
|
||||||
"EG, in windows c:\foo\bar
|
"EG, in windows c:\foo\bar
|
||||||
" in *nix /foo/bar
|
" in *nix /foo/bar
|
||||||
function! s:Path._strForOS()
|
function! s:Path._str()
|
||||||
let lead = s:Path.Slash()
|
let lead = s:Path.Slash()
|
||||||
|
|
||||||
"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
|
||||||
@@ -2531,7 +2531,7 @@ function! s:initNerdTreeMirror()
|
|||||||
while i < len(treeBufNames)
|
while i < len(treeBufNames)
|
||||||
let bufName = treeBufNames[i]
|
let bufName = treeBufNames[i]
|
||||||
let treeRoot = getbufvar(bufName, "NERDTreeRoot")
|
let treeRoot = getbufvar(bufName, "NERDTreeRoot")
|
||||||
let options[i+1 . '. ' . treeRoot.path.str({'format': 'OS'}) . ' (buf name: ' . bufName . ')'] = bufName
|
let options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName
|
||||||
let i = i + 1
|
let i = i + 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
@@ -3126,7 +3126,7 @@ function! s:renderView()
|
|||||||
call cursor(line(".")+1, col("."))
|
call cursor(line(".")+1, col("."))
|
||||||
|
|
||||||
"draw the header line
|
"draw the header line
|
||||||
call setline(line(".")+1, b:NERDTreeRoot.path.str())
|
call setline(line(".")+1, b:NERDTreeRoot.path.str({'format': 'UI'}))
|
||||||
call cursor(line(".")+1, col("."))
|
call cursor(line(".")+1, col("."))
|
||||||
|
|
||||||
"draw the tree
|
"draw the tree
|
||||||
@@ -3750,7 +3750,7 @@ function! s:openInNewTab(stayCurrentTab)
|
|||||||
if treenode != {}
|
if treenode != {}
|
||||||
if treenode.path.isDirectory
|
if treenode.path.isDirectory
|
||||||
tabnew
|
tabnew
|
||||||
call s:initNerdTree(treenode.path.str({'format': 'OS'}))
|
call s:initNerdTree(treenode.path.str())
|
||||||
else
|
else
|
||||||
exec "tabedit " . treenode.path.str({'format': 'Edit'})
|
exec "tabedit " . treenode.path.str({'format': 'Edit'})
|
||||||
endif
|
endif
|
||||||
@@ -3903,7 +3903,7 @@ endfunction
|
|||||||
"keepState: 1 if the current root should be left open when the tree is
|
"keepState: 1 if the current root should be left open when the tree is
|
||||||
"re-rendered
|
"re-rendered
|
||||||
function! s:upDir(keepState)
|
function! s:upDir(keepState)
|
||||||
let cwd = b:NERDTreeRoot.path.str()
|
let cwd = b:NERDTreeRoot.path.str({'format': 'UI'})
|
||||||
if cwd ==# "/" || cwd =~ '^[^/]..$'
|
if cwd ==# "/" || cwd =~ '^[^/]..$'
|
||||||
call s:echo("already at top dir")
|
call s:echo("already at top dir")
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user