"---------------------------------------------------------------------------
" Shougo's .vimrc
"---------------------------------------------------------------------------
" profile start profile.txt
" profile file ~/.vim/*
" profile file ~/.cache/dein/state_nvim.vim
" profile func dein#*

if &compatible
  set nocompatible
endif

" Set augroup.
augroup MyAutoCmd
  autocmd!
  autocmd FileType,Syntax,BufNewFile,BufNew,BufRead *?
        \ call vimrc#on_filetype()
  autocmd BufEnter *? call vimrc#check_syntax()
augroup END
augroup filetypedetect
augroup END

let $CACHE = expand('~/.cache')
if !isdirectory(expand($CACHE))
  call mkdir(expand($CACHE), 'p')
endif

" Use English interface.
language message C

if filereadable(expand('~/.secret_vimrc'))
  execute 'source' expand('~/.secret_vimrc')
endif

" Load dein.
if &runtimepath !~# '/dein.vim'
  let s:dein_dir = fnamemodify('dein.vim', ':p')
  if !isdirectory(s:dein_dir) && &runtimepath !~# '/dein.vim'
    let s:dein_dir = expand('$CACHE/dein')
          \. '/repos/github.com/Shougo/dein.vim'
    if !isdirectory(s:dein_dir)
      execute '!git clone https://github.com/Shougo/dein.vim' s:dein_dir
    endif
  endif
  execute 'set runtimepath^=' . substitute(
        \ fnamemodify(s:dein_dir, ':p') , '[/\\]$', '', '')
endif


"---------------------------------------------------------------------------
" dein configurations.

" In Windows, auto_recache is disabled.  It is too slow.
let g:dein#auto_recache = !has('win32')

let g:dein#lazy_rplugins = v:true
let g:dein#install_progress_type = 'title'
let g:dein#install_check_diff = v:true
let g:dein#enable_notification = v:true

let g:dein#inline_vimrcs = ['options.rc.vim', 'mappings.rc.vim']
if has('nvim')
  call add(g:dein#inline_vimrcs, 'neovim.rc.vim')
elseif has('gui_running')
  call add(g:dein#inline_vimrcs, 'gui.rc.vim')
endif
if has('win32')
  call add(g:dein#inline_vimrcs, 'windows.rc.vim')
else
  call add(g:dein#inline_vimrcs, 'unix.rc.vim')
endif

let s:base_dir = fnamemodify(expand('<sfile>'), ':h') . '/'
call map(g:dein#inline_vimrcs, { _, val -> s:base_dir . val })

let s:path = expand('$CACHE/dein')
if dein#min#load_state(s:path)
  let s:dein_toml = s:base_dir . 'dein.toml'
  let s:dein_lazy_toml = s:base_dir . 'deinlazy.toml'
  let s:dein_ddc_toml = s:base_dir . 'ddc.toml'
  let s:dein_ft_toml = s:base_dir . 'deinft.toml'

  call dein#begin(s:path, [
        \ expand('<sfile>'), s:dein_toml, s:dein_lazy_toml, s:dein_ft_toml
        \ ])

  call dein#load_toml(s:dein_toml, {'lazy': 0})
  call dein#load_toml(s:dein_lazy_toml, {'lazy' : 1})
  call dein#load_toml(s:dein_ddc_toml, {'lazy' : 1})
  call dein#load_toml(s:dein_ft_toml)

  if filereadable('vimrc_local.vim')
    " Load develop version plugins.
    call dein#local(getcwd(),
          \ {'frozen': 1, 'merged': 0},
          \ ['ddc-*', 'vim*', 'nvim-*', 'neco-*', '*.vim', '*.nvim'])
  endif

  call dein#end()
  call dein#save_state()
endif


"---------------------------------------------------------------------------

if !empty(argv())
  call vimrc#on_filetype()
endif

set secure