Skip to content

Commit a05c728

Browse files
Cimbalintpeters
authored andcommitted
Use a fallback for trim() in vim versions without it (#106)
See #104
1 parent f5726c4 commit a05c728

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

plugin/better-whitespace.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ let s:diff_cmd='diff -a --unchanged-group-format="" --old-group-format="" --new-
9999

100100
" Section: Actual work functions
101101

102+
" Function to implement trim() fro vim < 8.0.1630
103+
if v:version > 800 || (v:version == 800 && has('patch-1630'))
104+
function! s:Trim(s)
105+
return trim(a:s)
106+
endfunction
107+
else
108+
function! s:Trim(s)
109+
return substitute(a:s, '^\s*\(.\{-}\)\s*$', '\1', '')
110+
endfunction
111+
endif
112+
102113
" query per-buffer setting for whitespace highlighting
103114
function! s:ShouldHighlight()
104115
" Guess from the filetype if a) not locally decided, b) globally enabled, c) there is enough information
@@ -239,7 +250,7 @@ function! s:ChangedLines()
239250
redir => l:better_whitespace_changes_list
240251
silent! echo system(s:diff_cmd.' '.shellescape(expand('%')).' -', join(getline(1, line('$')), "\n") . "\n")
241252
redir END
242-
return map(split(trim(l:better_whitespace_changes_list), ' '), 'split(v:val, ",")')
253+
return map(split(s:Trim(l:better_whitespace_changes_list), ' '), 'split(v:val, ",")')
243254
endif
244255
return []
245256
endfunction

0 commit comments

Comments
 (0)