1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
" vimtex - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: karl.yngve@gmail.com
"
function! vimtex#echo#echo(message) abort " {{{1
echohl VimtexMsg
echo a:message
echohl None
endfunction
" }}}1
function! vimtex#echo#input(opts) abort " {{{1
if g:vimtex_echo_verbose_input
\ && has_key(a:opts, 'info')
call vimtex#echo#formatted(a:opts.info)
endif
let l:args = [get(a:opts, 'prompt', '> ')]
let l:args += [get(a:opts, 'default', '')]
if has_key(a:opts, 'complete')
let l:args += [a:opts.complete]
endif
echohl VimtexMsg
let l:reply = call('input', l:args)
echohl None
return l:reply
endfunction
" }}}1
function! vimtex#echo#choose(list_or_dict, prompt) abort " {{{1
if empty(a:list_or_dict) | return '' | endif
return type(a:list_or_dict) == type({})
\ ? s:choose_dict(a:list_or_dict, a:prompt)
\ : s:choose_list(a:list_or_dict, a:prompt)
endfunction
" }}}1
function! vimtex#echo#formatted(parts) abort " {{{1
echo ''
try
for part in a:parts
if type(part) == type('')
echohl VimtexMsg
echon part
else
execute 'echohl' part[0]
echon part[1]
endif
unlet part
endfor
finally
echohl None
endtry
endfunction
" }}}1
function! s:choose_dict(dict, prompt) abort " {{{1
if len(a:dict) == 1
return values(a:dict)[0]
endif
while 1
redraw!
if !empty(a:prompt)
echohl VimtexMsg
unsilent echo a:prompt
echohl None
endif
let l:choice = 0
for l:x in values(a:dict)
let l:choice += 1
unsilent call vimtex#echo#formatted([['VimtexWarning', l:choice], ': ', l:x])
endfor
try
let l:choice = str2nr(input('> ')) - 1
if l:choice >= 0 && l:choice < len(a:dict)
return keys(a:dict)[l:choice]
endif
endtry
endwhile
endfunction
" }}}1
function! s:choose_list(list, prompt) abort " {{{1
if len(a:list) == 1 | return a:list[0] | endif
while 1
redraw!
if !empty(a:prompt)
echohl VimtexMsg
unsilent echo a:prompt
echohl None
endif
let l:choice = 0
for l:x in a:list
let l:choice += 1
unsilent call vimtex#echo#formatted([['VimtexWarning', l:choice], ': ', l:x])
endfor
try
let l:choice = str2nr(input('> ')) - 1
if l:choice >= 0 && l:choice < len(a:list)
return a:list[l:choice]
endif
endtry
endwhile
endfunction
" }}}1
endif
|