vim-patch:7.4.566

Problem:    :argdo, :bufdo, :windo and :tabdo don't take a range.
Solution:   Support the range. (Marcin Szamotulski)

https://code.google.com/p/vim/source/detail?r=v7-4-566
This commit is contained in:
Felipe Morales
2015-01-20 01:02:35 -03:00
parent ca883df007
commit ff70129d96
8 changed files with 96 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
*editing.txt* For Vim version 7.4. Last change: 2014 Jul 19 *editing.txt* For Vim version 7.4. Last change: 2015 Apr 18
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -801,8 +801,9 @@ current window. The two windows then share this list, until one of them uses
USING THE ARGUMENT LIST USING THE ARGUMENT LIST
*:argdo* *:argdo*
:argdo[!] {cmd} Execute {cmd} for each file in the argument list. :[range]argdo[!] {cmd} Execute {cmd} for each file in the argument list or,
It works like doing this: > if [range] is specified, only for arguments in that
range. It works like doing this: >
:rewind :rewind
:{cmd} :{cmd}
:next :next

View File

@@ -1,4 +1,4 @@
*tabpage.txt* For Vim version 7.4. Last change: 2012 Aug 08 *tabpage.txt* For Vim version 7.4. Last change: 2015 Apr 18
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -222,8 +222,10 @@ clarification what +N means in this context see |[range]|.
LOOPING OVER TAB PAGES: LOOPING OVER TAB PAGES:
*:tabd* *:tabdo* *:tabd* *:tabdo*
:tabd[o] {cmd} Execute {cmd} in each tab page. :[range]tabd[o] {cmd}
It works like doing this: > Execute {cmd} in each tab page or, if [range] is given, only
in tabpages which tab page number is in the [range]. It works
like doing this: >
:tabfirst :tabfirst
:{cmd} :{cmd}
:tabnext :tabnext

View File

@@ -695,8 +695,9 @@ can also get to them with the buffer list commands, like ":bnext".
8. Do a command in all buffers or windows *list-repeat* 8. Do a command in all buffers or windows *list-repeat*
*:windo* *:windo*
:windo {cmd} Execute {cmd} in each window. :[range]windo {cmd} Execute {cmd} in each window or if [range] is given
It works like doing this: > only in windows for which the window number lies in
the [range]. It works like doing this: >
CTRL-W t CTRL-W t
:{cmd} :{cmd}
CTRL-W w CTRL-W w
@@ -714,8 +715,10 @@ can also get to them with the buffer list commands, like ":bnext".
Also see |:tabdo|, |:argdo| and |:bufdo|. Also see |:tabdo|, |:argdo| and |:bufdo|.
*:bufdo* *:bufdo*
:bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list. :[range]bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list or if
It works like doing this: > [range[ is given only for buffers for which their
buffer name is in the [range]. It works like doing
this: >
:bfirst :bfirst
:{cmd} :{cmd}
:bnext :bnext

View File

@@ -99,8 +99,8 @@ return {
}, },
{ {
command='argdo', command='argdo',
flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM), flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM, RANGE, NOTADR, DFLALL),
addr_type=ADDR_LINES, addr_type=ADDR_ARGUMENTS,
func='ex_listdo', func='ex_listdo',
}, },
{ {
@@ -273,8 +273,8 @@ return {
}, },
{ {
command='bufdo', command='bufdo',
flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM), flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM, RANGE, NOTADR, DFLALL),
addr_type=ADDR_LINES, addr_type=ADDR_BUFFERS,
func='ex_listdo', func='ex_listdo',
}, },
{ {
@@ -2583,8 +2583,8 @@ return {
}, },
{ {
command='tabdo', command='tabdo',
flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM), flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM, RANGE, NOTADR, DFLALL),
addr_type=ADDR_LINES, addr_type=ADDR_TABS,
func='ex_listdo', func='ex_listdo',
}, },
{ {
@@ -2997,8 +2997,8 @@ return {
}, },
{ {
command='windo', command='windo',
flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM), flags=bit.bor(BANG, NEEDARG, EXTRA, NOTRLCOM, RANGE, NOTADR, DFLALL),
addr_type=ADDR_LINES, addr_type=ADDR_WINDOWS,
func='ex_listdo', func='ex_listdo',
}, },
{ {

View File

@@ -1844,13 +1844,33 @@ void ex_listdo(exarg_T *eap)
|| !check_changed(curbuf, CCGD_AW || !check_changed(curbuf, CCGD_AW
| (eap->forceit ? CCGD_FORCEIT : 0) | (eap->forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD)) { | CCGD_EXCMD)) {
/* start at the first argument/window/buffer */
i = 0; i = 0;
/* start at the eap->line1 argument/window/buffer */
wp = firstwin; wp = firstwin;
tp = first_tabpage; tp = first_tabpage;
switch (eap->cmdidx) {
case CMD_windo:
for (; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) {
i++;
}
break;
case CMD_tabdo:
for (; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) {
i++;
}
break;
case CMD_argdo:
i = eap->line1 - 1;
break;
case CMD_bufdo:
i = eap->line1;
break;
default:
break;
}
/* set pcmark now */ /* set pcmark now */
if (eap->cmdidx == CMD_bufdo) if (eap->cmdidx == CMD_bufdo)
goto_buffer(eap, DOBUF_FIRST, FORWARD, 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, i);
else else
setpcmark(); setpcmark();
listcmd_busy = TRUE; /* avoids setting pcmark below */ listcmd_busy = TRUE; /* avoids setting pcmark below */
@@ -1873,7 +1893,6 @@ void ex_listdo(exarg_T *eap)
} }
if (curwin->w_arg_idx != i) if (curwin->w_arg_idx != i)
break; break;
++i;
} else if (eap->cmdidx == CMD_windo) { } else if (eap->cmdidx == CMD_windo) {
/* go to window "wp" */ /* go to window "wp" */
if (!win_valid(wp)) if (!win_valid(wp))
@@ -1899,13 +1918,14 @@ void ex_listdo(exarg_T *eap)
} }
} }
++i;
/* execute the command */ /* execute the command */
do_cmdline(eap->arg, eap->getline, eap->cookie, do_cmdline(eap->arg, eap->getline, eap->cookie,
DOCMD_VERBOSE + DOCMD_NOWAIT); DOCMD_VERBOSE + DOCMD_NOWAIT);
if (eap->cmdidx == CMD_bufdo) { if (eap->cmdidx == CMD_bufdo) {
/* Done? */ /* Done? */
if (next_fnum < 0) if (next_fnum < 0 || next_fnum > eap->line2)
break; break;
/* Check if the buffer still exists. */ /* Check if the buffer still exists. */
@@ -1939,6 +1959,14 @@ void ex_listdo(exarg_T *eap)
if (curwin->w_p_scb) if (curwin->w_p_scb)
do_check_scrollbind(TRUE); do_check_scrollbind(TRUE);
} }
if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo) {
if (i + 1 > eap->line2) {
break;
}
}
if (eap->cmdidx == CMD_argdo && i >= eap->line2) {
break;
}
} }
listcmd_busy = FALSE; listcmd_busy = FALSE;
} }

View File

@@ -90,6 +90,40 @@ STARTTEST
:only! :only!
:e! test.out :e! test.out
:call append(0, g:lines) :call append(0, g:lines)
:unlet g:lines
:w|bd
:se hidden
:b1
ENDTEST
STARTTEST
:only!
:let g:lines = []
:%argd
:arga a b c d e f
:3argu
:let args = ''
:.,$-argdo let args .= ' '.expand('%')
:call add(g:lines, 'argdo:' . args)
:split|split|split|split
:2wincmd w
:let windows = ''
:.,$-windo let windows .= ' '.winnr()
:call add(g:lines, 'windo:'. windows)
:b2
:let buffers = ''
:.,$-bufdo let buffers .= ' '.bufnr('%')
:call add(g:lines, 'bufdo:' . buffers)
:let buffers = ''
:3,7bufdo let buffers .= ' '.bufnr('%')
:call add(g:lines, 'bufdo:' . buffers)
:tabe|tabe|tabe|tabe
:normal! 2gt
:let tabpages = ''
:.,$-tabdo let tabpages .= ' '.tabpagenr()
:call add(g:lines, 'tabdo:' . tabpages)
:e! test.out
:call append('$', g:lines)
:w|qa! :w|qa!
ENDTEST ENDTEST

View File

@@ -28,3 +28,8 @@ $tabe 2
$+tabe E16: Invalid range $+tabe E16: Invalid range
0tabm x 0tabm x
argdo: c d e
windo: 2 3 4
bufdo: 2 3 4 5 6 7 8 9 10 12
bufdo: 3 4 5 6 7
tabdo: 2 3 4

View File

@@ -213,7 +213,7 @@ static int included_patches[] = {
//569, //569,
//568, //568,
567, 567,
//566, 566,
565, 565,
//564, //564,
563, 563,