fix: don't use trim() without checking first to see if it exists
authorGreg Hurrell <greg@hurrell.net>
Fri, 8 May 2020 19:37:19 +0000 (21:37 +0200)
committerGreg Hurrell <greg@hurrell.net>
Fri, 8 May 2020 19:37:19 +0000 (21:37 +0200)
The stock Vim that comes with macOS High Sierra doesn't have `trim()`.

autoload/pinnacle.vim

index 8031ce8d9bc974cca3d899be360bad920da9bdf4..ee55c8fd874922f6ab154b9ec70e9c1ffcbcd3b9 100644 (file)
@@ -326,6 +326,14 @@ function! pinnacle#underline(group) abort
   return pinnacle#decorate('underline', a:group)
 endfunction
 
+function! s:trim(string)
+  if exists('*trim')
+    return trim(a:string)
+  else
+    return substitute(a:string, '\v^\s+(\S*)\s+$', '\1', '')
+  endif
+endfunction
+
 ""
 " @function pinnacle#decorate
 "
@@ -354,7 +362,7 @@ function! pinnacle#decorate(style, group) abort
       let l:value = l:matches[2]
       let l:end = l:matches[3]
       for l:style in split(a:style, ',')
-        let l:trimmed=trim(l:style)
+        let l:trimmed=s:trim(l:style)
         if l:value =~# '\<' . l:trimmed . '\>'
           continue
         else