<commit_before>"=============================================================================
" FILE: vimproc.vim
" AUTHOR:  <NAME> <<EMAIL>> (Modified)
"          <NAME> <yukihiro.nakadaira at gmail.com> (Original)
" Last Modified: 22 Jun 2010
" License: MIT license  {{{
"     Permission is hereby granted, free of charge, to any person obtaining
"     a copy of this software and associated documentation files (the
"     "Software"), to deal in the Software without restriction, including
"     without limitation the rights to use, copy, modify, merge, publish,
"     distribute, sublicense, and/or sell copies of the Software, and to
"     permit persons to whom the Software is furnished to do so, subject to
"     the following conditions:
"
"     The above copyright notice and this permission notice shall be included
"     in all copies or substantial portions of the Software.
"
"     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
"     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
"     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
"     IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
"     CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
"     TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
"     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
" Version: 4.1, for Vim 7.0
"=============================================================================

function! vimproc#version()
  return str2nr(printf('%2d%02d', 4, 1))
endfunction

let s:is_win = has('win32') || has('win64')
let s:last_status = 0
let s:exists_vimshell = exists('*vimshell#version')

if exists('g:vimproc_dll_path')
  let s:dll_path = g:vimproc_dll_path
else
  let s:dll_path = expand("<sfile>:p:h") . ((s:is_win || has('win32unix'))? '/proc.dll' : '/proc.so')
endif

if !filereadable(s:dll_path)
  execute 'echoerr' printf('"%s" is not found. Please make it.', s:dll_path)
  finish
endif

if has('iconv')
  " Dll path should be encoded with default encoding.  Vim does not convert
  " it from &enc to default encoding.
  let s:dll_path = iconv(s:dll_path, &encoding, "default")
endif

"-----------------------------------------------------------
" API

function! vimproc#open(filename)"{{{
  let l:filename = a:filename
  if &termencoding != '' && &encoding != &termencoding
    " Convert encoding.
    let l:filename = iconv(l:filename, &encoding, &termencoding)
  endif

  " Detect desktop environment.
  if vimshell#iswin()
    " For URI only.
    "execute '!start rundll32 url.dll,FileProtocolHandler' l:filename
    
    call s:libcall('vp_open', [fnamemodify(a:filename, ':p')])
  elseif has('win32unix')
    " Cygwin.
    call vimproc#system(['cygstart', l:filename])
  elseif executable('xdg-open')
    " Linux.
    call vimproc#system_bg(['xdg-open', l:filename])
  elseif exists('$KDE_FULL_SESSION') && $KDE_FULL_SESSION ==# 'true'
    " KDE.
    call vimproc#system_bg(['kioclient', 'exec', l:filename])
  elseif exists('$GNOME_DESKTOP_SESSION_ID')
    " GNOME.
    call vimproc#system_bg(['gnome-open', l:filename])
  elseif executable('exo-open')
    " Xfce.
    call vimproc#system_bg(['exo-open', l:filename])
  elseif (has('macunix') || system('uname') =~? '^darwin') && executable('open')
    " Mac OS.
    call vimproc#system_bg(['open', l:filename])
  else
    " Give up.
    throw 'vimproc#open: Not supported.'
  endif
endfunction"}}}

function! vimproc#get_command_name(command, ...)"{{{
  if a:0 > 2
    throw 'vimproc#get_command_name: Invalid argument.'
  endif
  
  if a:0 >= 1
    let l:path = a:1
  elseif s:is_win 
    let l:path = substitute(substitute($PATH, ';', ',', 'g'), '\s', '\\\\ ', 'g')
  else
    let l:path = substitute(substitute($PATH, ':', ',', 'g'), '\s', '\\\\ ', 'g')
  endif

  let l:count = a:0 < 2 ? 1 : a:2
  
  let l:command = expand(a:command)
  
  let l:pattern = printf('[/~]\?\f\+[%s]\f*$', s:is_win ? '/\\' : '/')
  if l:command =~ l:pattern
    if s:is_win && fnamemodify(l:command, ':e') ==? 'lnk'
      let l:command = resolve(l:command)
    endif

    if !filereadable(l:command)
      throw printf('vimproc#get_command_name: File "%s" is not found.', l:command)
    elseif !executable(l:command)
      throw printf('vimproc#get_command_name: File "%s" is not executable.', l:command)
    endif

    return l:command
  endif

  " Command search.
  let l:suffixesadd_save = &l:suffixesadd
  let &l:suffixesadd = s:is_win ? substitute($PATHEXT.';.LNK', ';', ',', 'g') : ''
  let l:file = findfile(l:command, l:path, l:count)
  let &l:suffixesadd = l:suffixesadd_save

  if l:count < 0
    return filter(l:file, 'executable(v:val)')
  else
    if s:is_win && fnamemodify(l:file, ':e') ==? 'lnk'
      let l:file = resolve(l:file)
    endif

    if l:file == ''
      throw printf('vimproc#get_command_name: File "%s" is not found.', l:command)
    elseif !executable(l:file)
      throw printf('vimproc#get_command_name: File "%s" is not executable.', l:command)
    endif
  endif

  return l:file
endfunction"}}}

function! vimproc#system(cmdline, ...)"{{{
  if type(a:cmdline) == type('')
    if a:cmdline =~ '&\s*$'
      return vimproc#system_bg(a:cmdline)
    elseif (!has('unix') || a:cmdline !~ '^\s*man ') && s:exists_vimshell
      return (a:0 == 0) ? vimproc#parser#system(a:cmdline) : vimproc#parser#system(a:cmdline, join(a:000))
    else
      let l:output = (a:0 == 0) ? system(a:cmdline) : system(a:cmdline, join(a:000))
      let s:last_status = v:shell_error
      let s:last_errmsg = ''
      return l:output
    endif<commit_msg>- Improved error message.<commit_after>"=============================================================================
" FILE: vimproc.vim
" AUTHOR:  <NAME> <<EMAIL>> (Modified)
"          <NAME> <yukihiro.nakadaira at gmail.com> (Original)
" Last Modified: 22 Jun 2010
" License: MIT license  {{{
"     Permission is hereby granted, free of charge, to any person obtaining
"     a copy of this software and associated documentation files (the
"     "Software"), to deal in the Software without restriction, including
"     without limitation the rights to use, copy, modify, merge, publish,
"     distribute, sublicense, and/or sell copies of the Software, and to
"     permit persons to whom the Software is furnished to do so, subject to
"     the following conditions:
"
"     The above copyright notice and this permission notice shall be included
"     in all copies or substantial portions of the Software.
"
"     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
"     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
"     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
"     IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
"     CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
"     TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
"     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
" Version: 4.1, for Vim 7.0
"=============================================================================

function! vimproc#version()
  return str2nr(printf('%2d%02d', 4, 1))
endfunction

let s:is_win = has('win32') || has('win64')
let s:last_status = 0
let s:exists_vimshell = exists('*vimshell#version')

if exists('g:vimproc_dll_path')
  let s:dll_path = g:vimproc_dll_path
else
  let s:dll_path = expand("<sfile>:p:h") . ((s:is_win || has('win32unix'))? '/proc.dll' : '/proc.so')
endif

if !filereadable(s:dll_path)
  execute 'echoerr' printf('"%s" is not found. Please make it.', s:dll_path)
  finish
endif

if has('iconv')
  " Dll path should be encoded with default encoding.  Vim does not convert
  " it from &enc to default encoding.
  let s:dll_path = iconv(s:dll_path, &encoding, "default")
endif

"-----------------------------------------------------------
" API

function! vimproc#open(filename)"{{{
  let l:filename = a:filename
  if &termencoding != '' && &encoding != &termencoding
    " Convert encoding.
    let l:filename = iconv(l:filename, &encoding, &termencoding)
  endif

  " Detect desktop environment.
  if vimshell#iswin()
    " For URI only.
    "execute '!start rundll32 url.dll,FileProtocolHandler' l:filename
    
    call s:libcall('vp_open', [fnamemodify(a:filename, ':p')])
  elseif has('win32unix')
    " Cygwin.
    call vimproc#system(['cygstart', l:filename])
  elseif executable('xdg-open')
    " Linux.
    call vimproc#system_bg(['xdg-open', l:filename])
  elseif exists('$KDE_FULL_SESSION') && $KDE_FULL_SESSION ==# 'true'
    " KDE.
    call vimproc#system_bg(['kioclient', 'exec', l:filename])
  elseif exists('$GNOME_DESKTOP_SESSION_ID')
    " GNOME.
    call vimproc#system_bg(['gnome-open', l:filename])
  elseif executable('exo-open')
    " Xfce.
    call vimproc#system_bg(['exo-open', l:filename])
  elseif (has('macunix') || system('uname') =~? '^darwin') && executable('open')
    " Mac OS.
    call vimproc#system_bg(['open', l:filename])
  else
    " Give up.
    throw 'vimproc#open: Not supported.'
  endif
endfunction"}}}

function! vimproc#get_command_name(command, ...)"{{{
  if a:0 > 2
    throw 'vimproc#get_command_name: Invalid argument.'
  endif
  
  if a:0 >= 1
    let l:path = a:1
  elseif s:is_win 
    let l:path = substitute(substitute($PATH, ';', ',', 'g'), '\s', '\\\\ ', 'g')
  else
    let l:path = substitute(substitute($PATH, ':', ',', 'g'), '\s', '\\\\ ', 'g')
  endif

  let l:count = a:0 < 2 ? 1 : a:2
  
  let l:command = expand(a:command)
  
  let l:pattern = printf('[/~]\?\f\+[%s]\f*$', s:is_win ? '/\\' : '/')
  if l:command =~ l:pattern
    if s:is_win && fnamemodify(l:command, ':e') ==? 'lnk'
      let l:command = resolve(l:command)
    endif

    if !filereadable(l:command)
      throw printf('vimproc#get_command_name: File "%s" is not found.', l:command)
    elseif !executable(l:command)
      throw printf('vimproc#get_command_name: File "%s" is not executable.', l:command)
    endif

    return l:command
  endif

  " Command search.
  let l:suffixesadd_save = &l:suffixesadd
  let &l:suffixesadd = s:is_win ? substitute($PATHEXT.';.LNK', ';', ',', 'g') : ''
  let l:file = findfile(l:command, l:path, l:count)
  let &l:suffixesadd = l:suffixesadd_save

  if l:count < 0
    return filter(l:file, 'executable(v:val)')
  else
    if s:is_win && fnamemodify(l:file, ':e') ==? 'lnk'
      let l:file = resolve(l:file)
    endif

    if l:file == ''
      throw printf('vimproc#get_command_name: File "%s" is not found.', l:command)
    elseif !executable(l:file)
      throw printf('vimproc#get_command_name: File "%s" is not executable.', l:file)
    endif
  endif

  return l:file
endfunction"}}}

function! vimproc#system(cmdline, ...)"{{{
  if type(a:cmdline) == type('')
    if a:cmdline =~ '&\s*$'
      return vimproc#system_bg(a:cmdline)
    elseif (!has('unix') || a:cmdline !~ '^\s*man ') && s:exists_vimshell
      return (a:0 == 0) ? vimproc#parser#system(a:cmdline) : vimproc#parser#system(a:cmdline, join(a:000))
    else
      let l:output = (a:0 == 0) ? system(a:cmdline) : system(a:cmdline, join(a:000))
      let s:last_status = v:shell_error
      let s:last_errmsg = ''
      return l:output
    endif
{'fraction_non_alphanumeric': 0.18309234454005144, 'fraction_numerical': 0.00833850793932405, 'mean_word_length': 3.7092731829573933, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '2183476', 'n_tokens_mistral': 4001, 'n_tokens_neox': 3777, 'n_words': 1046}