annotate runtime/pack/dist/opt/cfilter/plugin/cfilter.vim @ 14595:2b9c586918f8 v8.1.0311

patch 8.1.0311: filtering entries in a quickfix list is not easy commit https://github.com/vim/vim/commit/8c5e0093c9badced73e382915fb024a5c3ea463b Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 21 19:22:23 2018 +0200 patch 8.1.0311: filtering entries in a quickfix list is not easy Problem: Filtering entries in a quickfix list is not easy. Solution: Add the cfilter plugin. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Tue, 21 Aug 2018 19:30:06 +0200
parents
children 0ecb909e3249
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14595
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " cfilter.vim: Plugin to filter entries from a quickfix/location list
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Last Change: May 12, 2018
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Maintainer: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Version: 1.0
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 "
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " Commands to filter the quickfix list:
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " :Cfilter[!] {pat}
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " Create a new quickfix list from entries matching {pat} in the current
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 " quickfix list. Both the file name and the text of the entries are
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " matched against {pat}. If ! is supplied, then entries not matching
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " {pat} are used.
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " :Lfilter[!] {pat}
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 " Same as :Cfilter but operates on the current location list.
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 "
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 if exists("loaded_cfilter")
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 finish
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endif
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let loaded_cfilter = 1
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 func s:Qf_filter(qf, pat, bang)
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 if a:qf
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let Xgetlist = function('getqflist')
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 let Xsetlist = function('setqflist')
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let cmd = ':Cfilter' . a:bang
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 else
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let Xgetlist = function('getloclist', [0])
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let Xsetlist = function('setloclist', [0])
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let cmd = ':Lfilter' . a:bang
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 endif
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 if a:bang == '!'
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 let cond = 'v:val.text !~# a:pat && bufname(v:val.bufnr) !~# a:pat'
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 else
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 let cond = 'v:val.text =~# a:pat || bufname(v:val.bufnr) =~# a:pat'
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 endif
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let items = filter(Xgetlist(), cond)
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let title = cmd . ' ' . a:pat
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 call Xsetlist([], ' ', {'title' : title, 'items' : items})
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 endfunc
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 com! -nargs=+ -bang Cfilter call s:Qf_filter(1, <q-args>, <q-bang>)
2b9c586918f8 patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 com! -nargs=+ -bang Lfilter call s:Qf_filter(0, <q-args>, <q-bang>)