Skip to content

Commit

Permalink
Implement toggle_break()
Browse files Browse the repository at this point in the history
  • Loading branch information
matchbox1014 committed May 5, 2024
1 parent 137f5bd commit 0f7c192
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/vimtex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function! s:init_default_mappings() abort " {{{1
call s:map(0, 'n', 'tsc', '<plug>(vimtex-cmd-toggle-star)')
call s:map(0, 'n', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'x', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'n', 'tsb', '<plug>(vimtex-cmd-toggle-break)')
call s:map(0, 'i', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'n', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'x', '<F7>', '<plug>(vimtex-cmd-create)')
Expand Down
23 changes: 23 additions & 0 deletions autoload/vimtex/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function! vimtex#cmd#init_buffer() abort " {{{1
xnoremap <silent><buffer> <plug>(vimtex-cmd-toggle-frac)
\ :<c-u>call vimtex#cmd#toggle_frac_visual()<cr>
nnoremap <silent><buffer> <plug>(vimtex-cmd-toggle-break)
\ :<c-u>call <sid>operator_setup('toggle_break')<bar>normal! g@l<cr>
endfunction

" }}}1
Expand Down Expand Up @@ -267,6 +270,25 @@ function! vimtex#cmd#toggle_frac_visual() abort " {{{1
call setreg('a', l:save_reg)
endfunction

" }}}1
function! vimtex#cmd#toggle_break() abort " {{{1
let l:lnum = line('.')
let l:line = getline(l:lnum)
let l:len = col('$') - 1

if l:len >= 3 && strpart(l:line, l:len - 3) == ' \\'
call setline(l:lnum,
\ strpart(l:line, 0, l:len - 3))
elseif l:len >= 2 && strpart(l:line, l:len - 2) == '\\'
call setline(l:lnum,
\ strpart(l:line, 0, l:len - 2))
else
call setline(l:lnum,
\ l:line
\ . ' \\')
endif
endfunction

" }}}1

function! vimtex#cmd#parser_separator_check(separator_string) abort " {{{1
Expand Down Expand Up @@ -609,6 +631,7 @@ function! s:operator_function(_) abort " {{{1
\ 'delete': 'delete()',
\ 'toggle_star': 'toggle_star()',
\ 'toggle_frac': 'toggle_frac()',
\ 'toggle_break': 'toggle_break()',
\ }[s:operator]
endfunction

Expand Down

0 comments on commit 0f7c192

Please sign in to comment.