From d474c779523c512e3bc91bc5ce7bc87cafc6372b Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Sat, 23 Sep 2023 22:05:37 +0200 Subject: Move user and auto cmds to plugins --- fnl/plugins/editor/comment.fnl | 16 ++++++++++++++++ fnl/plugins/editor/harpoon.fnl | 31 ++++++++++++++++++++++++++++--- fnl/plugins/editor/neogit.fnl | 12 ++++++++++++ fnl/plugins/editor/orgmode.fnl | 32 ++++++++++++++++++++++++++++---- fnl/plugins/editor/persistence.fnl | 21 +++++++++++++++++++++ fnl/plugins/editor/spectre.fnl | 28 ++++++++++++++++++++++++++++ fnl/plugins/editor/telescope.fnl | 22 +++++++++++++++++++--- fnl/plugins/editor/toggleterm.fnl | 20 ++++++++++++++++++++ 8 files changed, 172 insertions(+), 10 deletions(-) (limited to 'fnl/plugins/editor') diff --git a/fnl/plugins/editor/comment.fnl b/fnl/plugins/editor/comment.fnl index 63401a0..f15e61f 100644 --- a/fnl/plugins/editor/comment.fnl +++ b/fnl/plugins/editor/comment.fnl @@ -1,7 +1,23 @@ ;; Language aware commenting. +(local user-cmds [[:CommentNormal + (lambda [] + (let [comment-api (require :Comment.api)] + (comment-api.toggle.linewise.current))) + {:nargs 0}] + [:CommentVisual + (lambda [] + (let [comment-api (require :Comment.api)] + (comment-api.toggle.linewise (vim.fn.visualmode)))) + {:nargs 0}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds))) + {1 :numToStr/Comment.nvim :event :BufReadPost + : inti :opts {:toggler {;; Line-comment toggle keymap :line :mcc ;; Block-comment toggle keymap diff --git a/fnl/plugins/editor/harpoon.fnl b/fnl/plugins/editor/harpoon.fnl index 167cf3b..8a9818f 100644 --- a/fnl/plugins/editor/harpoon.fnl +++ b/fnl/plugins/editor/harpoon.fnl @@ -1,12 +1,37 @@ ;; Harpoon files for navigation. +(local user-cmds [[:HarpoonAdd + (lambda [] + (let [harpoon (require :harpoon.mark)] + (harpoon.add_file))) + {:nargs 0}] + [:HarpoonNext + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.nav_next))) + {:nargs 0}] + [:HarpoonPrev + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.nav_prev))) + {:nargs 0}] + [:HarpoonUI + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.toggle_quick_menu))) + {:nargs 0}]]) + (fn telescope-ext [ext fun opts] (let [telescope (require :telescope) themes (require :telescope.themes) theme (. opts :theme)] ((. (. (. telescope :extensions) ext) fun) ((. themes theme) opts)))) -(fn setup [] +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds))) + +(fn config [] (vim.keymap.set :n : (fn [] (telescope-ext :harpoon :marks @@ -22,9 +47,9 @@ {1 :ThePrimeagen/harpoon :event :BufReadPost + : init :keys [{1 :ma 2 :HarpoonAdd :desc :Harpoon} {1 :mr 2 :HarpoonUI :desc "Harpoon UI"} {1 :ms 2 :HarpoonPrev :desc "Harpoon Prev"} {1 :mt 2 :HarpoonNext :desc "Harpoon Next"}] - :config (fn [] - (setup))} + : config} diff --git a/fnl/plugins/editor/neogit.fnl b/fnl/plugins/editor/neogit.fnl index af3a738..5a3c5e3 100644 --- a/fnl/plugins/editor/neogit.fnl +++ b/fnl/plugins/editor/neogit.fnl @@ -1,9 +1,21 @@ ;; Git ui. +(local auto-cmds [[:FileType + {:pattern [:NeogitStatus + :NeogitCommitMessage + :NeogitNotification + :NeogitCommitView] + :command "setlocal spell!"}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-auto-cmds auto-cmds))) + (local opts {:integrations {:diffview true :telescope true}}) {1 :TimUntersberger/neogit :cmd :Neogit : opts + : init :dependencies [:nvim-lua/plenary.nvim] :keys [{1 :gm 2 :Neogit :desc :Neogit}]} diff --git a/fnl/plugins/editor/orgmode.fnl b/fnl/plugins/editor/orgmode.fnl index bb67b88..5324b8d 100644 --- a/fnl/plugins/editor/orgmode.fnl +++ b/fnl/plugins/editor/orgmode.fnl @@ -1,5 +1,28 @@ ;; Orgmode for nvim. +(local user-cmds [[:OrgAgendaPrompt + (lambda [] + (let [orgmode (require :orgmode)] + (orgmode.action :agenda.prompt))) + {:nargs 0}] + [:OrgCapturePrompt + (lambda [] + (let [orgmode (require :orgmode)] + (orgmode.action :capture.prompt))) + {:nargs 0}]]) + +(local auto-cmds + [[:FileType + {:pattern :org + :callback (fn [] + (tset vim.opt_local :conceallevel 2) + (tset vim.opt_local :concealcursor :nc))}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds) + (cmds.create-auto-cmds auto-cmds))) + (local templates {:t {:description :Task :template "* TODO %?\n %u\n DEADLINE: %T\n"} :m {:description :Meeting :template "* Meeting %?"} @@ -11,14 +34,15 @@ :org_default_notes_file "~/.local/share/org/refile.org" :org_agenda_templates templates}) -(fn setup [] - (let [orgmode (require :orgmode)] +(fn config [] + (let [orgmode (require :orgmode) + cmds (require :util.cmds)] (orgmode.setup_ts_grammar) (orgmode.setup opts))) {1 :nvim-orgmode/orgmode - :config (fn [] - (setup)) + : config + : init :event :BufReadPost :keys [{1 :ga 2 :OrgAgendaPrompt :desc "Open agenda prompt"} {1 :gc 2 :OrgCapturePrompt :desc "Open capture prompt"} diff --git a/fnl/plugins/editor/persistence.fnl b/fnl/plugins/editor/persistence.fnl index 0b4e7a8..492ef0d 100644 --- a/fnl/plugins/editor/persistence.fnl +++ b/fnl/plugins/editor/persistence.fnl @@ -1,7 +1,28 @@ ;; Session manager. +(local user-cmds [[:RestoreSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.load))) + {:nargs 0}] + [:RestoreLastSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.load {:last true}))) + {:nargs 0}] + [:IgnoreSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.stop))) + {:nargs 0}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds))) + {1 :folke/persistence.nvim :event :VeryLazy + : init :keys [{1 :sn 2 :RestoreSession :desc "Restore session"} {1 :se 2 :RestoreLastSession diff --git a/fnl/plugins/editor/spectre.fnl b/fnl/plugins/editor/spectre.fnl index 526b196..81cc77c 100644 --- a/fnl/plugins/editor/spectre.fnl +++ b/fnl/plugins/editor/spectre.fnl @@ -1,5 +1,32 @@ ;; Find and replace. +(local user-cmds [[:Replace + (lambda [] + (let [spectre (require :spectre)] + (spectre.open))) + {:nargs 0}] + [:ReplaceWord + (lambda [] + (let [spectre (require :spectre)] + (spectre.open_visual {:select_word true}))) + {:nargs 0}] + [:ReplaceInBuf + (lambda [] + (let [spectre (require :spectre)] + (spectre.open_file_search))) + {:nargs 0}]]) + +(local auto-cmds + [[:FileType + {:pattern [:spectre_panel] + :command "nnoremap q :close"}] + [:FileType {:pattern [:spectre_panel] :command "setlocal spell!"}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds) + (cmds.create-auto-cmds auto-cmds))) + (local opts {:color_devicons true :highlight {:ui :String :search :DiffChange :replace :DiffDelete} :mapping {:toggle_line {:map :t @@ -53,6 +80,7 @@ {1 :windwp/nvim-spectre :event :BufReadPost + : init :keys [{1 :rn 2 :ReplaceInBuf :desc "Replace in Buffer"} {1 :re 2 :Replace :desc :Replace} {1 :ri 2 :ReplaceWord :desc "Replace Word"}] diff --git a/fnl/plugins/editor/telescope.fnl b/fnl/plugins/editor/telescope.fnl index 8f2bff3..83cb4a1 100644 --- a/fnl/plugins/editor/telescope.fnl +++ b/fnl/plugins/editor/telescope.fnl @@ -6,6 +6,22 @@ (each [_ extension (ipairs extensions)] (telescope.load_extension extension))) +(fn telescope-builtin [builtin opts] + (let [telescope (require :telescope.builtin) + themes (require :telescope.themes) + theme (. opts :theme)] + ((. telescope builtin) ((. themes theme) opts)))) + +(local user-cmds [[:FindFiles + (lambda [] + (telescope-builtin :find_files + {:theme :get_dropdown :previewer false})) + {:nargs 0}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-user-cmds user-cmds))) + (local keys [{1 :mf 2 :FindFiles :desc "Find Files"} {1 :mg 2 "Telescope live_grep theme=dropdown" @@ -60,7 +76,7 @@ 2 "Telescope lsp_document_symbols theme=dropdown" :desc "Document Symbols"}]) -(fn setup [] +(fn config [] (let [telescope (require :telescope) actions (require :telescope.actions) icons (require :plugins.icons)] @@ -140,8 +156,8 @@ {1 :nvim-telescope/telescope.nvim :cmd :Telescope - :config (fn [] - (setup)) + : init + : config :dependencies [:nvim-lua/popup.nvim :nvim-telescope/telescope-frecency.nvim {1 :nvim-telescope/telescope-fzf-native.nvim :build :make} diff --git a/fnl/plugins/editor/toggleterm.fnl b/fnl/plugins/editor/toggleterm.fnl index 89d203d..9c2c5dc 100644 --- a/fnl/plugins/editor/toggleterm.fnl +++ b/fnl/plugins/editor/toggleterm.fnl @@ -1,6 +1,26 @@ ;; Terminal inside nvim. +(local auto-cmds [[:TermOpen + {:pattern "term://*toggleterm#*" + :callback (fn [] + (vim.keymap.set :t : "wincmd h" + {}) + (vim.keymap.set :t : "wincmd j" + {}) + (vim.keymap.set :t : "wincmd k" + {}) + (vim.keymap.set :t : "wincmd l" + {}))}] + [:TermOpen + {:pattern ["term://*toggleterm#*"] + :command "setlocal spell!"}]]) + +(fn init [] + (let [cmds (require :util.cmds)] + (cmds.create-auto-cmds auto-cmds))) + {1 :akinsho/toggleterm.nvim :cmd :ToggleTerm + : init :keys [{1 :t 2 :ToggleTerm :desc :Terminal}] :opts {:size 24 :shade_terminals false}} -- cgit v1.2.3-70-g09d2