aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:05:50 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-05 22:05:50 +1200
commit0353b63f885d2dc3f4c0f203e8d56a33436ecff6 (patch)
treeb866a4df9c87416ebd99123f946337b0ba1615a0
parent4aa756a6545e5646926c82fb9982253455b02d4c (diff)
parentcf9353c613dc7634f047f98290c3d620dfbfed8e (diff)
downloadvim-big-file-options-master.tar.gz
vim-big-file-options-master.zip
Merge branch 'release/v3.0.0'HEADv3.0.0master
* release/v3.0.0: Set filetype to blank string, not NONE Add a blank line Refactor to use deferred/dynamic hooks Remove repeated function definitions!
-rw-r--r--VERSION2
-rw-r--r--autoload/big_file_options.vim97
-rw-r--r--plugin/big_file_options.vim4
3 files changed, 24 insertions, 79 deletions
diff --git a/VERSION b/VERSION
index 7ec1d6d..4a36342 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.0
+3.0.0
diff --git a/autoload/big_file_options.vim b/autoload/big_file_options.vim
index 4d65bd4..381b0f7 100644
--- a/autoload/big_file_options.vim
+++ b/autoload/big_file_options.vim
@@ -1,48 +1,44 @@
" If we can use filesize to detect the big file early, we should
-function! big_file_options#CheckPre(filename) abort
+function! big_file_options#() abort
- " Try and get filesize, bail out if we can't
- let size = getfsize(a:filename)
+ " Try and get filesize; if we can't, defer another check attempt until after
+ " everything's been loaded
+ let size = getfsize(bufname('%'))
if size == -1
+ autocmd big_file_options BufReadPost,StdinReadPost <buffer>
+ \ call s:CheckPost()
+ \|autocmd! big_file_options BufReadPost,StdinReadPost <buffer>
return
endif
" Set the buffer's big flag to whether the file is verifiably outsize
- let b:big_file_options_big = size == -2 || size > s:Limit()
+ let b:big_file_options_big = size > s:Limit() || size == -2
" If we found it's a big file, call the early options set
if b:big_file_options_big
call s:SetPre()
+ autocmd big_file_options BufReadPost,StdinReadPost <buffer>
+ \ call s:SetPost()
+ \|autocmd! big_file_options BufReadPost,StdinReadPost <buffer>
endif
endfunction
" If it's still indeterminate (stdin read?), try to check the buffer size
" itself
-function! big_file_options#CheckPost() abort
-
- " The BufReadPre hook couldn't tell how big the file was; we'll examine it
- " now it's loaded into the buffer instead
- if !exists('b:big_file_options_big')
-
- " Test buffer size, bail if that doesn't work either
- let size = line2byte(line('$') + 1)
- if size == -1
- return
- endif
-
- " Flag the buffer's oversize status, if it's positive, we'll catch up and
- " run the early options set now
- let b:big_file_options_big = size > s:Limit()
- if b:big_file_options_big
- call s:SetPre()
- endif
+function! s:CheckPost() abort
+ " Test buffer size, bail if that doesn't work either
+ let size = line2byte(line('$') + 1)
+ if size == -1
+ return
endif
- " If the buffer size is verifiably over the threshold, run the late options
- " set
+ " Flag the buffer's oversize status; if it's positive, we'll catch up and
+ " run the early options set now
+ let b:big_file_options_big = size > s:Limit()
if b:big_file_options_big
+ call s:SetPre()
call s:SetPost()
endif
@@ -71,13 +67,14 @@ function! s:SetPre() abort
setlocal nomodifiable
setlocal readonly
endif
+
endfunction
" These options need to be set later, after the buffer has loaded
function! s:SetPost() abort
" Force filetype off
- setlocal filetype=NONE
+ setlocal filetype=
" Disable syntax highlighting if configured
let syntax = get(g:, 'big_file_options_syntax', 0)
@@ -95,53 +92,3 @@ function! s:SetPost() abort
echomsg 'Big file detected, set appropriate options'
endfunction
-
-" If we can use filesize to detect the big file early, we should
-function! big_file_options#CheckPre(filename) abort
-
- " Try and get filesize, bail out if we can't
- let size = getfsize(a:filename)
- if size == -1
- return
- endif
-
- " Set the buffer's big flag to whether the file is verifiably outsize
- let b:big_file_options_big = size == -2 || size > s:Limit()
-
- " If we found it's a big file, call the early options set
- if b:big_file_options_big
- call s:SetPre()
- endif
-
-endfunction
-
-" If it's still indeterminate (stdin read?), try to check the buffer size
-" itself
-function! big_file_options#CheckPost() abort
-
- " The BufReadPre hook couldn't tell how big the file was; we'll examine it
- " now it's loaded into the buffer instead
- if !exists('b:big_file_options_big')
-
- " Test buffer size, bail if that doesn't work either
- let size = line2byte(line('$') + 1)
- if size == -1
- return
- endif
-
- " Flag the buffer's oversize status, if it's positive, we'll catch up and
- " run the early options set now
- let b:big_file_options_big = size > s:Limit()
- if b:big_file_options_big
- call s:SetPre()
- endif
-
- endif
-
- " If the buffer size is verifiably over the threshold, run the late options
- " set
- if b:big_file_options_big
- call s:SetPost()
- endif
-
-endfunction
diff --git a/plugin/big_file_options.vim b/plugin/big_file_options.vim
index 89b65c2..e02e935 100644
--- a/plugin/big_file_options.vim
+++ b/plugin/big_file_options.vim
@@ -14,7 +14,5 @@ let loaded_big_file_options = 1
augroup big_file_options
autocmd!
autocmd BufReadPre,StdinReadPre *
- \ call big_file_options#CheckPre(expand('<afile>'))
- autocmd BufReadPost,StdinReadPost *
- \ call big_file_options#CheckPost()
+ \ call big_file_options#()
augroup end