Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/preservim/nerdtree into r…
Browse files Browse the repository at this point in the history
…eveal-windows-explorer

# Conflicts:
#	nerdtree_plugin/fs_menu.vim
  • Loading branch information
rzvxa committed Oct 22, 2023
2 parents 7f1aca9 + ea4833d commit c092341
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 21 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
PATCH versions are listed from newest to oldest under their respective MAJOR.MINOR
version in an unordered list. The format is:
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
or
- **.PATCH**:
- Pull Request Title 1 (PR Author) [PR Number](Link to PR)
- Pull Request Title 2 (PR Author) [PR Number](Link to PR)
.
.
.
- Pull Request Title n (PR Author) [PR Number](Link to PR)
-->
#### 7.0
- **.0**:
- Now we warn about invalid files instead of ignoring them silently. (rmonico) [#1365](https://github.com/preservim/nerdtree/pull/1365)
- New g:NERDTreeWinPos options for top and bottom. (rzvxa) [#1363](https://github.com/preservim/nerdtree/pull/1363)
- Fix error in README. (nickspoons) [#1330](https://github.com/preservim/nerdtree/pull/1330)
- Fix typo in the documentation. (chapeupreto) [#1306](https://github.com/preservim/nerdtree/pull/1306)
#### 6.10
- **.16**: Fix documentation errors. (lifecrisis) [#1269](https://github.com/preservim/nerdtree/pull/1269)
- **.15**: Ensure backward compatible testing of types. (lifecrisis) [#1266](https://github.com/preservim/nerdtree/pull/1266)
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTa
```vim
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
autocmd BufEnter * if winnr() == winnr('h') && bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
```
Expand Down
38 changes: 36 additions & 2 deletions autoload/nerdtree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,42 @@ function! nerdtree#postSourceActions() abort
runtime! nerdtree_plugin/**/*.vim
endfunction

"FUNCTION: nerdtree#runningWindows(dir) {{{2
"FUNCTION: nerdtree#runningWindows() {{{2
function! nerdtree#runningWindows() abort
return has('win16') || has('win32') || has('win64')
endfunction

"FUNCTION: nerdtree#runningCygwin(dir) {{{2
"FUNCTION: nerdtree#runningCygwin() {{{2
function! nerdtree#runningCygwin() abort
return has('win32unix')
endfunction

"FUNCTION: nerdtree#runningMac() {{{2
function! nerdtree#runningMac() abort
return has('gui_mac') || has('gui_macvim') || has('mac') || has('osx')
endfunction

" FUNCTION: nerdtree#osDefaultCaseSensitiveFS() {{{2
function! nerdtree#osDefaultCaseSensitiveFS() abort
return s:osDefaultCaseSensitiveFS
endfunction

" FUNCTION: nerdtree#caseSensitiveFS() {{{2
function! nerdtree#caseSensitiveFS() abort
return g:NERDTreeCaseSensitiveFS == 1 ||
\((g:NERDTreeCaseSensitiveFS == 2 || g:NERDTreeCaseSensitiveFS == 3) &&
\nerdtree#osDefaultCaseSensitiveFS())
endfunction

"FUNCTION: nerdtree#pathEquals(lhs, rhs) {{{2
function! nerdtree#pathEquals(lhs, rhs) abort
if nerdtree#caseSensitiveFS()
return a:lhs ==# a:rhs
else
return a:lhs ==? a:rhs
endif
endfunction

" SECTION: View Functions {{{1
"============================================================

Expand Down Expand Up @@ -246,4 +272,12 @@ function! nerdtree#renderView() abort
call b:NERDTree.render()
endfunction

if nerdtree#runningWindows()
let s:osDefaultCaseSensitiveFS = 0
elseif nerdtree#runningMac()
let s:osDefaultCaseSensitiveFS = 0
else
let s:osDefaultCaseSensitiveFS = 1
endif

" vim: set sw=4 sts=4 et fdm=marker:
23 changes: 23 additions & 0 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ the NERDTree. These settings should be set in your vimrc, using `:let`.

|NERDTreeAutoCenterThreshold| Controls the sensitivity of autocentering.

|NERDTreeCaseSensitiveFS| Tells the NERDTree whether or not it is
running in on a case sensitive file system.

|NERDTreeCaseSensitiveSort| Tells the NERDTree whether to be case
sensitive or not when sorting nodes.

Expand Down Expand Up @@ -808,6 +811,26 @@ Default: 3
This setting controls the "sensitivity" of the NERDTree auto centering. See
|NERDTreeAutoCenter| for details.

------------------------------------------------------------------------------
*NERDTreeCaseSensitiveFS*
Values: 0, 1, 2 or 3.
Default: 2.

If set to 0, the NERDTree will interact with the file system without case
sensitivity.

If set to 1, the NERDTree will interact with the file system in a case-sensitive
manner.

If set to 2, the NERDTree assumes its case sensitivity from the OS it is
running on. It Will default to case-insensitive on Windows and macOS
machines and case-sensitive on everything else. Since it's not a foolproof
way of detection, NERDTree won't proceed with any write actions when
the destination is ambiguous.

Setting it to 3 will perform just like 2, but without suppressing write
actions.

------------------------------------------------------------------------------
*NERDTreeCaseSensitiveSort*
Values: 0 or 1.
Expand Down
6 changes: 1 addition & 5 deletions lib/nerdtree/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,7 @@ endfunction
" Args:
" path: the other path obj to compare this with
function! s:Path.equals(path)
if nerdtree#runningWindows()
return self.str() ==? a:path.str()
else
return self.str() ==# a:path.str()
endif
return nerdtree#pathEquals(self.str(), a:path.str())
endfunction

" FUNCTION: Path.New(pathStr) {{{1
Expand Down
10 changes: 7 additions & 3 deletions lib/nerdtree/tree_dir_node.vim
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,15 @@ function! s:TreeDirNode._initChildren(silent)
endif

let invalidFilesFound = 0
let invalidFiles = []
for i in files
try
let path = g:NERDTreePath.New(i)
call self.createChild(path, 0)
call g:NERDTreePathNotifier.NotifyListeners('init', path, self.getNerdtree(), {})
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
let invalidFilesFound += 1
let invalidFiles += [i]
endtry
endfor

Expand All @@ -437,7 +439,7 @@ function! s:TreeDirNode._initChildren(silent)
call nerdtree#echo('')

if invalidFilesFound
call nerdtree#echoWarning(invalidFilesFound . ' file(s) could not be loaded into the NERD tree')
call nerdtree#echoWarning(invalidFilesFound . ' Invalid file(s): ' . join(invalidFiles, ', '))
endif
return self.getChildCount()
endfunction
Expand Down Expand Up @@ -564,6 +566,7 @@ function! s:TreeDirNode.refresh()
let files = self._glob('*', 1) + self._glob('.*', 0)
let newChildNodes = []
let invalidFilesFound = 0
let invalidFiles = []
for i in files
try
"create a new path and see if it exists in this nodes children
Expand All @@ -580,7 +583,8 @@ function! s:TreeDirNode.refresh()
call add(newChildNodes, newNode)
endif
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
let invalidFilesFound = 1
let invalidFilesFound += 1
let invalidFiles += [i]
endtry
endfor

Expand All @@ -589,7 +593,7 @@ function! s:TreeDirNode.refresh()
call self.sortChildren()

if invalidFilesFound
call nerdtree#echoWarning('some files could not be loaded into the NERD tree')
call nerdtree#echoWarning(invalidFilesFound . ' Invalid file(s): ' . join(invalidFiles, ', '))
endif
endif
endfunction
Expand Down
79 changes: 70 additions & 9 deletions nerdtree_plugin/fs_menu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callbac
call NERDTreeAddMenuItem({'text': '(m)ove the current node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'})
call NERDTreeAddMenuItem({'text': '(d)elete the current node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'})

if has('gui_mac') || has('gui_macvim') || has('mac')
if nerdtree#runningMac()
call NERDTreeAddMenuItem({'text': '(r)eveal the current node in the Finder', 'shortcut': 'r', 'callback': 'NERDTreeRevealInFinder'})
call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFile'})
call NERDTreeAddMenuItem({'text': '(q)uicklook the current node', 'shortcut': 'q', 'callback': 'NERDTreeQuickLook'})
Expand All @@ -46,6 +46,7 @@ call NERDTreeAddMenuItem({'text': (has('clipboard')?'copy (p)ath to clipboard':'

if has('unix') || has('osx')
call NERDTreeAddMenuItem({'text': '(l)ist the current node', 'shortcut': 'l', 'callback': 'NERDTreeListNode'})
call NERDTreeAddMenuItem({'text': '(C)hange node permissions', 'shortcut':'C', 'callback': 'NERDTreeChangePermissions'})
else
call NERDTreeAddMenuItem({'text': '(l)ist the current node', 'shortcut': 'l', 'callback': 'NERDTreeListNodeWin32'})
endif
Expand Down Expand Up @@ -149,18 +150,38 @@ function! s:renameBuffer(bufNum, newNodeName, isDirectory)
let quotedFileName = fnameescape(a:newNodeName)
let editStr = g:NERDTreePath.New(a:newNodeName).str({'format': 'Edit'})
endif
" 1. ensure that a new buffer is loaded
call nerdtree#exec('badd ' . quotedFileName, 0)
" 2. ensure that all windows which display the just deleted filename
" display a buffer for a new filename.
let s:originalTabNumber = tabpagenr()
let s:originalWindowNumber = winnr()
call nerdtree#exec('tabdo windo if winbufnr(0) ==# ' . a:bufNum . " | exec ':e! " . editStr . "' | endif", 0)
let l:tempBufferName = 'NERDTreeRenameTempBuffer'

" 1. swap deleted file buffer with a temporary one
" this step is needed to compensate for case insensitive filesystems

" 1.1. create an intermediate(temporary) buffer
call nerdtree#exec('badd ' . l:tempBufferName, 0)
let l:tempBufNum = bufnr(l:tempBufferName)
" 1.2. ensure that all windows which display the just deleted filename
" display the new temp buffer.
call nerdtree#exec('tabdo windo if winbufnr(0) ==# ' . a:bufNum . " | exec ':e! " . l:tempBufferName . "' | endif", 0)
" 1.3. We don't need the deleted file buffer anymore
try
call nerdtree#exec('confirm bwipeout ' . a:bufNum, 0)
catch
" This happens when answering Cancel if confirmation is needed. Do nothing.
endtry

" 2. swap temporary buffer with the new filename buffer
" 2.1. create the actual new file buffer
call nerdtree#exec('badd ' . quotedFileName, 0)

" 2.2. ensure that all windows which display the temporary buffer
" display a buffer for the new filename.
call nerdtree#exec('tabdo windo if winbufnr(0) ==# ' . l:tempBufNum . " | exec ':e! " . editStr . "' | endif", 0)
call nerdtree#exec('tabnext ' . s:originalTabNumber, 1)
call nerdtree#exec(s:originalWindowNumber . 'wincmd w', 1)
" 3. We don't need a previous buffer anymore
" 2.3. We don't need the temporary buffer anymore
try
call nerdtree#exec('confirm bwipeout ' . a:bufNum, 0)
call nerdtree#exec('confirm bwipeout ' . l:tempBufNum, 0)
catch
" This happens when answering Cancel if confirmation is needed. Do nothing.
endtry
Expand Down Expand Up @@ -206,7 +227,24 @@ function! NERDTreeMoveNode()
let prompt = s:inputPrompt('move')
let newNodePath = input(prompt, curNode.path.str(), 'file')
while filereadable(newNodePath)
call nerdtree#echoWarning('This destination already exists. Try again.')
" allow renames with different casing when g:NERDTreeCaseSensitiveFS
" is set to either 0 or 3 and the 2 paths are equal
if (g:NERDTreeCaseSensitiveFS == 0 || g:NERDTreeCaseSensitiveFS == 3) &&
\nerdtree#pathEquals(curNode.path.str(), newNodePath)
break
endif

call nerdtree#echoWarning('This destination already exists, Try again.')

" inform the user about the flag if we think it is a false positive
" when g:NERDTreeCaseSensitiveFS is set to 2
if g:NERDTreeCaseSensitiveFS == 2 &&
\!nerdtree#osDefaultCaseSensitiveFS() &&
\nerdtree#pathEquals(curNode.path.str(), newNodePath)
echon "\n(If it is a false positive please consider assigning NERDTreeCaseSensitiveFS's value)"
endif

" prompt the user again
let newNodePath = substitute(input(prompt, curNode.path.str(), 'file'), '\(^\s*\|\s*$\)', '', 'g')
endwhile

Expand Down Expand Up @@ -334,6 +372,29 @@ function! NERDTreeListNodeWin32()
call nerdtree#echo('node not recognized')
endfunction

" FUNCTION: NERDTreeChangePermissions() {{{1
function! NERDTreeChangePermissions()
let l:node = g:NERDTreeFileNode.GetSelected()
let l:prompt = "change node permissions: "
let l:newNodePerm = input(l:prompt)

if !empty(l:node)
let l:path = l:node.path.str()
let l:cmd = 'chmod ' .. newNodePerm .. ' ' .. path
let l:error = split(system(l:cmd), '\n')

if !empty(l:error)
call nerdtree#echo(l:error[0])
endif

call b:NERDTree.root.refresh()
call b:NERDTree.render()
return
endif

call nerdtree#echo('node not recognized')
endfunction

" FUNCTION: NERDTreeCopyNode() {{{1
function! NERDTreeCopyNode()
let currentNode = g:NERDTreeFileNode.GetSelected()
Expand Down
2 changes: 2 additions & 0 deletions plugin/NERD_tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set cpoptions&vim
"SECTION: Initialize variable calls and other random constants {{{2
let g:NERDTreeAutoCenter = get(g:, 'NERDTreeAutoCenter', 1)
let g:NERDTreeAutoCenterThreshold = get(g:, 'NERDTreeAutoCenterThreshold', 3)
let g:NERDTreeCaseSensitiveFS = get(g:, 'NERDTreeCaseSensitiveFS', 2)
let g:NERDTreeCaseSensitiveSort = get(g:, 'NERDTreeCaseSensitiveSort', 0)
let g:NERDTreeNaturalSort = get(g:, 'NERDTreeNaturalSort', 0)
let g:NERDTreeSortHiddenFirst = get(g:, 'NERDTreeSortHiddenFirst', 1)
Expand All @@ -53,6 +54,7 @@ let g:NERDTreeShowHidden = get(g:, 'NERDTreeShowHidden', 0
let g:NERDTreeShowLineNumbers = get(g:, 'NERDTreeShowLineNumbers', 0)
let g:NERDTreeSortDirs = get(g:, 'NERDTreeSortDirs', 1)


if !nerdtree#runningWindows() && !nerdtree#runningCygwin()
let g:NERDTreeDirArrowExpandable = get(g:, 'NERDTreeDirArrowExpandable', '')
let g:NERDTreeDirArrowCollapsible = get(g:, 'NERDTreeDirArrowCollapsible', '')
Expand Down
2 changes: 1 addition & 1 deletion syntax/nerdtree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else
hi! link NERDTreeNodeDelimiters Ignore
endif

"highlighing for directory nodes and file nodes
"highlighting for directory nodes and file nodes
syn match NERDTreeDirSlash #/# containedin=NERDTreeDir

if g:NERDTreeDirArrowExpandable !=# ''
Expand Down

0 comments on commit c092341

Please sign in to comment.