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
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
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
2 " Last Change: Aug 23, 2018
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
3 " Maintainer: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
11 " {pat} are used. The pattern can be optionally enclosed using one of
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
12 " the following characters: ', ", /. If the pattern is empty, then the
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
13 " last used search pattern is used.
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
33 let firstchar = a:searchpat[0]
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
34 let lastchar = a:searchpat[-1:]
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
35 if firstchar == lastchar &&
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
36 \ (firstchar == '/' || firstchar == '"' || firstchar == "'")
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
37 let pat = a:searchpat[1:-2]
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
38 if pat == ''
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
39 " Use the last search pattern
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
40 let pat = @/
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
41 endif
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
42 else
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
43 let pat = a:searchpat
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
44 endif
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
45
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
46 if pat == ''
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
47 return
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
48 endif
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 14595
diff changeset
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>)