Mercurial > dotfiles
comparison vim/autoload/ludo.vim @ 435:b7682004288d
Move Vim stuff to autoload, add FZF tags lister.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Apr 2018 20:36:11 -0700 |
parents | 71a080d4d83c |
children | 1a54ffbc3b15 |
comparison
equal
deleted
inserted
replaced
434:44afdeba29bf | 435:b7682004288d |
---|---|
1 let g:ludo_trace = 0 | 1 let g:ludo_trace = 0 |
2 | |
3 " Get the platform we're running on. | |
4 if has("win32") || has("win64") || has("dos32") | |
5 let s:vim_platform = "windows" | |
6 let s:path_sep = "\\" | |
7 elseif has("mac") | |
8 let s:vim_platform = "mac" | |
9 let s:path_sep = '/' | |
10 else | |
11 let s:vim_platform = "unix" | |
12 let s:path_sep = '/' | |
13 endif | |
14 function! ludo#platform() abort | |
15 return s:vim_platform | |
16 endfunction | |
17 | |
18 " Get our vim directory. | |
19 let s:vim_home = expand("<sfile>:h:h") | |
20 | |
21 " Get local path. | |
22 function! ludo#localpath(...) abort | |
23 return s:vim_home.s:path_sep.join(a:000, s:path_sep) | |
24 endfunction | |
2 | 25 |
3 " Debug logging. | 26 " Debug logging. |
4 function! ludo#trace(msg) abort | 27 function! ludo#trace(msg) abort |
5 if g:ludo_trace | 28 if g:ludo_trace |
6 echom a:msg | 29 echom a:msg |
72 endfor | 95 endfor |
73 endfor | 96 endfor |
74 call ludo#trace("Exclude list: ".join(g:pathogen_disabled, ', ')) | 97 call ludo#trace("Exclude list: ".join(g:pathogen_disabled, ', ')) |
75 endfunction | 98 endfunction |
76 | 99 |
100 " Goyo writing mode tweaks | |
101 " | |
77 let s:ludo_revert = {} | 102 let s:ludo_revert = {} |
78 | 103 |
79 function! ludo#on_goyo_enter() | 104 function! ludo#on_goyo_enter() |
80 let s:ludo_revert = { | 105 let s:ludo_revert = { |
81 \'spell': &spell, | 106 \'spell': &spell, |
112 | 137 |
113 function! ludo#writingmode() | 138 function! ludo#writingmode() |
114 Goyo | 139 Goyo |
115 endfunction | 140 endfunction |
116 | 141 |
142 " Better tags browser using FZF | |
143 " | |
144 function! ludo#run_fzf_tags(args, bang) abort | |
145 let l:tag_files = tagfiles() | |
146 let l:tag_lister = | |
147 \'python '. | |
148 \ludo#localpath('scripts', 'list_tags.py').' -a 24 '. | |
149 \join(map(l:tag_files, "shellescape(v:val)")) | |
150 let options = { | |
151 \'source': l:tag_lister, | |
152 \'sink': function('s:tags_sink'), | |
153 \'options': '--algo=v1 --tiebreak=begin --prompt "Tags> "' | |
154 \} | |
155 return fzf#run(fzf#wrap('tags', options, a:bang)) | |
156 endfunction | |
157 | |
158 function! s:tags_sink(line) abort | |
159 let l:tokens = matchlist( | |
160 \a:line, | |
161 \'\v^(\S+)\s+([^\t]+)\t([^\t]{-1,})(;")?\t[a-z]+\tline\:([0-9]+)') | |
162 if len(l:tokens) < 5 | |
163 call fb#warn("Couldn't parse line '".a:line."', got '".string(l:tokens)."'") | |
164 return | |
165 endif | |
166 | |
167 let [l:tag, l:source_path, l:regex, l:line] = | |
168 \[l:tokens[1], tolower(l:tokens[2]), l:tokens[3], l:tokens[4]] | |
169 let l:cur_path = fnamemodify(bufname('%'), ':p') | |
170 let l:candidates = taglist(l:tag, l:cur_path) | |
171 | |
172 if len(l:candidates) == 0 | |
173 call fb#warn("No candidates found for '".l:tag."'") | |
174 return | |
175 endif | |
176 | |
177 if len(l:candidates) == 1 | |
178 execute ':tjump '.l:tag | |
179 return | |
180 endif | |
181 | |
182 let l:tagidx = 0 | |
183 for cndd in l:candidates | |
184 let l:tagidx += 1 | |
185 if tolower(cndd['filename']) != l:source_path | |
186 continue | |
187 endif | |
188 if cndd['cmd'] != l:regex | |
189 continue | |
190 endif | |
191 break | |
192 endfor | |
193 execute ':'.string(l:tagidx).'tag '.l:tag | |
194 endfunction |