Permalink
Browse files

decompose the statusline long line warning function

  • Loading branch information...
1 parent ace4aec commit d47587e263fcf664e724843524cb0c4780a61c26 @scrooloose committed Jun 28, 2009
Showing with 27 additions and 27 deletions.
  1. +27 −27 vimrc
View
@@ -112,44 +112,44 @@ autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
"no &textwidth is set)
"
"return '' if no long lines
-"return '[#x,my,$z] if multiple long lines are found, were x is the number of
-"long lines, y is the median length of the long lines and z is the length of
-"the longest line
-"return '[$x]' if one long line is found, where x is the length of the line
+"return '[#x,my,$z] if long lines are found, were x is the number of long
+"lines, y is the median length of the long lines and z is the length of the
+"longest line
function! StatuslineLongLineWarning()
if !exists("b:statusline_long_line_warning")
- let threshold = (&tw ? &tw : 80)
- let spaces = repeat(" ", &ts)
-
- let long_line_lens = []
-
- let i = 1
- while i <= line("$")
- let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
- if len > threshold
- call add(long_line_lens, len)
- endif
- let i += 1
- endwhile
+ let long_line_lens = s:LongLines()
if len(long_line_lens) > 0
- let b:statusline_long_line_warning = "["
-
- if len(long_line_lens) > 1
- let b:statusline_long_line_warning .=
- \ '#' . len(long_line_lens) . "," .
- \ 'm' . s:Median(long_line_lens) . ","
- endif
-
- let b:statusline_long_line_warning .= '$' .
- \ max(long_line_lens) . "]"
+ let b:statusline_long_line_warning = "[" .
+ \ '#' . len(long_line_lens) . "," .
+ \ 'm' . s:Median(long_line_lens) . "," .
+ \ '$' . max(long_line_lens) . "]"
else
let b:statusline_long_line_warning = ""
endif
endif
return b:statusline_long_line_warning
endfunction
+"return a list containing the lengths of the long lines in this buffer
+function! s:LongLines()
+ let threshold = (&tw ? &tw : 80)
+ let spaces = repeat(" ", &ts)
+
+ let long_line_lens = []
+
+ let i = 1
+ while i <= line("$")
+ let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
+ if len > threshold
+ call add(long_line_lens, len)
+ endif
+ let i += 1
+ endwhile
+
+ return long_line_lens
+endfunction
+
"find the median of the given array of numbers
function! s:Median(nums)
let nums = sort(a:nums)

0 comments on commit d47587e

Please sign in to comment.