annotate vim/autoload/ludo.vim @ 469:07ee0d517d92

Don't auto `cd` into a project by default anymore.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 09 Apr 2019 18:55:39 -0700
parents b7682004288d
children 1a54ffbc3b15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
1 let g:ludo_trace = 0
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
2
435
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
3 " Get the platform we're running on.
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
4 if has("win32") || has("win64") || has("dos32")
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
5 let s:vim_platform = "windows"
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
6 let s:path_sep = "\\"
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
7 elseif has("mac")
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
8 let s:vim_platform = "mac"
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
9 let s:path_sep = '/'
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
10 else
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
11 let s:vim_platform = "unix"
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
12 let s:path_sep = '/'
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
13 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
14 function! ludo#platform() abort
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
15 return s:vim_platform
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
16 endfunction
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
17
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
18 " Get our vim directory.
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
19 let s:vim_home = expand("<sfile>:h:h")
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
20
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
21 " Get local path.
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
22 function! ludo#localpath(...) abort
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
23 return s:vim_home.s:path_sep.join(a:000, s:path_sep)
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
24 endfunction
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
25
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
26 " Debug logging.
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
27 function! ludo#trace(msg) abort
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
28 if g:ludo_trace
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
29 echom a:msg
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
30 endif
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
31 endfunction
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
32
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
33 " Warning message.
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
34 function! ludo#warn(msg) abort
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
35 echohl WarningMsg
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
36 echomsg "ludo: Warning: ".a:msg
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
37 echohl None
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
38 endfunction
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
39
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
40 " Error message.
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
41 function! ludo#error(msg) abort
430
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
42 let v:errmsg = "ludo: Error: ".a:msg
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
43 echohl ErrorMsg
430
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
44 echom v:errmsg
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
45 echohl None
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
46 endfunction
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
47
424
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 " Loads `pathogenrc` files in each bundle directory and, if found,
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 " builds an exclude list based on the glob patterns found in them.
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 "
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 function! ludo#setup_pathogen(bundle_dirs) abort
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 for bundle_dir in a:bundle_dirs
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
54 let l:rcfile = bundle_dir.'.pathogenrc'
424
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 if !filereadable(l:rcfile)
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
56 call ludo#trace("No bundle configuration file: ".l:rcfile)
424
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 continue
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 let l:included = []
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 let l:excluded = []
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
62 call ludo#trace("Reading bundle configuration file: ".l:rcfile)
424
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 let l:rclines = readfile(l:rcfile)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 for line in l:rclines
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 if line[0] == '#'
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 continue
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 if line[0] == '-'
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 let l:excls = glob(bundle_dir.'/'.line[1:], 1, 1)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 for excl in l:excls
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let l:idx = index(l:included, excl)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 if l:idx >= 0
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 call remove(l:included, l:idx)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 call add(l:excluded, excl)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 endfor
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 else
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 let l:incls = glob(bundle_dir.'/'.line, 1, 1)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 for incl in l:incls
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 let l:idx = index(l:excluded, incl)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 if l:idx >= 0
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 call remove(l:excluded, l:idx)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 call add(l:included, incl)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 endfor
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 endfor
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 for excl in l:excluded
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 if isdirectory(excl)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 let l:excl_name = fnamemodify(excl, ':t')
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 call add(g:pathogen_disabled, l:excl_name)
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 endif
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 endfor
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 endfor
426
67f14a8c2304 Improve Vim configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 424
diff changeset
97 call ludo#trace("Exclude list: ".join(g:pathogen_disabled, ', '))
424
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 endfunction
d8086f81b9c8 Pathogen config files.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99
435
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
100 " Goyo writing mode tweaks
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
101 "
430
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
102 let s:ludo_revert = {}
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
103
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
104 function! ludo#on_goyo_enter()
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
105 let s:ludo_revert = {
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
106 \'spell': &spell,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
107 \'copyindent': &copyindent,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
108 \'smartindent': &smartindent,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
109 \'autoindent': &autoindent,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
110 \'list': &list,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
111 \'showmode': &showmode,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
112 \'showcmd': &showcmd,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
113 \'scrolloff': &scrolloff,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
114 \'complete': &complete,
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
115 \'background': &background
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
116 \}
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
117 set spell
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
118 set nocopyindent nosmartindent noautoindent nolist noshowmode noshowcmd
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
119 set scrolloff=999
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
120 set complete+=s
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
121 set bg=light
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
122 if !has('gui_running')
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
123 let g:solarized_termcolors=256
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
124 endif
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
125 endfunction
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
126
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
127 function! ludo#on_goyo_leave()
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
128 if len(s:ludo_revert) == 0
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
129 call ludo#error("Can't revert settings!")
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
130 return
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
131 endif
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
132 for [key, val] in items(s:ludo_revert)
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
133 execute 'let &'.key.' = '.string(val)
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
134 endfor
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
135 let s:ludo_revert = {}
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
136 endfunction
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
137
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
138 function! ludo#writingmode()
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
139 Goyo
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
140 endfunction
71a080d4d83c Vim stuff: Goyo writing mode, Ack with Ag.
Ludovic Chabant <ludovic@chabant.com>
parents: 426
diff changeset
141
435
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
142 " Better tags browser using FZF
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
143 "
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
144 function! ludo#run_fzf_tags(args, bang) abort
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
145 let l:tag_files = tagfiles()
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
146 let l:tag_lister =
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
147 \'python '.
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
148 \ludo#localpath('scripts', 'list_tags.py').' -a 24 '.
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
149 \join(map(l:tag_files, "shellescape(v:val)"))
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
150 let options = {
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
151 \'source': l:tag_lister,
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
152 \'sink': function('s:tags_sink'),
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
153 \'options': '--algo=v1 --tiebreak=begin --prompt "Tags> "'
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
154 \}
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
155 return fzf#run(fzf#wrap('tags', options, a:bang))
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
156 endfunction
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
157
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
158 function! s:tags_sink(line) abort
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
159 let l:tokens = matchlist(
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
160 \a:line,
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
161 \'\v^(\S+)\s+([^\t]+)\t([^\t]{-1,})(;")?\t[a-z]+\tline\:([0-9]+)')
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
162 if len(l:tokens) < 5
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
163 call fb#warn("Couldn't parse line '".a:line."', got '".string(l:tokens)."'")
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
164 return
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
165 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
166
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
167 let [l:tag, l:source_path, l:regex, l:line] =
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
168 \[l:tokens[1], tolower(l:tokens[2]), l:tokens[3], l:tokens[4]]
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
169 let l:cur_path = fnamemodify(bufname('%'), ':p')
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
170 let l:candidates = taglist(l:tag, l:cur_path)
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
171
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
172 if len(l:candidates) == 0
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
173 call fb#warn("No candidates found for '".l:tag."'")
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
174 return
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
175 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
176
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
177 if len(l:candidates) == 1
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
178 execute ':tjump '.l:tag
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
179 return
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
180 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
181
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
182 let l:tagidx = 0
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
183 for cndd in l:candidates
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
184 let l:tagidx += 1
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
185 if tolower(cndd['filename']) != l:source_path
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
186 continue
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
187 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
188 if cndd['cmd'] != l:regex
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
189 continue
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
190 endif
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
191 break
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
192 endfor
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
193 execute ':'.string(l:tagidx).'tag '.l:tag
b7682004288d Move Vim stuff to autoload, add FZF tags lister.
Ludovic Chabant <ludovic@chabant.com>
parents: 430
diff changeset
194 endfunction