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 +++++++++---------------- 3 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 fnl/config/cmd.fnl (limited to 'fnl/config') 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) -- cgit v1.2.3-70-g09d2