Skip to content

Commit

Permalink
improve action funcref handling
Browse files Browse the repository at this point in the history
Use dict key to reference instead of wrapping in funcref. This allow
nnn#action to take vimL lambdas and lua functions
  • Loading branch information
mcchrish committed Jul 30, 2021
1 parent 9de4725 commit d37eb7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions autoload/nnn.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function! s:statusline()
setlocal statusline=%#StatusLineTerm#\ nnn\ %#StatusLineTermNC#
endfunction

function! nnn#select_action(action) abort
let s:action = a:action
function! nnn#select_action(key) abort
let s:action = g:nnn#action[a:key]
" quit nnn
if has('nvim')
call feedkeys("i\<cr>")
Expand Down Expand Up @@ -78,7 +78,7 @@ function! s:eval_temp_file(opts)
endif

" Action passed is function
if (type(l:Cmd) == 2)
if (type(l:Cmd) == v:t_func)
call l:Cmd(l:names)
else
" Edit the first item.
Expand Down
6 changes: 1 addition & 5 deletions ftplugin/nnn.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ endif
let b:nnn_ftplugin = 1

for key in keys(g:nnn#action)
if type(g:nnn#action[key]) == v:t_func
exec 'tnoremap <nowait><buffer><silent> '.key.' <c-\><c-n>:<c-u>call nnn#select_action('.string(g:nnn#action[key]).')<cr>'
else
exec 'tnoremap <nowait><buffer><silent> '.key.' <c-\><c-n>:<c-u>call nnn#select_action("'.g:nnn#action[key].'")<cr>'
endif
exec 'tnoremap <nowait><buffer><silent> '.key.' <cmd>call nnn#select_action("'.substitute(key, '<', '<lt>', 'g').'")<cr>'
endfor

setlocal nospell bufhidden=wipe nobuflisted nonumber
Expand Down

0 comments on commit d37eb7a

Please sign in to comment.