Permalink
Browse files

move the path string truncation into Path#str()

  • Loading branch information...
scrooloose committed Nov 22, 2009
1 parent a713a86 commit f34986d30fa0e97810d9ebce6128df7ad4fe82cf
Showing with 12 additions and 8 deletions.
  1. +12 −8 plugin/NERD_tree.vim
View
@@ -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("."))

0 comments on commit f34986d

Please sign in to comment.