]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.0311: filtering entries in a quickfix list is not easy v8.1.0311
authorBram Moolenaar <Bram@vim.org>
Tue, 21 Aug 2018 17:22:23 +0000 (19:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 21 Aug 2018 17:22:23 +0000 (19:22 +0200)
Problem:    Filtering entries in a quickfix list is not easy.
Solution:   Add the cfilter plugin. (Yegappan Lakshmanan)

runtime/doc/quickfix.txt
runtime/pack/dist/opt/cfilter/plugin/cfilter.vim [new file with mode: 0644]
src/version.c

index 1399d8bed4376b0380570d50174c654d6f96b19b..211fe961171ef4ea845d1dd00dbac4a359583248 100644 (file)
@@ -1551,6 +1551,22 @@ The backslashes before the pipe character are required to avoid it to be
 recognized as a command separator.  The backslash before each space is
 required for the set command.
 
+                                               *cfilter-plugin*
+If you have too many matching messages, you can use the cfilter plugin to
+reduce the number of entries.  Load the plugin with: >
+   packadd cfilter
+
+Then you can use these command: >
+   :Cfilter[!] {pat}
+   :Lfilter[!] {pat}
+
+:Cfilter creates a new quickfix list from entries matching {pat} in the
+current quickfix list. Both the file name and the text of the entries are
+matched against {pat}. If ! is supplied, then entries not matching {pat} are
+used.
+
+:Lfilter does the same as :Cfilter but operates on the current location list.
+
 =============================================================================
 8. The directory stack                         *quickfix-directory-stack*
 
diff --git a/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim b/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim
new file mode 100644 (file)
index 0000000..7a6464f
--- /dev/null
@@ -0,0 +1,43 @@
+" cfilter.vim: Plugin to filter entries from a quickfix/location list
+" Last Change:         May 12, 2018
+" Maintainer:  Yegappan Lakshmanan (yegappan AT yahoo DOT com)
+" Version:     1.0
+"
+" Commands to filter the quickfix list:
+"   :Cfilter[!] {pat}
+"       Create a new quickfix list from entries matching {pat} in the current
+"       quickfix list. Both the file name and the text of the entries are
+"       matched against {pat}. If ! is supplied, then entries not matching
+"       {pat} are used.
+"   :Lfilter[!] {pat}
+"       Same as :Cfilter but operates on the current location list.
+"
+if exists("loaded_cfilter")
+    finish
+endif
+let loaded_cfilter = 1
+
+func s:Qf_filter(qf, pat, bang)
+    if a:qf
+       let Xgetlist = function('getqflist')
+       let Xsetlist = function('setqflist')
+       let cmd = ':Cfilter' . a:bang
+    else
+       let Xgetlist = function('getloclist', [0])
+       let Xsetlist = function('setloclist', [0])
+       let cmd = ':Lfilter' . a:bang
+    endif
+
+    if a:bang == '!'
+       let cond = 'v:val.text !~# a:pat && bufname(v:val.bufnr) !~# a:pat'
+    else
+       let cond = 'v:val.text =~# a:pat || bufname(v:val.bufnr) =~# a:pat'
+    endif
+
+    let items = filter(Xgetlist(), cond)
+    let title = cmd . ' ' . a:pat
+    call Xsetlist([], ' ', {'title' : title, 'items' : items})
+endfunc
+
+com! -nargs=+ -bang Cfilter call s:Qf_filter(1, <q-args>, <q-bang>)
+com! -nargs=+ -bang Lfilter call s:Qf_filter(0, <q-args>, <q-bang>)
index cc62660160299f0a16da33d004c4cbe257d34764..f37cdfcf6fa3e9216a94d87fc2a8176da28b0e93 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    311,
 /**/
     310,
 /**/