# Lazy load plugins
# Colorscheme {{{
[[plugins]] # nvim-treesitter
repo = 'nvim-treesitter/nvim-treesitter'
on_event = 'BufRead'
hook_post_update = 'TSUpdate'
lua_source = '''
-- <% ./dein_toml/treesitter.lua
require("nvim-treesitter.configs").setup({
  ensure_installed = "all",
  highlight = {
    enable = true,
    disable = {
      'help',
    },
  },
  indent = {
    enable = true,
    disable = {
      'help',
    },
  },
})
-- %>
'''
hook_source = '''
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable
augroup treesitter_fold
  autocmd!
  autocmd FileType toml,help set foldmethod=marker foldenable
augroup END
'''

[[plugins]] # treesitter playground
repo = 'nvim-treesitter/playground'
depends = 'nvim-treesitter'
on_cmd = 'TSPlaygroundToggle'
lua_source = '''
-- <% ./dein_toml/ts_playground.lua
require("nvim-treesitter.configs").setup({
  playground = {
    enable = true,
    disable = {},
    updatetime = 25,
    persist_queries = true,
    keybindings = {
      toggle_query_editor = "o",
      toggle_hl_groups = "i",
      toggle_injected_languages = "t",
      toggle_anonymous_nodes = "a",
      toggle_language_display = "I",
      focus_language = "f",
      unfocus_language = "F",
      update = "R",
      goto_node = "<CR>",
      show_help = "?",
    },
  },
})
-- %>
'''

[[plugins]] # nightfox.nvim
repo = 'EdenEast/nightfox.nvim'
depends = ['nvim-treesitter']
on_event = 'VimEnter'
lua_source = '''
-- <% ./dein_toml/nightfox_settings.lua
local nightfox = require("nightfox")
local compile_path = vim.fn.stdpath("cache") .. "/nightfox"
nightfox.setup({
  options = {
    -- Compiled file's destination location
    compile_path = compile_path,
    compile_file_suffix = "_compiled", -- Compiled file suffix
    transparent = false, -- Disable setting background
    terminal_colors = true, -- Set terminal colors (vim.g.terminal_color_*)
    dim_inactive = false, -- Non focused panes set to alternative background
    module_default = true,
    styles = { -- Style to be applied to different syntax groups
      comments = "italic",
      conditionals = "NONE",
      constants = "NONE",
      functions = "bold",
      keywords = "NONE",
      numbers = "NONE",
      operators = "NONE",
      strings = "NONE",
      types = "NONE",
      variables = "NONE",
    },
    inverse = { -- Inverse highlight for different types
      match_paren = false,
      visual = true,
      search = false,
    },
    modules = { -- List of various plugins and additional options
      fidget = true,
      lsp_saga = true,
      notify = true,
      treesitter = true,
    },
  },
})
vim.cmd([[colorscheme nordfox]])
-- %>
'''
lua_post_source = '''
-- <% ./dein_toml/nightfox_compile.lua
local nightfox = require("nightfox")
local compile_path = vim.fn.stdpath("cache") .. "/nightfox"
if vim.fn.isdirectory(compile_path) then
  if vim.fn.empty(vim.fn.systemlist("ls " .. compile_path)) > 0 then
    nightfox.compile()
  end
else
  nightfox.compile()
end
-- %>
'''

[[plugins]] # lightline.vim
repo = 'itchyny/lightline.vim'
#on_event = ['InsertEnter', 'CmdlineEnter']
on_event = ['VimEnter']
depends = ['vim-gitbranch']
hook_source = '''
" <% ./dein_toml/lightline.vim
set noshowmode
set showtabline=2
set laststatus=3
let g:lightline = {}
let g:lightline.colorscheme = 'nordfox'
" active
let g:lightline.active = {}
let g:lightline.active.left = [
  \ ['mode', 'paste', 'skk_mode'], 
  \ ['relativepath', 'modified'],
  \ ]
let g:lightline.active.right = [
  \ ['percent', 'lineinfo'],
  \ ['fileformat', 'fileencoding', 'filetype'],
  \ ]

" inactive
let g:lightline.inactive = {}
let g:lightline.inactive.left = [
  \ ['filename']
  \ ]
let g:lightline.inactive.right = [
  \ ['lineinfo'],
  \ ['percent'],
  \ ]

let g:lightline.tabline = {}
let g:lightline.tabline.left = [
  \ ['tabs'],
  \ ]
let g:lightline.tabline.right = [
  \ ['git_branch'],
  \ ]

let g:lightline.tab = {}
let g:lightline.tab.active = ['tabnum', 'filename', 'modified']
let g:lightline.tab.inactive = ['tabnum', 'filename']

let g:lightline.separator = {
  \ 'left': '',
  \ 'right': '',
  \ }
let g:lightline.subseparator = {
  \ 'left': '',
  \ 'right': ' ',
  \ }

let g:lightline.component_function = {
  \ 'git_branch': 'vimrc#lightline_git_branch',
  \ 'mode': 'vimrc#lightline_custom_mode',
  \ 'skk_mode': 'lightline_skk#mode',
  \ }

let g:lightline.component_expand = {
  \ 'lsp_ok': 'lightline_lsp#ok',
  \ 'lsp_errors': 'lightline_lsp#errors',
  \ 'lsp_warnings': 'lightline_lsp#warnings',
  \ }

let g:lightline.component_expand_type = {
  \ 'lsp_ok': 'middle',
  \ 'lsp_errors': 'error',
  \ 'lsp_warnings': 'warning',
  \ }

command! -bar LightlineUpdate call lightline#init()| call lightline#colorscheme()| call lightline#update()
" %>
'''

# }}}

# Editor support plugins {{{
[[plugins]] # context_filetype.vim
repo = 'Shougo/context_filetype.vim'
hook_source = '''
let g:context_filetype#ignore_patterns = {
  \ 'toml': ['^\s*#\s*'],
  \ }
'''

[[plugins]] # vimproc.vim
repo = 'Shougo/vimproc.vim'
build = 'make'

[[plugins]]
repo = 'LeafCage/vimhelpgenerator'
on_cmd = ['VimHelpGenerator', 'VimHelpGeneratorVirtual']
hook_source = '''
let g:vimhelpgenerator_author = 'yasunori-kirin0418'
let g:vimhelpgenerator_uri = 'https://github.com/yasunori-kirin0418'
'''

[[plugins]] # nvim-notify
repo = 'rcarriga/nvim-notify'
on_source = 'nightfox.nvim'
lua_source = '''
-- <% ./dein_toml/notify.lua
require("notify").setup({
  stages = "slide",
  background_color = "NormalFloat",
})
vim.notify = require("notify")
-- %>
'''

[[plugins]] # suda.vim
repo = 'lambdalisue/suda.vim'
on_cmd = ['SudaRead', 'SudaWrite']

[[plugins]] # vim-quickrun
repo = 'thinca/vim-quickrun'
on_cmd = 'QuickRun'

[[plugins]] # vim-molder
repo = 'mattn/vim-molder'
hook_add = '''
augroup vimrc_molder
  autocmd BufEnter * call vimrc#molder_init()
augroup END
'''
hook_source = '''
let g:molder_show_hidden = v:true
'''

[[plugins]] # vim-molder-operations
repo = 'mattn/vim-molder-operations'
on_source = 'vim-molder'
[plugins.ftplugin]
molder = '''
nmap <buffer> ..    <Plug>(molder-up)
nmap <buffer> <C-l> <Plug>(molder-reload)
nmap <buffer> N     <Plug>(molder-operations-newdir)
nmap <buffer> D     <Plug>(molder-operations-delete)
nmap <buffer> R     <Plug>(molder-operations-rename)
nmap <buffer> S     <Plug>(molder-operations-shell)
nmap <buffer> !     <Plug>(molder-operations-command)
nmap <buffer> C <Cmd>call vimrc#molder_change_cwd()<CR>
'''

[[plugins]] # helpful.vim
repo = 'tweekmonster/helpful.vim'
on_cmd = 'HelpfulVersion'

[[plugins]] # bracey.vim
repo = 'turbio/bracey.vim'
on_cmd = 'Bracey'

[[plugins]] # deol.nvim
repo = 'Shougo/deol.nvim'
on_cmd = 'Deol'
hook_add = '''
nnoremap <term> <Nop>
nmap <Space>s <term>
nnoremap <term>a <Cmd>Deol
  \ -no-auto-cd
  \ -no-start-insert
  \ -split=floating
  \ -winheight=30
  \ -winwidth=120
  \ -toggle<CR>
nnoremap <term>t <Cmd>tabnew<Bar>Deol -no-start-insert<CR>
nnoremap <term>c <Cmd>execute 'Deol'
  \ '-cwd=' . fnamemodify(expand('%'), ':h')
  \ '-no-auto-cd'
  \ '-no-start-insert'
  \ '-split=floating'
  \ '-winheight=30'
  \ '-winwidth=120'
  \ '-toggle'<CR>
nnoremap <term>h <Cmd>Deol
  \ -cwd=~
  \ -no-start-insert
  \ -split=floating
  \ -winheight=30
  \ -winwidth=120
  \ -toggle<CR>

" Escape deol
tnoremap <Esc> <C-\><C-n>
'''
hook_source = '''
" let g:deol#prompt_pattern = '^❯ \?'
" let g:deol#enable_ddc_completion = v:true
let g:deol#shell_history_path = '~/.zsh_history'
let g:deol#enable_dir_changed = v:false
let g:deol#nvim_server = '~/.cache/nvim/server.pipe'
let g:deol#custom_map = {
  \ 'edit': '',
  \ }
let g:deol#floating_border = 'double'
'''

[[plugins]] # open-browser.vim
repo = 'tyru/open-browser.vim'
on_map = { 'nx' = '<Plug>(openbrowser-smart-search)' }
hook_add = '''
" open-browser.vim
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nmap gx <Plug>(openbrowser-smart-search)
xmap gx <Plug>(openbrowser-smart-search)
'''

[[plugins]]
repo = 'glidenote/memolist.vim'
on_cmd = ['MemoNew', 'MemoList', 'MemoNewWithMeta', 'MemoGrep']
hook_source = '''
let g:memolist_path = expand('~/Documents/memo')
'''

# }}}

# Coding support plugins {{{
[[plugins]] # lexima.vim
repo = 'cohama/lexima.vim'
on_event = 'InsertEnter'
hook_add = '''
let g:lexima_ctrlh_as_backspace = 1
'''

[[plugins]] # vim-eft
repo = 'hrsh7th/vim-eft'
on_map = { nxo = '<Plug>(eft-' }
hook_add = '''
nmap f <Plug>(eft-f)
xmap f <Plug>(eft-f)
omap f <Plug>(eft-f)
nmap F <Plug>(eft-F)
xmap F <Plug>(eft-F)
omap F <Plug>(eft-F)
nmap ; <Plug>(eft-repeat)
xmap ; <Plug>(eft-repeat)
'''
hook_source = '''
let g:eft_ignorecase = v:true
'''

[[plugins]] # vim-cursorword
repo = 'itchyny/vim-cursorword'
on_source = 'nightfox.nvim'

[[plugins]] # indent-blankline.nvim
repo = 'lukas-reineke/indent-blankline.nvim'
depends = 'nvim-treesitter'
on_source = 'nightfox.nvim'
lua_source = '''
-- <% ./dein_toml/indent_blankline.lua
require("indent_blankline").setup({
  char_list = { "│", "|", "¦", "┆", "┊" },
  char_list_blankline = { "│", "|", "¦", "┆", "┊" },
  show_current_context = true,
  show_current_context_start = true,
  show_current_context_start_on_current_line = true,
  show_end_of_line = true,
  show_first_indent_level = true,
  show_trailing_blankline_indent = true,
  space_char_blankline = " ",
  strict_tabs = true,
  use_treesitter = true,
  filetype_exclude = {
    "lspinfo",
    "packer",
    "checkhealth",
    "help",
    "man",
    "",
  },
  buftype_exclude = {
    "terminal",
    "nofile",
    "quickfix",
    "prompt",
  },
  bufname_exclude = {},
})
-- %>
'''

[[plugins]] # matchparen.nvim
repo = 'monkoose/matchparen.nvim'
depends = 'nvim-treesitter'
on_source = 'nightfox.nvim'
lua_source = '''
require('matchparen').setup()
'''

[[plugins]] # vim-sandwich
repo = 'machakann/vim-sandwich'
on_map = { nxo = '<Plug>(sandwich-' }
hook_add = '''
let g:sandwich_no_default_key_mappings = 1

" add
nmap sa <Plug>(sandwich-add)
xmap sa <Plug>(sandwich-add)
omap sa <Plug>(sandwich-add)

" delete
nmap sd <Plug>(sandwich-delete)
xmap sd <Plug>(sandwich-delete)
nmap sdb <Plug>(sandwich-delete-auto)

" replace
nmap sr <Plug>(sandwich-replace)
xmap sr <Plug>(sandwich-replace)
nmap srb <Plug>(sandwich-replace-auto)
'''

[[plugins]] # vim-partedit
repo = 'thinca/vim-partedit'
depends = 'context_filetype.vim'
on_func = 'partedit#start()'
hook_add = '''
nnoremap <Window>e <Cmd>call partedit#start(
  \ context_filetype#get_range()[0][0],
  \ context_filetype#get_range()[1][0],
  \ #{ filetype: context_filetype#get_filetype() })<CR>
'''
hook_source = '''
let g:partedit#opener = 'vsplit'
'''

[[plugins]]
repo = 'yasunori-kirin0418/partial.vim'
on_cmd = [
  'PartialOpen',
  'PartialEdit',
  'PartialTabedit',
  'PartialVsplit',
  'PartialSplit',
  'PartialCreate',
  'PartialUpdate',
  'PartialSurround',
]
hook_source = '''
let g:partial#partial_path_prefix = ' '
let g:partial#origin_path_prefix = ' '
let g:partial#relative_base_path = '~/.cache/partial.vim'
'''

[[plugins]] # Comment.nvim
repo = 'numToStr/Comment.nvim'
depends = 'nvim-treesitter'
on_map = { nox = '<Plug>(comment_toggle_' }
hook_add = '''
omap gc <Plug>(comment_toggle_linewise)
omap gb <Plug>(comment_toggle_blockwise)
nmap gc <Plug>(comment_toggle_linewise)
nmap gb <Plug>(comment_toggle_blockwise)
nmap <expr> gcc v:count == 0 ? '<Plug>(comment_toggle_linewise_current)' : '<Plug>(comment_toggle_linewise_count)'
nmap <expr> gbc v:count == 0 ? '<Plug>(comment_toggle_blockwise_current)' : '<Plug>(comment_toggle_blockwise_count)'
xmap gc <Plug>(comment_toggle_linewise_visual)
xmap gb <Plug>(comment_toggle_blockwise_visual)
'''
lua_source = '''
require('plugins.comment')
'''

[[plugins]] # vim-themis
repo = 'thinca/vim-themis'
on_cmd = 'StartThemis'
hook_add = '''
command! StartThemis call dein#source('vim-themis')
'''

# }}}

# Filetype plugins {{{
[[plugins]] # emmet-vim
repo = 'mattn/emmet-vim'
on_ft = ['html', 'css', 'scss', 'php']
hook_add = '''
let g:user_emmet_install_global = 0
let g:user_emmet_leader_key = '<C-k>'
autocmd FileType html,css,scss,php EmmetInstall
let g:user_emmet_settings = {
  \ 'variables': {
    \ 'lang': "ja"
    \ },
  \ 'html': {
    \ 'snippets': {
      \ 'html:5': "<!DOCTYPE html>\n"
      \ ."<html lang=\"${lang}\">\n"
      \ ."\t<head>\n"
      \ ."\t\t<meta charset=\"${charset}\">\n"
      \ ."\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
      \ ."\t\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n"
      \ ."\t\t<title></title>\n"
      \ ."\t\t<link rel=\"stylesheet\" href=\"css/style.css\">\n"
      \ ."\t</head>\n"
      \ ."\t<body>\n\t${child}|\n\t</body>\n"
      \ ."</html>",
      \ 'lrl:s': "{{ | }}",
      \ 'lrl:e': "{!! | !!}",
      \ }
    \ },
    \ 'php': {
      \ 'snippets': {
        \ 'php:s': "<?php | ?>",
        \ 'php:e': "<?= | ?>",
        \ 'lrl:s': "{{ | }}",
        \ 'lrl:e': "{!! | !!}",
        \ }
      \ }
  \ }
'''

[[plugins]] # vim-json
repo = 'elzr/vim-json'
on_ft = 'json'
hook_source = '''
augroup json_autocmd
  autocmd!
  autocmd FileType json setlocal autoindent
  autocmd FileType json setlocal formatoptions=tcq2l
  autocmd FileType json setlocal textwidth=78 shiftwidth=2
  autocmd FileType json setlocal softtabstop=2 tabstop=2
  autocmd FileType json setlocal expandtab
  autocmd FileType json setlocal foldmethod=syntax
augroup END
'''

[[plugins]] # plantuml-syntax
repo = 'aklt/plantuml-syntax'
on_ft = 'plantuml'

[[plugins]] # vim-maketable
repo = 'mattn/vim-maketable'
on_ft = 'markdown'

[[plugins]] # previm
repo = 'previm/previm'
depends = 'open-browser.vim'
on_ft = 'markdown'
on_cmd = 'PrevimOpen'
hook_add = '''
nnoremap <previm> <Nop>
nmap <Space>p <previm>
nnoremap <previm>o <Cmd>PrevimOpen<CR>
nnoremap <previm>r <Cmd>call previm#refresh()<CR>
'''
hook_source = '''
let g:previm_enable_realtime = 1
let g:previm_disable_default_css = 1
let g:previm_custom_css_path = expand('~/dotfiles/tmp/previm_markdown.css')
let g:previm_plantuml_imageprefix = 'http://localhost:58080/png/'
'''

[[plugins]]
repo = 'atusy/tsnode-marker.nvim'
on_ft = 'markdown'
lua_source = '''
-- <% dein_toml/tsnode-marker.lua
vim.api.nvim_create_autocmd("FileType", {
  group = vim.api.nvim_create_augroup("tsnode-marker-markdown", {}),
  pattern = "markdown",
  callback = function(ctx)
    require("tsnode-marker").set_automark(ctx.buf, {
      target = { "code_fence_content", "fenced_code_block_delimiter", "language" },
      hl_group = "DiffChange",
    })
  end,
})
-- %>
'''

# }}}