Function-local variables, instead of script-local variables, should
be used here. In addition, "empty()" is a better choice for testing
for the absence of an argument. Finally, the use of "else" is
removed.
The docstring is also updated to include the new argument.
I contend that we should use confirm() whenever possible. It makes
the code cleaner and uses a builtin feature rather than a custom
one. Doing it the "Vim way" is always preferable in my mind.
The "o" mapping, which toggles directory nodes open/closed, allowed
the user to close the tree root. This was not consistent with the
"x" mapping which stops the user from doing this. This applies to
a double-click on the root node as well.
It should be noted that, if the root node is somehow closed, "o" and
double click can still re-open the tree, even with this change. In
other words, I was careful.
Previously, pressing "x" on the tree root would result in
unpredictable behavior. The user would either an receive an error
message or the parent of the tree root (which is not visible) would
be closed. This commit repairs this problem.
In addition, some code duplication was removed.
This bug is subtle! Opening a directory node in a new tab (with the
"t" or "T" mappings) would previously fail and require a refresh
because it called the directory node's "activate()" method.
In reviewing that method (i.e., "activate()"), I discovered that the
directory node's NERDTree is rendered before the method returns,
which overwrites the content of the tree in the new tab or window.
To clarify, when "t" or "T" is used on a directory node, a new
directory node and tree must be created to be rendered in a new tab.
So, calling "self.getNerdtree().render()" at the bottom of
"activate()" will render the NERDTree instance from which "t" or "T"
was invoked, not the new NERDTree that is being displayed. This
overwrites the new NERDTree text, and, thus, a refresh is required.
Since a call to "render()" is almost always necessary at the bottom
of "activate()" to keep everything in sync for other mappings, we
avoid this problem entirely by using the "open()" method directly
(works for files and directories) in the callbacks.
Fixes#549.
This change will display the file size (printed with the "ml"
command) in an easy-to-read format, while still displaying its
precise value. It uses the "stat" command (with the correct
switches for Unix and OSX) to get the file size, "sed" to add the
commas, and "sed" again to replace the original size with the
modified number.
Previously, deleting a file in the NERDTree with "md" would cause
a new buffer to be created to fill the window(s) occupied by
a buffer on the file. This pull request makes it so that a new
buffer is not created. Instead, the next buffer in the buffer list
fills the window.
Fixes#755.
Directory tree navigation is broken because of directory signs which is
shown in UTF-8.
Cygwin is a Windows application, so it uses ASCII codepages and so
directory signs must be in ASCII, but if to modify
"nerdtree#runningWindows" function there are many other functions break
that convert paths, e.g.
So, the quick and reliable solution is to add a
separate function "nerdtree#runningCygwin" and use it in a specific
place.
When g:NERDTreeChDirMode is 2, changing the tree root will change the working
directory as well. This change was silent because the wrong function was used to
make the switch. This commit uses a better function that echoes a message.
This small change reverts to the previous method of breaking shell
output into lines. The reason for this is to avoid the printing of
trailing carriage return characters on Windows.
The (l) menu command breaks on Windows systems when 'shellslash' is
set. This is due to the fact that the menu item uses a hard coded
shell command, thus relying on the use of the default Windows shell
without the 'shellslash' setting.
The pattern used for the fix is localized to the problem function.
However, this technique could easily be abstracted into its own
function to execute Windows shell commands with the default shell
throughout the NERDTree codebase.
This check did not use the proper abstract method to check for a
path separator. It now does.
This fixes a problem with the 'u' macro that I noticed while working
on the fix for using the NERDTree with 'shellslash'.
This method used the brittle "Path._escChars()" method to do its
work. This created problems when 'shellslash' was in use on Windows
because excessive escape characters (i.e., backslashes!) are
interpreted by Vim as additional path separators.
The above problem made it impossible to edit files with weird names
using the NERDTree on Windows with 'shellslash' set. For example,
'+' should be escaped with ":edit", but '(' should not. So, when
escaping '(', Vim on Windows correctly sees the start of a new
directory in the path.
This was reported in five issues which may be read for further
details and commentary.
Fixes#398, fixes#474, fixes#653, fixes#674, and fixes#733.
Several issues (namely issue #733) report problems with using the NERDTree
on Windows when 'shellslash' is set. This commit doesn't solve all of these
problems, but it improves the NERDTree's recognition of this setting.
Especially note the improvements to the commentary on "Path.str()".
This method does too much. However, it is used heavily, and changing
its interface would be a major undertaking at this point.
This commit is the first in a series of commits that will rework
some of the methods responsible for escaping pathnames. Some of
these methods simply don't use the features that Vim has properly.
The custom "Path._escChars()" method is far too rigid for our
purposes, and better options have been available for some time.
See ":h fnameescape()" for an especially helpful function in this
effort.
The highlighting rules "NERDTreeClosable" and "NERDTreeOpenable" did
not recognize files beginning with a "~" character. This caused bad
highlighting on systems that use "~" and "+" for the dir arrow
symbols by default. Making these rules more specific solves this
problem.
The "~" characters in quickhelp section titles also would get
confused with a custom mapping for "~". Adjusting the
"NERDTreeHelpTitle" solved this problem.
I also changed the quickhelp title in a minor way to reflect the
proper spelling of "NERDTree".
The previous change to this function was simple. I figured that it
would be a good time to improve the style of this function with some
minor edits. The function is now cleaner and more readable.