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

function! vimtex#paths#pushd(path) abort " {{{1
  if empty(a:path) || getcwd() ==# fnamemodify(a:path, ':p')
    let s:qpath += ['']
  else
    let s:qpath += [getcwd()]
    execute s:cd fnameescape(a:path)
  endif
endfunction

" }}}1
function! vimtex#paths#popd() abort " {{{1
  let l:path = remove(s:qpath, -1)
  if !empty(l:path)
    execute s:cd fnameescape(l:path)
  endif
endfunction

" }}}1

function! vimtex#paths#join(root, tail) abort " {{{1
  return vimtex#paths#s(a:root . '/' . a:tail)
endfunction

" }}}1

function! vimtex#paths#s(path) abort " {{{1
  " Handle shellescape issues and simplify path
  let l:path = exists('+shellslash') && !&shellslash
        \ ? tr(a:path, '/', '\')
        \ : a:path

  return simplify(l:path)
endfunction

" }}}1
function! vimtex#paths#is_abs(path) abort " {{{1
  return a:path =~# s:re_abs
endfunction

" }}}1

function! vimtex#paths#shorten_relative(path) abort " {{{1
  " Input: An absolute path
  " Output: Relative path with respect to the VimTeX root, path relative to
  "         VimTeX root (unless absolute path is shorter)

  let l:relative = vimtex#paths#relative(a:path, b:vimtex.root)
  return strlen(l:relative) < strlen(a:path)
        \ ? l:relative : a:path
endfunction

" }}}1
function! vimtex#paths#relative(path, current) abort " {{{1
  " Note: This algorithm is based on the one presented by @Offirmo at SO,
  "       http://stackoverflow.com/a/12498485/51634

  let l:target = simplify(substitute(a:path, '\\', '/', 'g'))
  let l:common = simplify(substitute(a:current, '\\', '/', 'g'))

  " This only works on absolute paths
  if !vimtex#paths#is_abs(l:target)
    return substitute(a:path, '^\.\/', '', '')
  endif<commit_msg>fix: path handling on windows<commit_after>" VimTeX - LaTeX plugin for Vim
"
" Maintainer: <NAME>
" Email:      <EMAIL>
"

function! vimtex#paths#pushd(path) abort " {{{1
  if empty(a:path) || getcwd() ==# fnamemodify(a:path, ':p')
    let s:qpath += ['']
  else
    let s:qpath += [getcwd()]
    execute s:cd fnameescape(a:path)
  endif
endfunction

" }}}1
function! vimtex#paths#popd() abort " {{{1
  let l:path = remove(s:qpath, -1)
  if !empty(l:path)
    execute s:cd fnameescape(l:path)
  endif
endfunction

" }}}1

function! vimtex#paths#join(root, tail) abort " {{{1
  return vimtex#paths#s(a:root . '/' . a:tail)
endfunction

" }}}1

function! vimtex#paths#s(path) abort " {{{1
  " Use backslash on Windows
  return simplify(vimtex#util#is_win()
        \ ? tr(a:path, '/', '\')
        \ : a:path)
endfunction

" }}}1
function! vimtex#paths#is_abs(path) abort " {{{1
  return a:path =~# s:re_abs
endfunction

" }}}1

function! vimtex#paths#shorten_relative(path) abort " {{{1
  " Input: An absolute path
  " Output: Relative path with respect to the VimTeX root, path relative to
  "         VimTeX root (unless absolute path is shorter)

  let l:relative = vimtex#paths#relative(a:path, b:vimtex.root)
  return strlen(l:relative) < strlen(a:path)
        \ ? l:relative : a:path
endfunction

" }}}1
function! vimtex#paths#relative(path, current) abort " {{{1
  " Note: This algorithm is based on the one presented by @Offirmo at SO,
  "       http://stackoverflow.com/a/12498485/51634

  let l:target = simplify(substitute(a:path, '\\', '/', 'g'))
  let l:common = simplify(substitute(a:current, '\\', '/', 'g'))

  " This only works on absolute paths
  if !vimtex#paths#is_abs(l:target)
    return substitute(a:path, '^\.\/', '', '')
  endif
{'fraction_non_alphanumeric': 0.16990701606086223, 'fraction_numerical': 0.015215553677092139, 'mean_word_length': 3.863013698630137, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3917217', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1337, 'n_words': 321}