mzte-nv: load plugins in chunked event loop callbacks

TODO: move into MZTE-NV with libUV idler
This commit is contained in:
LordMZTE 2024-04-14 16:55:23 +02:00
parent 73b009dd51
commit acf4abc8ba
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
3 changed files with 56 additions and 44 deletions

View File

@ -7,16 +7,5 @@
:ignore false}
:renderer {:indent_markers {:enable true} :group_empty true}})
;; open on startup
(fn on-enter [data]
(local is-no-name (and (= data.file "") (= (. vim :bo data.buf :buftype) "")))
(local is-dir (= (vim.fn.isdirectory data.file) 1))
(when is-dir
(vim.cmd.cd data.file))
(when (or is-no-name is-dir)
((. (require :nvim-tree.api) :tree :open))))
(vim.api.nvim_create_autocmd [:VimEnter] {:callback on-enter})
(vim.keymap.set :n :TT #((. (require :nvim-tree.api) :tree :toggle))
(. (require :mzte_nv) :utils :map_opt))

View File

@ -34,7 +34,7 @@
(tset opt k v))
`(do
(nmap ,(.. :g suffix) ,action ,opt)
(nmap ,(.. :gt suffix) ,action
(nmap ,(.. :gn suffix) ,action
,(doto (collect [k v (pairs opt)] k v)
(tset :jump_type :tab)))
(nmap ,(.. :gs suffix) ,action

View File

@ -1,38 +1,61 @@
(local mztenv (require :mzte_nv))
(tset mztenv.reg :plugin_load_callbacks [])
(let [path mztenv.reg.nvim_plugins]
(when path
(vim.opt.runtimepath:append (.. path "/*"))))
(let [plugins [:lspconf
:cmp
:luasnip
:nullls
:catppuccin
:line
:treesitter
:devicons
:nvimtree
:neogit
:telescope
:autopairs
:tterm
:ts-context
:ufo
:aerial
:dap
:harpoon
:recorder
:noice
:tsn-actions
:lightbulb
:dressing]
errors {}]
(each [_ p (ipairs plugins)]
(let [(success ret) (pcall require (.. :pluginconf/p- p))]
(when (not success)
(tset errors p ret))))
(when (next errors)
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err))
vim.log.levels.error)))
;; Plugins to load before nvim finishes startup
(local startup-plugins [])
;; Plugins to load in the background
(local deferred-plugins [:lspconf
:cmp
:luasnip
:nullls
:catppuccin
:line
:treesitter
:nvimtree
:devicons
:neogit
:telescope
:autopairs
:tterm
:ts-context
:ufo
:aerial
:dap
:harpoon
:recorder
:noice
:tsn-actions
:lightbulb
:dressing])
(local errors {})
(fn load-plugin [plugin]
(let [(success ret) (pcall require (.. :pluginconf/p- plugin))]
(when (not success)
(tset errors p ret))))
(each [_ p (ipairs startup-plugins)]
(load-plugin p))
(fn load-one-deferred [idx]
(let [plugin (. deferred-plugins idx)]
(if plugin
(do
(load-plugin plugin)
(vim.schedule #(load-one-deferred (+ idx 1))))
(do
(when (next errors)
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err))
vim.log.levels.error))
(each [_ cb (ipairs mztenv.reg.plugin_load_callbacks)]
(pcall cb))))))
(vim.schedule #(load-one-deferred 1))