Skip to content

Commit ded2782

Browse files
committed
patch 8.0.0135
Problem: An address relative to the current line, ":.,+3y", does not work properly on a closed fold. (Efraim Yawitz) Solution: Correct for including the closed fold. (Christian Brabandt)
1 parent c4bfeda commit ded2782

File tree

5 files changed

+89
-8
lines changed

5 files changed

+89
-8
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,7 @@ test_arglist \
21062106
test_filter_map \
21072107
test_fnameescape \
21082108
test_fnamemodify \
2109+
test_fold \
21092110
test_glob2regpat \
21102111
test_gf \
21112112
test_gn \

src/ex_docmd.c

Lines changed: 20 additions & 8 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) \
@@ -1791,6 +1791,7 @@ do_one_cmd(
17911791
cmdmod_T save_cmdmod;
17921792
int ni; /* set when Not Implemented */
17931793
char_u *cmd;
1794+
int address_count = 1;
17941795

17951796
vim_memset(&ea, 0, sizeof(ea));
17961797
ea.line1 = 1;
@@ -2015,7 +2016,7 @@ do_one_cmd(
20152016
{
20162017
#ifdef FEAT_WINDOWS
20172018
long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS,
2018-
ea.skip, FALSE);
2019+
ea.skip, FALSE, 1);
20192020
if (tabnr == MAXLNUM)
20202021
cmdmod.tab = tabpage_index(curtab) + 1;
20212022
else
@@ -2175,7 +2176,7 @@ do_one_cmd(
21752176
}
21762177
ea.cmd = skipwhite(ea.cmd);
21772178
lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip,
2178-
ea.addr_count == 0);
2179+
ea.addr_count == 0, address_count++);
21792180
if (ea.cmd == NULL) /* error detected */
21802181
goto doend;
21812182
if (lnum == MAXLNUM)
@@ -4363,7 +4364,8 @@ get_address(
43634364
char_u **ptr,
43644365
int addr_type, /* flag: one of ADDR_LINES, ... */
43654366
int skip, /* only skip the address, don't use it */
4366-
int to_other_file) /* flag: may jump to other file */
4367+
int to_other_file, /* flag: may jump to other file */
4368+
int address_count) /* 1 for first address, >1 after comma */
43674369
{
43684370
int c;
43694371
int i;
@@ -4639,10 +4641,20 @@ get_address(
46394641
|| addr_type == ADDR_BUFFERS)
46404642
lnum = compute_buffer_local_count(
46414643
addr_type, lnum, (i == '-') ? -1 * n : n);
4642-
else if (i == '-')
4643-
lnum -= n;
46444644
else
4645-
lnum += n;
4645+
{
4646+
#ifdef FEAT_FOLDING
4647+
/* Relative line addressing, need to adjust for folded lines
4648+
* now, but only do it after the first address. */
4649+
if (addr_type == ADDR_LINES && (i == '-' || i == '+')
4650+
&& address_count >= 2)
4651+
(void)hasFolding(lnum, NULL, &lnum);
4652+
#endif
4653+
if (i == '-')
4654+
lnum -= n;
4655+
else
4656+
lnum += n;
4657+
}
46464658
}
46474659
} while (*cmd == '/' || *cmd == '?');
46484660

@@ -9301,7 +9313,7 @@ ex_copymove(exarg_T *eap)
93019313
{
93029314
long n;
93039315

9304-
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE);
9316+
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, 1);
93059317
if (eap->arg == NULL) /* error detected */
93069318
{
93079319
eap->nextcmd = NULL;

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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

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+
135,
767769
/**/
768770
134,
769771
/**/

0 commit comments

Comments
 (0)