Skip to content

Commit 1943c57

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 3b5d079 + 1321257 commit 1943c57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+791
-310
lines changed

runtime/doc/autocmd.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ and in a `:def` function) then {cmd} will be executed as in Vim9
7676
script. Thus this depends on where the autocmd is defined, not where it is
7777
triggered.
7878

79+
{cmd} can use a block, like with `:command`, see |:command-repl|. Example: >
80+
au BufReadPost *.xml {
81+
setlocal matchpairs+=<:>
82+
/<start
83+
}
84+
7985
Note: The ":autocmd" command can only be followed by another command when the
8086
'|' appears before {cmd}. This works: >
8187
:augroup mine | au! BufRead | augroup END

runtime/doc/eval.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11673,10 +11673,12 @@ win_gettype([{nr}]) *win_gettype()*
1167311673
Return the type of the window:
1167411674
"autocmd" autocommand window. Temporary window
1167511675
used to execute autocommands.
11676-
"popup" popup window |popup|
11677-
"preview" preview window |preview-window|
1167811676
"command" command-line window |cmdwin|
1167911677
(empty) normal window
11678+
"loclist" |location-list-window|
11679+
"popup" popup window |popup|
11680+
"preview" preview window |preview-window|
11681+
"quickfix" |quickfix-window|
1168011682
"unknown" window {nr} not found
1168111683

1168211684
When {nr} is omitted return the type of the current window.

runtime/doc/map.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim version 8.2. Last change: 2021 Jul 28
1+
*map.txt* For Vim version 8.2. Last change: 2021 Aug 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1571,7 +1571,7 @@ feature. Use the full name for new scripts.
15711571

15721572

15731573
Replacement text ~
1574-
1574+
*:command-repl*
15751575
The {repl} argument is normally one long string, possibly with "|" separated
15761576
commands. A special case is when the argument is "{", then the following
15771577
lines, up to a line starting with "}" are used and |Vim9| syntax applies.
@@ -1580,8 +1580,8 @@ Example: >
15801580
echo 'hello'
15811581
g:calledMyCommand = true
15821582
}
1583-
No nesting is supported. Using `:normal` directly does not work, you can use
1584-
it indirectly with `:execute`.
1583+
No nesting is supported, inline functions cannot be used. Using `:normal`
1584+
directly does not work, you can use it indirectly with `:execute`.
15851585

15861586
The replacement text {repl} for a user defined command is scanned for special
15871587
escape sequences, using <...> notation. Escape sequences are replaced with

src/Make_mvc.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ SODIUM = no
395395

396396
!if "$(SODIUM)" != "no"
397397
SOD_INC = /I "$(SODIUM)\include"
398-
SOD_DEFS = -DFEAT_SODIUM
398+
SOD_DEFS = -DHAVE_SODIUM
399399
SOD_LIB = $(SOD_LIB)\libsodium.lib
400400
!endif
401401

src/autocmd.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static int au_need_clean = FALSE; // need to delete marked patterns
259259

260260
static char_u *event_nr2name(event_T event);
261261
static int au_get_grouparg(char_u **argp);
262-
static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group);
262+
static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group, int flags);
263263
static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap);
264264
static void auto_next_pat(AutoPatCmd *apc, int stop_at_last);
265265
static int au_find_group(char_u *name);
@@ -616,7 +616,7 @@ free_all_autocmds(void)
616616

617617
for (current_augroup = -1; current_augroup < augroups.ga_len;
618618
++current_augroup)
619-
do_autocmd((char_u *)"", TRUE);
619+
do_autocmd(NULL, (char_u *)"", TRUE);
620620

621621
for (i = 0; i < augroups.ga_len; ++i)
622622
{
@@ -824,20 +824,23 @@ au_event_restore(char_u *old_ei)
824824
* :autocmd * *.c show all autocommands for *.c files.
825825
*
826826
* Mostly a {group} argument can optionally appear before <event>.
827+
* "eap" can be NULL.
827828
*/
828829
void
829-
do_autocmd(char_u *arg_in, int forceit)
830+
do_autocmd(exarg_T *eap, char_u *arg_in, int forceit)
830831
{
831832
char_u *arg = arg_in;
832833
char_u *pat;
833834
char_u *envpat = NULL;
834835
char_u *cmd;
836+
int cmd_need_free = FALSE;
835837
event_T event;
836-
int need_free = FALSE;
838+
char_u *tofree = NULL;
837839
int nested = FALSE;
838840
int once = FALSE;
839841
int group;
840842
int i;
843+
int flags = 0;
841844

842845
if (*arg == '|')
843846
{
@@ -936,10 +939,14 @@ do_autocmd(char_u *arg_in, int forceit)
936939
*/
937940
if (*cmd != NUL)
938941
{
942+
if (eap != NULL)
943+
// Read a {} block if it follows.
944+
cmd = may_get_cmd_block(eap, cmd, &tofree, &flags);
945+
939946
cmd = expand_sfile(cmd);
940947
if (cmd == NULL) // some error
941948
return;
942-
need_free = TRUE;
949+
cmd_need_free = TRUE;
943950
}
944951
}
945952

@@ -963,19 +970,20 @@ do_autocmd(char_u *arg_in, int forceit)
963970
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
964971
event = (event_T)((int)event + 1))
965972
if (do_autocmd_event(event, pat,
966-
once, nested, cmd, forceit, group) == FAIL)
973+
once, nested, cmd, forceit, group, flags) == FAIL)
967974
break;
968975
}
969976
else
970977
{
971978
while (*arg && *arg != '|' && !VIM_ISWHITE(*arg))
972979
if (do_autocmd_event(event_name2nr(arg, &arg), pat,
973-
once, nested, cmd, forceit, group) == FAIL)
980+
once, nested, cmd, forceit, group, flags) == FAIL)
974981
break;
975982
}
976983

977-
if (need_free)
984+
if (cmd_need_free)
978985
vim_free(cmd);
986+
vim_free(tofree);
979987
vim_free(envpat);
980988
}
981989

@@ -1025,7 +1033,8 @@ do_autocmd_event(
10251033
int nested,
10261034
char_u *cmd,
10271035
int forceit,
1028-
int group)
1036+
int group,
1037+
int flags)
10291038
{
10301039
AutoPat *ap;
10311040
AutoPat **prev_ap;
@@ -1252,6 +1261,8 @@ do_autocmd_event(
12521261
return FAIL;
12531262
ac->cmd = vim_strsave(cmd);
12541263
ac->script_ctx = current_sctx;
1264+
if (flags & UC_VIM9)
1265+
ac->script_ctx.sc_version = SCRIPT_VERSION_VIM9;
12551266
#ifdef FEAT_EVAL
12561267
ac->script_ctx.sc_lnum += SOURCING_LNUM;
12571268
#endif

src/errors.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,17 @@ EXTERN char e_string_or_blob_required_for_argument_nr[]
628628
EXTERN char e_string_or_list_required_for_argument_nr[]
629629
INIT(= N_("E1222: String or List required for argument %d"));
630630
EXTERN char e_string_or_dict_required_for_argument_nr[]
631-
INIT(= N_("E1223: String or List required for argument %d"));
632-
EXTERN char e_string_or_number_or_list_required_for_argument_nr[]
633-
INIT(= N_("E1224: String or List required for argument %d"));
634-
EXTERN char e_string_or_list_or_dict_required_for_argument_nr[]
635-
INIT(= N_("E1225: String or List required for argument %d"));
631+
INIT(= N_("E1223: String or Dictionary required for argument %d"));
632+
EXTERN char e_string_number_or_list_required_for_argument_nr[]
633+
INIT(= N_("E1224: String, Number or List required for argument %d"));
634+
EXTERN char e_string_list_or_dict_required_for_argument_nr[]
635+
INIT(= N_("E1225: String, List or Dictionary required for argument %d"));
636636
EXTERN char e_list_or_blob_required_for_argument_nr[]
637-
INIT(= N_("E1226: String or List required for argument %d"));
637+
INIT(= N_("E1226: List or Blob required for argument %d"));
638638
EXTERN char e_list_or_dict_required_for_argument_nr[]
639639
INIT(= N_("E1227: List or Dictionary required for argument %d"));
640-
EXTERN char e_list_or_dict_or_blob_required_for_argument_nr[]
641-
INIT(= N_("E1228: List or Dictionary or Blob required for argument %d"));
640+
EXTERN char e_list_dict_or_blob_required_for_argument_nr[]
641+
INIT(= N_("E1228: List, Dictionary or Blob required for argument %d"));
642642
EXTERN char e_expected_dictionary_for_using_key_str_but_got_str[]
643643
INIT(= N_("E1229: Expected dictionary for using key \"%s\", but got %s"));
644644
EXTERN char e_encryption_sodium_mlock_failed[]

src/eval.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,11 @@ tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
15151515
char_u *s;
15161516
int failed = FALSE;
15171517

1518-
// Can't do anything with a Funcref, Dict, v:true on the right.
1518+
// Can't do anything with a Funcref or Dict on the right.
1519+
// v:true and friends only work with "..=".
15191520
if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT
1520-
&& tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)
1521+
&& ((tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)
1522+
|| *op == '.'))
15211523
{
15221524
switch (tv1->v_type)
15231525
{

src/evalbuffer.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ f_append(typval_T *argvars, typval_T *rettv)
287287
}
288288

289289
/*
290-
* "appendbufline(buf, lnum, string/list)" function
290+
* Set or append lines to a buffer.
291291
*/
292-
void
293-
f_appendbufline(typval_T *argvars, typval_T *rettv)
292+
static void
293+
buf_set_append_line(typval_T *argvars, typval_T *rettv, int append)
294294
{
295295
linenr_T lnum;
296296
buf_T *buf;
@@ -307,10 +307,19 @@ f_appendbufline(typval_T *argvars, typval_T *rettv)
307307
else
308308
{
309309
lnum = tv_get_lnum_buf(&argvars[1], buf);
310-
set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv);
310+
set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
311311
}
312312
}
313313

314+
/*
315+
* "appendbufline(buf, lnum, string/list)" function
316+
*/
317+
void
318+
f_appendbufline(typval_T *argvars, typval_T *rettv)
319+
{
320+
buf_set_append_line(argvars, rettv, TRUE);
321+
}
322+
314323
/*
315324
* "bufadd(expr)" function
316325
*/
@@ -837,23 +846,7 @@ f_getline(typval_T *argvars, typval_T *rettv)
837846
void
838847
f_setbufline(typval_T *argvars, typval_T *rettv)
839848
{
840-
linenr_T lnum;
841-
buf_T *buf;
842-
843-
if (in_vim9script()
844-
&& (check_for_buffer_arg(argvars, 0) == FAIL
845-
|| check_for_lnum_arg(argvars, 1) == FAIL
846-
|| check_for_string_or_number_or_list_arg(argvars, 2) == FAIL))
847-
return;
848-
849-
buf = tv_get_buf(&argvars[0], FALSE);
850-
if (buf == NULL)
851-
rettv->vval.v_number = 1; // FAIL
852-
else
853-
{
854-
lnum = tv_get_lnum_buf(&argvars[1], buf);
855-
set_buffer_lines(buf, lnum, FALSE, &argvars[2], rettv);
856-
}
849+
buf_set_append_line(argvars, rettv, FALSE);
857850
}
858851

859852
/*

src/evalfunc.c

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static void f_line2byte(typval_T *argvars, typval_T *rettv);
9898
#ifdef FEAT_LUA
9999
static void f_luaeval(typval_T *argvars, typval_T *rettv);
100100
#endif
101-
static void f_maparg(typval_T *argvars, typval_T *rettv);
102-
static void f_mapcheck(typval_T *argvars, typval_T *rettv);
103101
static void f_match(typval_T *argvars, typval_T *rettv);
104102
static void f_matchend(typval_T *argvars, typval_T *rettv);
105103
static void f_matchlist(typval_T *argvars, typval_T *rettv);
@@ -932,17 +930,29 @@ ret_first_arg(int argcount, type_T **argtypes)
932930
if (argcount > 0)
933931
return argtypes[0];
934932
return &t_void;
933+
}
934+
static type_T *
935+
ret_repeat(int argcount, type_T **argtypes)
936+
{
937+
if (argcount == 0)
938+
return &t_any;
939+
if (argtypes[0] == &t_number)
940+
return &t_string;
941+
return argtypes[0];
935942
}
936943
// for map(): returns first argument but item type may differ
937944
static type_T *
938-
ret_first_cont(int argcount UNUSED, type_T **argtypes)
945+
ret_first_cont(int argcount, type_T **argtypes)
939946
{
940-
if (argtypes[0]->tt_type == VAR_LIST)
941-
return &t_list_any;
942-
if (argtypes[0]->tt_type == VAR_DICT)
943-
return &t_dict_any;
944-
if (argtypes[0]->tt_type == VAR_BLOB)
945-
return argtypes[0];
947+
if (argcount > 0)
948+
{
949+
if (argtypes[0]->tt_type == VAR_LIST)
950+
return &t_list_any;
951+
if (argtypes[0]->tt_type == VAR_DICT)
952+
return &t_dict_any;
953+
if (argtypes[0]->tt_type == VAR_BLOB)
954+
return argtypes[0];
955+
}
946956
return &t_any;
947957
}
948958

@@ -982,9 +992,9 @@ ret_argv(int argcount, type_T **argtypes UNUSED)
982992
}
983993

984994
static type_T *
985-
ret_remove(int argcount UNUSED, type_T **argtypes)
995+
ret_remove(int argcount, type_T **argtypes)
986996
{
987-
if (argtypes != NULL)
997+
if (argcount > 0)
988998
{
989999
if (argtypes[0]->tt_type == VAR_LIST
9901000
|| argtypes[0]->tt_type == VAR_DICT)
@@ -1815,7 +1825,7 @@ static funcentry_T global_functions[] =
18151825
{"rename", 2, 2, FEARG_1, arg2_string,
18161826
ret_number_bool, f_rename},
18171827
{"repeat", 2, 2, FEARG_1, arg2_repeat,
1818-
ret_first_arg, f_repeat},
1828+
ret_repeat, f_repeat},
18191829
{"resolve", 1, 1, FEARG_1, arg1_string,
18201830
ret_string, f_resolve},
18211831
{"reverse", 1, 1, FEARG_1, arg1_list_or_blob,
@@ -2441,6 +2451,7 @@ internal_func_get_argcount(int idx, int *argcount, int *min_argcount)
24412451
* Call the "f_retfunc" function to obtain the return type of function "idx".
24422452
* "argtypes" is the list of argument types or NULL when there are no
24432453
* arguments.
2454+
* "argcount" may be less than the actual count when only getting the type.
24442455
*/
24452456
type_T *
24462457
internal_func_ret_type(int idx, int argcount, type_T **argtypes)
@@ -6769,40 +6780,6 @@ f_luaeval(typval_T *argvars, typval_T *rettv)
67696780
}
67706781
#endif
67716782

6772-
/*
6773-
* "maparg()" function
6774-
*/
6775-
static void
6776-
f_maparg(typval_T *argvars, typval_T *rettv)
6777-
{
6778-
if (in_vim9script()
6779-
&& (check_for_string_arg(argvars, 0) == FAIL
6780-
|| check_for_opt_string_arg(argvars, 1) == FAIL
6781-
|| (argvars[1].v_type != VAR_UNKNOWN
6782-
&& (check_for_opt_bool_arg(argvars, 2) == FAIL
6783-
|| (argvars[2].v_type != VAR_UNKNOWN
6784-
&& check_for_opt_bool_arg(argvars, 3) == FAIL)))))
6785-
return;
6786-
6787-
get_maparg(argvars, rettv, TRUE);
6788-
}
6789-
6790-
/*
6791-
* "mapcheck()" function
6792-
*/
6793-
static void
6794-
f_mapcheck(typval_T *argvars, typval_T *rettv)
6795-
{
6796-
if (in_vim9script()
6797-
&& (check_for_string_arg(argvars, 0) == FAIL
6798-
|| check_for_opt_string_arg(argvars, 1) == FAIL
6799-
|| (argvars[1].v_type != VAR_UNKNOWN
6800-
&& check_for_opt_bool_arg(argvars, 2) == FAIL)))
6801-
return;
6802-
6803-
get_maparg(argvars, rettv, FALSE);
6804-
}
6805-
68066783
typedef enum
68076784
{
68086785
MATCH_END, // matchend()

src/evalwindow.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,12 @@ f_win_gettype(typval_T *argvars, typval_T *rettv)
953953
else if (wp == curwin && cmdwin_type != 0)
954954
rettv->vval.v_string = vim_strsave((char_u *)"command");
955955
#endif
956+
#ifdef FEAT_QUICKFIX
957+
else if (bt_quickfix(wp->w_buffer))
958+
rettv->vval.v_string = vim_strsave((char_u *)
959+
(wp->w_llist_ref != NULL ? "loclist" : "quickfix"));
960+
#endif
961+
956962
}
957963

958964
/*

0 commit comments

Comments
 (0)