<commit_before>" vimtex - LaTeX plugin for Vim
"
" Maintainer: <NAME>
" Email:      <EMAIL>
"

function! vimtex#latexmk#init_buffer() " {{{1
  if !g:vimtex_latexmk_enabled | return | endif

  " Check option validity
  if g:vimtex_latexmk_callback
        \ && !(has('clientserver') || has('nvim'))
    let g:vimtex_latexmk_callback = 0
    call vimtex#echo#warning('Can''t use callbacks without +clientserver')
    call vimtex#echo#wait()
  endif

  " Set compiler (this defines the errorformat)
  compiler latexmk

  " Define commands
  command! -buffer       VimtexCompile       call vimtex#latexmk#compile()
  command! -buffer -bang VimtexCompileSS     call vimtex#latexmk#compile_ss()
  command! -buffer       VimtexCompileToggle call vimtex#latexmk#toggle()
  command! -buffer       VimtexCompileOutput call vimtex#latexmk#output()
  command! -buffer       VimtexStop          call vimtex#latexmk#stop()
  command! -buffer       VimtexStopAll       call vimtex#latexmk#stop_all()
  command! -buffer       VimtexErrors        call vimtex#latexmk#errors()
  command! -buffer -bang VimtexClean         call vimtex#latexmk#clean(<q-bang> == "!")
  command! -buffer -bang VimtexStatus        call vimtex#latexmk#status(<q-bang> == "!")
  command! -buffer       VimtexLacheck       call vimtex#latexmk#lacheck()
  command! -buffer -range VimtexCompileSelected
        \ <line1>,<line2>call vimtex#latexmk#compile_selected('cmd')

  " Define mappings
  nnoremap <buffer> <plug>(vimtex-compile)        :call vimtex#latexmk#compile()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-ss)     :call vimtex#latexmk#compile_ss()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-toggle) :call vimtex#latexmk#toggle()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-output) :call vimtex#latexmk#output()<cr>
  nnoremap <buffer> <plug>(vimtex-stop)           :call vimtex#latexmk#stop()<cr>
  nnoremap <buffer> <plug>(vimtex-stop-all)       :call vimtex#latexmk#stop_all()<cr>
  nnoremap <buffer> <plug>(vimtex-errors)         :call vimtex#latexmk#errors()<cr>
  nnoremap <buffer> <plug>(vimtex-clean)          :call vimtex#latexmk#clean(0)<cr>
  nnoremap <buffer> <plug>(vimtex-clean-full)     :call vimtex#latexmk#clean(1)<cr>
  nnoremap <buffer> <plug>(vimtex-status)         :call vimtex#latexmk#status(0)<cr>
  nnoremap <buffer> <plug>(vimtex-status-all)     :call vimtex#latexmk#status(1)<cr>
  nnoremap <buffer> <plug>(vimtex-lacheck)        :call vimtex#latexmk#lacheck()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-selected)
        \ :set opfunc=vimtex#latexmk#compile_selected<cr>g@
  xnoremap <buffer> <plug>(vimtex-compile-selected)
        \ :<c-u>call vimtex#latexmk#compile_selected('visual')<cr>
endfunction

" }}}1
function! vimtex#latexmk#init_state(state) " {{{1
  if !g:vimtex_latexmk_enabled | return | endif

  " Initialize system PID
  call s:latexmk_init_pid(a:state)
endfunction

" }}}1

function! vimtex#latexmk#callback(status) " {{{1
  if get(s:, 'silence_next_callback', 0)
    let s:silence_next_callback = 0
    return
  endif

  call vimtex#latexmk#errors_open(0)
  redraw

  if exists('s:output')
    call s:output.update()
  endif

  call vimtex#echo#status(['latexmk compile: ',
        \ a:status ? ['VimtexSuccess', 'success'] : ['VimtexWarning', 'fail']])

  for l:hook in g:vimtex_latexmk_callback_hooks
    execute 'call' l:hook . '(' . a:status . ')'
  endfor

  return ''
endfunction

" }}}1
function! vimtex#latexmk#clean(full, ...) " {{{1
  if b:vimtex.pid && a:0 == 0
    silent call vimtex#latexmk#stop()
    let l:restart = 1
    let s:silence_next_callback = 1
  endif

  "
  " Run latexmk clean process
  "
  if has('win32')
    let cmd = 'cd /D "' . b:vimtex.root . '" & '
  else
    let cmd = 'cd ' . vimtex#util#shellescape(b:vimtex.root) . '; '
  endif
  let cmd .= 'latexmk'
  if g:vimtex_latexmk_build_dir !=# ''
    let cmd .= ' -outdir=' . g:vimtex_latexmk_build_dir
  endif
  let cmd .= a:full ? ' -C ' : ' -c '
  let cmd .= vimtex#util#shellescape(a:0 > 0 ? a:1 : b:vimtex.base)
  call vimtex#util#execute({'cmd' : cmd})
  let b:vimtex.cmd_latexmk_clean = cmd

  if get(l:, 'restart', 0)
    silent call vimtex#latexmk#compile()
  endif

  if a:0 == 0
    call vimtex#echo#status(['latexmk clean: ',
          \ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]])
  endif
endfunction

" }}}1
function! vimtex#latexmk#lacheck() " {{{1
  compiler lacheck

  silent lmake %
  lwindow
  silent redraw
  wincmd p

  compiler latexmk
endfunction

" }}}1
function! vimtex#latexmk#toggle() " {{{1
  if b:vimtex.pid
    call vimtex#latexmk#stop()
  else
    call vimtex#latexmk#compile()
  endif
endfunction

" }}}1
function! vimtex#latexmk#compile() " {{{1
  if b:vimtex.pid
    call vimtex#echo#status(['latexmk compile: ',
          \ ['VimtexWarning', 'already running for `' . b:vimtex.base . "'"]])
    return
  endif

  " Initialize build dir
  call s:latexmk_init_build_dir()

  " Build command line and start latexmk
  let l:exe = s:latexmk_build_cmd()
  if !g:vimtex_latexmk_continuous && !g:vimtex_latexmk_background
    let l:exe.bg = 0
    let l:exe.silent = 0
  endif
  call vimtex#util#execute(l:exe)

  if g:vimtex_latexmk_continuous
    call s:latexmk_set_pid()
    call vimtex#echo#status(['latexmk compile: ',
          \ ['VimtexSuccess', 'started continuous mode']])
    if exists('#User#VimtexEventCompileStarted')
      doautocmd User VimtexEventCompileStarted
    endif
  else
    if get(l:exe, 'bg', 1)
      call vimtex#echo#status(['latexmk compile: ',
            \ ['VimtexSuccess', 'started in background!']])
    else
      call vimtex#echo#status(['latexmk compile: ',
            \ vimtex#latexmk#errors_inquire()
            \   ? ['VimtexWarning', 'fail']
            \   : ['VimtexSuccess', 'success']])
    endif
  endif
endfunction

" }}}1
function! vimtex#latexmk#compile_ss(verbose) " {{{1
  let l:vimtex_latexmk_continuous = g:vimtex_latexmk_continuous
  let l:vimtex_latexmk_callback = g:vimtex_latexmk_callback

  if exists('v:servername')
    let g:vimtex_latexmk_callback = 1
    let g:vimtex_latexmk_continuous = 1
    let g:vimtex_latexmk_callback_hooks = ['VimtexSSCallback']
    function! VimtexSingleShotWithCallback(status)
      silent call vimtex#latexmk#stop()
      call remove(g:vimtex_latexmk_callback_hooks, 'VimtexSSCallback')
    endfunction
  else
    let g:vimtex_latexmk_continuous = 0
  endif

  call vimtex#latexmk#compile()

  let g:vimtex_latexmk_continuous = l:vimtex_latexmk_continuous
  let g:vimtex_latexmk_callback = l:vimtex_latexmk_callback
endfunction

" }}}1
function! vimtex#latexmk#compile_selected(type) range " {{{1
  let l:file = vimtex#parser#selection_to_texfile(a:type)
  if empty(l:file) | return | endif

  "
  " Compile the temporary file
  "
  let l:exe = s:latexmk_build_cmd_selected(l:file.base)
  let l:exe.bg = 0
  let l:exe.silent = 1
  call vimtex#echo#status([
        \ ['VimtexInfo', 'vimtex: '],
        \ ['VimtexMsg', 'compiling selected lines ...']])
  call vimtex#util#execute(l:exe)

  "<commit_msg>Fixed minor typo error (cf. #675)<commit_after>" vimtex - LaTeX plugin for Vim
"
" Maintainer: <NAME>
" Email:      <EMAIL>
"

function! vimtex#latexmk#init_buffer() " {{{1
  if !g:vimtex_latexmk_enabled | return | endif

  " Check option validity
  if g:vimtex_latexmk_callback
        \ && !(has('clientserver') || has('nvim'))
    let g:vimtex_latexmk_callback = 0
    call vimtex#echo#warning('Can''t use callbacks without +clientserver')
    call vimtex#echo#wait()
  endif

  " Set compiler (this defines the errorformat)
  compiler latexmk

  " Define commands
  command! -buffer       VimtexCompile       call vimtex#latexmk#compile()
  command! -buffer -bang VimtexCompileSS     call vimtex#latexmk#compile_ss()
  command! -buffer       VimtexCompileToggle call vimtex#latexmk#toggle()
  command! -buffer       VimtexCompileOutput call vimtex#latexmk#output()
  command! -buffer       VimtexStop          call vimtex#latexmk#stop()
  command! -buffer       VimtexStopAll       call vimtex#latexmk#stop_all()
  command! -buffer       VimtexErrors        call vimtex#latexmk#errors()
  command! -buffer -bang VimtexClean         call vimtex#latexmk#clean(<q-bang> == "!")
  command! -buffer -bang VimtexStatus        call vimtex#latexmk#status(<q-bang> == "!")
  command! -buffer       VimtexLacheck       call vimtex#latexmk#lacheck()
  command! -buffer -range VimtexCompileSelected
        \ <line1>,<line2>call vimtex#latexmk#compile_selected('cmd')

  " Define mappings
  nnoremap <buffer> <plug>(vimtex-compile)        :call vimtex#latexmk#compile()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-ss)     :call vimtex#latexmk#compile_ss()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-toggle) :call vimtex#latexmk#toggle()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-output) :call vimtex#latexmk#output()<cr>
  nnoremap <buffer> <plug>(vimtex-stop)           :call vimtex#latexmk#stop()<cr>
  nnoremap <buffer> <plug>(vimtex-stop-all)       :call vimtex#latexmk#stop_all()<cr>
  nnoremap <buffer> <plug>(vimtex-errors)         :call vimtex#latexmk#errors()<cr>
  nnoremap <buffer> <plug>(vimtex-clean)          :call vimtex#latexmk#clean(0)<cr>
  nnoremap <buffer> <plug>(vimtex-clean-full)     :call vimtex#latexmk#clean(1)<cr>
  nnoremap <buffer> <plug>(vimtex-status)         :call vimtex#latexmk#status(0)<cr>
  nnoremap <buffer> <plug>(vimtex-status-all)     :call vimtex#latexmk#status(1)<cr>
  nnoremap <buffer> <plug>(vimtex-lacheck)        :call vimtex#latexmk#lacheck()<cr>
  nnoremap <buffer> <plug>(vimtex-compile-selected)
        \ :set opfunc=vimtex#latexmk#compile_selected<cr>g@
  xnoremap <buffer> <plug>(vimtex-compile-selected)
        \ :<c-u>call vimtex#latexmk#compile_selected('visual')<cr>
endfunction

" }}}1
function! vimtex#latexmk#init_state(state) " {{{1
  if !g:vimtex_latexmk_enabled | return | endif

  " Initialize system PID
  call s:latexmk_init_pid(a:state)
endfunction

" }}}1

function! vimtex#latexmk#callback(status) " {{{1
  if get(s:, 'silence_next_callback', 0)
    let s:silence_next_callback = 0
    return
  endif

  call vimtex#latexmk#errors_open(0)
  redraw

  if exists('s:output')
    call s:output.update()
  endif

  call vimtex#echo#status(['latexmk compile: ',
        \ a:status ? ['VimtexSuccess', 'success'] : ['VimtexWarning', 'fail']])

  for l:hook in g:vimtex_latexmk_callback_hooks
    execute 'call' l:hook . '(' . a:status . ')'
  endfor

  return ''
endfunction

" }}}1
function! vimtex#latexmk#clean(full, ...) " {{{1
  if b:vimtex.pid && a:0 == 0
    silent call vimtex#latexmk#stop()
    let l:restart = 1
    let s:silence_next_callback = 1
  endif

  "
  " Run latexmk clean process
  "
  if has('win32')
    let cmd = 'cd /D "' . b:vimtex.root . '" & '
  else
    let cmd = 'cd ' . vimtex#util#shellescape(b:vimtex.root) . '; '
  endif
  let cmd .= 'latexmk'
  if g:vimtex_latexmk_build_dir !=# ''
    let cmd .= ' -outdir=' . g:vimtex_latexmk_build_dir
  endif
  let cmd .= a:full ? ' -C ' : ' -c '
  let cmd .= vimtex#util#shellescape(a:0 > 0 ? a:1 : b:vimtex.base)
  call vimtex#util#execute({'cmd' : cmd})
  let b:vimtex.cmd_latexmk_clean = cmd

  if get(l:, 'restart', 0)
    silent call vimtex#latexmk#compile()
  endif

  if a:0 == 0
    call vimtex#echo#status(['latexmk clean: ',
          \ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]])
  endif
endfunction

" }}}1
function! vimtex#latexmk#lacheck() " {{{1
  compiler lacheck

  silent lmake %
  lwindow
  silent redraw
  wincmd p

  compiler latexmk
endfunction

" }}}1
function! vimtex#latexmk#toggle() " {{{1
  if b:vimtex.pid
    call vimtex#latexmk#stop()
  else
    call vimtex#latexmk#compile()
  endif
endfunction

" }}}1
function! vimtex#latexmk#compile() " {{{1
  if b:vimtex.pid
    call vimtex#echo#status(['latexmk compile: ',
          \ ['VimtexWarning', 'already running for `' . b:vimtex.base . "'"]])
    return
  endif

  " Initialize build dir
  call s:latexmk_init_build_dir()

  " Build command line and start latexmk
  let l:exe = s:latexmk_build_cmd()
  if !g:vimtex_latexmk_continuous && !g:vimtex_latexmk_background
    let l:exe.bg = 0
    let l:exe.silent = 0
  endif
  call vimtex#util#execute(l:exe)

  if g:vimtex_latexmk_continuous
    call s:latexmk_set_pid()
    call vimtex#echo#status(['latexmk compile: ',
          \ ['VimtexSuccess', 'started continuous mode']])
    if exists('#User#VimtexEventCompileStarted')
      doautocmd User VimtexEventCompileStarted
    endif
  else
    if get(l:exe, 'bg', 1)
      call vimtex#echo#status(['latexmk compile: ',
            \ ['VimtexSuccess', 'started in background!']])
    else
      call vimtex#echo#status(['latexmk compile: ',
            \ vimtex#latexmk#errors_inquire()
            \   ? ['VimtexWarning', 'fail']
            \   : ['VimtexSuccess', 'success']])
    endif
  endif
endfunction

" }}}1
function! vimtex#latexmk#compile_ss(verbose) " {{{1
  let l:vimtex_latexmk_continuous = g:vimtex_latexmk_continuous
  let l:vimtex_latexmk_callback = g:vimtex_latexmk_callback

  if exists('v:servername')
    let g:vimtex_latexmk_callback = 1
    let g:vimtex_latexmk_continuous = 1
    let g:vimtex_latexmk_callback_hooks = ['VimtexSSCallback']
    function! VimtexSSCallback(status)
      silent call vimtex#latexmk#stop()
      call remove(g:vimtex_latexmk_callback_hooks, 'VimtexSSCallback')
    endfunction
  else
    let g:vimtex_latexmk_continuous = 0
  endif

  call vimtex#latexmk#compile()

  let g:vimtex_latexmk_continuous = l:vimtex_latexmk_continuous
  let g:vimtex_latexmk_callback = l:vimtex_latexmk_callback
endfunction

" }}}1
function! vimtex#latexmk#compile_selected(type) range " {{{1
  let l:file = vimtex#parser#selection_to_texfile(a:type)
  if empty(l:file) | return | endif

  "
  " Compile the temporary file
  "
  let l:exe = s:latexmk_build_cmd_selected(l:file.base)
  let l:exe.bg = 0
  let l:exe.silent = 1
  call vimtex#echo#status([
        \ ['VimtexInfo', 'vimtex: '],
        \ ['VimtexMsg', 'compiling selected lines ...']])
  call vimtex#util#execute(l:exe)

  "
{'fraction_non_alphanumeric': 0.13677639046538026, 'fraction_numerical': 0.0068813847900113505, 'mean_word_length': 3.8227848101265822, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5495514', 'n_tokens_mistral': 5593, 'n_tokens_neox': 5312, 'n_words': 1015}