From 3ad8c08acc506555667a070cf83c410ac9334f1e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 19:45:54 +0800 Subject: vim-patch:8.2.4770: cannot easily mix expression and heredoc Problem: Cannot easily mix expression and heredoc. Solution: Support in heredoc. (Yegappan Lakshmanan, closes vim/vim#10138) https://github.com/vim/vim/commit/efbfa867a146fcd93fdec2435597aa4ae7f1325c Co-authored-by: Yegappan Lakshmanan --- runtime/doc/eval.txt | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'runtime/doc/eval.txt') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 351690f4df..c8eea03f5f 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2540,14 +2540,30 @@ This does NOT work: > *:let=<<* *:let-heredoc* *E990* *E991* *E172* *E221* *E1145* -:let {var-name} =<< [trim] {endmarker} +:let {var-name} =<< [trim] [eval] {endmarker} text... text... {endmarker} Set internal variable {var-name} to a |List| containing the lines of text bounded by the string - {endmarker}. The lines of text is used as a - |literal-string|. + {endmarker}. + + If "eval" is not specified, then each line of text is + used as a |literal-string|. If "eval" is specified, + then any Vim expression in the form ``={expr}`` is + evaluated and the result replaces the expression. + Example where $HOME is expanded: > + let lines =<< trim eval END + some text + See the file `=$HOME`/.vimrc + more text + END +< There can be multiple Vim expressions in a single line + but an expression cannot span multiple lines. If any + expression evaluation fails, then the assignment fails. + once the "`=" has been found {expr} and a backtick + must follow. {expr} cannot be empty. + {endmarker} must not contain white space. {endmarker} cannot start with a lower case character. The last line should end only with the {endmarker} @@ -2597,6 +2613,13 @@ text... 1 2 3 4 5 6 7 8 DATA + + let code =<< trim eval CODE + let v = `=10 + 20` + let h = "`=$HOME`" + let s = "`=Str1()` abc `=Str2()`" + let n = `=MyFunc(3, 4)` + CODE < *E121* :let {var-name} .. List the value of variable {var-name}. Multiple -- cgit From bacb5021d4eff33c67eb659fb01125b2abcacd79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 21:08:00 +0800 Subject: vim-patch:8.2.4883: string interpolation only works in heredoc Problem: String interpolation only works in heredoc. Solution: Support interpolated strings. Use syntax for heredoc consistent with strings, similar to C#. (closes vim/vim#10327) https://github.com/vim/vim/commit/2eaef106e4a7fc9dc74a7e672b5f550ec1f9786e Cherry-pick Test_Debugger_breakadd_expr() from Vim. Co-authored-by: LemonBoy --- runtime/doc/eval.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'runtime/doc/eval.txt') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index c8eea03f5f..518a190d3c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1406,6 +1406,26 @@ to be doubled. These two commands are equivalent: > if a =~ '\s*' +------------------------------------------------------------------------------ +interpolated-string *interp-string* + +$"string" interpolated string constant *expr-$quote* +$'string' interpolated literal string constant *expr-$'* + +Interpolated strings are an extension of the |string| and |literal-string|, +allowing the inclusion of Vim script expressions (see |expr1|). Any +expression returning a value can be enclosed between curly braces. The value +is converted to a string. All the text and results of the expressions +are concatenated to make a new string. + +To include an opening brace '{' or closing brace '}' in the string content +double it. + +Examples: > + let your_name = input("What's your name? ") + echo $"Hello, {your_name}!" + echo $"The square root of 9 is {sqrt(9)}" + ------------------------------------------------------------------------------ option *expr-option* *E112* *E113* -- cgit From f2a9097d764cf61b9479d7633a9738077f75f43c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 19:02:02 +0800 Subject: vim-patch:partial:d899e5112079 Update runtime files https://github.com/vim/vim/commit/d899e51120798d3fb5420abb1f19dddf3f014d05 Co-authored-by: Bram Moolenaar --- runtime/doc/eval.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'runtime/doc/eval.txt') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 518a190d3c..072d894aff 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2569,20 +2569,20 @@ text... {endmarker}. If "eval" is not specified, then each line of text is - used as a |literal-string|. If "eval" is specified, - then any Vim expression in the form ``={expr}`` is - evaluated and the result replaces the expression. + used as a |literal-string|, except that single quotes + doe not need to be doubled. + If "eval" is specified, then any Vim expression in the + form {expr} is evaluated and the result replaces the + expression, like with |interp-string|. Example where $HOME is expanded: > let lines =<< trim eval END some text - See the file `=$HOME`/.vimrc + See the file {$HOME}/.vimrc more text END < There can be multiple Vim expressions in a single line but an expression cannot span multiple lines. If any expression evaluation fails, then the assignment fails. - once the "`=" has been found {expr} and a backtick - must follow. {expr} cannot be empty. {endmarker} must not contain white space. {endmarker} cannot start with a lower case character. @@ -2635,10 +2635,10 @@ text... DATA let code =<< trim eval CODE - let v = `=10 + 20` - let h = "`=$HOME`" - let s = "`=Str1()` abc `=Str2()`" - let n = `=MyFunc(3, 4)` + let v = {10 + 20} + let h = "{$HOME}" + let s = "{Str1()} abc {Str2()}" + let n = {MyFunc(3, 4)} CODE < *E121* -- cgit From 9f1d33307270e7d013896aea6042b73d091078f5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 19:04:55 +0800 Subject: vim-patch:3f32a5f1601a Update runtime files and translations https://github.com/vim/vim/commit/3f32a5f1601ab2b0eba0caad00d4c26fb86a02a2 Co-authored-by: Bram Moolenaar --- runtime/doc/eval.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'runtime/doc/eval.txt') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 072d894aff..dd9137649d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1417,14 +1417,22 @@ allowing the inclusion of Vim script expressions (see |expr1|). Any expression returning a value can be enclosed between curly braces. The value is converted to a string. All the text and results of the expressions are concatenated to make a new string. - + *E1278* To include an opening brace '{' or closing brace '}' in the string content -double it. +double it. For double quoted strings using a backslash also works. A single +closing brace '}' will result in an error. Examples: > let your_name = input("What's your name? ") +< What's your name? Peter ~ +> + echo echo $"Hello, {your_name}!" - echo $"The square root of 9 is {sqrt(9)}" +< Hello, Peter! ~ +> + echo $"The square root of {{9}} is {sqrt(9)}" +< The square root of {9} is 3.0 ~ + ------------------------------------------------------------------------------ option *expr-option* *E112* *E113* -- cgit From 57221e0d11d1c24bc2abada7559a1d20c5090b62 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Apr 2023 19:11:29 +0800 Subject: vim-patch:b59ae59a5870 Update runtime files https://github.com/vim/vim/commit/b59ae59a58706e454ef8c78276f021b1f58466e7 Co-authored-by: Bram Moolenaar --- runtime/doc/eval.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/doc/eval.txt') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index dd9137649d..1ff6e3c360 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1407,7 +1407,7 @@ to be doubled. These two commands are equivalent: > ------------------------------------------------------------------------------ -interpolated-string *interp-string* +interpolated-string *$quote* *interpolated-string* $"string" interpolated string constant *expr-$quote* $'string' interpolated literal string constant *expr-$'* @@ -2578,10 +2578,10 @@ text... If "eval" is not specified, then each line of text is used as a |literal-string|, except that single quotes - doe not need to be doubled. + does not need to be doubled. If "eval" is specified, then any Vim expression in the form {expr} is evaluated and the result replaces the - expression, like with |interp-string|. + expression, like with |interpolated-string|. Example where $HOME is expanded: > let lines =<< trim eval END some text -- cgit