[vim/vim] WIP: Add support for evaluating expression in a heredoc (PR #10138)

49 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Apr 9, 2022, 8:22:38 PM4/9/22
to vim/vim, Subscribed

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/10138

Commit Summary

  • bb43803 Add support for evaluating expression in a heredoc

File Changes

(5 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138@github.com>

codecov[bot]

unread,
Apr 9, 2022, 8:30:29 PM4/9/22
to vim/vim, Subscribed

Codecov Report

Merging #10138 (bb43803) into master (6013d00) will decrease coverage by 79.96%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@

##           master   #10138       +/-   ##

===========================================

- Coverage   81.97%    2.00%   -79.97%     

===========================================

  Files         167      152       -15     

  Lines      187863   170890    -16973     

  Branches    42368    39537     -2831     

===========================================

- Hits       153999     3432   -150567     

- Misses      21517   166763   +145246     

+ Partials    12347      695    -11652     
Flag Coverage Δ
huge-clang-none ?
huge-gcc-none ?
huge-gcc-testgui ?
huge-gcc-unittests 2.00% <0.00%> (-0.01%) ⬇️
linux 2.00% <0.00%> (-81.97%) ⬇️
mingw-x64-HUGE ?
mingw-x64-HUGE-gui ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/evalvars.c 4.46% <0.00%> (-86.87%) ⬇️
src/userfunc.c 0.13% <0.00%> (-89.55%) ⬇️
src/libvterm/src/rect.h 0.00% <0.00%> (-96.78%) ⬇️
src/sha256.c 0.00% <0.00%> (-96.45%) ⬇️
src/libvterm/src/parser.c 0.00% <0.00%> (-95.91%) ⬇️
src/gui_gtk_f.c 0.00% <0.00%> (-94.72%) ⬇️
src/crypt_zip.c 0.00% <0.00%> (-94.12%) ⬇️
src/vim9compile.c 0.00% <0.00%> (-92.42%) ⬇️
src/debugger.c 0.00% <0.00%> (-92.23%) ⬇️
src/eval.c 0.10% <0.00%> (-92.18%) ⬇️
... and 155 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6013d00...bb43803. Read the comment docs.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1094148293@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 2:04:49 AM4/10/22
to vim/vim, Push

@yegappan pushed 1 commit.

  • 77b0f0f Handle some corner conditions and add Vim9 test


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9585191318@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 2:27:04 AM4/10/22
to vim/vim, Push

@yegappan pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9585254557@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 11:03:06 AM4/10/22
to vim/vim, Push

@yegappan pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9587077080@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 11:03:28 AM4/10/22
to vim/vim, Push

@yegappan pushed 2 commits.

  • 14cf32c Add support for evaluating expression in a heredoc
  • c604d73 Add additional tests

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9587078574@github.com>

Bram Moolenaar

unread,
Apr 10, 2022, 2:25:25 PM4/10/22
to vim/vim, Subscribed

Let's leave this open a few days to allow for comments.

I'm not sure if we should use =expr or just expr. Compared to other places in Vim =expr would be more common,
but compared to any other language expr would be preferred.

The help is not clear: can the expression span multiple lines? So I could use

some literal text `=
 expr line
  expr line
` more literal text


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1094341777@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 2:56:15 PM4/10/22
to vim_dev, reply+ACY5DGGPE2RE7LZCFT...@reply.github.com, vim/vim, Subscribed
Hi Bram,

On Sun, Apr 10, 2022 at 11:25 AM Bram Moolenaar <vim-dev...@256bit.org> wrote:

Let's leave this open a few days to allow for comments.

I'm not sure if we should use =expr or just expr. Compared to other places in Vim =expr would be more common,
but compared to any other language expr would be preferred.

The help is not clear: can the expression span multiple lines? So I could use


An expression must be within a single line and cannot span multiple lines. I will update the help to reflect this.

Regards,
Yegappan

vim-dev ML

unread,
Apr 10, 2022, 2:56:32 PM4/10/22
to vim/vim, vim-dev ML, Your activity

Hi Bram,

On Sun, Apr 10, 2022 at 11:25 AM Bram Moolenaar ***@***.***>

wrote:

> Let's leave this open a few days to allow for comments.
>
> I'm not sure if we should use =expr or just expr. Compared to other
> places in Vim =expr would be more common,
> but compared to any other language expr would be preferred.
>
> The help is not clear: can the expression span multiple lines? So I could
> use
>

An expression must be within a single line and cannot span multiple lines.
I will update the help to reflect this.

Regards,
Yegappan


> some literal text `=
> expr line
> expr line
> ` more literal text
>
>
>


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1094348117@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 3:01:46 PM4/10/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • ff5ab03 Update help and add additional tests

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9588001564@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 3:02:15 PM4/10/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 2 commits.

  • bc7f02a Add support for evaluating expression in a heredoc
  • 654e39d Update help and add additional tests

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9588003417@github.com>

Yegappan Lakshmanan

unread,
Apr 10, 2022, 10:33:13 PM4/10/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9589665766@github.com>

lacygoill

unread,
Apr 10, 2022, 11:53:38 PM4/10/22
to vim/vim, vim-dev ML, Comment

I'm not sure if we should use =expr or just expr. Compared to other places in Vim =expr would be more common,
but compared to any other language expr would be preferred.

Yes, I suggested backtick equal to be as consistent as possible with the existing syntax, but in practice I suspect it's hardly ever used. Dropping the equal sign might make it easier for people coming from other languages to assimilate this new syntax.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1094515559@github.com>

Yegappan Lakshmanan

unread,
Apr 11, 2022, 12:52:55 AM4/11/22
to vim_dev, reply+ACY5DGELPFMSWGMSXH...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi Bram,

On Sun, Apr 10, 2022 at 8:53 PM lacygoill <vim-dev...@256bit.org> wrote:

I'm not sure if we should use =expr or just expr. Compared to other places in Vim =expr would be more common,
but compared to any other language expr would be preferred.

Yes, I suggested backtick equal to be as consistent as possible with the existing syntax, but in practice I suspect it's hardly ever used. Dropping the equal sign might make it easier for people coming from other languages to assimilate this new syntax.



Should we support using only backtick for expanding the Vim expression in a heredoc?

Thanks,
Yegappan
 

vim-dev ML

unread,
Apr 11, 2022, 12:53:12 AM4/11/22
to vim/vim, vim-dev ML, Your activity

Hi Bram,


On Sun, Apr 10, 2022 at 8:53 PM lacygoill ***@***.***> wrote:

> I'm not sure if we should use =expr or just expr. Compared to other places
> in Vim =expr would be more common,
> but compared to any other language expr would be preferred.
>
> Yes, I suggested backtick equal to be as consistent as possible with the
> existing syntax, but in practice I suspect it's hardly ever used. Dropping
> the equal sign might make it easier for people coming from other languages
> to assimilate this new syntax.
>
>
>
Should we support using only backtick for expanding the Vim expression in a
heredoc?

Thanks,
Yegappan


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1094549514@github.com>

Bram Moolenaar

unread,
Apr 11, 2022, 6:00:19 AM4/11/22
to vim...@googlegroups.com, Yegappan Lakshmanan, reply+ACY5DGGPE2RE7LZCFT...@reply.github.com

> On Sun, Apr 10, 2022 at 11:25 AM Bram Moolenaar <vim-dev...@256bit.org>
> wrote:
>
> > Let's leave this open a few days to allow for comments.
> >
> > I'm not sure if we should use =expr or just expr. Compared to other
> > places in Vim =expr would be more common,
> > but compared to any other language expr would be preferred.
> >
> > The help is not clear: can the expression span multiple lines? So I could
> > use
>
> An expression must be within a single line and cannot span multiple lines.
> I will update the help to reflect this.

I suppose that will cover most use cases. I expect most use will just
be a variable or something like "shellescape(bufname(bnr))".

--
ARTHUR: Be quiet! I order you to shut up.
OLD WOMAN: Order, eh -- who does he think he is?
ARTHUR: I am your king!
OLD WOMAN: Well, I didn't vote for you.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

vim-dev ML

unread,
Apr 11, 2022, 6:00:36 AM4/11/22
to vim/vim, vim-dev ML, Your activity


> On Sun, Apr 10, 2022 at 11:25 AM Bram Moolenaar ***@***.***>

> wrote:
>
> > Let's leave this open a few days to allow for comments.
> >
> > I'm not sure if we should use =expr or just expr. Compared to other
> > places in Vim =expr would be more common,
> > but compared to any other language expr would be preferred.
> >
> > The help is not clear: can the expression span multiple lines? So I could
> > use
>
> An expression must be within a single line and cannot span multiple lines.
> I will update the help to reflect this.

I suppose that will cover most use cases. I expect most use will just
be a variable or something like "shellescape(bufname(bnr))".

--
ARTHUR: Be quiet! I order you to shut up.
OLD WOMAN: Order, eh -- who does he think he is?
ARTHUR: I am your king!
OLD WOMAN: Well, I didn't vote for you.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\

/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1094847344@github.com>

Yegappan Lakshmanan

unread,
Apr 11, 2022, 10:29:56 AM4/11/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 98ea5a8 Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9595152361@github.com>

Yegappan Lakshmanan

unread,
Apr 12, 2022, 11:47:26 PM4/12/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 6b707d2 Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9612405157@github.com>

Bram Moolenaar

unread,
Apr 13, 2022, 6:30:02 AM4/13/22
to vim/vim, vim-dev ML, Comment

The help says "If the expression evaluation fails, then it is replaced with an empty string."
I think it's better to treat an error like an error and not silently use an empty string.
If you would have an assignment with a faling expression, it would also fail.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1097884724@github.com>

Yegappan Lakshmanan

unread,
Apr 13, 2022, 11:20:30 AM4/13/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 991a2e6 If an expression evaluation fails, then fail the variable assignment

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9618087752@github.com>

Yegappan Lakshmanan

unread,
Apr 13, 2022, 11:21:03 AM4/13/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 2 commits.

  • c6602f1 Add support for evaluating expression in a heredoc
  • 50fd646 If an expression evaluation fails, then fail the variable assignment

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9618093616@github.com>

Yegappan Lakshmanan

unread,
Apr 13, 2022, 11:28:49 AM4/13/22
to vim/vim, vim-dev ML, Comment

The help says "If the expression evaluation fails, then it is replaced with an empty string."
I think it's better to treat an error like an error and not silently use an empty string.
If you would have an assignment with a faling expression, it would also fail.

I have updated the PR to fail the assignment if an expression evaluation fails.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1098191942@github.com>

Yegappan Lakshmanan

unread,
Apr 13, 2022, 9:00:56 PM4/13/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9622073227@github.com>

Yegappan Lakshmanan

unread,
Apr 14, 2022, 11:44:05 AM4/14/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • b4125fd Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9628350696@github.com>

Yegappan Lakshmanan

unread,
Apr 15, 2022, 9:56:35 AM4/15/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • a43a70f Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9635816832@github.com>

Yegappan Lakshmanan

unread,
Apr 15, 2022, 11:53:45 PM4/15/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 5e57b51 Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9639611535@github.com>

Yegappan Lakshmanan

unread,
Apr 16, 2022, 9:57:31 PM4/16/22
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 3d84a66 Add support for evaluating expression in a heredoc

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/push/9643602167@github.com>

Yegappan Lakshmanan

unread,
Apr 16, 2022, 10:04:13 PM4/16/22
to vim_dev, nor...@github.com, vim/vim, vim-dev ML, Push
Hi Bram,

On Sat, Apr 16, 2022 at 6:57 PM Yegappan Lakshmanan <vim-dev...@256bit.org> wrote:

@yegappan pushed 1 commit.

  • 3d84a66 Add support for evaluating expression in a heredoc


If there are no other comments on this PR, then this is ready to be included.

Regards,
Yegappan

Bram Moolenaar

unread,
Apr 17, 2022, 6:51:31 AM4/17/22
to vim/vim, vim-dev ML, Comment

I have not seen comments objecting to using the "=expr" form, including the equal sign. So I guess it should be OK that way.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1100851891@github.com>

Bram Moolenaar

unread,
Apr 17, 2022, 7:24:05 AM4/17/22
to vim/vim, vim-dev ML, Comment

When adding another test I found that this doesn't work:

var x = 'X'
  code =<< eval trim END
    let b = `=x`
  END

This will require more work, since "x" would have to be evaluated at runtime. Let's do that in a followup change.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1100856519@github.com>

Bram Moolenaar

unread,
Apr 17, 2022, 7:48:02 AM4/17/22
to vim/vim, vim-dev ML, Comment

Closed #10138 via efbfa86.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/issue_event/6444455681@github.com>

Yegappan Lakshmanan

unread,
Apr 17, 2022, 9:39:38 AM4/17/22
to vim_dev, reply+ACY5DGHSU5DJZNIWOV...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi Bram,

On Sun, Apr 17, 2022 at 3:51 AM Bram Moolenaar <vim-dev...@256bit.org> wrote:

I have not seen comments objecting to using the "=expr" form, including the equal sign. So I guess it should be OK that way.



If you think using a single backquote will be easier and less confusing than using "`=",
then we can still change this.

Regards,
Yegappan
 

vim-dev ML

unread,
Apr 17, 2022, 9:39:53 AM4/17/22
to vim/vim, vim-dev ML, Your activity

Hi Bram,

On Sun, Apr 17, 2022 at 3:51 AM Bram Moolenaar ***@***.***>

wrote:

> I have not seen comments objecting to using the "=expr" form, including
> the equal sign. So I guess it should be OK that way.
>
>
>
If you think using a single backquote will be easier and less confusing
than using "`=",
then we can still change this.

Regards,
Yegappan


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10138/c1100877590@github.com>

errael

unread,
Apr 17, 2022, 12:28:35 PM4/17/22
to vim/vim, vim-dev ML, Comment

I've never use vimscript, or the = that I see around occasionally. From my perspective, whatever is consistent with what I'll see in vim9script is best; :help script explains vim9. Consistency with vim9 seems paramount. IMO, if the = is required in vim9 in situations, then OK; otherwise nuke it.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1100910897@github.com>

Bram Moolenaar

unread,
Apr 17, 2022, 1:28:38 PM4/17/22
to vim...@googlegroups.com, errael

> I've never use vimscript, or the `=` that I see around occasionally.
> From my perspective, whatever is consistent with what I'll see in
> vim9script is best; `:help script` explains vim9. Consistency with
> vim9 seems paramount. IMO, if the `=` is required in vim9 in
> situations, then OK; otherwise nuke it.

Using backticks to execute an expression is a more or less wide spread
syntax. On the command line this has been used in places where
expanding $VAR is insufficient, and uses the shell to evaluate the
expression. I believe other programs also support using backticks to
expand an expression, possibly with the shell.

Later we wanted to use a Vim expression, which is where `=expr` was
introduced. I don't think any other application does this.

So we can choose here to be more similar to other applications, just
using backtics, or be consistent with what is done on the command line,
using `=expr`.

I can't really think of a reason for one or the other. One slight
advantage of using `=expr` is that backticks can be used anywhere, only
`= is special, which should be quite rare.

--
hundred-and-one symptoms of being an internet addict:
10. And even your night dreams are in HTML.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\

Shane-XB-Qian

unread,
Apr 18, 2022, 9:55:32 AM4/18/22
to vim/vim, vim-dev ML, Comment

correct the syntax highlight when with/without trim and eval as well..
// currently it is broken.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1101426989@github.com>

Shane-XB-Qian

unread,
Apr 18, 2022, 9:59:09 AM4/18/22
to vim/vim, vim-dev ML, Comment

image
image


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1101429593@github.com>

Bram Moolenaar

unread,
Apr 18, 2022, 10:38:38 AM4/18/22
to vim/vim, vim-dev ML, Comment

@cecamp for the highlighting


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10138/c1101460047@github.com>

Reply all
Reply to author
Forward
0 new messages