From 5679e90f8a687ff1ce33fb2e4f579e4c17ec2d51 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 3 Jan 2023 21:39:21 +0100 Subject: Fix loading of telescope --- fnl/config/harpoon.fnl | 15 ++++-- fnl/config/util.fnl | 12 +++++ fnl/config/which-key.fnl | 123 +++++++++++++++++++++++++---------------------- 3 files changed, 88 insertions(+), 62 deletions(-) (limited to 'fnl') diff --git a/fnl/config/harpoon.fnl b/fnl/config/harpoon.fnl index 9905439..9f9d2f2 100644 --- a/fnl/config/harpoon.fnl +++ b/fnl/config/harpoon.fnl @@ -5,10 +5,15 @@ (util.setup :harpoon opts) -(nvim.set_keymap :n : - "lua require('telescope').extensions.harpoon.marks(require('telescope.themes').get_dropdown{previewer = false, initial_mode='normal', prompt_title='Harpoon'})" - opts) +(vim.keymap.set :n : + (fn [] + (util.telescope-ext :harpoon :marks + {:theme :get_dropdown + :previewer false + :initial_mode :normal + :prompt_title :Harpoon})) + {}) (nvim.set_keymap :n : - "lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false, initial_mode='normal'})" - opts) + "Telescope buffers theme=dropdown previewer=false initial_mode=normal" + {}) diff --git a/fnl/config/util.fnl b/fnl/config/util.fnl index a4dcf5b..7665a57 100644 --- a/fnl/config/util.fnl +++ b/fnl/config/util.fnl @@ -11,3 +11,15 @@ (defn setup [plugin config] (let [plugin (prequire plugin)] (plugin.setup config))) + +(defn telescope-ext [ext fun opts] + (let [telescope (prequire :telescope) + themes (prequire :telescope.themes) + theme (. opts :theme)] + ((. (. (. telescope :extensions) ext) fun) ((. themes theme) opts)))) + +(defn telescope-builtin [builtin opts] + (let [telescope (prequire :telescope.builtin) + themes (prequire :telescope.themes) + theme (. opts :theme)] + ((. telescope builtin) ((. themes theme) opts)))) diff --git a/fnl/config/which-key.fnl b/fnl/config/which-key.fnl index 570040f..310f7c4 100644 --- a/fnl/config/which-key.fnl +++ b/fnl/config/which-key.fnl @@ -36,20 +36,23 @@ :noremap true :nowait true}) -(def- mmappings {:a [:HarpoonAdd :Harpoon] - :c [:DiffviewClose :DiffviewClose] - :d [:DiffviewFileHistory :DiffviewFileHistory] - :x ["DiffviewOpen -uno" :DiffviewOpen] - :q ["Gitsigns diffthis HEAD" "Gitsigns diff"] - :f ["lua require('telescope.builtin').find_files(require('telescope.themes').get_dropdown{previewer = false})" - "Find files"] - :g ["Telescope live_grep theme=dropdown" "Find text"] - :l [:HarpoonNext "Harpoon Next"] - :h [:HarpoonPrev "Harpoon Prev"] - :v ["lua vim.lsp.buf.rename()" :Rename] - :p [:SaveSession "Save Session"] - :r [:HarpoonUI "Harpoon UI"] - :n [:Neogit :Neogit]}) +(def- mmappings + {:a [:HarpoonAdd :Harpoon] + :c [:DiffviewClose :DiffviewClose] + :d [:DiffviewFileHistory :DiffviewFileHistory] + :f [(fn [] + (util.telescope-builtin :find_files + {:theme :get_dropdown :previewer false})) + "Find files"] + :g ["Telescope live_grep theme=dropdown" "Find text"] + :n [:Neogit :Neogit] + :p [:SaveSession "Save Session"] + :q ["Gitsigns diffthis HEAD" "Gitsigns diff"] + :r [:HarpoonUI "Harpoon UI"] + :s [:HarpoonPrev "Harpoon Prev"] + :t [:HarpoonNext "Harpoon Next"] + :v ["lua vim.lsp.buf.rename()" :Rename] + :x ["DiffviewOpen -uno" :DiffviewOpen]}) (def- nopts {:mode :n :prefix : @@ -58,22 +61,25 @@ :noremap true :nowait true}) -(def- find {:name :Find - :b ["Telescope git_branches theme=dropdown" - "Checkout branch"] - :c ["Telescope colorscheme theme=dropdown" :Colorscheme] - :f ["Telescope find_files theme=dropdown" "Find files"] - :t ["Telescope live_grep theme=dropdown" "Find text"] - :s [:SearchSession "Find Session"] - :S ["Telescope grep_string theme=dropdown" "Find String"] - :h ["Telescope help_tags" :Help] - :H ["Telescope highlights" :Highlights] - :l ["Telescope resume" "Last Search"] - :p ["Telescope projects" "Find project"] - :r ["Telescope oldfiles theme=dropdown" "Recent File"] - :R ["Telescope registers" :Registers] - :k ["Telescope keymaps" :Keymaps] - :C ["Telescope commands" :Commands]}) +(def- find + {:name :Find + :C ["Telescope commands theme=dropdown" :Commands] + :H ["Telescope highlights" :Highlights] + :R ["Telescope registers theme=dropdown" :Registers] + :S ["Telescope grep_string theme=dropdown" "Find String"] + :b ["Telescope git_branches theme=dropdown" "Checkout branch"] + :c ["Telescope colorscheme theme=dropdown" :Colorscheme] + :f [(fn [] + (util.telescope-builtin :find_files + {:theme :get_dropdown :previewer false})) + "Find files"] + :h ["Telescope help_tags theme=dropdown" :Help] + :k ["Telescope keymaps theme=dropdown" :Keymaps] + :l ["Telescope resume theme=dropdown" "Last Search"] + :p ["Telescope projects theme=dropdown" "Find project"] + :r ["Telescope oldfiles theme=dropdown" "Recent File"] + :s [:SearchSession "Find Session"] + :t ["Telescope live_grep theme=dropdown" "Find text"]}) (def- diagnostics {:name :Diagnostics :d [:TroubleToggle :Trouble] @@ -81,33 +87,34 @@ "Telescope diagnostics"]}) (def- git {:name :Git + :R ["lua require 'gitsigns'.reset_buffer()" "Reset Buffer"] + :b ["Telescope git_branches theme=dropdown" + "Checkout branch"] + :c ["Telescope git_commits theme=dropdown" + "Checkout commit"] + :d ["Gitsigns diffthis HEAD" :Diff] :j ["lua require 'gitsigns'.next_hunk()" "Next Hunk"] :k ["lua require 'gitsigns'.prev_hunk()" "Prev Hunk"] :l ["lua require 'gitsigns'.blame_line()" :Blame] + :o ["Telescope git_status theme=dropdown" + "Open changed file"] :p ["lua require 'gitsigns'.preview_hunk()" "Preview Hunk"] :r ["lua require 'gitsigns'.reset_hunk()" "Reset Hunk"] - :R ["lua require 'gitsigns'.reset_buffer()" "Reset Buffer"] :s ["lua require 'gitsigns'.stage_hunk()" "Stage Hunk"] :u ["lua require 'gitsigns'.undo_stage_hunk()" - "Undo Stage Hunk"] - :o ["Telescope git_status theme=dropdown" - "Open changed file"] - :b ["Telescope git_branches theme=dropdown" - "Checkout branch"] - :c ["Telescope git_commits theme=dropdown" - "Checkout commit"] - :d ["Gitsigns diffthis HEAD" :Diff]}) - -(def- lsp {:name :LSP - :a ["lua vim.lsp.buf.code_action()" "Code Action"] - :f ["lua vim.lsp.buf.format { async = true }" :Format] - :i [:LspInfo :Info] - :l ["lua vim.lsp.codelens.run()" "CodeLens Action"] - :m [:Mason :Mason] - :r ["lua vim.lsp.buf.rename()" :Rename] - :s ["Telescope lsp_document_symbols" "Document Symbols"] - :S ["Telescope lsp_dynamic_workspace_symbols" - "Workspace Symbols"]}) + "Undo Stage Hunk"]}) + +(def- lsp + {:name :LSP + :S ["Telescope lsp_dynamic_workspace_symbols" + "Workspace Symbols"] + :a ["lua vim.lsp.buf.code_action()" "Code Action"] + :f ["lua vim.lsp.buf.format { async = true }" :Format] + :i [:LspInfo :Info] + :l ["lua vim.lsp.codelens.run()" "CodeLens Action"] + :m [:Mason :Mason] + :r ["lua vim.lsp.buf.rename()" :Rename] + :s ["Telescope lsp_document_symbols" "Document Symbols"]}) (def- lazy {:name :Lazy :C ["Lazy check" :Check] @@ -121,9 +128,9 @@ :u ["Lazy update" :Update]}) (def- replace {:name :Replace + :f [:ReplaceInBuf "Replace Buffer"] :r [:Replace :Replace] - :w [:ReplaceWord "Replace Word"] - :f [:ReplaceInBuf "Replace Buffer"]}) + :w [:ReplaceWord "Replace Word"]}) (def- treesitter {:name :Treesitter :p [:TSPlaygroundToggle :Playground]}) @@ -145,7 +152,9 @@ :l lsp :n [:CommentNormal :Comment] :r replace - :s [switch-window "Switch window"] + :s [(fn [] + (switch-window)) + "Switch window"] :t [:ToggleTerm :Terminal] :u [:UndotreeToggle :Undotree] :y lazy @@ -167,10 +176,10 @@ :noremap true :nowait true}) -(def- gmappings - {:a [:OrgAgendaPrompt "Open agenda prompt"] - :c [:OrgCapturePrompt "Open capture prompt"] - :m ["Telescope orgmode search_headings theme=dropdown" "Search Headings"]}) +(def- gmappings {:a [:OrgAgendaPrompt "Open agenda prompt"] + :c [:OrgCapturePrompt "Open capture prompt"] + :m ["Telescope orgmode search_headings theme=dropdown" + "Search Headings"]}) (let [which-key (util.prequire :which-key)] (which-key.setup setup) -- cgit v1.2.3-70-g09d2