From 0972cda24374350207a2bb00af6f7746df911b15 Mon Sep 17 00:00:00 2001 From: hav4ik Date: Wed, 25 Apr 2018 03:04:18 +0300 Subject: [PATCH] Fixed bug 'unknown function strcharpart' for older versions of Vim --- lib/nerdtree/bookmark.vim | 12 ++++++++---- lib/nerdtree/path.vim | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index 307211b..482afa2 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -287,10 +287,14 @@ function! s:Bookmark.str() let pathStr = self.path.str({'format': 'UI'}) if strdisplaywidth(pathStr) > pathStrMaxLen - while strdisplaywidth(pathStr) > pathStrMaxLen && strchars(pathStr) > 0 - let pathStr = strcharpart(pathStr, 1) - endwhile - let pathStr = '<' . pathStr + if exists("*strcharpart") + while strdisplaywidth(pathStr) > pathStrMaxLen && strchars(pathStr) > 0 + let pathStr = strcharpart(pathStr, 1) + endwhile + let pathStr = '<' . pathStr + else + let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen) + endif endif return '>' . self.name . ' ' . pathStr endfunction diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index f436d36..f51310a 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -720,9 +720,13 @@ function! s:Path.str(...) if has_key(options, 'truncateTo') let limit = options['truncateTo'] if strdisplaywidth(toReturn) > limit-1 - while strdisplaywidth(toReturn) > limit-1 && strchars(toReturn) > 0 - let toReturn = strcharpart(toReturn, 1) - endwhile + if exists("*strcharpart") + while strdisplaywidth(toReturn) > limit-1 && strchars(toReturn) > 0 + let toReturn = strcharpart(toReturn, 1) + endwhile + else + let toReturn = toReturn[(len(toReturn)-limit+1):] + endif if len(split(toReturn, '/')) > 1 let toReturn = '