Mercurial > dotfiles
comparison vim/autoload/quickfixed.vim @ 504:015e94f44cc0
Merged changes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 30 Sep 2020 21:17:47 -0700 |
parents | b452486b97c5 |
children |
comparison
equal
deleted
inserted
replaced
503:35094cf31de4 | 504:015e94f44cc0 |
---|---|
1 " Stolen from https://vimways.org/2018/colder-quickfix-lists/ | |
2 " ~/.vim/autoload/quickfixed.vim | |
3 function! s:isLocation() | |
4 " Get dictionary of properties of the current window | |
5 let wininfo = filter(getwininfo(), {i,v -> v.winnr == winnr()})[0] | |
6 return wininfo.loclist | |
7 endfunction | |
8 | |
9 function! s:length() | |
10 " Get the size of the current quickfix/location list | |
11 return len(s:isLocation() ? getloclist(0) : getqflist()) | |
12 endfunction | |
13 | |
14 function! s:getProperty(key, ...) | |
15 " getqflist() and getloclist() expect a dictionary argument | |
16 " If a 2nd argument has been passed in, use it as the value, else 0 | |
17 let l:what = {a:key : a:0 ? a:1 : 0} | |
18 let l:listdict = s:isLocation() ? getloclist(0, l:what) : getqflist(l:what) | |
19 return get(l:listdict, a:key) | |
20 endfunction | |
21 | |
22 function! s:isFirst() | |
23 return s:getProperty('nr') <= 1 | |
24 endfunction | |
25 | |
26 function! s:isLast() | |
27 return s:getProperty('nr') == s:getProperty('nr', '$') | |
28 endfunction | |
29 | |
30 function! s:history(goNewer) | |
31 " Build the command: one of colder/cnewer/lolder/lnewer | |
32 let l:cmd = (s:isLocation() ? 'l' : 'c') . (a:goNewer ? 'newer' : 'older') | |
33 | |
34 " Apply the cmd repeatedly until we hit a non-empty list, or first/last list | |
35 " is reached | |
36 while 1 | |
37 if (a:goNewer && s:isLast()) || (!a:goNewer && s:isFirst()) | break | endif | |
38 " Run the command. Use :silent to suppress message-history output. | |
39 " Note that the :try wrapper is no longer necessary | |
40 silent execute l:cmd | |
41 if s:length() | break | endif | |
42 endwhile | |
43 | |
44 " Set the height of the quickfix window to the size of the list, max-height 10 | |
45 execute 'resize' min([ 10, max([ 1, s:length() ]) ]) | |
46 | |
47 " Echo a description of the new quickfix / location list. | |
48 " And make it look like a rainbow. | |
49 let l:nr = s:getProperty('nr') | |
50 let l:last = s:getProperty('nr', '$') | |
51 echohl MoreMsg | echon '(' | |
52 echohl Identifier | echon l:nr | |
53 if l:last > 1 | |
54 echohl LineNr | echon ' of ' | |
55 echohl Identifier | echon l:last | |
56 endif | |
57 echohl MoreMsg | echon ') ' | |
58 echohl MoreMsg | echon '[' | |
59 echohl Identifier | echon s:length() | |
60 echohl MoreMsg | echon '] ' | |
61 echohl Normal | echon s:getProperty('title') | |
62 echohl None | |
63 endfunction | |
64 | |
65 function! quickfixed#older() | |
66 call s:history(0) | |
67 endfunction | |
68 | |
69 function! quickfixed#newer() | |
70 call s:history(1) | |
71 endfunction |