mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-15 05:13:47 -05:00
detect optimization; boosted line count to 20
This commit is contained in:
@@ -240,14 +240,14 @@ reasons) the textwidth will still be set by this plugin.
|
|||||||
### Detect via sampling
|
### Detect via sampling
|
||||||
|
|
||||||
If no modeline with a textwidth is found, _pencil_ will sample the initial
|
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.
|
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:
|
The maximum number of lines to sample from the start of the file:
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:pencil#softDetectSample = 10
|
let g:pencil#softDetectSample = 20
|
||||||
```
|
```
|
||||||
|
|
||||||
Set that value to `0` to disable detection via line sampling.
|
Set that value to `0` to disable detection via line sampling.
|
||||||
|
|||||||
@@ -17,21 +17,23 @@ let s:WRAP_MODE_SOFT = 2
|
|||||||
" Wrap-mode detector
|
" Wrap-mode detector
|
||||||
" Scan lines at end and beginning of file to determine the wrap mode.
|
" Scan lines at end and beginning of file to determine the wrap mode.
|
||||||
" Modelines has priority over long lines found.
|
" 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
|
let b:max_textwidth = -1 " assume no relevant modeline
|
||||||
call s:doModelines()
|
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
|
if b:max_textwidth > 0
|
||||||
" modelines(s) found with positive textwidth, so hard line breaks
|
" modelines(s) found with positive textwidth, so hard line breaks
|
||||||
return s:WRAP_MODE_HARD
|
return s:WRAP_MODE_HARD
|
||||||
endif
|
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
|
" scan initial lines in an attempt to detect long lines
|
||||||
for l:line in getline(1, g:pencil#softDetectSample)
|
for l:line in getline(1, g:pencil#softDetectSample)
|
||||||
if len(l:line) > g:pencil#softDetectThreshold
|
if len(l:line) > g:pencil#softDetectThreshold
|
||||||
@@ -83,7 +85,7 @@ function! pencil#init(...) abort
|
|||||||
let b:wrap_mode = s:WRAP_MODE_DEFAULT
|
let b:wrap_mode = s:WRAP_MODE_DEFAULT
|
||||||
else
|
else
|
||||||
" this can return s:WRAP_MODE_ for soft, hard or default
|
" 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
|
endif
|
||||||
|
|
||||||
" translate default(-1) to soft(1) or hard(2) or off(0)
|
" translate default(-1) to soft(1) or hard(2) or off(0)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ if !exists('g:pencil#softDetectSample')
|
|||||||
" if no modeline, read as many as this many lines at
|
" if no modeline, read as many as this many lines at
|
||||||
" start of file in attempt to detect at least one line
|
" start of file in attempt to detect at least one line
|
||||||
" whose byte count exceeds g:pencil#softDetectThreshold
|
" whose byte count exceeds g:pencil#softDetectThreshold
|
||||||
let g:pencil#softDetectSample = 10
|
let g:pencil#softDetectSample = 20
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists('g:pencil#softDetectThreshold')
|
if !exists('g:pencil#softDetectThreshold')
|
||||||
|
|||||||
Reference in New Issue
Block a user