skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

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

Closed mattia72 closed 1 year ago

mattia72 commented 1 year ago

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"
skywind3000 commented 1 year ago

change:

mycmd#cmd_args

to

mycmd\#cmd_args
wookayin commented 1 year ago
mycmd\#cmd_args

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

mattia72 commented 1 year ago

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: https://github.com/vim/vim/issues/6613 ? In my case, number in function name doesn't cause error.

skywind3000 commented 1 year ago

# 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.

mattia72 commented 1 year ago

Thank you, it works 👍

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