From 850e9475090a6b121c42306185c9f3ae76d2f245 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Tue, 13 Feb 2018 10:02:54 +0000 Subject: [PATCH] Add backward compatibility for lambda. Lambdas were introduced in Vim 7.4.2044. --- autoload/gitgutter/utility.vim | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 29ea097..7cdbb7c 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -106,10 +106,17 @@ function! gitgutter#utility#set_repo_path(bufnr) abort let cmd = gitgutter#utility#cd_cmd(a:bufnr, g:gitgutter_git_executable.' ls-files --error-unmatch --full-name '.gitgutter#utility#shellescape(s:filename(a:bufnr))) if g:gitgutter_async && gitgutter#async#available() - call gitgutter#async#execute(cmd, a:bufnr, { - \ 'out': {bufnr, path -> gitgutter#utility#setbufvar(bufnr, 'path', s:strip_trailing_new_line(path))}, - \ 'err': {bufnr -> gitgutter#utility#setbufvar(bufnr, 'path', -2)}, - \ }) + if has('lambda') + call gitgutter#async#execute(cmd, a:bufnr, { + \ 'out': {bufnr, path -> gitgutter#utility#setbufvar(bufnr, 'path', s:strip_trailing_new_line(path))}, + \ 'err': {bufnr -> gitgutter#utility#setbufvar(bufnr, 'path', -2)}, + \ }) + else + call gitgutter#async#execute(cmd, a:bufnr, { + \ 'out': function('s:set_path'), + \ 'err': function('s:set_path', [-2]) + \ }) + endif else let path = gitgutter#utility#system(cmd) if v:shell_error @@ -120,6 +127,15 @@ function! gitgutter#utility#set_repo_path(bufnr) abort endif endfunction +function! s:set_path(bufnr, path) + if a:bufnr == -2 + let [bufnr, path] = [a:path, a:bufnr] + call gitgutter#utility#setbufvar(bufnr, 'path', path) + else + call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(a:path)) + endif +endfunction + function! gitgutter#utility#cd_cmd(bufnr, cmd) abort return 'cd '.s:dir(a:bufnr).' && '.a:cmd endfunction