Mercurial > vim
annotate runtime/pack/dist/opt/cfilter/plugin/cfilter.vim @ 18478:94223687df0e
Added tag v8.1.2233 for changeset e93cab5d0f0f27fad7882f1f412927df055b090d
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 29 Oct 2019 04:30:05 +0100 |
parents | 0ecb909e3249 |
children | 912224cab37f |
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 |
14637 | 2 " Last Change: Aug 23, 2018 |
3 " Maintainer: Yegappan Lakshmanan (yegappan AT yahoo DOT com) | |
4 " Version: 1.1 | |
14595
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: |
14637 | 7 " :Cfilter[!] /{pat}/ |
14595
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 |
14637 | 11 " {pat} are used. The pattern can be optionally enclosed using one of |
12 " the following characters: ', ", /. If the pattern is empty, then the | |
13 " last used search pattern is used. | |
14 " :Lfilter[!] /{pat}/ | |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 " 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
|
16 " |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 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
|
18 finish |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 endif |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 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
|
21 |
14637 | 22 func s:Qf_filter(qf, searchpat, bang) |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 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
|
27 else |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 endif |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 |
14637 | 33 let firstchar = a:searchpat[0] |
34 let lastchar = a:searchpat[-1:] | |
35 if firstchar == lastchar && | |
36 \ (firstchar == '/' || firstchar == '"' || firstchar == "'") | |
37 let pat = a:searchpat[1:-2] | |
38 if pat == '' | |
39 " Use the last search pattern | |
40 let pat = @/ | |
41 endif | |
42 else | |
43 let pat = a:searchpat | |
44 endif | |
45 | |
46 if pat == '' | |
47 return | |
48 endif | |
49 | |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 if a:bang == '!' |
14637 | 51 let cond = 'v:val.text !~# pat && bufname(v:val.bufnr) !~# pat' |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 else |
14637 | 53 let cond = 'v:val.text =~# pat || bufname(v:val.bufnr) =~# pat' |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 endif |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 let items = filter(Xgetlist(), cond) |
14637 | 57 let title = cmd . ' /' . pat . '/' |
14595
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 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
|
59 endfunc |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 |
2b9c586918f8
patch 8.1.0311: filtering entries in a quickfix list is not easy
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 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
|
62 com! -nargs=+ -bang Lfilter call s:Qf_filter(0, <q-args>, <q-bang>) |