mhinz / neovim-remote

:ok_hand: Support for --remote and friends.
MIT License
1.75k stars 83 forks source link

Add option for calling functions #120

Closed cstyles closed 5 years ago

cstyles commented 5 years ago

This PR adds the ability to call a function directly. For example:

$ myvar=$(python3 nvr/nvr.py -f getreg)

or conversely:

$ python3 nvr/nvr.py -f setreg \" "$myvar"

Currently, you'd have to use something like -c 'call setreg(...)' which can be tricky to get working with quotes and backslashes and whatnot.

mhinz commented 5 years ago

You can achieve the same with:

$ myvar=$(python3 nvr/nvr.py --remote-expr 'getreg()')
$ python3 nvr/nvr.py --remote-expr "setreg('\"', '$myvar')"

The quoting here isn't too complicated and I'm reluctant to add yet another way to do something similar only slightly more convenient. We have enough options already. :) Especially since this new way would only work for single function calls.

But I understand the quoting problem if you have mixed ' and ". It gets a bit more complicated then:

$ setreg() { nvr --remote-expr "setreg('\"', '$(echo "$@" | sed "s|'|''|g")')"; }
$ setreg $myar

Would it be good enough if this example gets added to the FAQ?

cstyles commented 5 years ago

Would it be good enough if this example gets added to the FAQ?

Yeah, I suppose I can get by with --remote-expr. Thanks for taking the time to help me out!