From beb3ed1effdc5dbd047c583598b83615075363b7 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 29 Jul 2024 00:03:28 +0200 Subject: Update how lsp, snippets and plugins are loaded --- fnl/aktersnurra.fnl | 17 ++++++++--------- fnl/plugins/lsp.fnl | 3 +++ fnl/plugins/lsp/init.fnl | 3 --- fnl/plugins/snippets.fnl | 33 +++++++++++++++++++++++++++++++++ fnl/plugins/snippets/init.fnl | 33 --------------------------------- fnl/util/load.fnl | 8 ++++++++ 6 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 fnl/plugins/lsp.fnl delete mode 100644 fnl/plugins/lsp/init.fnl create mode 100644 fnl/plugins/snippets.fnl delete mode 100644 fnl/plugins/snippets/init.fnl create mode 100644 fnl/util/load.fnl (limited to 'fnl') diff --git a/fnl/aktersnurra.fnl b/fnl/aktersnurra.fnl index f86c2a2..898c454 100644 --- a/fnl/aktersnurra.fnl +++ b/fnl/aktersnurra.fnl @@ -1,17 +1,16 @@ ;; Load plugins with lazy. -(local plugins (let [plugins [] - path (.. (vim.fn.stdpath :config) :/fnl/plugins)] - (each [fname (vim.fs.dir path)] - (let [fname (fname:match "^(.*)%.fnl$")] - (if (not= fname nil) - (table.insert plugins (require (.. :plugins. fname)))))) - (table.insert plugins (require :plugins.lsp)) - (table.insert plugins (require :plugins.snippets)) - plugins)) +(λ load-plugin [tbl name] + (table.insert tbl (require (.. :plugins. name)))) (local icons (require :settings.icons)) +(local {: load-and-apply} (require :util.load)) + +(local plugins (let [tbl {}] + (load-and-apply :/fnl/plugins (partial load-plugin tbl)) + tbl)) + (local opts {:install {:colorscheme [:no-clown-fiesta]} :debug false :defaults {:lazy false} diff --git a/fnl/plugins/lsp.fnl b/fnl/plugins/lsp.fnl new file mode 100644 index 0000000..f04ba86 --- /dev/null +++ b/fnl/plugins/lsp.fnl @@ -0,0 +1,3 @@ +;; Lsp plugins. + +[(require :plugins.lsp.lspconfig) (require :plugins.lsp.mason)] diff --git a/fnl/plugins/lsp/init.fnl b/fnl/plugins/lsp/init.fnl deleted file mode 100644 index f04ba86..0000000 --- a/fnl/plugins/lsp/init.fnl +++ /dev/null @@ -1,3 +0,0 @@ -;; Lsp plugins. - -[(require :plugins.lsp.lspconfig) (require :plugins.lsp.mason)] diff --git a/fnl/plugins/snippets.fnl b/fnl/plugins/snippets.fnl new file mode 100644 index 0000000..91865d6 --- /dev/null +++ b/fnl/plugins/snippets.fnl @@ -0,0 +1,33 @@ +;; Snippets functionality. + +(local dependencies [:rafamadriz/friendly-snippets]) + +(λ add-snippets [name] + (let [snippets (require (.. :plugins.snippets. name))] + (snippets.add-snippets))) + +(local {: load-and-apply} (require :util.load)) + +(λ config [] + (let [ls (require :luasnip) + luasnip-vscode (require :luasnip.loaders.from_vscode)] + (luasnip-vscode.lazy_load) + (load-and-apply :/fnl/plugins/snippets add-snippets) + (ls.config.set_config {:history false + :updateevents "TextChanged,TextChangedI"}) + (vim.keymap.set [:i :s] : + (lambda [] + (when (ls.expand_or_jumpable) + (ls.expand_or_jump))) {:silent true}) + (vim.keymap.set [:i :s] : + (lambda [] + (when (ls.jumpable -1) + (ls.jump -1)) + {:silent true})) + (vim.keymap.set [:i] : + (lambda [] + (when (ls.choice_active) + (ls.change_choice 1))) + {:silent true}))) + +{1 :L3MON4D3/LuaSnip :event :InsertEnter : config : dependencies} diff --git a/fnl/plugins/snippets/init.fnl b/fnl/plugins/snippets/init.fnl deleted file mode 100644 index 016b3b6..0000000 --- a/fnl/plugins/snippets/init.fnl +++ /dev/null @@ -1,33 +0,0 @@ -;; Snippets functionality. - -(local dependencies [:rafamadriz/friendly-snippets]) - -(fn add-snippets [] - (let [org (require :plugins.snippets.org) - workflow (require :plugins.snippets.workflow)] - (org.add-snippets) - (workflow.add-snippets))) - -(fn config [] - (let [ls (require :luasnip) - luasnip-vscode (require :luasnip.loaders.from_vscode)] - (luasnip-vscode.lazy_load) - (add-snippets) - (ls.config.set_config {:history false - :updateevents "TextChanged,TextChangedI"}) - (vim.keymap.set [:i :s] : - (lambda [] - (when (ls.expand_or_jumpable) - (ls.expand_or_jump))) {:silent true}) - (vim.keymap.set [:i :s] : - (lambda [] - (when (ls.jumpable -1) - (ls.jump -1)) - {:silent true})) - (vim.keymap.set [:i] : - (lambda [] - (when (ls.choice_active) - (ls.change_choice 1))) - {:silent true}))) - -{1 :L3MON4D3/LuaSnip :event :InsertEnter : config : dependencies} diff --git a/fnl/util/load.fnl b/fnl/util/load.fnl new file mode 100644 index 0000000..fef9b6e --- /dev/null +++ b/fnl/util/load.fnl @@ -0,0 +1,8 @@ +;; Load file with function + +(λ load-and-apply [path f] + (each [fname type (vim.fs.dir (.. (vim.fn.stdpath :config) path))] + (when (= type :file) + (f (fname:match "^(.*)%.fnl$"))))) + +{: load-and-apply} -- cgit v1.2.3-70-g09d2