Skip to content

Commit 4c6d904

Browse files
committed
patch 8.1.1705: using ~{} for a literal dict is not nice
Problem: Using ~{} for a literal dict is not nice. Solution: Use #{} instead.
1 parent 69a5b86 commit 4c6d904

6 files changed

Lines changed: 182 additions & 181 deletions

File tree

runtime/doc/eval.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Dictionary An associative, unordered array: Each entry has a key and a
6060
value. |Dictionary|
6161
Examples:
6262
{'blue': "#0000ff", 'red': "#ff0000"}
63-
~{blue: "#0000ff", red: "#ff0000"}
63+
#{blue: "#0000ff", red: "#ff0000"}
6464

6565
Funcref A reference to a function |Funcref|.
6666
Example: function("strlen")
@@ -482,11 +482,11 @@ entry. Note that the String '04' and the Number 04 are different, since the
482482
Number will be converted to the String '4'. The empty string can also be used
483483
as a key.
484484
*literal-Dict*
485-
To avoid having to put quotes around every key the ~{} form can be used. This
485+
To avoid having to put quotes around every key the #{} form can be used. This
486486
does require the key to consist only of ASCII letters, digits, '-' and '_'.
487487
Example: >
488-
let mydict = ~{zero: 0, one_key: 1, two-key: 2, 333: 3}
489-
Note that 333 here is the string "333". Empty keys are not possible here.
488+
let mydict = #{zero: 0, one_key: 1, two-key: 2, 333: 3}
489+
Note that 333 here is the string "333". Empty keys are not possible with #{}.
490490

491491
A value can be any expression. Using a Dictionary for a value creates a
492492
nested Dictionary: >

runtime/doc/popup.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ DETAILS *popup-function-details*
178178
popup_atcursor({what}, {options}) *popup_atcursor()*
179179
Show the {what} above the cursor, and close it when the cursor
180180
moves. This works like: >
181-
call popup_create({what}, ~{
181+
call popup_create({what}, #{
182182
\ pos: 'botleft',
183183
\ line: 'cursor-1',
184184
\ col: 'cursor',
@@ -191,7 +191,7 @@ popup_beval({what}, {options}) *popup_beval()*
191191
Show the {what} above the position from 'ballooneval' and
192192
close it when the mouse moves. This works like: >
193193
let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
194-
call popup_create({what}, ~{
194+
call popup_create({what}, #{
195195
\ pos: 'botleft',
196196
\ line: pos.row - 1,
197197
\ col: pos.col,
@@ -240,7 +240,7 @@ popup_create({what}, {options}) *popup_create()*
240240

241241
popup_dialog({what}, {options}) *popup_dialog()*
242242
Just like |popup_create()| but with these default options: >
243-
call popup_create({what}, ~{
243+
call popup_create({what}, #{
244244
\ pos: 'center',
245245
\ zindex: 200,
246246
\ drag: 1,
@@ -249,7 +249,7 @@ popup_dialog({what}, {options}) *popup_dialog()*
249249
\})
250250
< Use {options} to change the properties. E.g. add a 'filter'
251251
option with value 'popup_filter_yesno'. Example: >
252-
call popup_create('do you want to quit (Yes/no)?', ~{
252+
call popup_create('do you want to quit (Yes/no)?', #{
253253
\ filter: 'popup_filter_yesno',
254254
\ callback: 'QuitCallback',
255255
\ })
@@ -356,7 +356,7 @@ popup_menu({what}, {options}) *popup_menu()*
356356
items with cursorkeys, and close it an item is selected with
357357
Space or Enter. {what} should have multiple lines to make this
358358
useful. This works like: >
359-
call popup_create({what}, ~{
359+
call popup_create({what}, #{
360360
\ pos: 'center',
361361
\ zindex: 200,
362362
\ drag: 1,
@@ -391,7 +391,7 @@ popup_move({id}, {options}) *popup_move()*
391391
popup_notification({what}, {options}) *popup_notification()*
392392
Show the {what} for 3 seconds at the top of the Vim window.
393393
This works like: >
394-
call popup_create({what}, ~{
394+
call popup_create({what}, #{
395395
\ line: 1,
396396
\ col: 10,
397397
\ minwidth: 20,
@@ -732,15 +732,15 @@ Prompt the user to press y/Y or n/N: >
732732
endif
733733
endfunc
734734
735-
call popup_dialog('Continue? y/n', ~{
735+
call popup_dialog('Continue? y/n', #{
736736
\ filter: 'popup_filter_yesno',
737737
\ callback: 'MyDialogHandler',
738738
\ })
739739
<
740740
*popup_menu-shortcut-example*
741741
Extend popup_filter_menu() with shortcut keys: >
742742
743-
call popup_menu(['Save', 'Cancel', 'Discard'], ~{
743+
call popup_menu(['Save', 'Cancel', 'Discard'], #{
744744
\ filter: 'MyMenuFilter',
745745
\ callback: 'MyMenuHandler',
746746
\ })
@@ -781,7 +781,7 @@ Example for using a popup window for 'ballooneval': >
781781
endif
782782
call popup_close(s:winid)
783783
endif
784-
let s:winid = popup_beval(v:beval_text, ~{mousemoved: 'word'})
784+
let s:winid = popup_beval(v:beval_text, #{mousemoved: 'word'})
785785
let s:last_text = v:beval_text
786786
return ''
787787
endfunc
@@ -812,7 +812,7 @@ this example simulated with a timer callback: >
812812
endfunc
813813
814814
func ShowPopup(id)
815-
let s:winid = popup_beval(s:balloonText, ~{mousemoved: 'word'})
815+
let s:winid = popup_beval(s:balloonText, #{mousemoved: 'word'})
816816
endfunc
817817
<
818818

src/eval.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,7 +4392,7 @@ eval6(
43924392
* (expression) nested expression
43934393
* [expr, expr] List
43944394
* {key: val, key: val} Dictionary
4395-
* ~{key: val, key: val} Dictionary with literal keys
4395+
* #{key: val, key: val} Dictionary with literal keys
43964396
*
43974397
* Also handle:
43984398
* ! in front logical NOT
@@ -4577,9 +4577,9 @@ eval7(
45774577
break;
45784578

45794579
/*
4580-
* Dictionary: ~{key: val, key: val}
4580+
* Dictionary: #{key: val, key: val}
45814581
*/
4582-
case '~': if ((*arg)[1] == '{')
4582+
case '#': if ((*arg)[1] == '{')
45834583
{
45844584
++*arg;
45854585
ret = dict_get_tv(arg, rettv, evaluate, TRUE);
@@ -7963,8 +7963,7 @@ find_var_ht(char_u *name, char_u **varname)
79637963
*varname = name + 2;
79647964
if (*name == 'g') /* global variable */
79657965
return &globvarht;
7966-
/* There must be no ':' or '#' in the rest of the name, unless g: is used
7967-
*/
7966+
// There must be no ':' or '#' in the rest of the name, unless g: is used
79687967
if (vim_strchr(name + 2, ':') != NULL
79697968
|| vim_strchr(name + 2, AUTOLOAD_CHAR) != NULL)
79707969
return NULL;

src/testdir/test_listdict.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func Test_dict_func_remove_in_use()
281281
endfunc
282282

283283
func Test_dict_literal_keys()
284-
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, ~{one: 1, two2: 2, 3three: 3, 44: 4},)
284+
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)
285285

286286
" why *{} cannot be used
287287
let blue = 'blue'

0 commit comments

Comments
 (0)