[patch] hiding directories in file explorer

Martin Rubli mrubli@gmx.net
Wed, 30 Mar 2005 18:38:13 +0200


--=-+o0Wo9h8jcW+j6mUd04c
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

Attached is a patch that adds support for the g:explHideDirs variable
which works for directories in the same way that g:explHideFiles does
for files. The patch includes changes for the corresponding
documentation file. (plus it corrects an obvious typo nearby :-)

Moreover it should fix the problem that occurs when the file explorer is
opened in a directory whose name contains spaces.

I've tested everything and it seems to work fine for me. But since I'm
new to writing VIM scripts, you might want to double check my
changes. :-)

Cheers,
Martin

--=-+o0Wo9h8jcW+j6mUd04c
Content-Disposition: attachment; filename=hidedirs.patch
Content-Type: text/x-patch; name=hidedirs.patch; charset=us-ascii
Content-Transfer-Encoding: 7bit

diff -ur orig/doc/pi_expl.txt new/doc/pi_expl.txt
--- orig/doc/pi_expl.txt	2005-03-28 19:56:27.000000000 +0200
+++ new/doc/pi_expl.txt	2005-03-30 14:13:11.000000000 +0200
@@ -129,7 +129,7 @@
 date should be invisible.
 
 							*g:explHideFiles*
-You can hide some files by filling the variable g:explHidFiles with regular
+You can hide some files by filling the variable g:explHideFiles with regular
 expressions. A filename that matches any of these regular expressions will not
 be shown. For example, >
 
@@ -140,6 +140,20 @@
 you'd like to see the hidden files as well, use the command "a".
 The explorer header will indicate if filtering is being done.
 
+							*g:explHideDirs*
+In the same way as for files you can hide directories matching given patterns
+by setting the variable g:explHideDirs to a list of regular expressions.
+Directory names matching any of these regular expressions will not show up in
+the list. For example, >
+
+  let g:explHideDirs='^\.[^.],^tmp$'
+
+will hide directories that begin with ".", except for "..", or that are called
+"tmp". The "a" command disables the directory filter. To reenable the filter
+simply use the ":e" command which will reload the directory. The explorer
+header displays the directory filter pattern after the "|" symbol that follows
+the file filter.
+
 							*g:explDetailedHelp*
 The help information spanning a few lines can be turned off (and just a single
 help message enabled) using the option >
diff -ur orig/plugin/explorer.vim new/plugin/explorer.vim
--- orig/plugin/explorer.vim	2005-03-30 14:16:16.000000000 +0200
+++ new/plugin/explorer.vim	2005-03-30 14:15:25.000000000 +0200
@@ -87,6 +87,11 @@
   let g:explDateFormat="%d %b %Y %H:%M"
 endif
 
+" Directories to hide
+if !exists("g:explHideDirs")
+  let g:explHideDirs=''
+endif
+
 " Files to hide
 if !exists("g:explHideFiles")
   let g:explHideFiles=''
@@ -187,6 +192,7 @@
   if fname == ""
     let fname = getcwd()
   endif
+  let fname = substitute(fname, ' ', '\\ ', 'g')
 
   " Create a variable to use if splitting vertically
   let splitMode = ""
@@ -327,6 +333,14 @@
     let b:filtering=""
   endif
 
+  " Set filter for hiding directories
+  let b:filterFormulaDir=substitute(g:explHideDirs, '\([^\\]\),', '\1\\|', 'g')
+  if b:filterFormulaDir != ''
+    let b:filteringDir=" | " . b:filterFormulaDir
+  else
+    let b:filteringDir=""
+  endif
+
   " Show the files
   call s:ShowDirectory()
 
@@ -685,7 +699,13 @@
   let currLine=getline(".")
   if isdirectory(b:completePath . currLine)
     s;$;/;
-    let fileLen=strlen(currLine)+1
+    if (b:filterFormulaDir!="") && (currLine =~ b:filterFormulaDir)
+      " Don't show the directory if it is to be filtered.
+      d _
+      let fileLen=strlen(currLine)
+    else
+      let fileLen=strlen(currLine)+1
+    endif
   else
     let fileLen=strlen(currLine)
     if (b:filterFormula!="") && (currLine =~ b:filterFormula)
@@ -791,7 +811,7 @@
     else
       let @f="\" Press ? for keyboard shortcuts\n"
     endif
-    let @f=@f."\" Sorted by ".w:sortdirlabel.w:sorttype.b:suffixeslast.b:filtering."\n"
+    let @f=@f."\" Sorted by ".w:sortdirlabel.w:sorttype.b:suffixeslast.b:filtering.b:filteringDir."\n"
     let @f=@f."\"= ".b:completePath."\n"
     put! f
     let @f=save_f
@@ -1002,7 +1022,9 @@
 function! s:ShowAllFiles()
   setlocal noreadonly modifiable
   let b:filterFormula=""
+  let b:filterFormulaDir=""
   let b:filtering=""
+  let b:filteringDir=""
   call s:ShowDirectory()
   setlocal readonly nomodifiable
 endfunction

--=-+o0Wo9h8jcW+j6mUd04c--