Hi all, I am attaching a patch to add the ":cfilter" and ":lfilter" commands to filter entries matching a pattern from the quickfix/location lists. The :cfilter command creates a new quickfix list with entries matching the specified regex pattern. When "!" is supplied, creates a list with entries not matching the pattern.
- Yegappan -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index 88abdd9..0e27aab 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1143,6 +1143,7 @@ tag command action ~ |:center| :ce[nter] format lines at the center |:cexpr| :cex[pr] read errors from expr and jump to first |:cfile| :cf[ile] read file with error messages and jump to first +|:cfilter| :cfilt[er] filter entries in the quickfix list |:cfirst| :cfir[st] go to the specified error, default first one |:cgetbuffer| :cgetb[uffer] get errors from buffer |:cgetexpr| :cgete[xpr] get errors from expr @@ -1300,6 +1301,7 @@ tag command action ~ |:lcscope| :lcs[cope] like ":cscope" but uses location list |:ldo| :ld[o] execute command in valid location list entries |:lfdo| :lfd[o] execute command in each file in location list +|:lfilter| :lfilt[er] filter entries in the location list |:left| :le[ft] left align lines |:leftabove| :lefta[bove] make split window appear left or above |:let| :let assign a value to a variable or option diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt index 3d42337..7e8c9a7 100644 --- a/runtime/doc/quickfix.txt +++ b/runtime/doc/quickfix.txt @@ -253,6 +253,15 @@ command with 'l'. :lad[dexpr] {expr} Same as ":caddexpr", except the location list for the current window is used instead of the quickfix list. + *:cfilt* *:cfilter* +:cfilt[er][!] {pattern} Create a new quickfix list with entries in the current + quickfix list matching {pattern}. With [!], entries + not matching {pattern} are used. + + *:lfilt* *:lfilter* +:lfilt[er][!] {pattern} Same as ":cfilter", except the location list for the + current window is used instead of the quickfix list. + *:cl* *:clist* :cl[ist] [from] [, [to]] List all errors that are valid |quickfix-valid|. diff --git a/src/ex_cmds.h b/src/ex_cmds.h index 34defea..fff235c 100644 --- a/src/ex_cmds.h +++ b/src/ex_cmds.h @@ -279,6 +279,9 @@ EX(CMD_cexpr, "cexpr", ex_cexpr, EX(CMD_cfile, "cfile", ex_cfile, TRLBAR|FILE1|BANG, ADDR_LINES), +EX(CMD_cfilter, "cfilter", ex_cfilter, + BANG|EXTRA|NEEDARG|NOTRLCOM|NOTADR, + ADDR_LINES), EX(CMD_cfdo, "cfdo", ex_listdo, BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|NOTADR|DFLALL, ADDR_QUICKFIX), @@ -750,6 +753,9 @@ EX(CMD_lexpr, "lexpr", ex_cexpr, EX(CMD_lfile, "lfile", ex_cfile, TRLBAR|FILE1|BANG, ADDR_LINES), +EX(CMD_lfilter, "lfilter", ex_cfilter, + BANG|EXTRA|NEEDARG|NOTRLCOM|NOTADR, + ADDR_LINES), EX(CMD_lfdo, "lfdo", ex_listdo, BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|NOTADR|DFLALL, ADDR_QUICKFIX), diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 9b116e2..8470173 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -120,6 +120,7 @@ static int getargopt(exarg_T *eap); # define ex_cc ex_ni # define ex_cnext ex_ni # define ex_cfile ex_ni +# define ex_cfilter ex_ni # define qf_list ex_ni # define qf_age ex_ni # define ex_helpgrep ex_ni diff --git a/src/proto/quickfix.pro b/src/proto/quickfix.pro index cc60edd..0957927 100644 --- a/src/proto/quickfix.pro +++ b/src/proto/quickfix.pro @@ -29,5 +29,6 @@ int get_errorlist(win_T *wp, list_T *list); int set_errorlist(win_T *wp, list_T *list, int action, char_u *title); void ex_cbuffer(exarg_T *eap); void ex_cexpr(exarg_T *eap); +void ex_cfilter(exarg_T *eap); void ex_helpgrep(exarg_T *eap); /* vim: set ft=c : */ diff --git a/src/quickfix.c b/src/quickfix.c index eb6433e..9252986 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -4178,6 +4178,121 @@ ex_cexpr(exarg_T *eap) #endif /* + * ":cfilter {pattern}" + * ":lfilter {pattern}" + */ + void +ex_cfilter(exarg_T *eap) +{ + regmatch_T regmatch; + char_u *s; + char_u *p; + qf_info_T *qi = &ql_info; + int i, qf_count, add_entry; + qfline_T *qfp; + dict_T *dict; + qfline_T *prevp = NULL; + + if (eap->cmdidx == CMD_lfilter) + { + qi = GET_LOC_LIST(curwin); + if (qi == NULL) + { + EMSG(_(e_loclist)); + return; + } + } + + if (qi->qf_curlist >= qi->qf_listcount + || qi->qf_lists[qi->qf_curlist].qf_count == 0) + { + EMSG(_(e_quickfix)); + return; + } + + if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) + return; + + /* Get the search pattern: either white-separated or enclosed in // */ + regmatch.regprog = NULL; + p = skip_vimgrep_pat(eap->arg, &s, NULL); + if (p == NULL) + { + EMSG(_(e_invalpat)); + return; + } + + if (s != NULL && *s == NUL) + { + /* Pattern is empty, use last search pattern. */ + if (last_search_pat() == NULL) + { + EMSG(_(e_noprevre)); + return; + } + s = last_search_pat(); + } + regmatch.regprog = vim_regcomp(s, RE_MAGIC + RE_STRING); + regmatch.rm_ic = FALSE; + + if (regmatch.regprog != NULL) + { + qfp = qi->qf_lists[qi->qf_curlist].qf_start; + qf_count = qi->qf_lists[qi->qf_curlist].qf_count; + + /* create a new quickfix list */ + qf_new_list(qi, *eap->cmdlinep); + + for (i = 1; !got_int && i <= qf_count; i++) + { + if (qfp->qf_valid) + { + add_entry = 0; + if (vim_regexec(®match, qfp->qf_text, (colnr_T)0)) + { + if (!eap->forceit) + add_entry = 1; + } else if (eap->forceit) + add_entry = 1; + if (add_entry) + { + if (qf_add_entry(qi, &prevp, + NULL, /* dir */ + NULL, /* file name */ + qfp->qf_fnum, + qfp->qf_text, + qfp->qf_lnum, + qfp->qf_col, + qfp->qf_viscol, + qfp->qf_pattern, + qfp->qf_nr, + qfp->qf_type, + qfp->qf_valid + ) == FAIL) + break; + } + } + qfp = qfp->qf_next; + } + + if (qi->qf_lists[qi->qf_curlist].qf_index == 0) + /* no valid entry */ + qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; + else + qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; + qi->qf_lists[qi->qf_curlist].qf_ptr = + qi->qf_lists[qi->qf_curlist].qf_start; + qi->qf_lists[qi->qf_curlist].qf_index = 1; + + vim_regfree(regmatch.regprog); + } + +#ifdef FEAT_WINDOWS + qf_update_buffer(qi); +#endif +} + +/* * ":helpgrep {pattern}" */ void