diff options
Diffstat (limited to 'autoload/vimtex')
| -rw-r--r-- | autoload/vimtex/cmd.vim | 4 | ||||
| -rw-r--r-- | autoload/vimtex/echo.vim | 4 | ||||
| -rw-r--r-- | autoload/vimtex/imaps.vim | 41 | ||||
| -rw-r--r-- | autoload/vimtex/include.vim | 3 | ||||
| -rw-r--r-- | autoload/vimtex/parser/toc.vim | 12 | ||||
| -rw-r--r-- | autoload/vimtex/syntax/load.vim | 9 | ||||
| -rw-r--r-- | autoload/vimtex/text_obj.vim | 63 | ||||
| -rw-r--r-- | autoload/vimtex/toc.vim | 5 | ||||
| -rw-r--r-- | autoload/vimtex/view/zathura.vim | 2 | 
9 files changed, 103 insertions, 40 deletions
| diff --git a/autoload/vimtex/cmd.vim b/autoload/vimtex/cmd.vim index 06b5e14c..62e3b470 100644 --- a/autoload/vimtex/cmd.vim +++ b/autoload/vimtex/cmd.vim @@ -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 diff --git a/autoload/vimtex/echo.vim b/autoload/vimtex/echo.vim index 9c761f8f..ee80c942 100644 --- a/autoload/vimtex/echo.vim +++ b/autoload/vimtex/echo.vim @@ -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 diff --git a/autoload/vimtex/imaps.vim b/autoload/vimtex/imaps.vim index 6b682f0c..5c507ad2 100644 --- a/autoload/vimtex/imaps.vim +++ b/autoload/vimtex/imaps.vim @@ -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 diff --git a/autoload/vimtex/include.vim b/autoload/vimtex/include.vim index 830292c5..59c37977 100644 --- a/autoload/vimtex/include.vim +++ b/autoload/vimtex/include.vim @@ -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 diff --git a/autoload/vimtex/parser/toc.vim b/autoload/vimtex/parser/toc.vim index 517a25be..a518ce53 100644 --- a/autoload/vimtex/parser/toc.vim +++ b/autoload/vimtex/parser/toc.vim @@ -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, diff --git a/autoload/vimtex/syntax/load.vim b/autoload/vimtex/syntax/load.vim index 5008e24a..3b61d886 100644 --- a/autoload/vimtex/syntax/load.vim +++ b/autoload/vimtex/syntax/load.vim @@ -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 diff --git a/autoload/vimtex/text_obj.vim b/autoload/vimtex/text_obj.vim index 27d1a8b6..3b9105ff 100644 --- a/autoload/vimtex/text_obj.vim +++ b/autoload/vimtex/text_obj.vim @@ -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 diff --git a/autoload/vimtex/toc.vim b/autoload/vimtex/toc.vim index ac660112..bb2d7ffb 100644 --- a/autoload/vimtex/toc.vim +++ b/autoload/vimtex/toc.vim @@ -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 diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim index a001fa7e..88e41468 100644 --- a/autoload/vimtex/view/zathura.vim +++ b/autoload/vimtex/view/zathura.vim @@ -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''')) | 
