vim-lf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 492e5d434f9e40d6d7544745541bd511fba7e5e7
parent 95b2ebdcac195ae71fc6f0dc84c1a269d5b33b86
Author: Doron Behar <doron.behar@gmail.com>
Date:   Wed, 10 Jun 2020 14:28:27 +0200

Improve Neovim functionality

Courtesy of @doronbehar.

Diffstat:
Mautoload/lf.vim | 100++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 51 insertions(+), 49 deletions(-)

diff --git a/autoload/lf.vim b/autoload/lf.vim @@ -7,55 +7,57 @@ function! lf#LF(path, edit_cmd) let oldguioptions = &guioptions let s:oldlaststatus = &laststatus let s:choice_file_path = tempname() - let s:edit_cmd = a:edit_cmd - try - if has('nvim') - set laststatus=0 - let currentPath = expand(a:path) - let lfCallback = { 'name': 'lf', 'edit_cmd': a:edit_cmd } - function! lfCallback.on_exit(job_id, code, event) - if a:code == 0 - if exists(":Bclose") - silent! Bclose! - else - echoerr "Failed to close buffer, make sure the `rbgrouleff/bclose.vim` plugin is installed" - endif + let s:mostLFArgs = 'lf -selection-path=' . s:choice_file_path . ' ' + " TODO: Test if currentPath needs shell quoting... + let currentPath = expand(a:path) + if has('nvim') + " For internal usage - not needed by the API + let termopen_opts = { 'edit_cmd': a:edit_cmd } + function! termopen_opts.on_exit(job_id, code, event) + if filereadable(s:choice_file_path) + for f in readfile(s:choice_file_path) + exec self.edit_cmd . ' ' . f + endfor + call delete(s:choice_file_path) + endif + if a:code == 0 + if exists(":Bclose") + silent! Bclose! # + elseif exists(":Bdelete") + silent! Bdelete! # + else + let v:errmsg = "lf.vim: Failed to close buffer lf buffer -" . + \ "No `:Bdelete` or `:Bclose` commands were found. You can implement either of them yourself, or install either of:\n" . + \ " - https://github.com/rbgrouleff/bclose.vim\n" . + \ " - https://github.com/moll/vim-bbye" + echo v:errmsg endif - try - if filereadable(s:choice_file_path) - for f in readfile(s:choice_file_path) - exec self.edit_cmd . f - endfor - call delete(s:choice_file_path) - endif - endtry - let &laststatus=s:oldlaststatus - endfunction - enew - call termopen('lf -selection-path=' . s:choice_file_path . ' "' . currentPath . '"', lfCallback) - startinsert - else - function! s:EditCallback() - if filereadable(s:choice_file_path) - for f in readfile(s:choice_file_path) - exec s:edit_cmd . f - filetype detect - endfor - 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 currentPath = expand(a:path) - echom 'lf -selection-path=' . s:choice_file_path . ' "' . currentPath . '"' - let buf = term_start('lf -selection-path=' . s:choice_file_path . ' "' . currentPath . '"', #{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()' - endif - endtry + endif + endfunction + enew + " We want Lf to quit after it saves the selections + call termopen(s:mostLFArgs . '-command "map <right> push :open<enter>:quit<enter>" "' . currentPath . '"', termopen_opts) + startinsert + else + let s:edit_cmd = a:edit_cmd + function! s:EditCallback() + if filereadable(s:choice_file_path) + for f in readfile(s:choice_file_path) + exec s:edit_cmd . f + filetype detect + endfor + 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(s:mostLFArgs . currentPath . '"', #{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()' + endif let &guioptions=oldguioptions endfunction