|
1 | 1 | " vim-qf - Tame the quickfix window
|
2 | 2 | " Maintainer: romainl <[email protected]>
|
3 |
| -" Version: 0.0.3 |
| 3 | +" Version: 0.0.2 |
4 | 4 | " License: Vim License (see :help license)
|
5 | 5 | " Location: autoload/qf.vim
|
6 | 6 | " Website: https://github.com/romainl/vim-qf
|
@@ -51,33 +51,174 @@ endfunction
|
51 | 51 |
|
52 | 52 | " filter the current list
|
53 | 53 | function qf#FilterList(pat)
|
| 54 | + call qf#AddList() |
| 55 | + call qf#AddTitle(w:quickfix_title) |
| 56 | + |
| 57 | + call qf#SetList(a:pat) |
| 58 | + |
| 59 | + call qf#SetTitle(a:pat) |
| 60 | + call qf#AddTitle(w:quickfix_title) |
| 61 | +endfunction |
| 62 | + |
| 63 | +" restore the original list |
| 64 | +function qf#RestoreList() |
54 | 65 | if exists("b:isLoc")
|
55 | 66 | if b:isLoc == 1
|
56 |
| - if !exists("b:locl") |
57 |
| - let b:locl = getloclist(0) |
58 |
| - let w:qf_title = w:quickfix_title |
| 67 | + let lists = getwinvar(winnr("#"), "qf_location_lists") |
| 68 | + if len(lists) > 0 |
| 69 | + call setloclist(0, getwinvar(winnr("#"), "qf_location_lists")[0], "r") |
| 70 | + let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0] |
| 71 | + else |
| 72 | + echo "No filter applied. Nothing to restore." |
59 | 73 | endif
|
60 |
| - call setloclist(0, filter(getloclist(0), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat")) |
61 | 74 | else
|
62 |
| - if !exists("b:qfl") |
63 |
| - let b:qfl = getqflist() |
64 |
| - let w:qf_title = w:quickfix_title |
| 75 | + if exists("g:qf_quickfix_lists") |
| 76 | + if len(g:qf_quickfix_lists) > 0 |
| 77 | + call setqflist(g:qf_quickfix_lists[0], "r") |
| 78 | + let w:quickfix_title = g:qf_quickfix_titles[0] |
| 79 | + else |
| 80 | + echo "No filter applied. Nothing to restore." |
| 81 | + endif |
65 | 82 | endif
|
66 |
| - call setqflist(filter(getqflist(), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat")) |
67 | 83 | endif
|
68 |
| - let w:quickfix_title = w:qf_title . "[filtered]" |
69 | 84 | endif
|
| 85 | + call qf#ResetLists() |
70 | 86 | endfunction
|
71 | 87 |
|
72 |
| -" restore the original list |
73 |
| -function qf#RestoreList() |
| 88 | +function qf#ResetLists() |
| 89 | + if exists("b:isLoc") |
| 90 | + if b:isLoc == 1 |
| 91 | + call setwinvar(winnr("#"), "qf_location_lists", []) |
| 92 | + call setwinvar(winnr("#"), "qf_location_titles", []) |
| 93 | + else |
| 94 | + let g:qf_quickfix_lists = [] |
| 95 | + let g:qf_quickfix_titles = [] |
| 96 | + endif |
| 97 | + endif |
| 98 | +endfunction |
| 99 | + |
| 100 | +function qf#SetStatusline() |
| 101 | + if exists("b:isLoc") |
| 102 | + if b:isLoc == 1 |
| 103 | + let titles = getwinvar(winnr("#"), "qf_location_titles") |
| 104 | + if len(titles) > 0 |
| 105 | + return titles[-1] |
| 106 | + else |
| 107 | + if exists("w:quickfix_title") |
| 108 | + return w:quickfix_title |
| 109 | + else |
| 110 | + return "" |
| 111 | + endif |
| 112 | + endif |
| 113 | + else |
| 114 | + if exists("g:qf_quickfix_titles") |
| 115 | + if len(g:qf_quickfix_titles) > 0 |
| 116 | + return g:qf_quickfix_titles[-1] |
| 117 | + else |
| 118 | + if exists("w:quickfix_title") |
| 119 | + return w:quickfix_title |
| 120 | + else |
| 121 | + return "" |
| 122 | + endif |
| 123 | + endif |
| 124 | + else |
| 125 | + if exists("w:quickfix_title") |
| 126 | + return w:quickfix_title |
| 127 | + else |
| 128 | + return "" |
| 129 | + endif |
| 130 | + endif |
| 131 | + endif |
| 132 | + endif |
| 133 | +endfunction |
| 134 | + |
| 135 | +function qf#SetList(pat) |
| 136 | + if exists("b:isLoc") |
| 137 | + if b:isLoc == 1 |
| 138 | + call setloclist(0, filter(getloclist(0), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat"), "r") |
| 139 | + else |
| 140 | + call setqflist(filter(getqflist(), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat"), "r") |
| 141 | + endif |
| 142 | + endif |
| 143 | +endfunction |
| 144 | + |
| 145 | +function qf#AddList() |
| 146 | + if exists("b:isLoc") |
| 147 | + if b:isLoc == 1 |
| 148 | + let locations = getwinvar(winnr("#"), "qf_location_lists") |
| 149 | + if len(locations) > 0 |
| 150 | + call add(locations, getloclist(0)) |
| 151 | + call setwinvar(winnr("#"), "qf_location_lists", locations) |
| 152 | + else |
| 153 | + call setwinvar(winnr("#"), "qf_location_lists", [getloclist(0)]) |
| 154 | + endif |
| 155 | + else |
| 156 | + if exists("g:qf_quickfix_lists") |
| 157 | + let g:qf_quickfix_lists = add(g:qf_quickfix_lists, getqflist()) |
| 158 | + else |
| 159 | + let g:qf_quickfix_lists = [getqflist()] |
| 160 | + endif |
| 161 | + endif |
| 162 | + endif |
| 163 | +endfunction |
| 164 | + |
| 165 | +function qf#SetTitle(pat) |
| 166 | + if exists("b:isLoc") |
| 167 | + if b:isLoc == 1 |
| 168 | + let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0] . " [filter: '" . a:pat . "']" |
| 169 | + else |
| 170 | + if len(g:qf_quickfix_titles) > 0 |
| 171 | + let w:quickfix_title = g:qf_quickfix_titles[0] . " [filter: '" . a:pat . "']" |
| 172 | + else |
| 173 | + let w:quickfix_title = w:quickfix_title . " [filter: '" . a:pat . "']" |
| 174 | + endif |
| 175 | + endif |
| 176 | + endif |
| 177 | +endfunction |
| 178 | + |
| 179 | +function qf#AddTitle(title) |
| 180 | + if exists("b:isLoc") |
| 181 | + if b:isLoc == 1 |
| 182 | + let titles = getwinvar(winnr("#"), "qf_location_titles") |
| 183 | + if len(titles) > 0 |
| 184 | + call add(titles, a:title) |
| 185 | + call setwinvar(winnr("#"), "qf_location_titles", titles) |
| 186 | + else |
| 187 | + call setwinvar(winnr("#"), "qf_location_titles", [a:title]) |
| 188 | + endif |
| 189 | + else |
| 190 | + if exists("g:qf_quickfix_titles") |
| 191 | + let g:qf_quickfix_titles = add(g:qf_quickfix_titles, a:title) |
| 192 | + else |
| 193 | + let g:qf_quickfix_titles = [a:title] |
| 194 | + endif |
| 195 | + endif |
| 196 | + endif |
| 197 | +endfunction |
| 198 | + |
| 199 | +function qf#ReuseTitle() |
74 | 200 | if exists("b:isLoc")
|
75 |
| - if b:isLoc == 1 && exists("b:locl") |
76 |
| - call setloclist(0, b:locl) |
77 |
| - elseif b:isLoc != 1 && !exists("b:locl") |
78 |
| - call setqflist(b:qfl) |
| 201 | + if b:isLoc == 1 |
| 202 | + let titles = getwinvar(winnr("#"), "qf_location_titles") |
| 203 | + if len(titles) > 0 |
| 204 | + let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0]" |
| 205 | + endif |
| 206 | + else |
| 207 | + if exists("g:qf_quickfix_titles") |
| 208 | + let w:quickfix_title = g:qf_quickfix_titles[0] |
| 209 | + endif |
| 210 | + endif |
| 211 | + endif |
| 212 | +endfunction |
| 213 | + |
| 214 | +" template |
| 215 | +function qf#FunctionName(argument) |
| 216 | + if exists("b:isLoc") |
| 217 | + if b:isLoc == 1 |
| 218 | + " do something |
| 219 | + else |
| 220 | + " do something else |
79 | 221 | endif
|
80 |
| - let w:quickfix_title = w:qf_title |
81 | 222 | endif
|
82 | 223 | endfunction
|
83 | 224 |
|
|
0 commit comments