Skip to content

Commit

Permalink
feat: allow flexibility in cmd parser
Browse files Browse the repository at this point in the history
refer: #2628
  • Loading branch information
lervag committed Feb 15, 2023
1 parent cb1460f commit cb29cd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 16 additions & 12 deletions autoload/vimtex/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ endfunction

" }}}1

function! vimtex#cmd#parser_separator_check(separator_string) abort " {{{1
return empty(substitute(a:separator_string, '\_s\+', '', 'g'))
\ && count(a:separator_string, "\n") < 2
endfunction

" }}}1

function! s:get_frac_toggled(origin, numerator, denominator) abort " {{{1
let l:target = get(g:vimtex_toggle_fractions, a:origin, 'INLINE')

Expand Down Expand Up @@ -686,18 +693,15 @@ function! s:get_cmd_part(part, start_pos) abort " {{{1
call vimtex#pos#set_cursor(a:start_pos)
let l:open = vimtex#delim#get_next('delim_tex', 'open')
call vimtex#pos#set_cursor(l:save_pos)
if empty(l:open) | return | endif

"
" Ensure that the delimiter
" 1) is of the right type,
" 2) and is the next non-whitespace character.
"
let l:separate = s:text_between(a:start_pos, l:open)
let l:newlines = count(l:separate, "\n")
if l:open.match !=# a:part
\ || strlen(substitute(l:separate, '\_s\+', '', 'g')) != 0
\ || l:newlines > 1

" Ensure that the next delimiter is found and is of the right type
if empty(l:open) || l:open.match !=# a:part | return {} | endif

" Ensure that the delimiter is the next non-whitespace character according to
" a configurable rule
if ! call(g:vimtex_parser_cmd_separator_check, [
\ s:text_between(a:start_pos, l:open)
\])
return {}
endif

Expand Down
2 changes: 2 additions & 0 deletions autoload/vimtex/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ function! vimtex#options#init() abort " {{{1
\ '-n1 -n3 -n8 -n25 -n36')

call s:init_option('vimtex_parser_bib_backend', 'bibtex')
call s:init_option('vimtex_parser_cmd_separator_check',
\ 'vimtex#cmd#parser_separator_check')

call s:init_option('vimtex_quickfix_enabled', 1)
call s:init_option('vimtex_quickfix_method', 'latexlog')
Expand Down

0 comments on commit cb29cd1

Please sign in to comment.