From 54fab2f2e55e9a413e2a1f5aec0f9129036d2168 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Thu, 5 Jan 2012 11:41:51 +0000 Subject: [PATCH] add dir and file flags to NERDTreeIgnore regexes This allows users to specify whether each regex in NERDTreeIgnore should apply to only files or only dirs. --- doc/NERD_tree.txt | 9 +++++++++ plugin/NERD_tree.vim | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index 5598dae..a6a0390 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -780,6 +780,14 @@ For example if you put the following line in your vimrc: > < then all files ending in .vim or ~ will be ignored. +There are 2 magic flags that can be appended to the end of each regular +expression to specify that the regex should match only files or only dirs. +These flags are "[[dir]]" and "[[file]]". Example: > + let NERDTreeIgnore=['.d$[[dir]]', '.o$[[file]]'] +< +This will cause all dirs ending in ".d" to be ignored and all files ending in +".o" to be ignored. + Note: to tell the NERD tree not to ignore any files you must use the following line: > let NERDTreeIgnore=[] @@ -1129,6 +1137,7 @@ The latest dev versions are on github Next - add 'scope' argument to the key map API - add NERDTreeCustomIgnoreFilter hook - needs doc + - add magic [[dir]] and [[file]] flags to NERDTreeIgnore 4.2.0 - Add NERDTreeDirArrows option to make the UI use pretty arrow chars diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 92a5a5e..b1a6445 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -2291,19 +2291,17 @@ endfunction "FUNCTION: Path.ignore() {{{3 "returns true if this path should be ignored function! s:Path.ignore() - let lastPathComponent = self.getLastPathComponent(0) - "filter out the user specified paths to ignore if b:NERDTreeIgnoreEnabled for i in g:NERDTreeIgnore - if lastPathComponent =~# i + if self._ignorePatternMatches(i) return 1 endif endfor endif "dont show hidden files unless instructed to - if b:NERDTreeShowHidden ==# 0 && lastPathComponent =~# '^\.' + if b:NERDTreeShowHidden ==# 0 && self.getLastPathComponent(0) =~# '^\.' return 1 endif @@ -2318,6 +2316,24 @@ function! s:Path.ignore() return 0 endfunction +"FUNCTION: Path._ignorePatternMatches(pattern) {{{3 +"returns true if this path matches the given ignore pattern +function! s:Path._ignorePatternMatches(pattern) + let pat = a:pattern + if strpart(pat,len(pat)-7) == '[[dir]]' + if !self.isDirectory + return 0 + endif + let pat = strpart(pat,0, len(pat)-7) + elseif strpart(pat,len(pat)-8) == '[[file]]' + if self.isDirectory + return 0 + endif + let pat = strpart(pat,0, len(pat)-8) + endif + + return self.getLastPathComponent(0) =~# pat +endfunction "FUNCTION: Path.isUnder(path) {{{3 "return 1 if this path is somewhere under the given path in the filesystem. "