From e316ef5df7c70fb67a07886b48c95d36a4e8c984 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:20:00 +1300 Subject: 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. --- vim/plugin/bigfile.vim | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'vim/plugin') 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('') - 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(''), g:bigfile_size) augroup end + endif -- cgit v1.2.3