From 8f7ccdc5e95302223c516a0113f5af7e075dc041 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 4 Mar 2020 20:56:22 +0000 Subject: [PATCH] Refactor the "s:LoadArgCount()" function (#3025) * Refactor the "s:LoadArgCount()" function Previously, this function would always set "v:errmsg" on the first call with a given function. This is because autoloaded functions are not defined on the first call. A number of improvements have been made: - a useless local function ("l:Function") is removed - the "execute()" builtin captures the output, instead of ":redir" - a ":try" block handles the case where a function is not defined - a useless ":if" is removed since ":redir" always defines the var - confusing quoting is re-written (remove double "'" chars) Fixes: #3021 --- autoload/ale/util.vim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 99cd856a..8d166625 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -336,15 +336,11 @@ function! ale#util#GetMatches(lines, patterns) abort endfunction function! s:LoadArgCount(function) abort - let l:Function = a:function - - redir => l:output - silent! function Function - redir END - - if !exists('l:output') + try + let l:output = execute('function a:function') + catch /E123/ return 0 - endif + endtry let l:match = matchstr(split(l:output, "\n")[0], '\v\([^)]+\)')[1:-2] let l:arg_list = filter(split(l:match, ', '), 'v:val isnot# ''...''')