Hi,

On Sat, Apr 9, 2022 at 1:20 AM lacygoill <[email protected]> wrote:

> *Is your feature request about something that is currently impossible or
> hard to do? Please describe the problem.*
>
> It is not easy to include the value of a Vim script expression inside a
> heredoc:
>
> vim9script
> var lines =<< trim END
>
>     echo $HOME
>
> END
> echo lines
>
> ['echo $HOME']
>
>
> If we want $HOME to be evaluated, we need an extra call to a combination
> of map() and substitute():
>
> vim9script
> var lines =<< trim END
>
>     echo $HOME
>
> END
> lines->map((_, line) => line->substitute('$HOME', $HOME, ''))
> echo lines
>
> [echo /home/user]
>
>
> Which makes the code less readable, and is probably not always reliable in
> the general case (i.e. substitute() might replace tokens which we might
> want to be left alone).
>
> *Describe the solution you'd like*
>
> Extend the backtick expansion syntax which supports Vim script expressions
> (the one documented at :help E1083
> <https://vimhelp.org/editing.txt.html#E1083>) to heredocs:
>
> :e `=tempname()`
>
>    ^^          ^
>
>
> With this feature, the previous snippet could be simplified into this:
>
> vim9script
> var lines =<< trim eval END
>
>     echo `=$HOME`
>
> END
> echo lines
>
> Notice the presence of the new eval argument on the first line of the
> assigment:
>
> var lines =<< trim eval END
>
>                    ^--^
>
>
> It would be necessary to avoid breaking existing scripts. With eval, Vim
> would look for Vim script expressions to evaluate.
>
> *Describe alternatives you've considered*
>
> An alternative is to continue using an extra call to a combination of
> map() and substitute(), which – again – is less readable and less
> reliable than the proposed syntax.
>
> *Additional context*
>
> In bash, there are 2 kinds of heredocs. The ones which do not try to
> expand any parameter:
>
> cat <<'EOF'
>     echo $HOME
> EOF
>
> echo $HOME
>
>
> And the ones which do:
>
> cat <<EOF
>     echo $HOME
> EOF
>
> echo /home/user
>
>
> The difference between the 2 depends on whether the end word is quoted.
> Currently, Vim script only supports the first kind. I think it would be
> useful to support the second one too.
>
>
>
I have created PR https://github.com/vim/vim/pull/10138 with the support
for this.
I have tested this only with the legacy script. Can you try this out and
let me know if
you see any issues?

Thanks,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7mTbk5ogMv6N1CeFUkR3Dm%2BKzBG-Gq3GssE60uEOWryCA%40mail.gmail.com.

Raspunde prin e-mail lui