(au! :grep-cmd :QuickFixCmdPost :cwindow {:pattern :*grep*})
;; remind cursor position
(au! :restore-position
:BufReadPost
(when (and (> (vim.fn.line "'\"") 1)
(<= (vim.fn.line "'\"") (vim.fn.line "$")))
(vim.cmd "normal! g'\"")))
(au! :reload-copilot
:VimEnter
(async-do! (vim.cmd "Copilot restart")))
(local M {})
(fn _callback [group event body ?opt]
`(let [opt# {:callback (λ [] ,body)
:group (vim.api.nvim_create_augroup ,group {:clear true})}]
(each [k# v# (pairs (or ,?opt {}))]
(tset opt# k# v#))
(vim.api.nvim_create_autocmd ,event opt#)))
(fn _command [group event command ?opt]
`(let [opt# {:command ,command
:group (vim.api.nvim_create_augroup ,group {:clear true})}]
(each [k# v# (pairs (or ,?opt {}))]
(tset opt# k# v#))
(vim.api.nvim_create_autocmd ,event opt#)))
(fn M.au! [group event body ?opt]
(if
(= (type body) :table) (_callback group event body ?opt)
(= (type body) :string) (_command group event body ?opt)
(assert-compile false "au: body must be a sequence or string" body)))
(fn M.async-do! [body]
`(do
(var async# nil)
(set async#
(vim.loop.new_async
(vim.schedule_wrap
(λ []
,body
(async#:close)))))
(async#:send)))
M
(fn _group_handler [group]
`(if
(= (type ,group) :string)
(vim.api.nvim_create_augroup ,group {:clear true})
(= (type ,group) :number)
,group
(print "au: group must be number or string" ,group)))
(fn _callback [group event body ?opt]
`(let [opt# {:callback (λ [] ,body)
:group ,(_group_handler group)}]
(each [k# v# (pairs (or ,?opt {}))]
(tset opt# k# v#))
(vim.api.nvim_create_autocmd ,event opt#)))
(fn _command [group event command ?opt]
`(let [opt# {:command ,command
:group ,(_group_handler group)}]
(each [k# v# (pairs (or ,?opt {}))]
(tset opt# k# v#))
(vim.api.nvim_create_autocmd ,event opt#)))
(fn M.au! [group event body ?opt]
(if
(= (type body) :table) (_callback group event body ?opt)
(= (type body) :string) (_command group event body ?opt)
(assert-compile false "au: body must be a sequence or string" body)))
cmp-skkeleton
(let [g (vim.api.nvim_create_augroup :init-skkeleton {:clear true})]
(au! g :User
(vim.fn.skkeleton#config {})
{:pattern :skkeleton-initialize-pre})
(au! g :User (let [cmp (require :cmp)]
(cmp.setup.buffer {:view {:entries :native}}))
{:pattern :skkeleton-enable-pre})
(au! g :User (let [cmp (require :cmp)]
(cmp.setup.buffer {:view {:entries :custom}}))
{:pattern :skkeleton-disable-pre})
(au! g :User :redrawstatus {:pattern :skkeleton-mode-changed}))