This commit is contained in:
Adam Stankiewicz
2020-05-20 16:59:09 +02:00
parent 0a7c62b3b2
commit a688c66a04
30 changed files with 276 additions and 152 deletions

View File

@@ -274,7 +274,7 @@ endfunction
function! s:get_frac_cmd() abort " {{{1
let l:save_pos = vimtex#pos#get_cursor()
while v:true
while 1
let l:cmd = s:get_cmd('prev')
if empty(l:cmd) || l:cmd.pos_start.lnum < line('.')
call vimtex#pos#set_cursor(l:save_pos)
@@ -375,7 +375,7 @@ function! s:get_frac_inline() abort " {{{1
let l:pos_after = -1
let l:pos_before = -1
while v:true
while 1
let l:pos_before = l:pos_after
let l:pos_after = match(l:line, '\/', l:pos_after+1)
if l:pos_after < 0 || l:pos_after >= l:col | break | endif

View File

@@ -66,7 +66,7 @@ function! s:choose_dict(dict, prompt) abort " {{{1
return values(a:dict)[0]
endif
while v:true
while 1
redraw!
if !empty(a:prompt)
echohl VimtexMsg
@@ -93,7 +93,7 @@ endfunction
function! s:choose_list(list, prompt) abort " {{{1
if len(a:list) == 1 | return a:list[0] | endif
while v:true
while 1
redraw!
if !empty(a:prompt)
echohl VimtexMsg

View File

@@ -9,6 +9,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
function! vimtex#imaps#init_buffer() abort " {{{1
if !g:vimtex_imaps_enabled | return | endif
" Store mappings in buffer
if !exists('b:vimtex_imaps')
let b:vimtex_imaps = []
endif
"
" Create imaps
"
@@ -32,16 +37,18 @@ endfunction
function! vimtex#imaps#add_map(map) abort " {{{1
let s:custom_maps = get(s:, 'custom_maps', []) + [a:map]
if exists('s:created_maps')
if exists('b:vimtex_imaps')
call s:create_map(a:map)
endif
endfunction
" }}}1
function! vimtex#imaps#list() abort " {{{1
let l:maps = b:vimtex_imaps
silent new vimtex\ imaps
for l:map in s:created_maps
for l:map in l:maps
call append('$', printf('%5S -> %-30S %S',
\ get(l:map, 'leader', get(g:, 'vimtex_imaps_leader', '`')) . l:map.lhs,
\ l:map.rhs,
@@ -78,15 +85,16 @@ endfunction
" The imap generator
"
function! s:create_map(map) abort " {{{1
if index(s:created_maps, a:map) >= 0 | return | endif
if index(b:vimtex_imaps, a:map) >= 0 | return | endif
let l:map = deepcopy(a:map)
let l:leader = get(a:map, 'leader', get(g:, 'vimtex_imaps_leader', '`'))
let l:leader = get(l:map, 'leader', get(g:, 'vimtex_imaps_leader', '`'))
if l:leader !=# '' && !hasmapto(l:leader, 'i')
silent execute 'inoremap <silent><nowait><buffer>' l:leader . l:leader l:leader
endif
let l:lhs = l:leader . a:map.lhs
let l:lhs = l:leader . l:map.lhs
let l:wrapper = get(a:map, 'wrapper', 'vimtex#imaps#wrap_math')
let l:wrapper = get(l:map, 'wrapper', 'vimtex#imaps#wrap_math')
if ! exists('*' . l:wrapper)
echoerr 'vimtex error: imaps wrapper does not exist!'
echoerr ' ' . l:wrapper
@@ -95,25 +103,25 @@ function! s:create_map(map) abort " {{{1
" Some wrappers use a context which must be made available to the wrapper
" function at run time.
if has_key(a:map, 'context')
if has_key(l:map, 'context')
execute 'let l:key = "' . escape(l:lhs, '<') . '"'
let l:key .= a:map.rhs
let l:key .= l:map.rhs
if !exists('b:vimtex_context')
let b:vimtex_context = {}
endif
let b:vimtex_context[l:key] = a:map.context
let b:vimtex_context[l:key] = l:map.context
endif
" The rhs may be evaluated before being passed to wrapper, unless expr is
" disabled (which it is by default)
if !get(a:map, 'expr')
let a:map.rhs = string(a:map.rhs)
if !get(l:map, 'expr')
let l:map.rhs = string(l:map.rhs)
endif
silent execute 'inoremap <expr><silent><nowait><buffer>' l:lhs
\ l:wrapper . '("' . escape(l:lhs, '\') . '", ' . a:map.rhs . ')'
\ l:wrapper . '("' . escape(l:lhs, '\') . '", ' . l:map.rhs . ')'
let s:created_maps += [a:map]
let b:vimtex_imaps += [l:map]
endfunction
" }}}1
@@ -182,11 +190,4 @@ endfunction
" }}}1
" {{{1 Initialize module
let s:created_maps = []
" }}}1
endif

View File

@@ -82,7 +82,8 @@ endfunction
" }}}1
function! s:search_candidates_texinputs(fname) abort " {{{1
for l:suffix in [''] + split(&l:suffixesadd, ',')
let l:candidates = glob(b:vimtex.root . '/**/' . a:fname . l:suffix, 0, 1)
let l:candidates = glob(b:vimtex.root . '/**/'
\ . fnameescape(a:fname) . l:suffix, 0, 1)
if !empty(l:candidates)
return l:candidates[0]
endif

View File

@@ -154,7 +154,7 @@ let s:re_prefilter = '\v%(\\' . join([
\ 'tableofcontents',
\ 'todo',
\], '|') . ')'
\ . '|\%\s*%(' . join(g:vimtex_toc_todo_keywords, '|') . ')'
\ . '|\%\s*%(' . join(keys(g:vimtex_toc_todo_labels), '|') . ')'
\ . '|\%\s*vimtex-include'
for s:m in g:vimtex_toc_custom_matchers
if has_key(s:m, 'prefilter')
@@ -513,14 +513,16 @@ endfunction
let s:matcher_todos = {
\ 're' : g:vimtex#re#not_bslash . '\%\s+('
\ . join(g:vimtex_toc_todo_keywords, '|') . ')[ :]+\s*(.*)',
\ . join(keys(g:vimtex_toc_todo_labels), '|') . ')[ :]+\s*(.*)',
\ 'in_preamble' : 1,
\ 'priority' : 2,
\}
function! s:matcher_todos.get_entry(context) abort dict " {{{1
let [l:type, l:text] = matchlist(a:context.line, self.re)[1:2]
let l:label = g:vimtex_toc_todo_labels[toupper(l:type)]
return {
\ 'title' : toupper(l:type) . ': ' . l:text,
\ 'title' : l:label . l:text,
\ 'number' : '',
\ 'file' : a:context.file,
\ 'line' : a:context.lnum,
@@ -547,8 +549,10 @@ function! s:matcher_todonotes.get_entry(context) abort dict " {{{1
let s:matcher_continue = deepcopy(self)
endif
let l:label = get(g:vimtex_toc_todo_labels, 'TODO', 'TODO: ')
return {
\ 'title' : 'TODO: ' . title,
\ 'title' : l:label . title,
\ 'number' : '',
\ 'file' : a:context.file,
\ 'line' : a:context.lnum,

View File

@@ -79,6 +79,15 @@ function! vimtex#syntax#load#packages() abort " {{{1
catch /E117:/
endtry
endfor
for l:pkg in g:vimtex_syntax_autoload_packages
try
call vimtex#syntax#p#{l:pkg}#load()
catch /E117:/
call vimtex#log#warning('Syntax package does not exist: ' . l:pkg,
\ 'Please see :help g:vimtex_syntax_autoload_packages')
endtry
endfor
endfunction
" }}}1

View File

@@ -385,23 +385,70 @@ endfunction
" }}}1
function! s:get_sel_items(is_inner) abort " {{{1
let l:pos_cursor = vimtex#pos#get_cursor()
let l:val_cursor = vimtex#pos#val(l:pos_cursor)
" Find previous \item
call vimtex#pos#set_cursor(l:pos_cursor[0], 1)
let l:pos_start = searchpos('^\s*\\item\S*', 'bcnWz')
if l:pos_start == [0, 0] | return [[], []] | endif
let l:depth = 0
let l:pos_cur = vimtex#pos#next(l:pos_cursor)
while 1
call vimtex#pos#set_cursor(vimtex#pos#prev(l:pos_cur))
if l:depth > 5 | return [[], []] | endif
let l:pos_start = searchpos(
\ l:depth > 0 ? '\\begin{\w\+}' : '^\s*\\item\S*',
\ 'bcnW')
let l:val_start = vimtex#pos#val(l:pos_start)
if l:val_start == 0 | return [[], []] | endif
let l:pos_endenv = searchpos('\%(^\s*\)\?\\end{\w\+}', 'bcnW')
let l:val_endenv = vimtex#pos#val(l:pos_endenv)
if l:val_endenv == 0 || l:val_start > l:val_endenv
if l:depth == 0 | break | endif
let l:pos_cur = l:pos_start
let l:depth -= 1
else
let l:pos_cur = l:pos_endenv
let l:depth += 1
endif
endwhile
" Find end of current \item
call vimtex#pos#set_cursor(l:pos_start)
let l:pos_end = searchpos('\ze\n\s*\%(\\item\|\\end{itemize}\)', 'nW')
if l:pos_end == [0, 0]
\ || vimtex#pos#val(l:pos_cursor) > vimtex#pos#val(l:pos_end)
let l:depth = 0
let l:pos_cur = l:pos_start
while 1
call vimtex#pos#set_cursor(vimtex#pos#next(l:pos_cur))
let l:re = l:depth > 0
\ ? '\\end{\w\+}'
\ : '\n\s*\%(\\item\|\\end{\(itemize\|enumerate\)}\)'
let l:pos_end = searchpos(l:re, 'nW')
let l:val_end = vimtex#pos#val(l:pos_end)
if l:depth == 0 && l:val_end == 0
return [[], []]
endif
let l:pos_beginenv = searchpos('\\begin{\w\+}', 'cnW')
let l:val_beginenv = vimtex#pos#val(l:pos_beginenv)
if l:val_beginenv == 0 || l:val_end < l:val_beginenv
if l:depth == 0 | break | endif
let l:pos_cur = l:pos_end
let l:depth -= 1
else
let l:pos_cur = l:pos_beginenv
let l:depth += 1
endif
endwhile
" The region must include the cursor
if l:val_cursor > l:val_end
return [[], []]
endif
" Adjust for outer text object
if a:is_inner
let l:pos_start[1] = searchpos('^\s*\\item\S*\s\?', 'cne')[1] + 1
let l:pos_start[1] = searchpos('^\s*\\item\S*\s', 'cne')[1] + 1
let l:pos_end[1] = col([l:pos_end[0], '$']) - 1
endif

View File

@@ -354,7 +354,8 @@ function! s:toc.set_syntax() abort dict "{{{1
syntax match VimtexTocNum /\v(([A-Z]+>|\d+)(\.\d+)*)?\s*/ contained
execute 'syntax match VimtexTocTodo'
\ '/\v\s\zs%(' . toupper(join(g:vimtex_toc_todo_keywords, '|')) . '): /'
\ '/\v\s\zs%('
\ . toupper(join(keys(g:vimtex_toc_todo_labels), '|')) . '): /'
\ 'contained'
syntax match VimtexTocHotkey /\[[^]]\+\]/ contained
@@ -751,7 +752,7 @@ endfunction
function! s:foldtext() abort " {{{1
let l:line = getline(v:foldstart)[3:]
if b:toc.todo_sorted
\ && l:line =~# '\v%(' . join(g:vimtex_toc_todo_keywords, '|') . ')'
\ && l:line =~# '\v%(' . join(keys(g:vimtex_toc_todo_labels), '|') . ')'
return substitute(l:line, '\w+\zs:.*', 's', '')
else
return l:line

View File

@@ -13,7 +13,7 @@ function! vimtex#view#zathura#new() abort " {{{1
return {}
endif
if executable('ldd')
if g:vimtex_view_zathura_check_libsynctex && executable('ldd')
let l:shared = split(system("sh -c 'ldd $(which zathura)'"))
if v:shell_error == 0
\ && empty(filter(l:shared, 'v:val =~# ''libsynctex'''))