commit 696f1377bc7052afc15e72ce3f17f35130a035d2
parent 516f48be9487aed536bdd3dd935cc485c10d821d
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Sun, 14 Jun 2020 11:58:09 +0200
Style & variable naming
Diffstat:
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/autoload/lf.vim b/autoload/lf.vim
@@ -3,19 +3,18 @@ if exists('g:loaded_lf_autoload')
endif
let g:loaded_lf_autoload = 1
-function! lf#LF(path, edit_cmd, extra_lf_args)
- " To be used inside functions defined here
+function! lf#LF(path, edit_cmd, user_args)
+ " Save the edit cmd in a script variable to make it accessible in the callback
let s:edit_cmd = a:edit_cmd
" To revert back guioptions after changing them for Vim
let oldguioptions = &guioptions
- " To save what files were chosen by lf
+ " To temporarily save what files were chosen by lf
let s:choice_file_path = tempname()
- let s:lfArgs = [
- \ 'lf', '-selection-path=' . s:choice_file_path,
- \] + a:extra_lf_args + [
- \ fnameescape(expand(a:path))
- \]
- " Quote it in a shell safe manner
+
+ let s:lf_cmd = ['lf', '-selection-path=' . s:choice_file_path,]
+ \ + a:user_args
+ \ + [fnameescape(expand(a:path))]
+
if has('nvim')
" To be passed down to termopen
let termopen_opts = { }
@@ -51,7 +50,7 @@ function! lf#LF(path, edit_cmd, extra_lf_args)
endfunction
enew
" We want Lf to quit after it saves the selections
- call termopen(s:lfArgs, termopen_opts)
+ call termopen(s:lf_cmd, termopen_opts)
startinsert
else
function! s:EditCallback()
@@ -63,12 +62,9 @@ function! lf#LF(path, edit_cmd, extra_lf_args)
call delete(s:choice_file_path)
endif
redraw!
- " reset the filetype to fix the issue that happens
- " when opening lf on VimEnter (with `vim .`)
- " filetype detect
endfunction
set guioptions+=! " Make it work with MacVim
- let buf = term_start(join(s:lfArgs, ' '), #{hidden: 1, term_finish: 'close'})
+ let buf = term_start(join(s:lf_cmd, ' '), #{hidden: 1, term_finish: 'close'})
let winid = popup_dialog(buf, #{minwidth: 150, minheight: 20, highlight: 'Normal'})
let bufn = winbufnr(winid)
exe 'autocmd! BufWinLeave <buffer='.bufn.'> call s:EditCallback()'