Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VimL heredoc (<<HERE) for user commands #7638

Open
ZyX-I opened this issue Nov 26, 2017 · 2 comments
Open

VimL heredoc (<<HERE) for user commands #7638

ZyX-I opened this issue Nov 26, 2017 · 2 comments
Labels
Milestone

Comments

@ZyX-I
Copy link
Contributor

ZyX-I commented Nov 26, 2017

Currently if one wants to emulate :python with user commands he will be stuck at implementing << EOF: there is no way for user commands to have multiline input, except for not adding -bar and using :execute 'MyCmd' "multiline\nstring". On the other hand it is impossible to just add command -herestring and expect it to work fine: not unless somebody wants to state that user commands must be defined not prior to its usage, but prior to its appearance (i.e. prior to the first function definition which happens to have that command inside) and can’t switch definition after that (or give up on having proper parser). Thus the suggestion: knowing that python << EOF\n{multiline string}\nEOF yields just the same result as execute 'python' "{multiline string}" I am suggesting to add :here command used like that:

here MyCmd << EOF
foo
EOF

and

if 1
  here! MyCmd << EOF
    First non-empty line appears as having zero indent when bang is used.
   And this appears as an error for it being less indented then the first one.
  EOF
endif

. The only thing which :here command will do is calling MyCmd with multiline string in <args>, universally and without requiring any additional support in MyCmd definition.

Additionally :here may accept range and forward it to MyCmd. Also :here! is good for built-in :python itself.

@justinmk justinmk added enhancement feature request vimscript labels Nov 26, 2017
@justinmk justinmk added this to the todo milestone Nov 26, 2017
@justinmk justinmk changed the title Add some <<HERE argument suitable for user commands VimL heredoc (<<HERE) for user commands Mar 6, 2019
@justinmk justinmk added the complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md label Mar 6, 2019
@justinmk
Copy link
Member

justinmk commented Mar 6, 2019

Implementation notes:

  • Currently the :{lua,python,...} <<EOF logic is hacked into ex_function.
  • That could be extended to support user commands, and would call out to provider#foo#Call() in that case (via eval_call_provider)
  • Add a flag to :command, e.g. :command -heredoc ...
  • Introduce an explicit builtin :here (?) command: :here Foo <<EOF (as suggested in the original issue description)

todo:

  • does the "closed" scope (local variables) need to be passed to the heredoc block?
  • can a heredoc block return a value?

@justinmk justinmk added complexity:non-trivial and removed complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md labels Mar 6, 2019
@blueyed
Copy link
Contributor

blueyed commented Jun 18, 2019

Vim 8.1.1354 has it for :let (vim/vim@f5842c5).

@blueyed blueyed added the vim-patch See https://neovim.io/doc/user/dev_vimpatch.html label Jun 18, 2019
@dundargoc dundargoc added has:vim-patch issue is fixed in vim and patch needs to be ported and removed vim-patch See https://neovim.io/doc/user/dev_vimpatch.html labels Dec 21, 2021
@zeertzjq zeertzjq removed the has:vim-patch issue is fixed in vim and patch needs to be ported label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants