Skip to content

Commit c6e15ba

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 4bf9153 + 269aec7 commit c6e15ba

File tree

8 files changed

+187
-21
lines changed

8 files changed

+187
-21
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ test_arglist \
21232123
test_filter_map \
21242124
test_fnameescape \
21252125
test_fnamemodify \
2126+
test_fold \
21262127
test_glob2regpat \
21272128
test_gf \
21282129
test_gn \

src/ex_docmd.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int getargopt(exarg_T *eap);
137137
#endif
138138

139139
static int check_more(int, int);
140-
static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int to_other_file);
140+
static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int to_other_file, int address_count);
141141
static void get_flags(exarg_T *eap);
142142
#if !defined(FEAT_PERL) \
143143
|| !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \
@@ -794,8 +794,13 @@ do_cmdline(
794794
#endif
795795

796796
/* It's possible to create an endless loop with ":execute", catch that
797-
* here. The value of 200 allows nested function calls, ":source", etc. */
798-
if (call_depth == 200)
797+
* here. The value of 200 allows nested function calls, ":source", etc.
798+
* Allow 200 or 'maxfuncdepth', whatever is larger. */
799+
if (call_depth >= 200
800+
#ifdef FEAT_EVAL
801+
&& call_depth >= p_mfd
802+
#endif
803+
)
799804
{
800805
EMSG(_("E169: Command too recursive"));
801806
#ifdef FEAT_EVAL
@@ -1798,6 +1803,7 @@ do_one_cmd(
17981803
cmdmod_T save_cmdmod;
17991804
int ni; /* set when Not Implemented */
18001805
char_u *cmd;
1806+
int address_count = 1;
18011807

18021808
vim_memset(&ea, 0, sizeof(ea));
18031809
ea.line1 = 1;
@@ -2022,7 +2028,7 @@ do_one_cmd(
20222028
{
20232029
#ifdef FEAT_WINDOWS
20242030
long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS,
2025-
ea.skip, FALSE);
2031+
ea.skip, FALSE, 1);
20262032
if (tabnr == MAXLNUM)
20272033
cmdmod.tab = tabpage_index(curtab) + 1;
20282034
else
@@ -2182,7 +2188,7 @@ do_one_cmd(
21822188
}
21832189
ea.cmd = skipwhite(ea.cmd);
21842190
lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip,
2185-
ea.addr_count == 0);
2191+
ea.addr_count == 0, address_count++);
21862192
if (ea.cmd == NULL) /* error detected */
21872193
goto doend;
21882194
if (lnum == MAXLNUM)
@@ -4380,7 +4386,8 @@ get_address(
43804386
char_u **ptr,
43814387
int addr_type, /* flag: one of ADDR_LINES, ... */
43824388
int skip, /* only skip the address, don't use it */
4383-
int to_other_file) /* flag: may jump to other file */
4389+
int to_other_file, /* flag: may jump to other file */
4390+
int address_count UNUSED) /* 1 for first address, >1 after comma */
43844391
{
43854392
int c;
43864393
int i;
@@ -4656,10 +4663,20 @@ get_address(
46564663
|| addr_type == ADDR_BUFFERS)
46574664
lnum = compute_buffer_local_count(
46584665
addr_type, lnum, (i == '-') ? -1 * n : n);
4659-
else if (i == '-')
4660-
lnum -= n;
46614666
else
4662-
lnum += n;
4667+
{
4668+
#ifdef FEAT_FOLDING
4669+
/* Relative line addressing, need to adjust for folded lines
4670+
* now, but only do it after the first address. */
4671+
if (addr_type == ADDR_LINES && (i == '-' || i == '+')
4672+
&& address_count >= 2)
4673+
(void)hasFolding(lnum, NULL, &lnum);
4674+
#endif
4675+
if (i == '-')
4676+
lnum -= n;
4677+
else
4678+
lnum += n;
4679+
}
46634680
}
46644681
} while (*cmd == '/' || *cmd == '?');
46654682

@@ -7589,7 +7606,7 @@ ex_all(exarg_T *eap)
75897606
#endif /* FEAT_WINDOWS */
75907607

75917608
static void
7592-
ex_hide(exarg_T *eap)
7609+
ex_hide(exarg_T *eap UNUSED)
75937610
{
75947611
/* ":hide" or ":hide | cmd": hide current window */
75957612
#ifdef FEAT_WINDOWS
@@ -9320,7 +9337,7 @@ ex_copymove(exarg_T *eap)
93209337
{
93219338
long n;
93229339

9323-
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE);
9340+
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, 1);
93249341
if (eap->arg == NULL) /* error detected */
93259342
{
93269343
eap->nextcmd = NULL;

src/ops.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,6 @@ op_shift(oparg_T *oap, int curs_top, int amount)
259259
}
260260

261261
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
262-
#ifdef FEAT_FOLDING
263-
/* The cursor line is not in a closed fold */
264-
foldOpenCursor();
265-
#endif
266-
267262
if (oap->block_mode)
268263
{
269264
curwin->w_cursor.lnum = oap->start.lnum;
@@ -277,6 +272,12 @@ op_shift(oparg_T *oap, int curs_top, int amount)
277272
else
278273
--curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */
279274

275+
#ifdef FEAT_FOLDING
276+
/* The cursor line is not in a closed fold */
277+
foldOpenCursor();
278+
#endif
279+
280+
280281
if (oap->line_count > p_report)
281282
{
282283
if (oap->op_type == OP_RSHIFT)
@@ -3350,6 +3351,8 @@ do_put(
33503351
*/
33513352
if (regname == '.')
33523353
{
3354+
if (VIsual_active)
3355+
stuffcharReadbuff(VIsual_mode);
33533356
(void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') :
33543357
(count == -1 ? 'O' : 'i')), count, FALSE);
33553358
/* Putting the text is done later, so can't really move the cursor to

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ NEW_TESTS = test_arglist.res \
151151
test_display.res \
152152
test_farsi.res \
153153
test_fnameescape.res \
154+
test_fold.res \
154155
test_gf.res \
155156
test_gn.res \
156157
test_gui.res \

src/testdir/test_fold.vim

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
" Test for folding
2+
3+
function! Test_address_fold()
4+
new
5+
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
6+
\ 'after fold 1', 'after fold 2', 'after fold 3'])
7+
setl fen fdm=marker
8+
" The next ccommands should all copy the same part of the buffer,
9+
" regardless of the adressing type, since the part to be copied
10+
" is folded away
11+
:1y
12+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
13+
:.y
14+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
15+
:.+y
16+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
17+
:.,.y
18+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
19+
:sil .1,.y
20+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
21+
" use silent to make E493 go away
22+
:sil .+,.y
23+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
24+
:,y
25+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
26+
:,+y
27+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1))
28+
" using .+3 as second address should copy the whole folded line + the next 3
29+
" lines
30+
:.,+3y
31+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/',
32+
\ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1))
33+
:sil .,-2y
34+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
35+
36+
" now test again with folding disabled
37+
set nofoldenable
38+
:1y
39+
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
40+
:.y
41+
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
42+
:.+y
43+
call assert_equal(['1'], getreg(0,1,1))
44+
:.,.y
45+
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
46+
" use silent to make E493 go away
47+
:sil .1,.y
48+
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
49+
" use silent to make E493 go away
50+
:sil .+,.y
51+
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
52+
:,y
53+
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
54+
:,+y
55+
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
56+
" using .+3 as second address should copy the whole folded line + the next 3
57+
" lines
58+
:.,+3y
59+
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1))
60+
:7
61+
:sil .,-2y
62+
call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
63+
64+
quit!
65+
endfunction
66+
67+
function! Test_indent_fold()
68+
new
69+
call setline(1, ['', 'a', ' b', ' c'])
70+
setl fen fdm=indent
71+
2
72+
norm! >>
73+
let a=map(range(1,4), 'foldclosed(v:val)')
74+
call assert_equal([-1,-1,-1,-1], a)
75+
endfu
76+
77+
function! Test_indent_fold()
78+
new
79+
call setline(1, ['', 'a', ' b', ' c'])
80+
setl fen fdm=indent
81+
2
82+
norm! >>
83+
let a=map(range(1,4), 'foldclosed(v:val)')
84+
call assert_equal([-1,-1,-1,-1], a)
85+
bw!
86+
endfu
87+
88+
function! Test_indent_fold2()
89+
new
90+
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
91+
setl fen fdm=marker
92+
2
93+
norm! >>
94+
let a=map(range(1,5), 'foldclosed(v:val)')
95+
call assert_equal([-1,-1,-1,4,4], a)
96+
bw!
97+
endfu

src/testdir/test_nested_function.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,28 @@ func Test_nested_argument()
4040
delfunc g:X
4141
unlet g:Y
4242
endfunc
43+
44+
func Recurse(count)
45+
if a:count > 0
46+
call Recurse(a:count - 1)
47+
endif
48+
endfunc
49+
50+
func Test_max_nesting()
51+
" TODO: why does this fail on Windows? Runs out of stack perhaps?
52+
if has('win32')
53+
return
54+
endif
55+
let call_depth_here = 2
56+
let ex_depth_here = 5
57+
set mfd&
58+
59+
call Recurse(99 - call_depth_here)
60+
call assert_fails('call Recurse(' . (100 - call_depth_here) . ')', 'E132:')
61+
62+
set mfd=210
63+
call Recurse(209 - ex_depth_here)
64+
call assert_fails('call Recurse(' . (210 - ex_depth_here) . ')', 'E169:')
65+
66+
set mfd&
67+
endfunc

src/testdir/test_visual.vim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
" Tests for Visual mode. Uses double-wide character.
2-
if !has('multi_byte')
3-
finish
4-
endif
5-
1+
" Tests for various Visual mode.
62
if !has('visual')
73
finish
84
endif
95

106
func Test_block_shift_multibyte()
7+
" Uses double-wide character.
8+
if !has('multi_byte')
9+
return
10+
endif
1111
split
1212
call setline(1, ['xヹxxx', 'ヹxxx'])
1313
exe "normal 1G0l\<C-V>jl>"
1414
call assert_equal('x ヹxxx', getline(1))
1515
call assert_equal(' ヹxxx', getline(2))
1616
q!
1717
endfunc
18+
19+
func Test_dotregister_paste()
20+
new
21+
exe "norm! ihello world\<esc>"
22+
norm! 0ve".p
23+
call assert_equal('hello world world', getline(1))
24+
q!
25+
endfunc

src/version.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,20 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
141,
784+
/**/
785+
140,
786+
/**/
787+
139,
788+
/**/
789+
138,
790+
/**/
791+
137,
792+
/**/
793+
136,
794+
/**/
795+
135,
782796
/**/
783797
134,
784798
/**/

0 commit comments

Comments
 (0)