Skip to content

Commit f9248a4

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents f7c4ef2 + f422bcc commit f9248a4

File tree

17 files changed

+219
-73
lines changed

17 files changed

+219
-73
lines changed

runtime/doc/eval.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8420,6 +8420,8 @@ timers Compiled with |timer_start()| support.
84208420
title Compiled with window title support |'title'|.
84218421
toolbar Compiled with support for |gui-toolbar|.
84228422
transparency Compiled with 'transparency' support.
8423+
ttyin input is a terminal (tty)
8424+
ttyout output is a terminal (tty)
84238425
unix Unix version of Vim.
84248426
user_commands User-defined commands.
84258427
vertsplit Compiled with vertically split windows |:vsplit|.

runtime/doc/starting.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ a slash. Thus "-R" means recovery and "-/R" readonly.
421421
not connected to a terminal. This will avoid the warning and
422422
the two second delay that would happen. {not in Vi}
423423

424+
*--ttyfail*
425+
--ttyfail When the stdin or stdout is not a terminal (tty) then exit
426+
right away.
427+
424428
*-d*
425429
-d Start in diff mode, like |vimdiff|.
426430
{not in Vi} {not available when compiled without the |+diff|

src/channel.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,11 @@ channel_parse_messages(void)
38403840
int ret = FALSE;
38413841
int r;
38423842
ch_part_T part = PART_SOCK;
3843+
#ifdef ELAPSED_FUNC
3844+
ELAPSED_TYPE start_tv;
3845+
3846+
ELAPSED_INIT(start_tv);
3847+
#endif
38433848

38443849
++safe_to_invoke_callback;
38453850

@@ -3884,7 +3889,14 @@ channel_parse_messages(void)
38843889
r = may_invoke_callback(channel, part);
38853890
if (r == OK)
38863891
ret = TRUE;
3887-
if (channel_unref(channel) || r == OK)
3892+
if (channel_unref(channel) || (r == OK
3893+
#ifdef ELAPSED_FUNC
3894+
/* Limit the time we loop here to 100 msec, otherwise
3895+
* Vim becomes unresponsive when the callback takes
3896+
* more than a bit of time. */
3897+
&& ELAPSED_FUNC(start_tv) < 100L
3898+
#endif
3899+
))
38883900
{
38893901
/* channel was freed or something was done, start over */
38903902
channel = first_channel;
@@ -3912,6 +3924,31 @@ channel_parse_messages(void)
39123924
return ret;
39133925
}
39143926

3927+
/*
3928+
* Return TRUE if any channel has readahead. That means we should not block on
3929+
* waiting for input.
3930+
*/
3931+
int
3932+
channel_any_readahead(void)
3933+
{
3934+
channel_T *channel = first_channel;
3935+
ch_part_T part = PART_SOCK;
3936+
3937+
while (channel != NULL)
3938+
{
3939+
if (channel_has_readahead(channel, part))
3940+
return TRUE;
3941+
if (part < PART_ERR)
3942+
++part;
3943+
else
3944+
{
3945+
channel = channel->ch_next;
3946+
part = PART_SOCK;
3947+
}
3948+
}
3949+
return FALSE;
3950+
}
3951+
39153952
/*
39163953
* Mark references to lists used in channels.
39173954
*/

src/evalfunc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5978,6 +5978,10 @@ f_has(typval_T *argvars, typval_T *rettv)
59785978
}
59795979
else if (STRICMP(name, "vim_starting") == 0)
59805980
n = (starting != 0);
5981+
else if (STRICMP(name, "ttyin") == 0)
5982+
n = mch_input_isatty();
5983+
else if (STRICMP(name, "ttyout") == 0)
5984+
n = stdout_isatty;
59815985
#ifdef FEAT_MBYTE
59825986
else if (STRICMP(name, "multi_byte_encoding") == 0)
59835987
n = has_mbyte;

src/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ EXTERN int exiting INIT(= FALSE);
643643
EXTERN int really_exiting INIT(= FALSE);
644644
/* TRUE when we are sure to exit, e.g., after
645645
* a deadly signal */
646+
EXTERN int stdout_isatty INIT(= TRUE); /* is stdout a terminal? */
647+
646648
#if defined(FEAT_AUTOCHDIR)
647649
EXTERN int test_autochdir INIT(= FALSE);
648650
#endif

src/gui_gtk_x11.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,7 +3102,7 @@ drawarea_configure_event_cb(GtkWidget *widget,
31023102
g_return_val_if_fail(event
31033103
&& event->width >= 1 && event->height >= 1, TRUE);
31043104

3105-
# if GTK_CHECK_VERSION(3,22,2)
3105+
# if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4)
31063106
/* As of 3.22.2, GdkWindows have started distributing configure events to
31073107
* their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0).
31083108
*
@@ -3123,6 +3123,10 @@ drawarea_configure_event_cb(GtkWidget *widget,
31233123
* implementation details. Therefore, watch out any relevant internal
31243124
* changes happening in GTK in the feature (sigh).
31253125
*/
3126+
/* Follow-up
3127+
* After a few weeks later, the GdkWindow change mentioned above was
3128+
* reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155).
3129+
* The corresponding official release is 3.22.4. */
31263130
if (event->send_event == FALSE)
31273131
return TRUE;
31283132
# endif
@@ -4492,7 +4496,7 @@ form_configure_event(GtkWidget *widget UNUSED,
44924496
{
44934497
int usable_height = event->height;
44944498

4495-
#if GTK_CHECK_VERSION(3,22,2)
4499+
#if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4)
44964500
/* As of 3.22.2, GdkWindows have started distributing configure events to
44974501
* their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0).
44984502
*
@@ -4508,6 +4512,10 @@ form_configure_event(GtkWidget *widget UNUSED,
45084512
* To filter out such fallacious events, check if the given event is the
45094513
* one that was sent out to the right place. Ignore it if not.
45104514
*/
4515+
/* Follow-up
4516+
* After a few weeks later, the GdkWindow change mentioned above was
4517+
* reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155).
4518+
* The corresponding official release is 3.22.4. */
45114519
if (event->window != gtk_widget_get_window(gui.formwin))
45124520
return TRUE;
45134521
#endif

src/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ common_init(mparm_T *paramp)
10361036
* (needed for :! to * work). mch_check_win() will also handle the -d or
10371037
* -dev argument.
10381038
*/
1039-
paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
1039+
stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
10401040
TIME_MSG("window checked");
10411041

10421042
/*
@@ -1906,6 +1906,7 @@ command_line_scan(mparm_T *parmp)
19061906
/* "--literal" take files literally */
19071907
/* "--nofork" don't fork */
19081908
/* "--not-a-term" don't warn for not a term */
1909+
/* "--ttyfail" exit if not a term */
19091910
/* "--noplugin[s]" skip plugins */
19101911
/* "--cmd <cmd>" execute cmd before vimrc */
19111912
if (STRICMP(argv[0] + argv_idx, "help") == 0)
@@ -1935,6 +1936,8 @@ command_line_scan(mparm_T *parmp)
19351936
p_lpl = FALSE;
19361937
else if (STRNICMP(argv[0] + argv_idx, "not-a-term", 10) == 0)
19371938
parmp->not_a_term = TRUE;
1939+
else if (STRNICMP(argv[0] + argv_idx, "ttyfail", 7) == 0)
1940+
parmp->tty_fail = TRUE;
19381941
else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
19391942
{
19401943
want_argument = TRUE;
@@ -2573,7 +2576,7 @@ check_tty(mparm_T *parmp)
25732576
if (!input_isatty)
25742577
silent_mode = TRUE;
25752578
}
2576-
else if (parmp->want_full_screen && (!parmp->stdout_isatty || !input_isatty)
2579+
else if (parmp->want_full_screen && (!stdout_isatty || !input_isatty)
25772580
#ifdef FEAT_GUI
25782581
/* don't want the delay when started from the desktop */
25792582
&& !gui.starting
@@ -2588,7 +2591,7 @@ check_tty(mparm_T *parmp)
25882591
* input buffer so fast I can't even kill the process in under 2
25892592
* minutes (and it beeps continuously the whole time :-)
25902593
*/
2591-
if (netbeans_active() && (!parmp->stdout_isatty || !input_isatty))
2594+
if (netbeans_active() && (!stdout_isatty || !input_isatty))
25922595
{
25932596
mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n"));
25942597
exit(1);
@@ -2601,11 +2604,13 @@ check_tty(mparm_T *parmp)
26012604
exit(1);
26022605
}
26032606
#endif
2604-
if (!parmp->stdout_isatty)
2607+
if (!stdout_isatty)
26052608
mch_errmsg(_("Vim: Warning: Output is not to a terminal\n"));
26062609
if (!input_isatty)
26072610
mch_errmsg(_("Vim: Warning: Input is not from a terminal\n"));
26082611
out_flush();
2612+
if (parmp->tty_fail && (!stdout_isatty || !input_isatty))
2613+
exit(1);
26092614
if (scriptin[0] == NULL)
26102615
ui_delay(2000L, TRUE);
26112616
TIME_MSG("Warning delay");
@@ -3371,6 +3376,7 @@ usage(void)
33713376
#endif
33723377
main_msg(_("-T <terminal>\tSet terminal type to <terminal>"));
33733378
main_msg(_("--not-a-term\t\tSkip warning for input/output not being a terminal"));
3379+
main_msg(_("--ttyfail\t\tExit if input or output is not a terminal"));
33743380
main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc"));
33753381
#ifdef FEAT_GUI
33763382
main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc"));

src/misc2.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6269,3 +6269,31 @@ parse_queued_messages(void)
62696269
# endif
62706270
}
62716271
#endif
6272+
6273+
#ifdef ELAPSED_TIMEVAL /* no PROTO here, proto is defined in vim.h */
6274+
/*
6275+
* Return time in msec since "start_tv".
6276+
*/
6277+
long
6278+
elapsed(struct timeval *start_tv)
6279+
{
6280+
struct timeval now_tv;
6281+
6282+
gettimeofday(&now_tv, NULL);
6283+
return (now_tv.tv_sec - start_tv->tv_sec) * 1000L
6284+
+ (now_tv.tv_usec - start_tv->tv_usec) / 1000L;
6285+
}
6286+
#endif
6287+
6288+
#ifdef ELAPSED_TICKCOUNT
6289+
/*
6290+
* Return time in msec since "start_tick".
6291+
*/
6292+
long
6293+
elapsed(DWORD start_tick)
6294+
{
6295+
DWORD now = GetTickCount();
6296+
6297+
return (long)now - (long)start_tick;
6298+
}
6299+
#endif

src/option.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,11 @@ struct vimoption
458458
#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459459
#define P_INSECURE 0x800000L /* option was set from a modeline */
460460
#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
461-
side effects) */
461+
side effects) */
462462
#define P_NO_ML 0x2000000L /* not allowed in modeline */
463463
#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
464464
* there is a redraw flag */
465+
#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
465466

466467
#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467468

@@ -1004,7 +1005,7 @@ static struct vimoption options[] =
10041005
(char_u *)NULL, PV_NONE,
10051006
#endif
10061007
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1007-
{"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
1008+
{"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
10081009
#ifdef FEAT_INS_EXPAND
10091010
(char_u *)&p_dict, PV_DICT,
10101011
#else
@@ -2111,7 +2112,7 @@ static struct vimoption options[] =
21112112
{(char_u *)NULL, (char_u *)0L}
21122113
#endif
21132114
SCRIPTID_INIT},
2114-
{"printexpr", "pexpr", P_STRING|P_VI_DEF,
2115+
{"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
21152116
#ifdef FEAT_POSTSCRIPT
21162117
(char_u *)&p_pexpr, PV_NONE,
21172118
{(char_u *)"", (char_u *)0L}
@@ -2712,7 +2713,7 @@ static struct vimoption options[] =
27122713
{"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
27132714
(char_u *)&p_tw, PV_TW,
27142715
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2715-
{"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
2716+
{"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
27162717
#ifdef FEAT_INS_EXPAND
27172718
(char_u *)&p_tsr, PV_TSR,
27182719
#else
@@ -5961,11 +5962,13 @@ did_set_string_option(
59615962
errmsg = e_secure;
59625963
}
59635964

5964-
/* Check for a "normal" file name in some options. Disallow a path
5965-
* separator (slash and/or backslash), wildcards and characters that are
5966-
* often illegal in a file name. */
5967-
else if ((options[opt_idx].flags & P_NFNAME)
5968-
&& vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
5965+
/* Check for a "normal" directory or file name in some options. Disallow a
5966+
* path separator (slash and/or backslash), wildcards and characters that
5967+
* are often illegal in a file name. */
5968+
else if (((options[opt_idx].flags & P_NFNAME)
5969+
&& vim_strpbrk(*varp, (char_u *)"/\\*?[|;&<>\r\n") != NULL)
5970+
|| ((options[opt_idx].flags & P_NDNAME)
5971+
&& vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
59695972
{
59705973
errmsg = e_invarg;
59715974
}
@@ -7111,6 +7114,7 @@ did_set_string_option(
71117114

71127115

71137116
#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7117+
/* 'toolbar' */
71147118
else if (varp == &p_toolbar)
71157119
{
71167120
if (opt_strings_flags(p_toolbar, p_toolbar_values,
@@ -7335,6 +7339,7 @@ did_set_string_option(
73357339
#endif
73367340

73377341
#if defined(FEAT_RENDER_OPTIONS)
7342+
/* 'renderoptions' */
73387343
else if (varp == &p_rop && gui.in_use)
73397344
{
73407345
if (!gui_mch_set_rendering_options(p_rop))
@@ -7362,19 +7367,19 @@ did_set_string_option(
73627367
else
73637368
{
73647369
p = NULL;
7365-
if (varp == &p_ww)
7370+
if (varp == &p_ww) /* 'whichwrap' */
73667371
p = (char_u *)WW_ALL;
7367-
if (varp == &p_shm)
7372+
if (varp == &p_shm) /* 'shortmess' */
73687373
p = (char_u *)SHM_ALL;
7369-
else if (varp == &(p_cpo))
7374+
else if (varp == &(p_cpo)) /* 'cpoptions' */
73707375
p = (char_u *)CPO_ALL;
7371-
else if (varp == &(curbuf->b_p_fo))
7376+
else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
73727377
p = (char_u *)FO_ALL;
73737378
#ifdef FEAT_CONCEAL
7374-
else if (varp == &curwin->w_p_cocu)
7379+
else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
73757380
p = (char_u *)COCU_ALL;
73767381
#endif
7377-
else if (varp == &p_mouse)
7382+
else if (varp == &p_mouse) /* 'mouse' */
73787383
{
73797384
#ifdef FEAT_MOUSE
73807385
p = (char_u *)MOUSE_ALL;
@@ -7384,7 +7389,7 @@ did_set_string_option(
73847389
#endif
73857390
}
73867391
#if defined(FEAT_GUI)
7387-
else if (varp == &p_go)
7392+
else if (varp == &p_go) /* 'guioptions' */
73887393
p = (char_u *)GO_ALL;
73897394
#endif
73907395
if (p != NULL)

0 commit comments

Comments
 (0)