diff options
author | Bram Moolenaar <Bram@vim.org> | 2015-09-08 18:46:31 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2015-09-08 18:46:31 +0200 |
commit | aa23b379421aa214e6543b06c974594a25799b09 (patch) | |
tree | 88d37433372978ab8248d916093d6bba639fe5b2 /src/ex_cmds2.c | |
parent | 4a4b821085847651b71d8ad9fab9f180635cb453 (diff) | |
download | vim-git-aa23b379421aa214e6543b06c974594a25799b09.tar.gz |
patch 7.4.858v7.4.858
Problem: It's a bit clumsy to execute a command on a list of matches.
Solution: Add the ":ldo", ":lfdo", ":cdo" and ":cfdo" commands. (Yegappan
Lakshmanan)
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r-- | src/ex_cmds2.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index eefd5d237..3cc2d45a7 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -2429,7 +2429,7 @@ ex_argdelete(eap) } /* - * ":argdo", ":windo", ":bufdo", ":tabdo" + * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" */ void ex_listdo(eap) @@ -2446,6 +2446,10 @@ ex_listdo(eap) char_u *save_ei = NULL; #endif char_u *p_shm_save; +#ifdef FEAT_QUICKFIX + int qf_size; + int qf_idx; +#endif #ifndef FEAT_WINDOWS if (eap->cmdidx == CMD_windo) @@ -2498,18 +2502,37 @@ ex_listdo(eap) } /* set pcmark now */ if (eap->cmdidx == CMD_bufdo) - { + { /* Advance to the first listed buffer after "eap->line1". */ - for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 + for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl); buf = buf->b_next) if (buf->b_fnum > eap->line2) { buf = NULL; break; } - if (buf != NULL) + if (buf != NULL) goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum); - } + } +#ifdef FEAT_QUICKFIX + else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo + || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) + { + qf_size = qf_get_size(eap); + if (qf_size <= 0 || eap->line1 > qf_size) + buf = NULL; + else + { + ex_cc(eap); + + buf = curbuf; + i = eap->line1 - 1; + if (eap->addr_count <= 0) + /* default is all the quickfix/location list entries */ + eap->line2 = qf_size; + } + } +#endif else setpcmark(); listcmd_busy = TRUE; /* avoids setting pcmark below */ @@ -2595,11 +2618,28 @@ ex_listdo(eap) set_option_value((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); - /* If autocommands took us elsewhere, quit here */ + /* If autocommands took us elsewhere, quit here. */ if (curbuf->b_fnum != next_fnum) break; } +#ifdef FEAT_QUICKFIX + if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo + || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) + { + if (i >= qf_size || i >= eap->line2) + break; + + qf_idx = qf_get_cur_idx(eap); + + ex_cnext(eap); + + /* If jumping to the next quickfix entry fails, quit here */ + if (qf_get_cur_idx(eap) == qf_idx) + break; + } +#endif + if (eap->cmdidx == CMD_windo) { validate_cursor(); /* cursor may have moved */ |