"-----------------------------------------------------------------------------
" Initialize:
"
let s:is_windows = has('win16') || has('win32') || has('win64')
let s:is_cygwin = has('win32unix')
let s:vimdev_dir = resolve(expand('~/vim_dev'))

function! s:source_rc(path) abort "{{{
  execute 'source' fnameescape('~/.vim/rc/' . a:path)
endfunction "}}}

function! IsWindows() abort "{{{
  return s:is_windows
endfunction "}}}

function! IsPowerlineEnabled() abort "{{{
  if has('nvim')
    " TODO Enable when powerline implement neovim feature
    return 0
  endif

  let has_python = has('python') && executable('python')
  let has_python3 = has('python3') && executable('python3')
  return (has_python3 || has_python) && executable('powerline-daemon')
endfunction "}}}

function! IsHomePC() abort "{{{
  return isdirectory(s:vimdev_dir)
endfunction "}}}

function! VimDevDir() abort "{{{
  return s:vimdev_dir
endfunction "}}}

call s:source_rc('init.rc.vim')

call s:source_rc('dein.rc.vim')

if IsHomePC()
  " Load develop version settings
  let s:vimrc_dev = s:vimdev_dir . '/vimrc'
  if filereadable(s:vimrc_dev)
    execute 'source' s:vimrc_dev
  endif

  unlet s:vimrc_dev
endif

if !has('vim_starting')
  call dein#call_hook('source')
  call dein#call_hook('post_source')
endif

filetype plugin indent on
syntax enable

"-----------------------------------------------------------------------------
" Encoding:
"
call s:source_rc('encoding.rc.vim')

"-----------------------------------------------------------------------------
" Search:
"
call s:source_rc('search.rc.vim')

"-----------------------------------------------------------------------------
" Edit:
"
call s:source_rc('edit.rc.vim')

"-----------------------------------------------------------------------------
" View:
"
call s:source_rc('view.rc.vim')

"-----------------------------------------------------------------------------
" FileType:
"
call s:source_rc('filetype.rc.vim')

"-----------------------------------------------------------------------------
" Mappings:
"
call s:source_rc('mappings.rc.vim')

"-----------------------------------------------------------------------------
" Platform:
"
if has('nvim')
  call s:source_rc('neovim.rc.vim')
endif

if IsWindows()
  call s:source_rc('windows.rc.vim')
else
  call s:source_rc('unix.rc.vim')
endif

if !has('nvim') && has('gui_running')
  call s:source_rc('gui.rc.vim')
endif

"-----------------------------------------------------------------------------
" Statusline:
"
if IsPowerlineEnabled()
  call s:source_rc('powerline.rc.vim')
elseif dein#is_sourced('lightline.vim')
  call s:source_rc('lightline.rc.vim')
endif

"-----------------------------------------------------------------------------
" Colorscheme:
"
call s:source_rc('colorscheme.rc.vim')

"-----------------------------------------------------------------------------
" Local Settings:
"
if filereadable(expand('~/.vimrc_local'))
  execute 'source' expand('~/.vimrc_local')
endif
if filereadable(expand('~/.nvimrc_local'))
  execute 'source' expand('~/.nvimrc_local')
endif

set helplang& helplang=en,ja
set secure