Skip to content

Commit 2256c99

Browse files
committed
patch 8.0.0086
Problem: Cannot add a comment after ":hide". (Norio Takagi) Solution: Make it work, add a test. (Hirohito Higashi)
1 parent 8a01f96 commit 2256c99

File tree

6 files changed

+127
-31
lines changed

6 files changed

+127
-31
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,7 @@ test_arglist \
20972097
test_gui \
20982098
test_hardcopy \
20992099
test_help_tagjump \
2100+
test_hide \
21002101
test_history \
21012102
test_hlsearch \
21022103
test_increment \

src/ex_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ EX(CMD_highlight, "highlight", ex_highlight,
623623
BANG|EXTRA|TRLBAR|SBOXOK|CMDWIN,
624624
ADDR_LINES),
625625
EX(CMD_hide, "hide", ex_hide,
626-
BANG|RANGE|NOTADR|COUNT|EXTRA|NOTRLCOM,
626+
BANG|RANGE|NOTADR|COUNT|EXTRA|TRLBAR,
627627
ADDR_WINDOWS),
628628
EX(CMD_history, "history", ex_history,
629629
EXTRA|TRLBAR|CMDWIN,

src/ex_docmd.c

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5632,15 +5632,16 @@ find_nextcmd(char_u *p)
56325632
#endif
56335633

56345634
/*
5635-
* Check if *p is a separator between Ex commands.
5636-
* Return NULL if it isn't, (p + 1) if it is.
5635+
* Check if *p is a separator between Ex commands, skipping over white space.
5636+
* Return NULL if it isn't, the following character if it is.
56375637
*/
56385638
char_u *
56395639
check_nextcmd(char_u *p)
56405640
{
5641-
p = skipwhite(p);
5642-
if (*p == '|' || *p == '\n')
5643-
return (p + 1);
5641+
char_u *s = skipwhite(p);
5642+
5643+
if (*s == '|' || *s == '\n')
5644+
return (s + 1);
56445645
else
56455646
return NULL;
56465647
}
@@ -7572,38 +7573,32 @@ ex_all(exarg_T *eap)
75727573
static void
75737574
ex_hide(exarg_T *eap)
75747575
{
7575-
if (*eap->arg != NUL && check_nextcmd(eap->arg) == NULL)
7576-
eap->errmsg = e_invarg;
7577-
else
7578-
{
7579-
/* ":hide" or ":hide | cmd": hide current window */
7580-
eap->nextcmd = check_nextcmd(eap->arg);
7576+
/* ":hide" or ":hide | cmd": hide current window */
75817577
#ifdef FEAT_WINDOWS
7582-
if (!eap->skip)
7583-
{
7578+
if (!eap->skip)
7579+
{
75847580
# ifdef FEAT_GUI
7585-
need_mouse_correct = TRUE;
7581+
need_mouse_correct = TRUE;
75867582
# endif
7587-
if (eap->addr_count == 0)
7588-
win_close(curwin, FALSE); /* don't free buffer */
7589-
else
7590-
{
7591-
int winnr = 0;
7592-
win_T *win;
7583+
if (eap->addr_count == 0)
7584+
win_close(curwin, FALSE); /* don't free buffer */
7585+
else
7586+
{
7587+
int winnr = 0;
7588+
win_T *win;
75937589

7594-
FOR_ALL_WINDOWS(win)
7595-
{
7596-
winnr++;
7597-
if (winnr == eap->line2)
7598-
break;
7599-
}
7600-
if (win == NULL)
7601-
win = lastwin;
7602-
win_close(win, FALSE);
7590+
FOR_ALL_WINDOWS(win)
7591+
{
7592+
winnr++;
7593+
if (winnr == eap->line2)
7594+
break;
76037595
}
7596+
if (win == NULL)
7597+
win = lastwin;
7598+
win_close(win, FALSE);
76047599
}
7605-
#endif
76067600
}
7601+
#endif
76077602
}
76087603

76097604
/*

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ NEW_TESTS = test_arglist.res \
156156
test_gn.res \
157157
test_gui.res \
158158
test_hardcopy.res \
159+
test_hide.res \
159160
test_history.res \
160161
test_hlsearch.res \
161162
test_increment.res \

src/testdir/test_hide.vim

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
" Tests for :hide command/modifier and 'hidden' option
2+
3+
function SetUp()
4+
let s:save_hidden = &hidden
5+
let s:save_bufhidden = &bufhidden
6+
let s:save_autowrite = &autowrite
7+
set nohidden
8+
set bufhidden=
9+
set noautowrite
10+
endfunc
11+
12+
function TearDown()
13+
let &hidden = s:save_hidden
14+
let &bufhidden = s:save_bufhidden
15+
let &autowrite = s:save_autowrite
16+
endfunc
17+
18+
function Test_hide()
19+
let orig_bname = bufname('')
20+
let orig_winnr = winnr('$')
21+
22+
new Xf1
23+
set modified
24+
call assert_fails('edit Xf2')
25+
bwipeout! Xf1
26+
27+
new Xf1
28+
set modified
29+
edit! Xf2
30+
call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
31+
call assert_equal([1, 0], [buflisted('Xf1'), bufloaded('Xf1')])
32+
bwipeout! Xf1
33+
bwipeout! Xf2
34+
35+
new Xf1
36+
set modified
37+
" :hide as a command
38+
hide
39+
call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
40+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
41+
bwipeout! Xf1
42+
43+
new Xf1
44+
set modified
45+
" :hide as a command with trailing comment
46+
hide " comment
47+
call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
48+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
49+
bwipeout! Xf1
50+
51+
new Xf1
52+
set modified
53+
" :hide as a command with bar
54+
hide | new Xf2 " comment
55+
call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
56+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
57+
bwipeout! Xf1
58+
bwipeout! Xf2
59+
60+
new Xf1
61+
set modified
62+
" :hide as a modifier with trailing comment
63+
hide edit Xf2 " comment
64+
call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
65+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
66+
bwipeout! Xf1
67+
bwipeout! Xf2
68+
69+
new Xf1
70+
set modified
71+
" To check that the bar is not recognized to separate commands
72+
hide echo "one|two"
73+
call assert_equal(['Xf1', 2], [bufname(''), winnr('$')])
74+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
75+
bwipeout! Xf1
76+
77+
" set hidden
78+
new Xf1
79+
set hidden
80+
set modified
81+
edit Xf2 " comment
82+
call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
83+
call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
84+
bwipeout! Xf1
85+
bwipeout! Xf2
86+
87+
" set hidden bufhidden=wipe
88+
new Xf1
89+
set bufhidden=wipe
90+
set modified
91+
hide edit! Xf2 " comment
92+
call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
93+
call assert_equal([0, 0], [buflisted('Xf1'), bufloaded('Xf1')])
94+
bwipeout! Xf2
95+
endfunc
96+
97+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
86,
767769
/**/
768770
85,
769771
/**/

0 commit comments

Comments
 (0)