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

function! latex#view#init(initialized) " {{{1
  call latex#util#set_default('g:latex_view_enabled', 1)
  if !g:latex_view_enabled | return | endif

  "
  " Set default options
  "
  call latex#util#set_default('g:latex_view_general_options', '')
  call latex#util#set_default_os_specific('g:latex_view_general_viewer',
        \ {
        \   'linux' : 'xdg-open',
        \   'mac'   : 'open',
        \ })
  call latex#util#set_default('g:latex_view_method', '')
  call latex#util#set_default('g:latex_view_mupdf_options', '')
  call latex#util#set_default('g:latex_view_okular_options', '')
  call latex#util#set_default('g:latex_view_sumatrapdf_options', '')
  call latex#util#error_deprecated('g:latex_viewer')

  "
  " Set view functions
  "
  let data = g:latex#data[b:latex.id]
  if g:latex_view_method == 'mupdf'
    call s:check_method_mupdf()
    let data.view = function('latex#view#mupdf')
    let data.rsearch = function('latex#view#mupdf_rsearch')
  elseif g:latex_view_method == 'okular'
    call s:check_method_okular()
    let data.view = function('latex#view#okular')
  elseif g:latex_view_method == 'sumatrapdf'
    call s:check_method_sumatrapdf()
    let data.view = function('latex#view#sumatrapdf')
  else
    call s:check_method_general()
    let data.view = function('latex#view#general')
  endif

  "
  " Define commands
  "
  command! -buffer VimLatexView call g:latex#data[b:latex.id].view()
  if has_key(data, 'rsearch')
    command! -buffer -nargs=* VimLatexRSearch
          \ call g:latex#data[b:latex.id].rsearch()
  endif

  "
  " Define mappings
  "
  if g:latex_mappings_enabled
    nnoremap <silent><buffer> <localleader>lv
          \ :call g:latex#data[b:latex.id].view()<cr>

    if has_key(data, 'rsearch')
      nnoremap <silent><buffer> <localleader>lr
            \ :call g:latex#data[b:latex.id].rsearch()<cr>
    endif
  endif
endfunction

"}}}1
function! latex#view#general() " {{{1
  let exe = {}
  let exe.cmd = g:latex_view_general_viewer

  let outfile = g:latex#data[b:latex.id].out()
  if !filereadable(outfile)
    echomsg "Can't view: Output file is not readable!"
    return
  endif
  let exe.cmd .= ' ' . g:latex_view_general_options
  let exe.cmd .= ' ' . shellescape(outfile)

  call latex#util#execute(exe)
  let g:latex#data[b:latex.id].cmds.view = exe.cmd
endfunction

"}}}1
function! latex#view#mupdf() "{{{1
  if !s:mupdf_exists_win()
    call s:mupdf_start()
  endif

  if s:mupdf_forward_search
    call s:mupdf_forward_search()
  endif
endfunction

" }}}1
function! latex#view#mupdf_rsearch() "{{{1
  if !s:mupdf_exists_win()
    echomsg "Can't search backwards: Is the PDF file open?"
    return
  endif

  let data = g:latex#data[b:latex.id]
  let outfile = data.out()
  let mupdf_id = data.mupdf_id
  let data.mupdf_rsearch = {}

  " Get page number
  let cmd  = "xdotool getwindowname " . mupdf_id
  let cmd .= " | sed 's:.* - \\([0-9]*\\)/.*:\\1:' | tr -d '\n'"
  let mupdf_page = system(cmd)
  let data.mupdf_rsearch.page = mupdf_page
  let data.mupdf_rsearch.page_cmd = cmd
  if mupdf_page <= 0 | return | endif<commit_msg>Minor change<commit_after>" LaTeX plugin for Vim
"
" Maintainer: <NAME>
" Email:      <EMAIL>
"

function! latex#view#init(initialized) " {{{1
  call latex#util#set_default('g:latex_view_enabled', 1)
  if !g:latex_view_enabled | return | endif

  "
  " Set default options
  "
  call latex#util#set_default('g:latex_view_general_options', '')
  call latex#util#set_default_os_specific('g:latex_view_general_viewer',
        \ {
        \   'linux' : 'xdg-open',
        \   'mac'   : 'open',
        \ })
  call latex#util#set_default('g:latex_view_method', '')
  call latex#util#set_default('g:latex_view_mupdf_options', '')
  call latex#util#set_default('g:latex_view_okular_options', '')
  call latex#util#set_default('g:latex_view_sumatrapdf_options', '')
  call latex#util#error_deprecated('g:latex_viewer')

  "
  " Set view functions
  "
  let data = g:latex#data[b:latex.id]
  if g:latex_view_method == 'mupdf'
    call s:check_method_mupdf()
    let data.view = function('latex#view#mupdf')
    let data.rsearch = function('latex#view#mupdf_rsearch')
  elseif g:latex_view_method == 'okular'
    call s:check_method_okular()
    let data.view = function('latex#view#okular')
  elseif g:latex_view_method == 'sumatrapdf'
    call s:check_method_sumatrapdf()
    let data.view = function('latex#view#sumatrapdf')
  else
    call s:check_method_general()
    let data.view = function('latex#view#general')
  endif

  "
  " Define commands
  "
  command! -buffer VimLatexView call g:latex#data[b:latex.id].view()
  if has_key(data, 'rsearch')
    command! -buffer -nargs=* VimLatexRSearch
          \ call g:latex#data[b:latex.id].rsearch()
  endif

  "
  " Define mappings
  "
  if g:latex_mappings_enabled
    nnoremap <silent><buffer> <localleader>lv
          \ :call g:latex#data[b:latex.id].view()<cr>

    if has_key(data, 'rsearch')
      nnoremap <silent><buffer> <localleader>lr
            \ :call g:latex#data[b:latex.id].rsearch()<cr>
    endif
  endif
endfunction

"}}}1
function! latex#view#general() " {{{1
  let exe = {}
  let exe.cmd = g:latex_view_general_viewer

  let outfile = g:latex#data[b:latex.id].out()
  if !filereadable(outfile)
    echomsg "Can't view: Output file is not readable!"
    return
  endif
  let exe.cmd .= ' ' . g:latex_view_general_options
  let exe.cmd .= ' ' . shellescape(outfile)

  call latex#util#execute(exe)
  let g:latex#data[b:latex.id].cmds.view = exe.cmd
endfunction

"}}}1
function! latex#view#mupdf() "{{{1
  if !s:mupdf_exists_win()
    call s:mupdf_start()
  endif

  if s:mupdf_forward_search
    call s:mupdf_forward_search()
  endif
endfunction

" }}}1
function! latex#view#mupdf_rsearch() "{{{1
  if !s:mupdf_exists_win()
    echomsg "Can't search backwards: Is the PDF file open?"
    return
  endif

  let data = g:latex#data[b:latex.id]
  let outfile = data.out()
  let mupdf_id = data.mupdf_id
  let data.mupdf_rsearch = {}

  " Get page number
  let cmd  = "xdotool getwindowname " . mupdf_id
  let cmd .= " | sed 's:.* - \\([0-9]*\\)/.*:\\1:'"
  let cmd .= " | tr -d '\n'"
  let mupdf_page = system(cmd)
  let data.mupdf_rsearch.page = mupdf_page
  let data.mupdf_rsearch.page_cmd = cmd
  if mupdf_page <= 0 | return | endif
{'fraction_non_alphanumeric': 0.14475951746827512, 'fraction_numerical': 0.0037599874667084443, 'mean_word_length': 3.8547528517110266, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '6238120', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2511, 'n_words': 454}