<commit_before>"=============================================================================
" FILE: config.vim
" AUTHOR:  <NAME> <Shougo.Matsu at gmail.com>
" 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.
" }}}
"=============================================================================

let s:save_cpo = &cpo
set cpo&vim

if !exists('s:neobundles')
  let s:within_block = 0
  let s:lazy_rtp_bundles = []
  let s:neobundles = {}
  let neobundle#tapped = {}
endif

function! neobundle#config#init() "{{{
  if neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  for bundle in values(s:neobundles)
    if !(bundle.lazy && bundle.sourced)
      " Reset.
      call neobundle#config#rtp_rm(bundle)

      call remove(s:neobundles, bundle.name)
    endif
  endfor

  augroup neobundle
    autocmd VimEnter * call s:on_vim_enter()
  augroup END

  call s:filetype_off()

  let s:within_block = 1
  let s:lazy_rtp_bundles = []

  " Load extra bundles configuration.
  call neobundle#config#load_extra_bundles()
endfunction"}}}
function! neobundle#config#append() "{{{
  if neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  if neobundle#get_rtp_dir() == ''
    call neobundle#util#print_error(
          \ 'You must call neobundle#begin() before.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  call s:filetype_off()

  let s:within_block = 1
  let s:lazy_rtp_bundles = []
endfunction"}}}
function! neobundle#config#final() "{{{
  if !neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  " Join to the tail in runtimepath.
  let rtps = neobundle#util#split_rtp(&runtimepath)
  let index = index(rtps, neobundle#get_rtp_dir())
  for bundle in filter(s:lazy_rtp_bundles,
        \ 'isdirectory(v:val.rtp) && !v:val.disabled')
    let bundle.sourced = 1
    call insert(rtps, bundle.rtp, index)
    let index += 1

    if isdirectory(bundle.rtp.'/after')
      call add(rtps, s:get_rtp_after(bundle))
    endif
  endfor
  let &runtimepath = neobundle#util#join_rtp(rtps, &runtimepath, '')

  call neobundle#call_hook('on_source', s:lazy_rtp_bundles)

  let s:within_block = 0
  let s:lazy_rtp_bundles = []
endfunction"}}}
function! neobundle#config#within_block() "{{{
  return s:within_block
endfunction"}}}

function! neobundle#config#get(name) "{{{
  return get(s:neobundles, a:name, {})
endfunction"}}}

function! neobundle#config#get_neobundles() "{{{
  return values(s:neobundles)
endfunction"}}}

function! neobundle#config#get_enabled_bundles() "{{{
  return filter(values(s:neobundles),
        \ "!v:val.disabled")
endfunction"}}}

function! neobundle#config#get_autoload_bundles() "{{{
  return filter(values(s:neobundles),
        \ "!v:val.sourced && v:val.lazy && !v:val.disabled")
endfunction"}}}

function! neobundle#config#source_bundles(bundles) "{{{
  if !empty(a:bundles)
    call neobundle#config#source(map(copy(a:bundles),
          \ "type(v:val) == type({}) ? v:val.name : v:val"))
  endif
endfunction"}}}

function! neobundle#config#check_not_exists(names, ...) "{{{
  " For infinite loop.
  let self = get(a:000, 0, [])

  let _ = map(neobundle#get_not_installed_bundles(a:names), 'v:val.name')
  for bundle in map(filter(copy(a:names),
        \ 'index(self, v:val) < 0 && has_key(s:neobundles, v:val)'),
        \ 's:neobundles[v:val]')
    call add(self, bundle.name)

    if !empty(bundle.depends)
      let _ += neobundle#config#check_not_exists(
            \ map(copy(bundle.depends), 'v:val.name'), self)
    endif
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#source(names, ...) "{{{
  let is_force = get(a:000, 0, 1)

  let bundles = neobundle#config#search(
        \ neobundle#util#convert2list(a:names))

  let rtps = neobundle#util#split_rtp(&runtimepath)
  let bundles = filter(bundles, "!v:val.disabled
        \ && (!v:val.sourced || (v:val.rtp != ''
        \                        && index(rtps, v:val.rtp) < 0))")
  if empty(bundles)
    return
  endif

  let filetype_before = neobundle#util#redir("autocmd FileType")

  let reset_ftplugin = 0
  for bundle in bundles
    let bundle.sourced = 1
    let bundle.disabled = 0

    if !empty(bundle.dummy_mappings)
      for [mode, mapping] in bundle.dummy_mappings
        silent! execute mode.'unmap' mapping
      endfor
      let bundle.dummy_mappings = []
    endif

    call neobundle#config#rtp_add(bundle)

    if exists('g:loaded_neobundle') || is_force
      try
        call s:on_source(bundle)
      catch
        call neobundle#util#print_error(
              \ 'Uncaught error while sourcing "' . bundle.name .
              \ '": '.v:exception . ' in ' . v:throwpoint)
      endtry
    endif

    call neobundle#autoload#source(bundle.name)

    if !reset_ftplugin
      let reset_ftplugin = s:is_reset_ftplugin(&filetype, bundle.rtp)
    endif
  endfor

  let filetype_after = neobundle#util#redir('autocmd FileType')

  if reset_ftplugin
    if &verbose
      call neobundle#util#print_error(
            \ "Neobundle: resetting ftplugin, after loading bundles:"
            \ .join(map(copy(bundles), 'v:val.name'), ", "))
    endif
    call s:reset_ftplugin()
  elseif filetype_before !=# filetype_after
    if &verbose
      call neobundle#util#print_error(
            \ "Neobundle: FileType autocommand triggered by:"
            \ .join(map(copy(bundles), 'v:val.name'), ", "))
    endif
    execute 'doautocmd FileType' &filetype
  endif

  if exists('g:loaded_neobundle')
    call neobundle#call_hook('on_post_source', bundles)
  endif
endfunction"}}}

function! neobundle#config#disable(...) "{{{
  let bundle_names = neobundle#config#search(a:000)
  if empty(bundle_names)
    call neobundle#util#print_error(
          \ 'Disabled bundles ' . string(a:000) . ' are not found.')
    return
  endif

  for bundle in bundle_names
    call neobundle#config#rtp_rm(bundle)
    let bundle.refcnt -= 1

    if bundle.refcnt <= 0
      if bundle.sourced
        call neobundle#util#print_error(
              \ bundle.name . ' is already sourced.  Cannot be disabled.')
        continue
      endif

      let bundle.disabled = 1
    endif
  endfor
endfunction"}}}

function! neobundle#config#is_disabled(name) "{{{
  return get(neobundle#config#get(a:name), 'disabled', 1)
endfunction"}}}

function! neobundle#config#is_sourced(name) "{{{
  return get(neobundle#config#get(a:name), 'sourced', 0)
endfunction"}}}

function! neobundle#config#is_installed(name) "{{{
  return isdirectory(get(neobundle#config#get(a:name), 'path', ''))
endfunction"}}}

function! neobundle#config#rm(path) "{{{
  for bundle in filter(neobundle#config#get_neobundles(),
        \ 'v:val.path ==# a:path')
    call neobundle#config#rtp_rm(bundle)
    call remove(s:neobundles, bundle.name)
  endfor
endfunction"}}}

function! neobundle#config#get_types(...) "{{{
  let type = get(a:000, 0, '')

  if type ==# 'git'
    if !exists('s:neobundle_type_git')
      let s:neobundle_type_git = neobundle#types#git#define()
    endif

    return s:neobundle_type_git
  endif

  if !exists('s:neobundle_types')
    " Load neobundle types.
    let s:neobundle_types = []
    for list in map(split(globpath(&runtimepath,
          \ 'autoload/neobundle/types/*.vim', 1), '\n'),
          \ "neobundle#util#convert2list(
          \    neobundle#types#{fnamemodify(v:val, ':t:r')}#define())")
      let s:neobundle_types += list
    endfor

    let s:neobundle_types = neobundle#util#uniq(
          \ s:neobundle_types, 'v:val.name')
  endif

  return (type == '') ? s:neobundle_types :
        \ get(filter(copy(s:neobundle_types), 'v:val.name ==# type'), 0, {})
endfunction"}}}

function! neobundle#config#rtp_rm_all_bundles() "{{{
  call filter(values(s:neobundles), 'neobundle#config#rtp_rm(v:val)')
endfunction"}}}

function! neobundle#config#rtp_rm(bundle) "{{{
  execute 'set rtp-='.fnameescape(a:bundle.rtp)
  if isdirectory(a:bundle.rtp.'/after')
    execute 'set rtp-='.s:get_rtp_after(a:bundle)
  endif
endfunction"}}}

function! neobundle#config#rtp_add(bundle) abort "{{{
  if has_key(s:neobundles, a:bundle.name)
    call neobundle#config#rtp_rm(s:neobundles[a:bundle.name])
  endif

  if s:within_block && !a:bundle.force
    " Add rtp lazily.
    call add(s:lazy_rtp_bundles, a:bundle)
    return
  endif

  let rtp = a:bundle.rtp
  if isdirectory(rtp)
    " Join to the tail in runtimepath.
    let rtps = neobundle#util#split_rtp(&runtimepath)
    let &runtimepath = neobundle#util#join_rtp(
          \ insert(rtps, rtp, index(rtps, neobundle#get_rtp_dir())),
          \ &runtimepath, rtp)
  endif
  if isdirectory(rtp.'/after')
    execute 'set rtp+='.s:get_rtp_after(a:bundle)
  endif

  call neobundle#call_hook('on_source', a:bundle)
endfunction"}}}

function! neobundle#config#search(bundle_names, ...) "{{{
  if empty(a:bundle_names)
    return []
  endif

  " For infinite loop.
  let self = get(a:000, 0, [])

  let _ = []
  let bundles = len(a:bundle_names) != 1 ?
        \ filter(neobundle#config#get_neobundles(),
        \ 'index(a:bundle_names, v:val.name) >= 0 &&
        \  (empty(self) || index(self, v:val.name) < 0)') :
        \ has_key(s:neobundles, a:bundle_names[0]) ?
        \     [s:neobundles[a:bundle_names[0]]] : []
  for bundle in bundles
    call add(self, bundle.name)

    if !empty(bundle.depends)
      let _ += neobundle#config#search(
            \ map(copy(bundle.depends), 'v:val.name'), self)
    endif
    call add(_, bundle)
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#search_simple(bundle_names) "{{{
  return filter(neobundle#config#get_neobundles(),
        \ 'index(a:bundle_names, v:val.name) >= 0')
endfunction"}}}

function! neobundle#config#fuzzy_search(bundle_names) "{{{
  let bundles = []
  for name in a:bundle_names
    let bundles += filter(neobundle#config#get_neobundles(),
          \ 'stridx(v:val.name, name) >= 0')
  endfor

  let _ = []
  for bundle in bundles
    if !empty(bundle.depends)
      let _ += neobundle#config#search(
            \ map(copy(bundle.depends), 'v:val.name'))
    endif
    call add(_, bundle)
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#load_extra_bundles() "{{{
  let path = neobundle#get_neobundle_dir() . '/extra_bundles.vim'

  if filereadable(path)
    execute 'source' fnameescape(path)
  endif
endfunction"}}}

function! neobundle#config#save_direct(arg) "{{{
  if neobundle#util#is_sudo()
    call neobundle#util#print_error(
          \ '"sudo vim" is detected. This feature is disabled.')
    return
  endif

  let path = neobundle#get_neobundle_dir() . '/extra_bundles.vim'
  let bundles = filereadable(path) ? readfile(path) : []
  call writefile(add(bundles, 'NeoBundle ' . a:arg), path)
endfunction"}}}

function! neobundle#config#set(name, dict) "{{{
  let bundle = neobundle#config#get(a:name)
  if empty(bundle)
    call neobundle#util#print_error(
          \ 'Plugin name "' . a:name . '" is not defined.')
    return
  endif

  let bundle = neobundle#init#_bundle(extend(bundle, a:dict))
  if bundle.lazy && bundle.sourced
    " Remove from runtimepath.
    call neobundle#config#rtp_rm(bundle)
    let bundle.sourced = 0
  endif

  call neobundle#config#add(bundle, 1)
endfunction"}}}

function! neobundle#config#add(bundle, ...) "{{{
  if empty(a:bundle)
    return
  endif

  let bundle = a:bundle
  let is_force = get(a:000, 0, bundle.local)

  if !is_force && !bundle.overwrite &&
        \     has_key(s:neobundles, bundle.name)
    return
  endif

  if !empty(bundle.depends)
    call s:add_depends(bundle)
  endif

  let prev_bundle = get(s:neobundles, bundle.name, {})

  if !empty(prev_bundle)
    if prev_bundle.sourced
      return
    endif

    call neobundle#config#rtp_rm(prev_bundle)
  endif
  let s:neobundles[bundle.name] = bundle

  if bundle.disabled
    " Ignore load.
    return
  endif

  if !bundle.lazy && bundle.rtp != ''
    if !has('vim_starting')
      " Load automatically.
      call neobundle#config#source(bundle.name, bundle.force)
    else
      call neobundle#config#rtp_add(bundle)

      if bundle.force
        runtime! plugin/**/*.vim
      endif
    endif
  elseif bundle.lazy
    call s:add_lazy(bundle)
  endif
endfunction"}}}

function! neobundle#config#tsort(bundles) "{{{
  let sorted = []
  let mark = {}
  for target in a:bundles
    call s:tsort_impl(target, a:bundles, mark, sorted)
  endfor

  return sorted
endfunction"}}}

function! neobundle#config#get_lazy_rtp_bundles() "{{{
  return s:lazy_rtp_bundles
endfunction"}}}

function! neobundle#config#check_commands(commands) "{{{
  " Environment check.
  if type(a:commands) == type([])
        \ || type(a:commands) == type('')
    let commands = a:commands
  elseif neobundle#util#is_windows() && has_key(a:commands, 'windows')
    let commands = a:commands.windows
  elseif neobundle#util#is_mac() && has_key(a:commands, 'mac')
    let commands = a:commands.mac
  elseif neobundle#util#is_cygwin() && has_key(a:commands, 'cygwin')
    let commands = a:commands.cygwin
  elseif !neobundle#util#is_windows() && has_key(a:commands, 'unix')
    let commands = a:commands.unix
  elseif has_key(a:commands, 'others')
    let commands = a:commands.others
  else
    " Invalid.
    return 0
  endif

  for command in neobundle#util#convert2list(commands)
    if !executable(command)
      return 1
    endif
  endfor
endfunction"}}}

function! s:tsort_impl(target, bundles, mark, sorted) "{{{
  if has_key(a:mark, a:target.name)
    return
  endif

  let a:mark[a:target.name] = 1
  for depend in get(a:target, 'depends', [])
    call s:tsort_impl(get(s:neobundles, depend.name, depend),
          \ a:bundles, a:mark, a:sorted)
  endfor

  call add(a:sorted, a:target)
endfunction"}}}

function! s:on_vim_enter() "{{{
  if !empty(s:lazy_rtp_bundles)
    call neobundle#util#print_error(
          \ 'neobundle#begin() was called without calling ' .
          \ 'neobundle#end() in .vimrc.')
    " We're past the point of plugins being sourced, so don't bother
    " trying to recover.
    return
  endif

  call neobundle#call_hook('on_post_source')
endfunction"}}}

function! s:add_depends(bundle) "{{{
  " Add depends.
  for depend in a:bundle.depends
    if !has_key(s:neobundles, depend.name)
      call neobundle#config#add(depend)
    else
      " Add reference count
      let s:neobundles[depend.name].refcnt += 1

      if !depend.lazy
        " Load automatically.
        call neobundle#config#source(depend.name, depend.force)
      endif
    endif
  endfor
endfunction"}}}

function! s:add_lazy(bundle) "{{{
  let bundle = a:bundle

  " Auto set autoload keys.
  for key in filter([
        \ 'filetypes', 'filename_patterns',
        \ 'commands', 'functions', 'mappings', 'unite_sources',<commit_msg>Fix source depends problem<commit_after>"=============================================================================
" FILE: config.vim
" AUTHOR:  <NAME> <<EMAIL>.<EMAIL> at <EMAIL>>
" 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.
" }}}
"=============================================================================

let s:save_cpo = &cpo
set cpo&vim

if !exists('s:neobundles')
  let s:within_block = 0
  let s:lazy_rtp_bundles = []
  let s:neobundles = {}
  let neobundle#tapped = {}
endif

function! neobundle#config#init() "{{{
  if neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  for bundle in values(s:neobundles)
    if !(bundle.lazy && bundle.sourced)
      " Reset.
      call neobundle#config#rtp_rm(bundle)

      call remove(s:neobundles, bundle.name)
    endif
  endfor

  augroup neobundle
    autocmd VimEnter * call s:on_vim_enter()
  augroup END

  call s:filetype_off()

  let s:within_block = 1
  let s:lazy_rtp_bundles = []

  " Load extra bundles configuration.
  call neobundle#config#load_extra_bundles()
endfunction"}}}
function! neobundle#config#append() "{{{
  if neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  if neobundle#get_rtp_dir() == ''
    call neobundle#util#print_error(
          \ 'You must call neobundle#begin() before.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  call s:filetype_off()

  let s:within_block = 1
  let s:lazy_rtp_bundles = []
endfunction"}}}
function! neobundle#config#final() "{{{
  if !neobundle#config#within_block()
    call neobundle#util#print_error(
          \ 'neobundle#begin()/neobundle#end() usage is invalid.')
    call neobundle#util#print_error(
          \ 'Please check your .vimrc.')
    return
  endif

  " Join to the tail in runtimepath.
  let rtps = neobundle#util#split_rtp(&runtimepath)
  let index = index(rtps, neobundle#get_rtp_dir())
  for bundle in filter(s:lazy_rtp_bundles,
        \ 'isdirectory(v:val.rtp) && !v:val.disabled')
    let bundle.sourced = 1
    call insert(rtps, bundle.rtp, index)
    let index += 1

    if isdirectory(bundle.rtp.'/after')
      call add(rtps, s:get_rtp_after(bundle))
    endif
  endfor
  let &runtimepath = neobundle#util#join_rtp(rtps, &runtimepath, '')

  call neobundle#call_hook('on_source', s:lazy_rtp_bundles)

  let s:within_block = 0
  let s:lazy_rtp_bundles = []
endfunction"}}}
function! neobundle#config#within_block() "{{{
  return s:within_block
endfunction"}}}

function! neobundle#config#get(name) "{{{
  return get(s:neobundles, a:name, {})
endfunction"}}}

function! neobundle#config#get_neobundles() "{{{
  return values(s:neobundles)
endfunction"}}}

function! neobundle#config#get_enabled_bundles() "{{{
  return filter(values(s:neobundles),
        \ "!v:val.disabled")
endfunction"}}}

function! neobundle#config#get_autoload_bundles() "{{{
  return filter(values(s:neobundles),
        \ "!v:val.sourced && v:val.lazy && !v:val.disabled")
endfunction"}}}

function! neobundle#config#source_bundles(bundles) "{{{
  if !empty(a:bundles)
    call neobundle#config#source(map(copy(a:bundles),
          \ "type(v:val) == type({}) ? v:val.name : v:val"))
  endif
endfunction"}}}

function! neobundle#config#check_not_exists(names, ...) "{{{
  " For infinite loop.
  let self = get(a:000, 0, [])

  let _ = map(neobundle#get_not_installed_bundles(a:names), 'v:val.name')
  for bundle in map(filter(copy(a:names),
        \ 'index(self, v:val) < 0 && has_key(s:neobundles, v:val)'),
        \ 's:neobundles[v:val]')
    call add(self, bundle.name)

    if !empty(bundle.depends)
      let _ += neobundle#config#check_not_exists(
            \ map(copy(bundle.depends), 'v:val.name'), self)
    endif
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#source(names, ...) "{{{
  let is_force = get(a:000, 0, 1)

  let bundles = neobundle#config#search(
        \ neobundle#util#convert2list(a:names))

  let rtps = neobundle#util#split_rtp(&runtimepath)
  let bundles = filter(bundles, "!v:val.disabled
        \ && (!v:val.sourced || (v:val.rtp != ''
        \                        && index(rtps, v:val.rtp) < 0))")
  if empty(bundles)
    return
  endif

  let filetype_before = neobundle#util#redir("autocmd FileType")

  let reset_ftplugin = 0
  for bundle in bundles
    let bundle.sourced = 1
    let bundle.disabled = 0

    if !empty(bundle.dummy_mappings)
      for [mode, mapping] in bundle.dummy_mappings
        silent! execute mode.'unmap' mapping
      endfor
      let bundle.dummy_mappings = []
    endif

    call neobundle#config#rtp_add(bundle)

    if exists('g:loaded_neobundle') || is_force
      try
        call s:on_source(bundle)
      catch
        call neobundle#util#print_error(
              \ 'Uncaught error while sourcing "' . bundle.name .
              \ '": '.v:exception . ' in ' . v:throwpoint)
      endtry
    endif

    call neobundle#autoload#source(bundle.name)

    if !reset_ftplugin
      let reset_ftplugin = s:is_reset_ftplugin(&filetype, bundle.rtp)
    endif
  endfor

  let filetype_after = neobundle#util#redir('autocmd FileType')

  if reset_ftplugin
    if &verbose
      call neobundle#util#print_error(
            \ "Neobundle: resetting ftplugin, after loading bundles:"
            \ .join(map(copy(bundles), 'v:val.name'), ", "))
    endif
    call s:reset_ftplugin()
  elseif filetype_before !=# filetype_after
    if &verbose
      call neobundle#util#print_error(
            \ "Neobundle: FileType autocommand triggered by:"
            \ .join(map(copy(bundles), 'v:val.name'), ", "))
    endif
    execute 'doautocmd FileType' &filetype
  endif

  if exists('g:loaded_neobundle')
    call neobundle#call_hook('on_post_source', bundles)
  endif
endfunction"}}}

function! neobundle#config#disable(...) "{{{
  let bundle_names = neobundle#config#search(a:000)
  if empty(bundle_names)
    call neobundle#util#print_error(
          \ 'Disabled bundles ' . string(a:000) . ' are not found.')
    return
  endif

  for bundle in bundle_names
    call neobundle#config#rtp_rm(bundle)
    let bundle.refcnt -= 1

    if bundle.refcnt <= 0
      if bundle.sourced
        call neobundle#util#print_error(
              \ bundle.name . ' is already sourced.  Cannot be disabled.')
        continue
      endif

      let bundle.disabled = 1
    endif
  endfor
endfunction"}}}

function! neobundle#config#is_disabled(name) "{{{
  return get(neobundle#config#get(a:name), 'disabled', 1)
endfunction"}}}

function! neobundle#config#is_sourced(name) "{{{
  return get(neobundle#config#get(a:name), 'sourced', 0)
endfunction"}}}

function! neobundle#config#is_installed(name) "{{{
  return isdirectory(get(neobundle#config#get(a:name), 'path', ''))
endfunction"}}}

function! neobundle#config#rm(path) "{{{
  for bundle in filter(neobundle#config#get_neobundles(),
        \ 'v:val.path ==# a:path')
    call neobundle#config#rtp_rm(bundle)
    call remove(s:neobundles, bundle.name)
  endfor
endfunction"}}}

function! neobundle#config#get_types(...) "{{{
  let type = get(a:000, 0, '')

  if type ==# 'git'
    if !exists('s:neobundle_type_git')
      let s:neobundle_type_git = neobundle#types#git#define()
    endif

    return s:neobundle_type_git
  endif

  if !exists('s:neobundle_types')
    " Load neobundle types.
    let s:neobundle_types = []
    for list in map(split(globpath(&runtimepath,
          \ 'autoload/neobundle/types/*.vim', 1), '\n'),
          \ "neobundle#util#convert2list(
          \    neobundle#types#{fnamemodify(v:val, ':t:r')}#define())")
      let s:neobundle_types += list
    endfor

    let s:neobundle_types = neobundle#util#uniq(
          \ s:neobundle_types, 'v:val.name')
  endif

  return (type == '') ? s:neobundle_types :
        \ get(filter(copy(s:neobundle_types), 'v:val.name ==# type'), 0, {})
endfunction"}}}

function! neobundle#config#rtp_rm_all_bundles() "{{{
  call filter(values(s:neobundles), 'neobundle#config#rtp_rm(v:val)')
endfunction"}}}

function! neobundle#config#rtp_rm(bundle) "{{{
  execute 'set rtp-='.fnameescape(a:bundle.rtp)
  if isdirectory(a:bundle.rtp.'/after')
    execute 'set rtp-='.s:get_rtp_after(a:bundle)
  endif
endfunction"}}}

function! neobundle#config#rtp_add(bundle) abort "{{{
  if has_key(s:neobundles, a:bundle.name)
    call neobundle#config#rtp_rm(s:neobundles[a:bundle.name])
  endif

  if s:within_block && !a:bundle.force
    " Add rtp lazily.
    call add(s:lazy_rtp_bundles, a:bundle)
    return
  endif

  let rtp = a:bundle.rtp
  if isdirectory(rtp)
    " Join to the tail in runtimepath.
    let rtps = neobundle#util#split_rtp(&runtimepath)
    let &runtimepath = neobundle#util#join_rtp(
          \ insert(rtps, rtp, index(rtps, neobundle#get_rtp_dir())),
          \ &runtimepath, rtp)
  endif
  if isdirectory(rtp.'/after')
    execute 'set rtp+='.s:get_rtp_after(a:bundle)
  endif

  call neobundle#call_hook('on_source', a:bundle)
endfunction"}}}

function! neobundle#config#search(bundle_names, ...) "{{{
  if empty(a:bundle_names)
    return []
  endif

  " For infinite loop.
  let self = get(a:000, 0, [])

  let _ = []
  let bundles = len(a:bundle_names) != 1 ?
        \ filter(neobundle#config#get_neobundles(),
        \ 'index(a:bundle_names, v:val.name) >= 0 &&
        \  (empty(self) || index(self, v:val.name) < 0)') :
        \ has_key(s:neobundles, a:bundle_names[0]) ?
        \     [s:neobundles[a:bundle_names[0]]] : []
  for bundle in bundles
    call add(self, bundle.name)

    if !empty(bundle.depends)
      let _ += neobundle#config#search(
            \ map(copy(bundle.depends), 'v:val.name'), self)
    endif
    call add(_, bundle)
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#search_simple(bundle_names) "{{{
  return filter(neobundle#config#get_neobundles(),
        \ 'index(a:bundle_names, v:val.name) >= 0')
endfunction"}}}

function! neobundle#config#fuzzy_search(bundle_names) "{{{
  let bundles = []
  for name in a:bundle_names
    let bundles += filter(neobundle#config#get_neobundles(),
          \ 'stridx(v:val.name, name) >= 0')
  endfor

  let _ = []
  for bundle in bundles
    if !empty(bundle.depends)
      let _ += neobundle#config#search(
            \ map(copy(bundle.depends), 'v:val.name'))
    endif
    call add(_, bundle)
  endfor

  if len(_) > 1
    let _ = neobundle#util#uniq(_)
  endif

  return _
endfunction"}}}

function! neobundle#config#load_extra_bundles() "{{{
  let path = neobundle#get_neobundle_dir() . '/extra_bundles.vim'

  if filereadable(path)
    execute 'source' fnameescape(path)
  endif
endfunction"}}}

function! neobundle#config#save_direct(arg) "{{{
  if neobundle#util#is_sudo()
    call neobundle#util#print_error(
          \ '"sudo vim" is detected. This feature is disabled.')
    return
  endif

  let path = neobundle#get_neobundle_dir() . '/extra_bundles.vim'
  let bundles = filereadable(path) ? readfile(path) : []
  call writefile(add(bundles, 'NeoBundle ' . a:arg), path)
endfunction"}}}

function! neobundle#config#set(name, dict) "{{{
  let bundle = neobundle#config#get(a:name)
  if empty(bundle)
    call neobundle#util#print_error(
          \ 'Plugin name "' . a:name . '" is not defined.')
    return
  endif

  let bundle = neobundle#init#_bundle(extend(bundle, a:dict))
  if bundle.lazy && bundle.sourced
    " Remove from runtimepath.
    call neobundle#config#rtp_rm(bundle)
    let bundle.sourced = 0
  endif

  call neobundle#config#add(bundle, 1)
endfunction"}}}

function! neobundle#config#add(bundle, ...) "{{{
  if empty(a:bundle)
    return
  endif

  let bundle = a:bundle
  let is_force = get(a:000, 0, bundle.local)

  if !is_force && !bundle.overwrite &&
        \     has_key(s:neobundles, bundle.name)
    return
  endif

  if !empty(bundle.depends)
    call s:add_depends(bundle)
  endif

  let prev_bundle = get(s:neobundles, bundle.name, {})

  if !empty(prev_bundle)
    if prev_bundle.sourced
      return
    endif

    call neobundle#config#rtp_rm(prev_bundle)
  endif
  let s:neobundles[bundle.name] = bundle

  if bundle.disabled
    " Ignore load.
    return
  endif

  if !bundle.lazy && bundle.rtp != ''
    if !has('vim_starting')
      " Load automatically.
      call neobundle#config#source(bundle.name, bundle.force)
    else
      call neobundle#config#rtp_add(bundle)

      if bundle.force
        runtime! plugin/**/*.vim
      endif
    endif
  elseif bundle.lazy
    call s:add_lazy(bundle)
  endif
endfunction"}}}

function! neobundle#config#tsort(bundles) "{{{
  let sorted = []
  let mark = {}
  for target in a:bundles
    call s:tsort_impl(target, a:bundles, mark, sorted)
  endfor

  return sorted
endfunction"}}}

function! neobundle#config#get_lazy_rtp_bundles() "{{{
  return s:lazy_rtp_bundles
endfunction"}}}

function! neobundle#config#check_commands(commands) "{{{
  " Environment check.
  if type(a:commands) == type([])
        \ || type(a:commands) == type('')
    let commands = a:commands
  elseif neobundle#util#is_windows() && has_key(a:commands, 'windows')
    let commands = a:commands.windows
  elseif neobundle#util#is_mac() && has_key(a:commands, 'mac')
    let commands = a:commands.mac
  elseif neobundle#util#is_cygwin() && has_key(a:commands, 'cygwin')
    let commands = a:commands.cygwin
  elseif !neobundle#util#is_windows() && has_key(a:commands, 'unix')
    let commands = a:commands.unix
  elseif has_key(a:commands, 'others')
    let commands = a:commands.others
  else
    " Invalid.
    return 0
  endif

  for command in neobundle#util#convert2list(commands)
    if !executable(command)
      return 1
    endif
  endfor
endfunction"}}}

function! s:tsort_impl(target, bundles, mark, sorted) "{{{
  if has_key(a:mark, a:target.name)
    return
  endif

  let a:mark[a:target.name] = 1
  for depend in get(a:target, 'depends', [])
    call s:tsort_impl(get(s:neobundles, depend.name, depend),
          \ a:bundles, a:mark, a:sorted)
  endfor

  call add(a:sorted, a:target)
endfunction"}}}

function! s:on_vim_enter() "{{{
  if !empty(s:lazy_rtp_bundles)
    call neobundle#util#print_error(
          \ 'neobundle#begin() was called without calling ' .
          \ 'neobundle#end() in .vimrc.')
    " We're past the point of plugins being sourced, so don't bother
    " trying to recover.
    return
  endif

  call neobundle#call_hook('on_post_source')
endfunction"}}}

function! s:add_depends(bundle) "{{{
  " Add depends.
  for depend in a:bundle.depends
    if !has_key(s:neobundles, depend.name)
      call neobundle#config#add(depend)
    else
      " Add reference count
      let s:neobundles[depend.name].refcnt += 1

      if !s:neobundles[depend.name].sourced
        " Load automatically.
        call neobundle#config#source(depend.name, depend.force)
      endif
    endif
  endfor
endfunction"}}}

function! s:add_lazy(bundle) "{{{
  let bundle = a:bundle

  " Auto set autoload keys.
  for key in filter([
        \ 'filetypes', 'filename_patterns',
        \ 'commands', 'functions', 'mappings', 'unite_sources',
{'fraction_non_alphanumeric': 0.14182793754144812, 'fraction_numerical': 0.00385844335925725, 'mean_word_length': 3.575862068965517, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5498771', 'n_tokens_mistral': 12085, 'n_tokens_neox': 11584, 'n_words': 2486}