vim-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)

ded2782783
This commit is contained in:
Justin M. Keyes 2017-03-02 00:00:51 +01:00
parent 985bc6c6e0
commit 3c740f7424
2 changed files with 133 additions and 9 deletions

View File

@ -1244,6 +1244,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
cmdmod_T save_cmdmod; cmdmod_T save_cmdmod;
int ni; /* set when Not Implemented */ int ni; /* set when Not Implemented */
char_u *cmd; char_u *cmd;
int address_count = 1;
memset(&ea, 0, sizeof(ea)); memset(&ea, 0, sizeof(ea));
ea.line1 = 1; ea.line1 = 1;
@ -1405,7 +1406,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
continue; continue;
case 't': if (checkforcmd(&p, "tab", 3)) { case 't': if (checkforcmd(&p, "tab", 3)) {
long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS, ea.skip, false); long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS, ea.skip, false, 1);
if (tabnr == MAXLNUM) { if (tabnr == MAXLNUM) {
cmdmod.tab = tabpage_index(curtab) + 1; cmdmod.tab = tabpage_index(curtab) + 1;
} else { } else {
@ -1543,7 +1544,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
} }
ea.cmd = skipwhite(ea.cmd); ea.cmd = skipwhite(ea.cmd);
lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip,
ea.addr_count == 0); ea.addr_count == 0, address_count++);
if (ea.cmd == NULL) { // error detected if (ea.cmd == NULL) { // error detected
goto doend; goto doend;
} }
@ -3422,8 +3423,8 @@ static linenr_T get_address(exarg_T *eap,
char_u **ptr, char_u **ptr,
int addr_type, // flag: one of ADDR_LINES, ... int addr_type, // flag: one of ADDR_LINES, ...
int skip, // only skip the address, don't use it int skip, // only skip the address, don't use it
int to_other_file // flag: may jump to other file int to_other_file, // flag: may jump to other file
) int address_count) // 1 for first, >1 after comma
{ {
int c; int c;
int i; int i;
@ -3656,10 +3657,19 @@ static linenr_T get_address(exarg_T *eap,
if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS)
lnum = compute_buffer_local_count( lnum = compute_buffer_local_count(
addr_type, lnum, (i == '-') ? -1 * n : n); addr_type, lnum, (i == '-') ? -1 * n : n);
else if (i == '-') else {
lnum -= n; // Relative line addressing, need to adjust for folded lines
else // now, but only do it after the first address.
lnum += n; if (addr_type == ADDR_LINES && (i == '-' || i == '+')
&& address_count >= 2) {
(void)hasFolding(lnum, NULL, &lnum);
}
if (i == '-') {
lnum -= n;
} else {
lnum += n;
}
}
} }
} while (*cmd == '/' || *cmd == '?'); } while (*cmd == '/' || *cmd == '?');
@ -7237,7 +7247,7 @@ static void ex_put(exarg_T *eap)
*/ */
static void ex_copymove(exarg_T *eap) static void ex_copymove(exarg_T *eap)
{ {
long n = get_address(eap, &eap->arg, eap->addr_type, false, false); long n = get_address(eap, &eap->arg, eap->addr_type, false, false, 1);
if (eap->arg == NULL) { // error detected if (eap->arg == NULL) { // error detected
eap->nextcmd = NULL; eap->nextcmd = NULL;
return; return;

View File

@ -0,0 +1,114 @@
" Test for folding
func! Test_address_fold()
new
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
\ 'after fold 1', 'after fold 2', 'after fold 3'])
setl fen fdm=marker
" The next ccommands should all copy the same part of the buffer,
" regardless of the adressing type, since the part to be copied
" is folded away
:1y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:.y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:.+y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:.,.y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:sil .1,.y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
" use silent to make E493 go away
:sil .+,.y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:,y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
:,+y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1))
" using .+3 as second address should copy the whole folded line + the next 3
" lines
:.,+3y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/',
\ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1))
:sil .,-2y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
" now test again with folding disabled
set nofoldenable
:1y
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
:.y
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
:.+y
call assert_equal(['1'], getreg(0,1,1))
:.,.y
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
" use silent to make E493 go away
:sil .1,.y
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
" use silent to make E493 go away
:sil .+,.y
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
:,y
call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
:,+y
call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
" using .+3 as second address should copy the whole folded line + the next 3
" lines
:.,+3y
call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1))
:7
:sil .,-2y
call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
quit!
endfunc
func! Test_indent_fold()
new
call setline(1, ['', 'a', ' b', ' c'])
setl fen fdm=indent
2
norm! >>
let a=map(range(1,4), 'foldclosed(v:val)')
call assert_equal([-1,-1,-1,-1], a)
endfunc
func! Test_indent_fold()
new
call setline(1, ['', 'a', ' b', ' c'])
setl fen fdm=indent
2
norm! >>
let a=map(range(1,4), 'foldclosed(v:val)')
call assert_equal([-1,-1,-1,-1], a)
bw!
endfunc
func! Test_indent_fold2()
new
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
setl fen fdm=marker
2
norm! >>
let a=map(range(1,5), 'foldclosed(v:val)')
call assert_equal([-1,-1,-1,4,4], a)
bw!
endfunc
func Test_manual_fold_with_filter()
if !executable('cat')
return
endif
new
call setline(1, range(1, 20))
4,$fold
%foldopen
10,$fold
%foldopen
" This filter command should not have an effect
1,8! cat
call feedkeys('5ggzdzMGdd', 'xt')
call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$'))
bwipe!
endfunc