[[plugins]]
repo = '$VIMCONF/bundle/gin-preview.vim'
depends = 'vim-gin'
on_cmd = 'GinPreview'

[plugins.ftplugin]
gin-status = '''
nnoremap <buffer> gs <Cmd>GinPreview!<CR>
'''

[[plugins]]
repo = '$VIMCONF/bundle/vim-operandi'
on_func = 'operandi#'
hook_add = '''
nnoremap ti <Cmd>call operandi#open('myterm')<CR>
nnoremap <Space>; <Cmd>call operandi#open('mycommand')<CR>
nnoremap <Space><Space> <Cmd>call operandi#open('mycommand')<CR>
xnoremap <Space><Space> <Esc><Cmd>call operandi#open('mycommand')<CR><Cmd>call setline(1, "'<,'>")<CR>
'''
hook_source = '''
function s:operandi_map()
  nnoremap <buffer> <nowait> <CR> <Cmd>call operandi#execute()<CR>
  inoremap <buffer> <nowait> <CR> <Esc><Cmd>call operandi#execute()<CR>
endfunction
autocmd vimrc User operandi#open#* call s:operandi_map()
'''

[[plugins]]
repo = 'hrsh7th/vim-vsnip'
on_func = 'vsnip#'
hook_add = '''
inoremap <C-f> <Plug>(vsnip-jump-next)
'''
hook_source = '''
runtime autoload/vsnip.vim
'''

[[plugins]]
repo = 'https://github.com/kawarimidoll/autoplay.vim'

[[plugins]]
repo = 'https://github.com/kuuote/mydicts'
if = false

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-fern'
on_cmd = 'Fern'
hook_source = '''
let g:fern#default_hidden = 1
let g:fern#disable_default_mappings = 1
'''

[plugins.ftplugin]
fern = '''
nnoremap <buffer> <nowait> a <Plug>(fern-action-choice)
nnoremap <buffer> <nowait> d <Plug>(fern-action-leave)
nnoremap <buffer> <nowait> h <Plug>(fern-action-collapse)
nnoremap <buffer> <nowait> l <Plug>(fern-action-open-or-expand)
nnoremap <buffer> <nowait> tt <Plug>(fern-action-open:tabedit)
'''

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-gin'
on_cmd = [
  'Gin',
]
hook_add = '''
nnoremap gb <Cmd>tab split<CR><Cmd>GinBranch -a<CR>
nnoremap gl <Cmd>tab split<CR><Cmd>GinLog --oneline<CR>
nnoremap gs <Cmd>tab split<CR><Cmd>GinStatus<CR>
'''

[plugins.ftplugin]
gin-log = '''
function s:push_confirm() abort
  if confirm('Do :Gin push?', "&Yes\n&No", 2) == 1
    Gin push
  endif
endfunction
nnoremap <buffer> <nowait> p <Cmd>call <SID>push_confirm()<CR>
'''
gin-status = '''
nnoremap <buffer> <nowait> c <Cmd>call p#gin#komitto()<CR>
nnoremap <buffer> <nowait> h <Plug>(gin-action-stage)
nnoremap <buffer> <nowait> l <Plug>(gin-action-unstage)

function s:open_diff() abort
  if !exists('w:gin_interactive_diff')
    return
  endif
  let data = w:gin_interactive_diff
  if bufnr() != data.bufnr
    unlet w:gin_interactive_diff
    autocmd! gin_interactive_diff
    execute 'close' data.diff
    return
  endif
  let view = winsaveview()
  if view.lnum == data.lnum
    return
  endif
  let data.lnum = view.lnum
  let worktree = gin#util#worktree()
  let path = printf('%s/%s', gin#util#worktree(), getline('.')[3:])
  call win_gotoid(data.diff)
  execute 'GinDiff --' path
  call win_gotoid(data.status)
endfunction

function s:interactive_diff() abort
  " 私はtab切ってるから他のウィンドウを雑に始末する
  silent! only!
  let bufnr = bufnr()
  let status = win_getid()
  botright vsplit
  let diff = win_getid()
  call win_gotoid(status)
  let w:gin_interactive_diff = #{bufnr: bufnr, status: status, diff: diff, lnum: -1}
  augroup gin_interactive_diff
    autocmd!
    autocmd CursorMoved * ++nested call s:open_diff()
  augroup END
  call s:open_diff()
endfunction

nnoremap <buffer> D <Cmd>call <SID>interactive_diff()<CR>
'''
gitcommit = '''
nnoremap <buffer> ZZ <Cmd>Apply<CR>
'''

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-gina'
on_cmd = 'Gina'

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-kensaku'
# X<dpp-lazy-kensaku_vim>
lazy = 1
hook_source = '''
let g:kensaku_dictionary_cache = '/data/vim/cache/kensaku_dict'
'''

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-mr'
# on_event = ['BufReadPre', 'BufWritePre']
hook_source = '''
let g:mr#mru#filename = '/data/mr/mru'
let g:mr#mrw#filename = '/data/mr/mrw'
let g:mr#mrr#filename = '/data/mr/mrr'
let g:mr#mrd#filename = '/data/mr/mrd'

let s:mr_buffer = mr#recorder#new('/tmp/mr_buffer')
let s:mr_close = mr#recorder#new('/tmp/mr_close')
augroup vimrc
  autocmd BufEnter,BufWritePost * call s:mr_buffer.record(expand('<afile>'))
  autocmd BufWinLeave,VimLeave * call s:mr_close.record(expand('<afile>'))
  autocmd VimLeave * call s:mr_buffer.dump()
  autocmd VimLeave * call s:mr_close.dump()
augroup END
function s:mr_scratch(name) abort
  let list = s:[a:name].list()
  if list[0] == expand('%:p')
    call remove(list, 0)
  endif

  enew
  setlocal buftype=nofile bufhidden=wipe noswapfile
  call setline(1, list)
  nnoremap <buffer> <CR> gf
endfunction
nnoremap mb <Cmd>call <SID>mr_scratch('mr_buffer')<CR>
nnoremap mc <Cmd>call <SID>mr_scratch('mr_close')<CR>
'''

[[plugins]]
repo = 'https://github.com/lambdalisue/vim-suda'
on_cmd = ['SudaRead', 'SudaWrite']

[[plugins]]
repo = 'https://github.com/machakann/vim-sandwich'
on_map = {n = 's'}
lazy = true
hook_add = '''
autocmd vimrc ModeChanged *:*[ovV\x16]* ++once ++nested call dpp#source('vim-sandwich')
'''
hook_source = '''
" 改めてs殺しておく
nnoremap s <Nop>
" https://github.com/yuki-yano/dotfiles/blob/f1b6ac0c2a178177cc546bab19a175a498192e1e/.vim/lua/plugins/coding.lua#L485-L487
" saa( などで空白を含めないようにするやつ
call operator#sandwich#set('add', 'char', 'skip_space', 1)
autocmd vimrc ModeChanged [vV\x16]*:* call operator#sandwich#set('add', 'char', 'skip_space', 1)
autocmd vimrc ModeChanged *:[vV\x16]* call operator#sandwich#set('add', 'char', 'skip_space', 0)

" from https://github.com/nekowasabi/dotfiles/blob/2a06ecd2ef3d0bfed92099b14baa60fbf97bc658/vim_integrate/rc/plugins/vim-sandwich.vim?plain=1#L18-L24
let g:sandwich#recipes = deepcopy(g:sandwich#default_recipes)
let g:sandwich#recipes += [
\   {'buns': ['(', ')'], 'nesting': 1, 'input': ['j(', 'j)', 'jp']},
\   {'buns': ['「', '」'], 'nesting': 1, 'input': ['j[', 'j]', 'jB']},
\   {'buns': ['『', '』'], 'nesting': 1, 'input': ['j{', 'j}', 'jb']},
\   {'buns': ['【', '】'], 'nesting': 1, 'input': ['j<', 'j>', 'jk']},
\ ]

'''
# lua_post_source = '''
# local vimx = require('artemis')
# -- https://github.com/yuki-yano/dotfiles/blob/f1b6ac0c2a178177cc546bab19a175a498192e1e/.vim/lua/plugins/coding.lua#L451-L458
# -- console.log() などをまとめて指定できるやつ
# vimx.g['sandwich#magicchar#f#patterns'] = {
#   {
#     header = [[\<\%(\h\k*\.\)*\h\k*]],
#     bra = '(',
#     ket = ')',
#     footer = '',
#   },
# }
# '''

[[plugins]]
repo = 'https://github.com/mattn/vim-molder'
# サブ環境で使ってるだけなので切っておく
if = false

[[plugins]]
repo = 'https://github.com/rbtnn/vim-layout'
on_cmd = ['LayoutLoad', 'LayoutSave']
on_func = ['layout#']

[[plugins]]
repo = 'https://github.com/Shougo/cmdline.vim'
# ddu-ui-ffに合わせる
hook_add = '''
call cmdline#set_option('border', ['+', '-', '+', '|', '+', '-', '+', '|']->map('[v:val, "DduBorder"]'))
call cmdline#set_option('col', 4)
call cmdline#set_option('row', 0)
call cmdline#set_option('width', &columns - 8 - 2)
autocmd vimrc WinResized * call cmdline#set_option('width', &columns - 8 - 2)
'''

[[plugins]]
repo = 'https://github.com/skk-dev/dict'
if = false

[[plugins]]
repo = 'https://github.com/tani/vim-artemis'

[[plugins]]
repo = 'https://github.com/thinca/vim-localrc'

[[plugins]]
repo = 'https://github.com/thinca/vim-partedit'
on_cmd = 'Partedit'

[[plugins]]
repo = 'https://github.com/thinca/vim-prettyprint'
on_cmd = ['PrettyPrint', 'PP']
on_func = ['PrettyPrint', 'PP']

[[plugins]]
repo = 'https://github.com/thinca/vim-qfreplace'
on_cmd = 'Qfreplace'

[[plugins]]
repo = 'https://github.com/thinca/vim-themis'

[[plugins]]
repo = 'https://github.com/tweekmonster/helpful.vim'

[[plugins]]
repo = 'https://github.com/tyru/capture.vim'
on_cmd = 'Capture'

[[plugins]]
repo = 'https://github.com/uga-rosa/denippet.vim'
lazy = true
denops_wait = false
hook_source = '''
source $VIMCONF/conf/plug/denippet.vim
'''

[[plugins]]
repo = 'https://github.com/uga-rosa/estrela.lua'

[[plugins]]
repo = 'https://github.com/vim-denops/denops.vim'

[[plugins]]
repo = 'https://github.com/vim-jp/vimdoc-ja'
hook_add = '''
set helplang=ja
'''

[[plugins]]
# sort_repo = 'skkeleton'
# https://github.com/NI57721/dotfiles/blob/79d2decf4b1e2bf5522c3af5f0ffdefd87b7ff50/.config/vim/rc/dein.toml#L20-L24
# repo = 'kei-s16/skkeleton-azik-kanatable'
repo = 'https://github.com/NI57721/skkeleton-azik-kanatable'
rev = 'feature/delete-some-mappings'
on_source = 'skkeleton'

[[plugins]]
# sort_repo = 'skkeleton'
repo = 'https://github.com/NI57721/skkeleton-state-popup'
hook_add = '''
autocmd vimrc User skkeleton-initialize-post source $VIMCONF/conf/plug/skkeleton_state_popup.vim
'''

[[plugins]]
# sort_repo = 'skkeleton'
repo = 'https://github.com/vim-skk/skkeleton'
lazy = true
denops_wait = false
on_cmd = ['SKKAzik', 'SKKTsuki']
hook_add = '''
noremap! ;<Space> <Cmd>call dpp#source(['skkeleton'])<CR><Plug>(skkeleton-enable)
noremap! <Plug>(henkan) <Cmd>call dpp#source(['skkeleton'])<CR><Plug>(skkeleton-enable)
noremap! <Plug>(muhenkan) <Plug>(skkeleton-disable)
" ref: atusy: normal modeの `<C-J>`をskkeleton-enableにあてちゃうのアリな気がしてきた。特にmarkdownで日本語書きまくってる時とか。"
nnoremap ;<Space> <Cmd>call dpp#source(['skkeleton'])<CR>i<Plug>(skkeleton-enable)
'''
hook_source = '''
source $VIMCONF/conf/plug/skkeleton.vim
'''

[[plugins]]
repo = 'tani/dmacro.vim'
if = 'has("nvim-0.10") || has("patch-9.1.0597")'
hook_add = '''
inoremap <C-y> <Plug>(dmacro-play-macro)
nnoremap <C-y> <Plug>(dmacro-play-macro)
'''