Skip to content

Commit

Permalink
move the path string truncation into Path#str()
Browse files Browse the repository at this point in the history
  • Loading branch information
marty committed Nov 22, 2009
1 parent a713a86 commit f34986d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions plugin/NERD_tree.vim
Expand Up @@ -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 = ""
Expand All @@ -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

Expand Down Expand Up @@ -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("."))

Expand Down

0 comments on commit f34986d

Please sign in to comment.