skywind3000/asyncrun.vim

-post function calling fails if function has character # in name

Closed this issue · 5 comments

If I define two commands with AsyncRun like this:

function! g:Cmd_func()
  echom 'post Cmd_func called'
endfun

function! g:mycmd#cmd_func()
  echom 'post mycmd#cmd_func called'
endfun

function! g:mycmd#cmd_args(...)
  echom 'args: '.join(a:000, ' ')
  return join(a:000, ' ')
endfun

command! -bar -nargs=? MyCmdOk
      \ echom 'start MyCmdOk'
      \| execute 'AsyncRun -post='.fnameescape('call g:Cmd_func()').' '.mycmd#cmd_args(<f-args>)
      \| echom 'end MyCmdOk'


command! -bar -nargs=? MyCmdErr
      \ echom 'start MyCmdErr'
      \| execute 'AsyncRun -post='.fnameescape('call g:mycmd#cmd_func()').' '.mycmd#cmd_args(<f-args>)
      \| echom 'end MyCmdErr'

And try them so:

:so %
:MyCmdOk rg -w foo . 
:MyCmdErr rg -w foo . 

Then I get the following error:

start MyCmdOk
args: rg -w foo .
end MyCmdOk
post Cmd_func called
start MyCmdErr
args: rg -w foo .
end MyCmdErr
Error detected while processing function AsyncRun_Job_OnTimer[19]..<SNR>100_AsyncRun_Job_OnFinish:
line   38:
E107: Missing parentheses: g:mycmd\#cmd_func()

Verison:

NVIM v0.8.0-1210-gd367ed9b2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az177-603

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"

change:

mycmd#cmd_args

to

mycmd\#cmd_args
mycmd\#cmd_args

It looks weird and quite inconvenient. Why can't you escape properly inside the command or asyncrun#run()?

change:
mycmd#cmd_args
to
mycmd#cmd_args

You meant probably mycmd\#cmd_func not cmd_args but it doesn't work either. Instead of

E107: Missing parentheses: g:mycmd\#cmd_func()

I get:

E107: Missing parentheses: g:mycmd\\#cmd_func()

Could it be a neovim issue like this: vim/vim#6613 ?
In my case, number in function name doesn't cause error.

# has special meaning as alternate file, see :h expand

you can try asyncrun#run function as well:

call asyncrun#run('', {'post': 'call g:mycmd#cmd_func()'}, 'my command')

It will not require escaping.

Thank you, it works 👍

call asyncrun#run('<bang>',{'post':'call g:mycmd#cmd_func()'}, mycmd#cmd_args('<f-args>'))