question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors when using do_action with custom vim function

See original GitHub issue

With vimfiler I can use the following to open ranger file manager at the current directory:

        if executable('ranger')
            nmap <buffer>ge <Plug>(vimfiler_cd_vim_current_dir)
                        \ <C-u>:call <SID>TmuxSplitCmd('ranger')<CR>
        endif

where the TmuxSplitCmd function is:

function! s:TmuxSplitCmd(cmd)
    if empty('$TMUX')
        return
    endif
   silent execute '!tmux split-window -p 30 -c '. getcwd() . ' ' . a:cmd
endfunction

I’m trying to do the same with defx:

    if s:is_linux && executable('ranger')
        nmap <silent><buffer><expr>ge defx#do_action('change_vim_cwd',
                    \ "call <SID>TmuxSplitCmd('ranger')")
    endif

but I get the following error


Error detected while processing function defx#_do_action[6]..defx#util#rpcrequest[15].._defx_do_action[1]..remote#define#request:
line    2:
error caught in request handler '/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx:function:_defx_do_action [['change_vim_cwd', ["call <SNR>1_TmuxSplitCmd('ranger')"], {
'columns': 'mark:filename:type', 'auto_cd': False, 'prev_bufnr': 7, 'resume': False, 'listed': False, 'new': False, 'fnamewidth': 100, 'direction': '', 'winheight': 0, 'profile': False, 'search': '', 'buffer_name
': 'default', 'winwidth': 0, 'split': 'no', 'cursor': 22, 'toggle': False}]]':
Traceback (most recent call last):
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx/__init__.py", line 41, in do_action
    self._rplugin.do_action(args)
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx/rplugin.py", line 37, in do_action
    view.do_action(args[0], args[1], args[2])
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx/view.py", line 321, in do_action
    ret = action.do_action(self, defx, action_name, context)
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx/action.py", line 38, in do_action
    action.func(view, defx, context)
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/defx/action.py", line 74, in _change_vim_cwd
    view._vim.command(f'silent {command} {defx._cwd}')
  File "/home/pedro/.local/lib/python3.7/site-packages/pynvim/api/nvim.py", line 287, in command
    return self.request('nvim_command', string, **kwargs)
  File "/home/pedro/.local/lib/python3.7/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/home/pedro/.local/lib/python3.7/site-packages/pynvim/msgpack_rpc/session.py", line 102, in request
    raise self.error_wrapper(err)
pynvim.api.nvim.NvimError: b'Vim(call):E488: Trailing characters'
Error detected while processing function defx#_do_action[6]..defx#util#rpcrequest:
line   15:
E171: Missing :endif

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Shougocommented, Mar 21, 2019

Why don’t read the documentation?

call 						*defx-action-call*
		Call the function.
		You can get the files path as "a:context.targets".

		Action args:
			0. function name
			Note: It must be string.  You cannot use |funcref| or
			|lambda|.

		Example: >

		function! Test(context) abort
		  echomsg string(a:context.targets)
		endfunction
		nnoremap <silent><buffer><expr> f
		\ defx#do_action('call', 'Test')

		" or you can use SID hack
		function! s:Test(context) abort
		  echomsg string(a:context.targets)
		endfunction
		function! s:SID_PREFIX() abort
		  return matchstr(expand('<sfile>'),
		  \ '<SNR>\d\+_\zeSID_PREFIX$')
		endfunction
		let g:sid = s:SID_PREFIX()
  		nnoremap <silent><buffer><expr> f
  		\ defx#do_action('call', g:sid.'Test')

call action argument must be function instead of command.

0reactions
petobenscommented, Mar 21, 2019

I’m afraid I don’t follow. None of the following works:

call defx#do_action('call', ['TmuxRanger'])
call defx#call_action('TmuxRanger')
call defx#call_action('do_action', 'TmuxRanger')
Read more comments on GitHub >

github_iconTop Results From Across the Web

folding - How-to handle errors in Vim Script?
In my .vimrc file, I have the following function, which folds the licensing ... Edit: complete solution (using Bryan Ross answer).
Read more >
Execute with system function results in error of `undefined ...
There are a couple of problems here. First of all, you want to run an ex command, so you don't need the :norm!...
Read more >
custom keymap function not working after update to HEAD
local map = vim.keymap.set local function map_group(group, ... got nil stack traceback: [C]: in function 'error' vim/shared.lua: in function ...
Read more >
Act on text objects with custom functions - Vim Tips Wiki
In all cases, ultimately it is DoAction that gets called. The algorithm argument tells the user-defined function that should be called, and type ......
Read more >
coc-explorer
Install by coc.nvim command: :CocInstall coc-explorer; Configuration custom vim mapping :nnoremap <space>e :CocCommand explorer<CR>; Open explorer <space>e
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found