<commit_before>" ============================================================================
" FILE: mplayer.vim
" AUTHOR: koturn <<EMAIL>>
" DESCRIPTION: {{{
" A mplayer frontend for Vim.
" }}}
" ============================================================================
let s:save_cpo = &cpo
set cpo&vim


if has('win32unix')
  let g:mplayer#use_win_mplayer_in_cygwin = get(g:, 'mplayer#use_win_mplayer_in_cygwin', 0)
  let g:mplayer#cygwin_mount_dir = get(g:, 'mplayer#cygwin_mount_dir', '/cygdrive')
endif

let g:mplayer#mplayer = get(g:, 'mplayer#mplayer', 'mplayer')
if has('win32') || has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let g:mplayer#option = get(g:, 'mplayer#option',
        \ '-nofontconfig -idle -quiet -slave -af equalizer=0:0:0:0:0:0:0:0:0:0 -vo direct3d')
else
  let g:mplayer#option = get(g:, 'mplayer#option',
        \ '-nofontconfig -idle -quiet -slave -af equalizer=0:0:0:0:0:0:0:0:0:0')
endif
let g:mplayer#suffixes = get(g:, 'mplayer#suffixes', ['*'])
let g:mplayer#engine = get(g:, 'mplayer#engine', has('job') || has('nvim') ? 'job' : 'vimproc')
let g:mplayer#_use_timer = get(g:, 'mplayer#_use_timer', has('timers'))
let g:mplayer#tiemr_cycle = 1000

let g:mplayer#enable_ctrlp_multi_select = get(g:, 'mplayer#enable_ctrlp_multi_select', 1)

let s:V = vital#mplayer#new()
let s:List = s:V.import('Data.List')
let s:PM = s:V.import('ProcessManager')

if has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let s:TENC = 'cp932'
else
  let s:TENC = &termencoding
endif
lockvar s:TENC
if has('win32') || has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let s:LINE_BREAK = "\r\n"
else
  let s:LINE_BREAK = "\n"
endif
lockvar s:LINE_BREAK

let s:DUMMY_COMMAND = 'get_property __NONE__'
lockvar s:DUMMY_COMMAND
let s:DUMMY_PATTERN = '.*ANS_ERROR=PROPERTY_UNKNOWN' . s:LINE_BREAK
lockvar s:DUMMY_PATTERN

let s:INFO_COMMANDS = [
      \ 'get_time_pos', 'get_time_length', 'get_percent_pos', 'get_file_name',
      \ 'get_meta_title', 'get_meta_artist', 'get_meta_album', 'get_meta_year',
      \ 'get_meta_comment', 'get_meta_track', 'get_meta_genre',
      \ 'get_audio_codec', 'get_audio_bitrate', 'get_audio_samples',
      \ 'get_video_codec', 'get_video_bitrate', 'get_video_resolution'
      \]
lockvar s:INFO_COMMANDS

let s:eq_presets = mplayer#complete#_import_local_var('eq_presets')
let s:SUB_ARG_DICT = mplayer#complete#_import_local_var('SUB_ARG_DICT')
let s:HELP_DICT = mplayer#complete#_import_local_var('HELP_DICT')


let s:MPlayer = {
      \ 'mplayer': g:mplayer#mplayer,
      \ 'option': g:mplayer#option,
      \}
let s:instance_id = 0
let s:mplayer_list = []


function! mplayer#new(...) abort
  let engine = a:0 > 0 ? a:1 : g:mplayer#engine
  let mplayer = extend(copy(s:MPlayer), mplayer#engine#{engine}#define())
  let mplayer.id = s:instance_id
  let s:instance_id += 1
  call add(s:mplayer_list, mplayer)

  let group = 'MPlayer' . mplayer.id
  execute 'augroup' group
  execute '  autocmd!'
  execute '  autocmd' group 'VimLeave * call s:mplayer_list[' . mplayer.id . '].stop()'
  execute 'augroup END'
  return mplayer
endfunction

function! mplayer#_import_local_var(name) abort
  return s:[a:name]
endfunction


function! s:MPlayer.play(...) abort
  let pos = match(a:000, '^--$')
  if pos == -1
    let pos = a:0
  endif
  let custom_option = join(a:000[pos + 1 :], ' ')
  call self.start(custom_option)
  let filelist = a:000[: pos - 1]
  call self.enqueue(filelist)
endfunction

function! s:MPlayer.enqueue(...) abort
  if !self.is_playing()
    call self.start('')
  endif
  call self._write(join(extend(s:make_loadcmds(s:List.flatten(a:000)), [s:DUMMY_COMMAND, '']), "\n"))
  call self._read()
endfunction

function! s:MPlayer.stop() abort
  if !self.is_playing() | return | endif
  call self._write("quit\n")
endfunction

function! s:MPlayer.get_file_info() abort
  if !self.is_playing() | return | endif
  return s:get_file_info(substitute(iconv(self._command(join(s:INFO_COMMANDS, "\n")), s:TENC, &enc), "'", '', 'g'))
endfunction

function! s:MPlayer._command(cmd) abort
  if !self.is_playing() | return | endif
  call self._write(join([s:DUMMY_COMMAND, a:cmd, ''], "\n"))
  return substitute(self._read(), s:DUMMY_PATTERN, '', 'g')
endfunction

function! s:MPlayer.command(cmd, ...) abort
  let is_iconv = a:0 > 0 ? a:1 : 0
  let str = self._command(a:cmd)
  if is_iconv
    let str = iconv(str, s:TENC, &enc)
  endif
  return matchstr(substitute(str, "^\e[A\r\e[K", '', ''), '^ANS_.\+=\zs.*$')
endfunction
<commit_msg>Simplify s:MPlayer.command()<commit_after>" ============================================================================
" FILE: mplayer.vim
" AUTHOR: koturn <<EMAIL>>
" DESCRIPTION: {{{
" A mplayer frontend for Vim.
" }}}
" ============================================================================
let s:save_cpo = &cpo
set cpo&vim


if has('win32unix')
  let g:mplayer#use_win_mplayer_in_cygwin = get(g:, 'mplayer#use_win_mplayer_in_cygwin', 0)
  let g:mplayer#cygwin_mount_dir = get(g:, 'mplayer#cygwin_mount_dir', '/cygdrive')
endif

let g:mplayer#mplayer = get(g:, 'mplayer#mplayer', 'mplayer')
if has('win32') || has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let g:mplayer#option = get(g:, 'mplayer#option',
        \ '-nofontconfig -idle -quiet -slave -af equalizer=0:0:0:0:0:0:0:0:0:0 -vo direct3d')
else
  let g:mplayer#option = get(g:, 'mplayer#option',
        \ '-nofontconfig -idle -quiet -slave -af equalizer=0:0:0:0:0:0:0:0:0:0')
endif
let g:mplayer#suffixes = get(g:, 'mplayer#suffixes', ['*'])
let g:mplayer#engine = get(g:, 'mplayer#engine', has('job') || has('nvim') ? 'job' : 'vimproc')
let g:mplayer#_use_timer = get(g:, 'mplayer#_use_timer', has('timers'))
let g:mplayer#tiemr_cycle = 1000

let g:mplayer#enable_ctrlp_multi_select = get(g:, 'mplayer#enable_ctrlp_multi_select', 1)

let s:V = vital#mplayer#new()
let s:List = s:V.import('Data.List')
let s:PM = s:V.import('ProcessManager')

if has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let s:TENC = 'cp932'
else
  let s:TENC = &termencoding
endif
lockvar s:TENC
if has('win32') || has('win32unix') && g:mplayer#use_win_mplayer_in_cygwin
  let s:LINE_BREAK = "\r\n"
else
  let s:LINE_BREAK = "\n"
endif
lockvar s:LINE_BREAK

let s:DUMMY_COMMAND = 'get_property __NONE__'
lockvar s:DUMMY_COMMAND
let s:DUMMY_PATTERN = '.*ANS_ERROR=PROPERTY_UNKNOWN' . s:LINE_BREAK
lockvar s:DUMMY_PATTERN

let s:INFO_COMMANDS = [
      \ 'get_time_pos', 'get_time_length', 'get_percent_pos', 'get_file_name',
      \ 'get_meta_title', 'get_meta_artist', 'get_meta_album', 'get_meta_year',
      \ 'get_meta_comment', 'get_meta_track', 'get_meta_genre',
      \ 'get_audio_codec', 'get_audio_bitrate', 'get_audio_samples',
      \ 'get_video_codec', 'get_video_bitrate', 'get_video_resolution'
      \]
lockvar s:INFO_COMMANDS

let s:eq_presets = mplayer#complete#_import_local_var('eq_presets')
let s:SUB_ARG_DICT = mplayer#complete#_import_local_var('SUB_ARG_DICT')
let s:HELP_DICT = mplayer#complete#_import_local_var('HELP_DICT')


let s:MPlayer = {
      \ 'mplayer': g:mplayer#mplayer,
      \ 'option': g:mplayer#option,
      \}
let s:instance_id = 0
let s:mplayer_list = []


function! mplayer#new(...) abort
  let engine = a:0 > 0 ? a:1 : g:mplayer#engine
  let mplayer = extend(copy(s:MPlayer), mplayer#engine#{engine}#define())
  let mplayer.id = s:instance_id
  let s:instance_id += 1
  call add(s:mplayer_list, mplayer)

  let group = 'MPlayer' . mplayer.id
  execute 'augroup' group
  execute '  autocmd!'
  execute '  autocmd' group 'VimLeave * call s:mplayer_list[' . mplayer.id . '].stop()'
  execute 'augroup END'
  return mplayer
endfunction

function! mplayer#_import_local_var(name) abort
  return s:[a:name]
endfunction


function! s:MPlayer.play(...) abort
  let pos = match(a:000, '^--$')
  if pos == -1
    let pos = a:0
  endif
  let custom_option = join(a:000[pos + 1 :], ' ')
  call self.start(custom_option)
  let filelist = a:000[: pos - 1]
  call self.enqueue(filelist)
endfunction

function! s:MPlayer.enqueue(...) abort
  if !self.is_playing()
    call self.start('')
  endif
  call self._write(join(extend(s:make_loadcmds(s:List.flatten(a:000)), [s:DUMMY_COMMAND, '']), "\n"))
  call self._read()
endfunction

function! s:MPlayer.stop() abort
  if !self.is_playing() | return | endif
  call self._write("quit\n")
endfunction

function! s:MPlayer.get_file_info() abort
  if !self.is_playing() | return | endif
  return s:get_file_info(substitute(iconv(self._command(join(s:INFO_COMMANDS, "\n")), s:TENC, &enc), "'", '', 'g'))
endfunction

function! s:MPlayer._command(cmd) abort
  if !self.is_playing() | return | endif
  call self._write(join([s:DUMMY_COMMAND, a:cmd, ''], "\n"))
  return substitute(self._read(), s:DUMMY_PATTERN, '', 'g')
endfunction

function! s:MPlayer.command(cmd, ...) abort
  let is_iconv = a:0 > 0 ? a:1 : 0
  let str = self._command(a:cmd)
  return matchstr(substitute(is_iconv ? iconv(str, s:TENC, &enc) : str, "^\e[A\r\e[K", '', ''), '^ANS_.\+=\zs.*$')
endfunction

{'fraction_non_alphanumeric': 0.19643252825171725, 'fraction_numerical': 0.014846000443164193, 'mean_word_length': 5.294979079497908, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '767959', 'n_tokens_mistral': 3706, 'n_tokens_neox': 3570, 'n_words': 667}