Skip to content

Commit e2edc2e

Browse files
committed
patch 8.2.2366: when using ":sleep" the cursor is always displayed
Problem: When using ":sleep" the cursor is always displayed. Solution: Do not display the cursor when using ":sleep!". (Jeremy Lerner, closes #7688)
1 parent 70250fb commit e2edc2e

10 files changed

Lines changed: 49 additions & 10 deletions

File tree

runtime/doc/index.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,8 @@ tag command action ~
15901590
|:sign| :sig[n] manipulate signs
15911591
|:silent| :sil[ent] run a command silently
15921592
|:sleep| :sl[eep] do nothing for a few seconds
1593+
|:sleep!| :sl[eep]! do nothing for a few seconds, without the
1594+
cursor visible
15931595
|:slast| :sla[st] split window and go to last file in the
15941596
argument list
15951597
|:smagic| :sm[agic] :substitute with 'magic'

runtime/doc/various.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,12 @@ K Run a program to lookup the keyword under the
707707
not more than one line.
708708

709709
[N]gs *gs* *:sl* *:sleep*
710-
:[N]sl[eep] [N] [m] Do nothing for [N] seconds. When [m] is included,
710+
:[N]sl[eep] [N][m] Do nothing for [N] seconds. When [m] is included,
711711
sleep for [N] milliseconds. The count for "gs" always
712712
uses seconds. The default is one second. >
713713
:sleep "sleep for one second
714714
:5sleep "sleep for five seconds
715-
:sleep 100m "sleep for a hundred milliseconds
715+
:sleep 100m "sleep for 100 milliseconds
716716
10gs "sleep for ten seconds
717717
< Can be interrupted with CTRL-C (CTRL-Break on
718718
MS-Windows). "gs" stands for "goto sleep".

src/ex_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ EXCMD(CMD_silent, "silent", ex_wrongmodifier,
13651365
EX_NEEDARG|EX_EXTRA|EX_BANG|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
13661366
ADDR_NONE),
13671367
EXCMD(CMD_sleep, "sleep", ex_sleep,
1368-
EX_RANGE|EX_COUNT|EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
1368+
EX_BANG|EX_RANGE|EX_COUNT|EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
13691369
ADDR_OTHER),
13701370
EXCMD(CMD_slast, "slast", ex_last,
13711371
EX_EXTRA|EX_BANG|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,

src/ex_docmd.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7225,14 +7225,17 @@ ex_sleep(exarg_T *eap)
72257225
case NUL: len *= 1000L; break;
72267226
default: semsg(_(e_invarg2), eap->arg); return;
72277227
}
7228-
do_sleep(len);
7228+
7229+
// Hide the cursor if invoked with !
7230+
do_sleep(len, eap->forceit);
72297231
}
72307232

72317233
/*
72327234
* Sleep for "msec" milliseconds, but keep checking for a CTRL-C every second.
7235+
* Hide the cursor if "hide_cursor" is TRUE.
72337236
*/
72347237
void
7235-
do_sleep(long msec)
7238+
do_sleep(long msec, int hide_cursor)
72367239
{
72377240
long done = 0;
72387241
long wait_now;
@@ -7244,7 +7247,11 @@ do_sleep(long msec)
72447247
ELAPSED_INIT(start_tv);
72457248
# endif
72467249

7247-
cursor_on();
7250+
if (hide_cursor)
7251+
cursor_off();
7252+
else
7253+
cursor_on();
7254+
72487255
out_flush_cursor(FALSE, FALSE);
72497256
while (!got_int && done < msec)
72507257
{

src/normal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ normal_cmd(
993993
// something different from CTRL-N. Can't be avoided.
994994
while ((c = vpeekc()) <= 0 && towait > 0L)
995995
{
996-
do_sleep(towait > 50L ? 50L : towait);
996+
do_sleep(towait > 50L ? 50L : towait, FALSE);
997997
towait -= 50L;
998998
}
999999
if (c > 0)
@@ -6230,7 +6230,7 @@ nv_g_cmd(cmdarg_T *cap)
62306230
* "gs": Goto sleep.
62316231
*/
62326232
case 's':
6233-
do_sleep(cap->count1 * 1000L);
6233+
do_sleep(cap->count1 * 1000L, FALSE);
62346234
break;
62356235

62366236
/*

src/proto/ex_docmd.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void free_cd_dir(void);
4242
void post_chdir(cdscope_T scope);
4343
int changedir_func(char_u *new_dir, int forceit, cdscope_T scope);
4444
void ex_cd(exarg_T *eap);
45-
void do_sleep(long msec);
45+
void do_sleep(long msec, int hide_cursor);
4646
void ex_may_print(exarg_T *eap);
4747
void ex_redraw(exarg_T *eap);
4848
int vim_mkdir_emsg(char_u *name, int prot);

src/term.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ out_str_cf(char_u *s)
27132713
else
27142714
{
27152715
++p;
2716-
do_sleep(duration);
2716+
do_sleep(duration, FALSE);
27172717
}
27182718
# else
27192719
// Rely on the terminal library to sleep.

src/testdir/Make_all.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ NEW_TESTS = \
246246
test_shortpathname \
247247
test_signals \
248248
test_signs \
249+
test_sleep \
249250
test_smartindent \
250251
test_sort \
251252
test_sound \
@@ -472,6 +473,7 @@ NEW_TESTS_RES = \
472473
test_shortpathname.res \
473474
test_signals.res \
474475
test_signs.res \
476+
test_sleep.res \
475477
test_smartindent.res \
476478
test_sort.res \
477479
test_sound.res \

src/testdir/test_sleep.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
" Test for sleep and sleep! commands
2+
3+
func! s:get_time_ms()
4+
let timestr = reltimestr(reltime())
5+
let dotidx = stridx(timestr, '.')
6+
let sec = str2nr(timestr[:dotidx])
7+
let msec = str2nr(timestr[dotidx + 1:])
8+
return (sec * 1000) + (msec / 1000)
9+
endfunc
10+
11+
func! s:assert_takes_longer(cmd, time_ms)
12+
let start = s:get_time_ms()
13+
execute a:cmd
14+
let end = s:get_time_ms()
15+
call assert_true(end - start >=# a:time_ms)
16+
endfun
17+
18+
func! Test_sleep_bang()
19+
call s:assert_takes_longer('sleep 50m', 50)
20+
call s:assert_takes_longer('sleep! 50m', 50)
21+
call s:assert_takes_longer('sl 50m', 50)
22+
call s:assert_takes_longer('sl! 50m', 50)
23+
call s:assert_takes_longer('1sleep', 1000)
24+
endfunc
25+
26+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2366,
753755
/**/
754756
2365,
755757
/**/

0 commit comments

Comments
 (0)