From e16303d85286e5661093e2029d54593e3a3481ec Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 17 Oct 2022 23:33:57 +0200 Subject: Add cmds for plugins to lazy load them --- fnl/config/cmd.fnl | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ fnl/config/orgmode.fnl | 6 ++--- fnl/config/which-key.fnl | 35 +++++++++---------------- fnl/init.fnl | 4 ++- fnl/plugins.fnl | 9 ++++--- 5 files changed, 90 insertions(+), 32 deletions(-) create mode 100644 fnl/config/cmd.fnl diff --git a/fnl/config/cmd.fnl b/fnl/config/cmd.fnl new file mode 100644 index 0000000..20ef377 --- /dev/null +++ b/fnl/config/cmd.fnl @@ -0,0 +1,68 @@ +;; Commands for plugins. +(module config.cmd {autoload {nvim aniseed.nvim util config.util}}) + +(nvim.create_user_command :OrgAgendaPrompt + (lambda [] + (let [orgmode (util.prequire :orgmode)] + (orgmode.action :agenda.prompt))) + {:nargs 0}) + +(nvim.create_user_command :OrgCapturePrompt + (lambda [] + (let [orgmode (util.prequire :orgmode)] + (orgmode.action :capture.prompt))) + {:nargs 0}) + +(nvim.create_user_command :CommentNormal + (lambda [] + (let [comment-api (util.prequire :Comment.api)] + (comment-api.toggle.linewise.current))) + {:nargs 0}) + +(nvim.create_user_command :CommentVisual + (lambda [] + (let [comment-api (util.prequire :Comment.api)] + (comment-api.toggle.linewise (vim.fn.visualmode)))) + {:nargs 0}) + +(nvim.create_user_command :HarpoonAdd + (lambda [] + (let [harpoon (util.prequire :harpoon.mark)] + (harpoon.add_file))) + {:nargs 0}) + +(nvim.create_user_command :HarpoonNext + (lambda [] + (let [harpoon (util.prequire :harpoon.ui)] + (harpoon.nav_next))) + {:nargs 0}) + +(nvim.create_user_command :HarpoonPrev + (lambda [] + (let [harpoon (util.prequire :harpoon.ui)] + (harpoon.nav_prev))) + {:nargs 0}) + +(nvim.create_user_command :HarpoonUI + (lambda [] + (let [harpoon (util.prequire :harpoon.ui)] + (harpoon.toggle_quick_menu))) + {:nargs 0}) + +(nvim.create_user_command :Replace + (lambda [] + (let [spectre (util.prequire :spectre)] + (spectre.open))) + {:nargs 0}) + +(nvim.create_user_command :ReplaceWord + (lambda [] + (let [spectre (util.prequire :spectre)] + (spectre.open.open_visual {:select_word true}))) + {:nargs 0}) + +(nvim.create_user_command :ReplaceInBuf + (lambda [] + (let [spectre (util.prequire :spectre)] + (spectre.open_file_search))) + {:nargs 0}) diff --git a/fnl/config/orgmode.fnl b/fnl/config/orgmode.fnl index a21eaa0..216fe4c 100644 --- a/fnl/config/orgmode.fnl +++ b/fnl/config/orgmode.fnl @@ -5,10 +5,8 @@ (nvim.ex.set :concealcursor=nc) (def- templates - {:t {:description :Task - :template "* TODO %?\n %u\n DEADLINE: %T\n"} - :m {:description :Meeting - :template "* Meeting %?"} + {:t {:description :Task :template "* TODO %?\n %u\n DEADLINE: %T\n"} + :m {:description :Meeting :template "* Meeting %?"} :n {:description :Note :template "* NOTE %? :NOTE:\n %u\n"}}) (defn- create-title [task] diff --git a/fnl/config/which-key.fnl b/fnl/config/which-key.fnl index 1412c1a..11a6dce 100644 --- a/fnl/config/which-key.fnl +++ b/fnl/config/which-key.fnl @@ -35,8 +35,7 @@ :noremap true :nowait true}) -(def- mmappings {:a ["lua require('harpoon.mark').add_file()" - :Harpoon] +(def- mmappings {:a [:HarpoonAdd :Harpoon] :b ["lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{sort_lastused = true, initial_mode = 'normal', previewer = false})" "Switch buffers"] :c [:DiffviewClose :DiffviewClose] @@ -46,16 +45,11 @@ :f ["lua require('telescope.builtin').find_files(require('telescope.themes').get_dropdown{previewer = false})" "Find files"] :g ["Telescope live_grep theme=ivy" "Find text"] - :l ["lua require('harpoon.ui').nav_next()" - "Harpoon Next"] - :h ["lua require('harpoon.ui').nav_prev()" - "Harpoon Prev"] - :t ["Telescope harpoon marks theme=dropdown" - "Search Harpoon"] + :l [:HarpoonNext "Harpoon Next"] + :h [:HarpoonPrev "Harpoon Prev"] :v ["lua vim.lsp.buf.rename()" :Rename] :p [:SaveSession "Save Session"] - :r ["lua require('harpoon.ui').toggle_quick_menu()" - "Harpoon UI"] + :r [:HarpoonUI "Harpoon UI"] :n [:Neogit :Neogit]}) (def- nopts {:mode :n @@ -124,11 +118,9 @@ :u [:PackerUpdate :Update]}) (def- replace {:name :Replace - :r ["lua require('spectre').open()" :Replace] - :w ["lua require('spectre').open_visual({select_word=true})" - "Replace Word"] - :f ["lua require('spectre').open_file_search()" - "Replace Buffer"]}) + :r [:Replace :Replace] + :w [:ReplaceWord "Replace Word"] + :f [:ReplaceInBuf "Replace Buffer"]}) (def- treesitter {:name :Treesitter :p [:TSPlaygroundToggle :Playground]}) @@ -147,8 +139,7 @@ :g git :h [:ColorizerToggle :Colorizer] :l lsp - :n ["lua require('Comment.api').toggle.linewise.current()" - :Comment] + :n [:CommentNormal :Comment] :p packer :r replace :u [:UndotreeToggle :Undotree] @@ -164,8 +155,7 @@ :noremap true :nowait true}) -(def- vmappings {:n ["lua require('Comment.api').toggle.linewise(vim.fn.visualmode())" - :Comment]}) +(def- vmappings {:n [:CommentVisual :Comment]}) (def- gopts {:mode :n :prefix :g @@ -174,10 +164,9 @@ :noremap true :nowait true}) -(def- gmappings {:a ["lua require('orgmode').action('agenda.prompt')" - "Open agenda prompt"] - :c ["lua require('orgmode').action('capture.prompt')" - "Open capture prompt"]}) +(def- gmappings + {:a [:OrgAgendaPrompt "Open agenda prompt"] + :c [:OrgCapturePrompt "Open capture prompt"]}) (let [which-key (util.prequire :which-key)] (which-key.setup setup) diff --git a/fnl/init.fnl b/fnl/init.fnl index 2e25da9..a28d2b6 100644 --- a/fnl/init.fnl +++ b/fnl/init.fnl @@ -1,5 +1,7 @@ ;; Load plugins with packer. -(module init {autoload {: plugins : packer} require [settings config.packer config.autocmd]}) +(module init + {autoload {: plugins : packer} + require [settings config.packer config.autocmd config.cmd]}) (packer.startup (fn [use] (each [_ plugin (pairs plugins.all)] diff --git a/fnl/plugins.fnl b/fnl/plugins.fnl index 13da672..c0195bd 100644 --- a/fnl/plugins.fnl +++ b/fnl/plugins.fnl @@ -76,7 +76,7 @@ (require :config.trouble))}]) (def misc [{1 :nvim-orgmode/orgmode - :event :BufReadPre + :event :BufRead :config (fn [] (require :config.orgmode))} {1 :moll/vim-bbye :event :BufRead} @@ -106,11 +106,12 @@ :config (fn [] (require :config.flit))} {1 :ahmedkhalf/project.nvim + :event :VimEnter :requires :nvim-telescope/telescope.nvim :config (fn [] (require :config.project))} {1 :windwp/nvim-spectre - :event :InsertEnter + :cmd [:Replace :ReplaceWord :ReplaceInBuf] :config (fn [] (require :config.spectre))} {1 :junegunn/vim-slash @@ -118,7 +119,7 @@ :config (fn [] (require :config.vim-slash))} {1 :ThePrimeagen/harpoon - :event :InsertEnter + :cmd [:HapoonAdd :HapoonNext :HapoonPrev :HarpoonUI] :requires :nvim-telescope/telescope.nvim :config (fn [] (require :config.harpoon))}]) @@ -133,7 +134,7 @@ (def snippets [:rafamadriz/friendly-snippets]) (def text [{1 :numToStr/Comment.nvim - :event :InsertEnter + :cmd [:CommentNormal :CommentVisual] :config (fn [] (require :config.comment))} {1 :JoosepAlviste/nvim-ts-context-commentstring :event :BufReadPost} -- cgit v1.2.3-70-g09d2