The commentary in "tree_dir_node.vim" needed to be cleaned up a
little. Spaces after leading quotes are a good idea, to avoid the
"clustered" appearance that comments can sometimes have.
Use the following substitution command...
:s/^"\ze\S/" /
to make this change to longer scripts.
Pull request #710 also brought to my attention some glaring code
duplication in the TreeDirNode class. This commit renames and
expands the glob method defined in PR #710 into a more general
purpose helper method.
The new method also ensures that 'wildignore' rules are applied
consistently. Issue #569 noted that the application of the
'wildignore' setting in populating a node's children was
unpredictable. When a node was rendered, "_initChildren()" would
load the children with its own call to "globpath()". Refreshing the
same node would then invoke "globpath()" again, but with different
arguments.
The result was that a node's children were initialized using the
'g:NERDTreeRespectWildIgnore' setting, but refreshing ignored this
setting. So, if it the setting was 0, "test.class" might render when
the parent was initialized, and then be removed on refresh (if
'wildignore' contained '*.class').
This commit solves this problem by ensuring that the NERDTree
setting mentioned above is only checked and applied to a node's
children in one place by cleaning up the duplication.
Fixes#569.
Pull request #710 correctly noted that TreeDirNode directories must
be passed to "globpath()" as relative paths (i.e., to the working
directory) if 'wildignore' rules for relative paths are to be
obeyed.
The solution was to use "fnamemodify()" to get a relative path to
the TreeDirNode object's directory, if possible. However, this
method does not modify our TreeDirNode path if it IS the current
working directory. Thus, immediate children of the node are seen as
absolute paths in glob results when our PWD is pointing to their
parent. This is not consistent behavior.
This commit defines the result of this function as ',' when this
special case arises to fix this problem.
See ":h 'path'" for an explanation of how this works.
Older Vim versions seem to require that calls to sort() specify a
dictionary when the compare function argument is a dictionary
function. This seems to be required even when the dictionary is not
used. Since this change does not seem to affect behavior in later
Vim editions, I see no harm in including it.
Issues #597, #642, and #650 all report problems with the NERDTree
handler function for middle mouse clicks. In all cases, the problems
arose from the use of a function that didn't exist and from the use
of a bad argument in the call to the "g:NERDTreeAddKeyMap" function.
The fix for the first problem is obvious, but the solution to the
second bug merits explanation.
Previously, middle click events in the NERDTree window were
triggered with the "<MiddleRelease>" Vim key code. Since
"<MiddleMouse>" is always triggered before "<MiddleRelease>", The
error in #642 was bound to occur (because of the default behavior
for middle mouse clicks). Thus, the problem was easily solved by
using "<MiddleMouse>" instead of "<MiddleRelease>" in the mapping.
As an enhancement, I added the trigger of a "<LeftMouse>" event as
the first command in the handler function. This will cause the
middle click to reposition the cursor below the pointer before
continuing with its normal behavior. The benefits of this are clear.
This mapping has no defined behavior for bookmarks. Unless an issue
is raised to address this, it will be left just so for now.
Fixes#597, fixes#642, and fixes#650.
In Windows, fnamemodify with ':.' will strip the drive letter from a
path that isn't under CWD. This update ensures such a path has the drive
letter.
references #709
It came to my attention that the option summary has been neglected for
the past few commits. I added the new option in this feature branch and
updated the descriptions of two nearby options.
This section could use some focused editing.
I altered the behavior of the ":OpenBookmark" command to match that of
the "NERDTree-o" mapping. This is acceptable for the following reasons:
1. It was broken, so no one was using it.
2. The name matches its behavior.
If a bookmark is to be opened in an explorer window, we should have a
command with a matching name for that behavior (":ExploreBookmark", for
example). This can be added later if there is enough demand for the
feature. Otherwise, this is a perfectly valid change.
A few minor changes were made to the "Bookmark.getNode()" function for
the purposes of improving readability and documentation clarity.
This process also led me to the conclusion that the "findNode()"
function should be refactored to throw an error if a node cannot be
found. This would lead to greater uniformity in the reporting of
failures to find a node. It is generally better style to have an error
thrown as close to the source as possible. A substantial change like
this should wait for now.
A missing argument sigil is effectively a syntax error in VimL. The
function in which the error occurred was called in the execution of at
least three buffer-local NERDTree commands:
1. :Bookmark (specifically, when trying to overwrite a Bookmark)
2. :OpenBookmark
3. :RevealBookmark
Only one specific type of error message associated with these commands
is fixed here (see issue #677).
The problems with the above commands are not fully addressed by this
commit, and their behavior can be improved immensely by further
refactoring. However, no one has been able to even use these commands at
all before now because the fix given here was not in place.
More work will need to be done to improve the behavior of these commands
so that they truly function as any reasonable user would expect.
Fixes#677.
The header in "bookmark.vim" was pretty weak. It provided no description
of the class it contains and no direction for the reader. In particular
it did not note the dual purpose of the "Bookmark" class.
The fact that the "Bookmark" class serves two purposes must be noted
because many readers will expect class definitions to obey the single
responsibility principle!
If there is a chance for a major refactor of this class in the future, a
priority would be splitting the class in two so that a "BookmarkList"
class can assume the responsibility for providing a container for all
"Bookmark" objects.
The function in "bookmark.vim" that allows the caller to query the list
of Bookmarks by name had stale commentary. In addition, the internals of
the function needed to be reworked to improve readability. Making this
function very clean is important because it is heavily used elsewhere.
As a side note, it might be beneficial to later rename this function to
something like "GetBookmarkByName" to further improve readability. That
change is not critical and can be safely delayed.
It makes the most sense to sort the global bookmarks list just before
rendering them in the NERDTree window. Since Vim's sort function is fast
and stable, and since users are very unlikely to have a number of
bookmarks that is too large, we can sort before rendering without
concern for the negligible performance penalty.
This has two benefits:
1. Users can change their sort settings and have them take effect
on the next render or refresh.
2. As mentioned, code duplication is avoided.
Sorting the list of user bookmarks requires care to ensure that Vim's
builtin sort function is called correctly. Previously, this function was
called incorrectly. This is why the sorting of bookmarks never worked.
The offending functions have been removed here and replaced with
"s:Bookmark.CompareBookmarksByName". To understand the necessity for
this change, read ":h sort()" for the requirements of the function
reference argument (esp., note that it must return -1, 0, or 1).
In addition to fixing this problem, the new comparison function will
inspect the "g:NERDTreeBookmarksSort" setting to determine whether
case-sensitivity is preferred in the sort. The documentation has been
modified to accurately reflect this adjustment. The change is also made
in such a way as not to break any existing configurations.
Fixes#361 ("My bookmarks aren't sorted").
The trailing fold markers in "bookmark.vim" varied in how far they were
from the end of the line. This created an unpleasant visual effect when
folding was in use.
Wildignore rules that involve directories aren't handled properly (or at
least as one might expect) when globpath uses absolute paths. For
example, when wildignore contains `src/*.js`, `globpath("src", "*")`
works as expected, while `globpath("/home/user/project/src", "*")`
doesn't.
So :bprev was failing to jump back to the right buffer. I dont fully
understand this yet, but I'm fairly sure this is because there is a
magic <directory> buffer that we delete when creating a wintree :-/
Anyway, we are explicitly storing the prev buffer again - and updating
it when reusing treewins. It's worky, but there may be a superior way...