Mercurial > dotfiles
diff 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 |
line wrap: on
line diff
--- a/vim/autoload/ludo.vim Wed Apr 04 20:35:50 2018 -0700 +++ b/vim/autoload/ludo.vim Wed Apr 04 20:36:11 2018 -0700 @@ -1,5 +1,28 @@ let g:ludo_trace = 0 +" Get the platform we're running on. +if has("win32") || has("win64") || has("dos32") + let s:vim_platform = "windows" + let s:path_sep = "\\" +elseif has("mac") + let s:vim_platform = "mac" + let s:path_sep = '/' +else + let s:vim_platform = "unix" + let s:path_sep = '/' +endif +function! ludo#platform() abort + return s:vim_platform +endfunction + +" Get our vim directory. +let s:vim_home = expand("<sfile>:h:h") + +" Get local path. +function! ludo#localpath(...) abort + return s:vim_home.s:path_sep.join(a:000, s:path_sep) +endfunction + " Debug logging. function! ludo#trace(msg) abort if g:ludo_trace @@ -74,6 +97,8 @@ call ludo#trace("Exclude list: ".join(g:pathogen_disabled, ', ')) endfunction +" Goyo writing mode tweaks +" let s:ludo_revert = {} function! ludo#on_goyo_enter() @@ -114,3 +139,56 @@ Goyo endfunction +" Better tags browser using FZF +" +function! ludo#run_fzf_tags(args, bang) abort + let l:tag_files = tagfiles() + let l:tag_lister = + \'python '. + \ludo#localpath('scripts', 'list_tags.py').' -a 24 '. + \join(map(l:tag_files, "shellescape(v:val)")) + let options = { + \'source': l:tag_lister, + \'sink': function('s:tags_sink'), + \'options': '--algo=v1 --tiebreak=begin --prompt "Tags> "' + \} + return fzf#run(fzf#wrap('tags', options, a:bang)) +endfunction + +function! s:tags_sink(line) abort + let l:tokens = matchlist( + \a:line, + \'\v^(\S+)\s+([^\t]+)\t([^\t]{-1,})(;")?\t[a-z]+\tline\:([0-9]+)') + if len(l:tokens) < 5 + call fb#warn("Couldn't parse line '".a:line."', got '".string(l:tokens)."'") + return + endif + + let [l:tag, l:source_path, l:regex, l:line] = + \[l:tokens[1], tolower(l:tokens[2]), l:tokens[3], l:tokens[4]] + let l:cur_path = fnamemodify(bufname('%'), ':p') + let l:candidates = taglist(l:tag, l:cur_path) + + if len(l:candidates) == 0 + call fb#warn("No candidates found for '".l:tag."'") + return + endif + + if len(l:candidates) == 1 + execute ':tjump '.l:tag + return + endif + + let l:tagidx = 0 + for cndd in l:candidates + let l:tagidx += 1 + if tolower(cndd['filename']) != l:source_path + continue + endif + if cndd['cmd'] != l:regex + continue + endif + break + endfor + execute ':'.string(l:tagidx).'tag '.l:tag +endfunction