From 00d314196215ea25c8ad0e91d1b023d3ac87ace5 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 26 May 2017 21:21:15 +0100 Subject: Fix #577 Add an option preventing linting of large files --- autoload/ale.vim | 14 +++++++++----- autoload/ale/cursor.vim | 14 ++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'autoload') diff --git a/autoload/ale.vim b/autoload/ale.vim index 62a8bf4d..4286e4af 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -6,6 +6,13 @@ let s:lint_timer = -1 let s:queued_buffer_number = -1 let s:should_lint_file_for_buffer = {} +" Return 1 if a file is too large for ALE to handle. +function! ale#FileTooLarge() abort + let l:max = ale#Var(bufnr(''), 'maximum_file_size') + + return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0 +endfunction + " A function for checking various conditions whereby ALE just shouldn't " attempt to do anything, say if particular buffer types are open in Vim. function! ale#ShouldDoNothing() abort @@ -14,6 +21,8 @@ function! ale#ShouldDoNothing() abort return index(g:ale_filetype_blacklist, &filetype) >= 0 \ || (exists('*getcmdwintype') && !empty(getcmdwintype())) \ || ale#util#InSandbox() + \ || !ale#Var(bufnr(''), 'enabled') + \ || ale#FileTooLarge() endfunction " (delay, [linting_flag]) @@ -29,11 +38,6 @@ function! ale#Queue(delay, ...) abort throw "linting_flag must be either '' or 'lint_file'" endif - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 572880a9..86391d5c 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -66,11 +66,6 @@ function! s:StopCursorTimer() abort endfunction function! ale#cursor#EchoCursorWarning(...) abort - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif @@ -98,11 +93,6 @@ let s:cursor_timer = -1 let s:last_pos = [0, 0, 0] function! ale#cursor#EchoCursorWarningWithDelay() abort - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif @@ -122,6 +112,10 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort endfunction function! ale#cursor#ShowCursorDetail() abort + if ale#ShouldDoNothing() + return + endif + " Only echo the warnings in normal mode, otherwise we will get problems. if mode() !=# 'n' return -- cgit v1.2.3