Skip to content

Commit 3b3d235

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents a1a9cc7 + 156919f commit 3b3d235

31 files changed

Lines changed: 415 additions & 141 deletions

runtime/doc/eval.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,9 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
42874287
locale locale names (as output of locale -a)
42884288
mapping mapping name
42894289
menu menus
4290+
messages |:messages| suboptions
42904291
option options
4292+
packadd optional package |pack-add| names
42914293
shellcmd Shell command
42924294
sign |:sign| suboptions
42934295
syntax syntax file names |'syntax'|

runtime/doc/map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ completion can be enabled:
12801280
-complete=locale locale names (as output of locale -a)
12811281
-complete=mapping mapping name
12821282
-complete=menu menus
1283+
-complete=messages |:messages| suboptions
12831284
-complete=option options
12841285
-complete=packadd optional package |pack-add| names
12851286
-complete=shellcmd Shell command

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ test1 \
20642064
test40 test41 test42 test43 test44 test45 test48 test49 \
20652065
test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \
20662066
test60 test64 test65 test66 test67 test68 test69 \
2067-
test70 test72 test73 test74 test75 test76 test77 test78 test79 \
2067+
test70 test72 test73 test74 test75 test77 test78 test79 \
20682068
test80 test82 test83 test84 test85 test86 test87 test88 test89 \
20692069
test90 test91 test92 test93 test94 test95 test97 test98 test99 \
20702070
test100 test101 test103 test104 test107 test108:

src/channel.c

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,39 @@ job_free(job_T *job)
44534453
}
44544454
}
44554455

4456+
static void
4457+
job_cleanup(job_T *job)
4458+
{
4459+
if (job->jv_status != JOB_ENDED)
4460+
return;
4461+
4462+
if (job->jv_exit_cb != NULL)
4463+
{
4464+
typval_T argv[3];
4465+
typval_T rettv;
4466+
int dummy;
4467+
4468+
/* invoke the exit callback; make sure the refcount is > 0 */
4469+
++job->jv_refcount;
4470+
argv[0].v_type = VAR_JOB;
4471+
argv[0].vval.v_job = job;
4472+
argv[1].v_type = VAR_NUMBER;
4473+
argv[1].vval.v_number = job->jv_exitval;
4474+
call_func(job->jv_exit_cb, (int)STRLEN(job->jv_exit_cb),
4475+
&rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE,
4476+
job->jv_exit_partial, NULL);
4477+
clear_tv(&rettv);
4478+
--job->jv_refcount;
4479+
channel_need_redraw = TRUE;
4480+
}
4481+
if (job->jv_refcount == 0)
4482+
{
4483+
/* The job was already unreferenced, now that it ended it can be
4484+
* freed. Careful: caller must not use "job" after this! */
4485+
job_free(job);
4486+
}
4487+
}
4488+
44564489
#if defined(EXITFREE) || defined(PROTO)
44574490
void
44584491
job_free_all(void)
@@ -4470,10 +4503,15 @@ job_free_all(void)
44704503
static int
44714504
job_still_useful(job_T *job)
44724505
{
4473-
return job->jv_status == JOB_STARTED
4474-
&& (job->jv_stoponexit != NULL || job->jv_exit_cb != NULL
4475-
|| (job->jv_channel != NULL
4476-
&& channel_still_useful(job->jv_channel)));
4506+
return (job->jv_stoponexit != NULL || job->jv_exit_cb != NULL
4507+
|| (job->jv_channel != NULL
4508+
&& channel_still_useful(job->jv_channel)));
4509+
}
4510+
4511+
static int
4512+
job_still_alive(job_T *job)
4513+
{
4514+
return (job->jv_status == JOB_STARTED) && job_still_useful(job);
44774515
}
44784516

44794517
/*
@@ -4487,7 +4525,7 @@ set_ref_in_job(int copyID)
44874525
typval_T tv;
44884526

44894527
for (job = first_job; job != NULL; job = job->jv_next)
4490-
if (job_still_useful(job))
4528+
if (job_still_alive(job))
44914529
{
44924530
tv.v_type = VAR_JOB;
44934531
tv.vval.v_job = job;
@@ -4503,7 +4541,7 @@ job_unref(job_T *job)
45034541
{
45044542
/* Do not free the job when it has not ended yet and there is a
45054543
* "stoponexit" flag or an exit callback. */
4506-
if (!job_still_useful(job))
4544+
if (!job_still_alive(job))
45074545
{
45084546
job_free(job);
45094547
}
@@ -4528,7 +4566,7 @@ free_unused_jobs_contents(int copyID, int mask)
45284566

45294567
for (job = first_job; job != NULL; job = job->jv_next)
45304568
if ((job->jv_copyID & mask) != (copyID & mask)
4531-
&& !job_still_useful(job))
4569+
&& !job_still_alive(job))
45324570
{
45334571
/* Free the channel and ordinary items it contains, but don't
45344572
* recurse into Lists, Dictionaries etc. */
@@ -4548,7 +4586,7 @@ free_unused_jobs(int copyID, int mask)
45484586
{
45494587
job_next = job->jv_next;
45504588
if ((job->jv_copyID & mask) != (copyID & mask)
4551-
&& !job_still_useful(job))
4589+
&& !job_still_alive(job))
45524590
{
45534591
/* Free the job struct itself. */
45544592
job_free_job(job);
@@ -4639,34 +4677,31 @@ has_pending_job(void)
46394677
job_T *job;
46404678

46414679
for (job = first_job; job != NULL; job = job->jv_next)
4642-
if (job->jv_status == JOB_STARTED && job_still_useful(job))
4680+
if (job_still_alive(job))
46434681
return TRUE;
46444682
return FALSE;
46454683
}
46464684

4685+
#define MAX_CHECK_ENDED 8
4686+
46474687
/*
46484688
* Called once in a while: check if any jobs that seem useful have ended.
46494689
*/
46504690
void
46514691
job_check_ended(void)
46524692
{
4653-
static time_t last_check = 0;
4654-
time_t now;
4655-
job_T *job;
4656-
job_T *next;
4693+
int i;
46574694

4658-
/* Only do this once in 10 seconds. */
4659-
now = time(NULL);
4660-
if (last_check + 10 < now)
4695+
for (i = 0; i < MAX_CHECK_ENDED; ++i)
46614696
{
4662-
last_check = now;
4663-
for (job = first_job; job != NULL; job = next)
4664-
{
4665-
next = job->jv_next;
4666-
if (job->jv_status == JOB_STARTED && job_still_useful(job))
4667-
job_status(job); /* may free "job" */
4668-
}
4697+
job_T *job = mch_detect_ended_job(first_job);
4698+
4699+
if (job == NULL)
4700+
break;
4701+
if (job_still_useful(job))
4702+
job_cleanup(job); /* may free "job" */
46694703
}
4704+
46704705
if (channel_need_redraw)
46714706
{
46724707
channel_need_redraw = FALSE;
@@ -4887,32 +4922,7 @@ job_status(job_T *job)
48874922
{
48884923
result = mch_job_status(job);
48894924
if (job->jv_status == JOB_ENDED)
4890-
ch_log(job->jv_channel, "Job ended");
4891-
if (job->jv_status == JOB_ENDED && job->jv_exit_cb != NULL)
4892-
{
4893-
typval_T argv[3];
4894-
typval_T rettv;
4895-
int dummy;
4896-
4897-
/* invoke the exit callback; make sure the refcount is > 0 */
4898-
++job->jv_refcount;
4899-
argv[0].v_type = VAR_JOB;
4900-
argv[0].vval.v_job = job;
4901-
argv[1].v_type = VAR_NUMBER;
4902-
argv[1].vval.v_number = job->jv_exitval;
4903-
call_func(job->jv_exit_cb, (int)STRLEN(job->jv_exit_cb),
4904-
&rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE,
4905-
job->jv_exit_partial, NULL);
4906-
clear_tv(&rettv);
4907-
--job->jv_refcount;
4908-
channel_need_redraw = TRUE;
4909-
}
4910-
if (job->jv_status == JOB_ENDED && job->jv_refcount == 0)
4911-
{
4912-
/* The job was already unreferenced, now that it ended it can be
4913-
* freed. Careful: caller must not use "job" after this! */
4914-
job_free(job);
4915-
}
4925+
job_cleanup(job);
49164926
}
49174927
return result;
49184928
}

src/edit.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ static void ins_compl_add_dict(dict_T *dict);
179179
#endif
180180
static int ins_compl_get_exp(pos_T *ini);
181181
static void ins_compl_delete(void);
182-
static void ins_compl_insert(void);
183-
static int ins_compl_next(int allow_get_expansion, int count, int insert_match);
182+
static void ins_compl_insert(int in_compl_func);
183+
static int ins_compl_next(int allow_get_expansion, int count, int insert_match, int in_compl_func);
184184
static int ins_compl_key2dir(int c);
185185
static int ins_compl_pum_key(int c);
186186
static int ins_compl_key2count(int c);
@@ -861,7 +861,7 @@ edit(
861861
&& (c == CAR || c == K_KENTER || c == NL)))
862862
{
863863
ins_compl_delete();
864-
ins_compl_insert();
864+
ins_compl_insert(FALSE);
865865
}
866866
}
867867
}
@@ -3306,7 +3306,7 @@ ins_compl_files(
33063306
break;
33073307
}
33083308
line_breakcheck();
3309-
ins_compl_check_keys(50);
3309+
ins_compl_check_keys(50, FALSE);
33103310
}
33113311
fclose(fp);
33123312
}
@@ -4050,8 +4050,6 @@ ins_compl_next_buf(buf_T *buf, int flag)
40504050
}
40514051

40524052
#ifdef FEAT_COMPL_FUNC
4053-
static void expand_by_function(int type, char_u *base);
4054-
40554053
/*
40564054
* Execute user defined complete function 'completefunc' or 'omnifunc', and
40574055
* get matches in "matches".
@@ -4610,7 +4608,7 @@ ins_compl_get_exp(pos_T *ini)
46104608
break;
46114609
/* Fill the popup menu as soon as possible. */
46124610
if (type != -1)
4613-
ins_compl_check_keys(0);
4611+
ins_compl_check_keys(0, FALSE);
46144612

46154613
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
46164614
|| compl_interrupted)
@@ -4667,9 +4665,12 @@ ins_compl_delete(void)
46674665
set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
46684666
}
46694667

4670-
/* Insert the new text being completed. */
4668+
/*
4669+
* Insert the new text being completed.
4670+
* "in_compl_func" is TRUE when called from complete_check().
4671+
*/
46714672
static void
4672-
ins_compl_insert(void)
4673+
ins_compl_insert(int in_compl_func)
46734674
{
46744675
dict_T *dict;
46754676

@@ -4696,7 +4697,8 @@ ins_compl_insert(void)
46964697
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO]));
46974698
}
46984699
set_vim_var_dict(VV_COMPLETED_ITEM, dict);
4699-
compl_curr_match = compl_shown_match;
4700+
if (!in_compl_func)
4701+
compl_curr_match = compl_shown_match;
47004702
}
47014703

47024704
/*
@@ -4720,7 +4722,8 @@ ins_compl_next(
47204722
int allow_get_expansion,
47214723
int count, /* repeat completion this many times; should
47224724
be at least 1 */
4723-
int insert_match) /* Insert the newly selected match */
4725+
int insert_match, /* Insert the newly selected match */
4726+
int in_compl_func) /* called from complete_check() */
47244727
{
47254728
int num_matches = -1;
47264729
int i;
@@ -4870,7 +4873,7 @@ ins_compl_next(
48704873
else if (insert_match)
48714874
{
48724875
if (!compl_get_longest || compl_used_match)
4873-
ins_compl_insert();
4876+
ins_compl_insert(in_compl_func);
48744877
else
48754878
ins_bytes(compl_leader + ins_compl_len());
48764879
}
@@ -4935,9 +4938,11 @@ ins_compl_next(
49354938
* mode. Also, when compl_pending is not zero, show a completion as soon as
49364939
* possible. -- webb
49374940
* "frequency" specifies out of how many calls we actually check.
4941+
* "in_compl_func" is TRUE when called from complete_check(), don't set
4942+
* compl_curr_match.
49384943
*/
49394944
void
4940-
ins_compl_check_keys(int frequency)
4945+
ins_compl_check_keys(int frequency, int in_compl_func)
49414946
{
49424947
static int count = 0;
49434948

@@ -4963,7 +4968,7 @@ ins_compl_check_keys(int frequency)
49634968
c = safe_vgetc(); /* Eat the character */
49644969
compl_shows_dir = ins_compl_key2dir(c);
49654970
(void)ins_compl_next(FALSE, ins_compl_key2count(c),
4966-
c != K_UP && c != K_DOWN);
4971+
c != K_UP && c != K_DOWN, in_compl_func);
49674972
}
49684973
else
49694974
{
@@ -4986,7 +4991,7 @@ ins_compl_check_keys(int frequency)
49864991
int todo = compl_pending > 0 ? compl_pending : -compl_pending;
49874992

49884993
compl_pending = 0;
4989-
(void)ins_compl_next(FALSE, todo, TRUE);
4994+
(void)ins_compl_next(FALSE, todo, TRUE, in_compl_func);
49904995
}
49914996
}
49924997

@@ -5504,7 +5509,8 @@ ins_complete(int c, int enable_pum)
55045509
* Find next match (and following matches).
55055510
*/
55065511
save_w_wrow = curwin->w_wrow;
5507-
n = ins_compl_next(TRUE, ins_compl_key2count(c), ins_compl_use_match(c));
5512+
n = ins_compl_next(TRUE, ins_compl_key2count(c),
5513+
ins_compl_use_match(c), FALSE);
55085514

55095515
/* may undisplay the popup menu */
55105516
ins_compl_upd_pum();

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ f_complete_check(typval_T *argvars UNUSED, typval_T *rettv)
21752175
int saved = RedrawingDisabled;
21762176

21772177
RedrawingDisabled = 0;
2178-
ins_compl_check_keys(0);
2178+
ins_compl_check_keys(0, TRUE);
21792179
rettv->vval.v_number = compl_interrupted;
21802180
RedrawingDisabled = saved;
21812181
}

src/ex_docmd.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,6 +4291,11 @@ set_one_cmd_context(
42914291
xp->xp_pattern = arg;
42924292
break;
42934293

4294+
case CMD_messages:
4295+
xp->xp_context = EXPAND_MESSAGES;
4296+
xp->xp_pattern = arg;
4297+
break;
4298+
42944299
#if defined(FEAT_CMDHIST)
42954300
case CMD_history:
42964301
xp->xp_context = EXPAND_HISTORY;
@@ -5910,6 +5915,7 @@ static struct
59105915
#endif
59115916
{EXPAND_MAPPINGS, "mapping"},
59125917
{EXPAND_MENUS, "menu"},
5918+
{EXPAND_MESSAGES, "messages"},
59135919
{EXPAND_OWNSYNTAX, "syntax"},
59145920
#if defined(FEAT_PROFILE)
59155921
{EXPAND_SYNTIME, "syntime"},
@@ -11936,6 +11942,18 @@ get_behave_arg(expand_T *xp UNUSED, int idx)
1193611942
return (char_u *)"xterm";
1193711943
return NULL;
1193811944
}
11945+
11946+
/*
11947+
* Function given to ExpandGeneric() to obtain the possible arguments of the
11948+
* ":messages {clear}" command.
11949+
*/
11950+
char_u *
11951+
get_messages_arg(expand_T *xp UNUSED, int idx)
11952+
{
11953+
if (idx == 0)
11954+
return (char_u *)"clear";
11955+
return NULL;
11956+
}
1193911957
#endif
1194011958

1194111959
#ifdef FEAT_AUTOCMD

src/ex_getln.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,6 +4843,7 @@ ExpandFromContext(
48434843
{
48444844
{EXPAND_COMMANDS, get_command_name, FALSE, TRUE},
48454845
{EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE},
4846+
{EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE},
48464847
#ifdef FEAT_CMDHIST
48474848
{EXPAND_HISTORY, get_history_arg, TRUE, TRUE},
48484849
#endif

0 commit comments

Comments
 (0)