diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 14:20:00 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 14:24:38 +1300 |
commit | e316ef5df7c70fb67a07886b48c95d36a4e8c984 (patch) | |
tree | fbf9451d6c9a977d3e0ada052e7c2f63cdd495de /vim/plugin | |
parent | Rename variable and autocmd to use plugin prefix (diff) | |
download | dotfiles-e316ef5df7c70fb67a07886b48c95d36a4e8c984.tar.gz dotfiles-e316ef5df7c70fb67a07886b48c95d36a4e8c984.zip |
Refactor plugin function for dependency injection
Pass the filename to check and the size limit into the function directly
from the autocmd hook.
Improve commenting and spacing as we go.
Diffstat (limited to 'vim/plugin')
-rw-r--r-- | vim/plugin/bigfile.vim | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index 962d7153..82d1a7dd 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -14,24 +14,32 @@ if has('eval') && has('autocmd') endif " Declare function for turning off slow options - function! s:BigFileMeasures() - let l:file = expand('<afile>') - if getfsize(l:file) > g:bigfile_size - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - if exists('&synmaxcol') - setlocal synmaxcol=256 - endif + function! s:BigFileOptions(name, size) + + " Don't do anything if the file is under the threshold + if getfsize(a:name) <= a:size + return + endif + + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile endif + + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') + setlocal synmaxcol=256 + endif + endfunction " Define autocmd for calling to check filesize augroup bigfile_options_bufreadpre autocmd! - autocmd BufReadPre * call s:BigFileMeasures() + autocmd BufReadPre * call s:BigFileOptions(expand('<afile>'), g:bigfile_size) augroup end + endif |