detect optimization; boosted line count to 20

This commit is contained in:
Reed Esau
2014-01-15 09:00:22 -07:00
parent 78fa058b84
commit ffebe64a88
3 changed files with 12 additions and 10 deletions

View File

@@ -240,14 +240,14 @@ reasons) the textwidth will still be set by this plugin.
### Detect via sampling
If no modeline with a textwidth is found, _pencil_ will sample the initial
lines from the file looking for excessively-long lines.
lines from the file, looking for those excessively-long.
There are two settings you can add to your `.vimrc` to tweak this behavior.
The maximum number of lines to sample from the start of the file:
```vim
let g:pencil#softDetectSample = 10
let g:pencil#softDetectSample = 20
```
Set that value to `0` to disable detection via line sampling.

View File

@@ -17,21 +17,23 @@ let s:WRAP_MODE_SOFT = 2
" Wrap-mode detector
" Scan lines at end and beginning of file to determine the wrap mode.
" Modelines has priority over long lines found.
function! s:detect_mode() abort
function! s:detect_wrap_mode() abort
let b:max_textwidth = -1 " assume no relevant modeline
call s:doModelines()
if b:max_textwidth == 0
" modeline(s) found only with zero textwidth, so it's soft wrapped
return s:WRAP_MODE_SOFT
endif
if b:max_textwidth > 0
" modelines(s) found with positive textwidth, so hard line breaks
return s:WRAP_MODE_HARD
endif
if b:max_textwidth == 0 || g:pencil#wrapModeDefault ==# 'soft'
" modeline(s) found only with zero textwidth, so it's soft line wrap
" or, the user wants to default to soft line wrap
return s:WRAP_MODE_SOFT
endif
" attempt to rule out soft line wrap
" scan initial lines in an attempt to detect long lines
for l:line in getline(1, g:pencil#softDetectSample)
if len(l:line) > g:pencil#softDetectThreshold
@@ -83,7 +85,7 @@ function! pencil#init(...) abort
let b:wrap_mode = s:WRAP_MODE_DEFAULT
else
" this can return s:WRAP_MODE_ for soft, hard or default
let b:wrap_mode = s:detect_mode()
let b:wrap_mode = s:detect_wrap_mode()
endif
" translate default(-1) to soft(1) or hard(2) or off(0)

View File

@@ -45,7 +45,7 @@ if !exists('g:pencil#softDetectSample')
" if no modeline, read as many as this many lines at
" start of file in attempt to detect at least one line
" whose byte count exceeds g:pencil#softDetectThreshold
let g:pencil#softDetectSample = 10
let g:pencil#softDetectSample = 20
endif
if !exists('g:pencil#softDetectThreshold')