nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit f34986d30fa0e97810d9ebce6128df7ad4fe82cf
parent a713a86f0662dc6ca405384dd8a5df35c8b91a6a
Author: marty <martin_grenfell@msn.com>
Date:   Sun, 22 Nov 2009 18:25:23 +1300

move the path string truncation into Path#str()

Diffstat:
Mplugin/NERD_tree.vim | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim
@@ -2208,16 +2208,18 @@ endfunction
 "The dict may have the following keys:
 "  'format'
 "  'escape'
+"  'truncateTo'
 "
 "The 'format' key may have a value of:
 "  'Cd' - a string to be used with the :cd command
 "  'Edit' - a string to be used with :e :sp :new :tabedit etc
 "  'UI' - a string used in the NERD tree UI
 "
-"If not specified, a generic unix style path string will be returned
-"
 "The 'escape' key, if specified will cause the output to be escaped with
 "shellescape()
+"
+"The 'truncateTo' key causes the resulting string to be truncated to the value
+"'truncateTo' maps to. A '<' char will be prepended.
 function! s:Path.str(...)
     let options = a:0 ? a:1 : {}
     let toReturn = ""
@@ -2237,6 +2239,13 @@ function! s:Path.str(...)
         let toReturn = shellescape(toReturn)
     endif
 
+    if has_key(options, 'truncateTo')
+        let limit = options['truncateTo']
+        if len(toReturn) > limit
+            let toReturn = "<" . strpart(toReturn, len(toReturn) - limit + 1)
+        endif
+    endif
+
     return toReturn
 endfunction
 
@@ -3133,12 +3142,7 @@ function! s:renderView()
     call cursor(line(".")+1, col("."))
 
     "draw the header line
-    let header = b:NERDTreeRoot.path.str({'format': 'UI'})
-    let wid = winwidth(0)
-    if len(header) > wid
-        let header = "<" . strpart(header, len(header) - wid + 1)
-    endif
-
+    let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
     call setline(line(".")+1, header)
     call cursor(line(".")+1, col("."))