From 7a867af35889d24b6c74ce4dcecaf49af5457c46 Mon Sep 17 00:00:00 2001 From: Ben Lubas Date: Sat, 13 Jul 2024 19:52:04 -0400 Subject: [PATCH 1/2] fix: all the keybinds --- README.md | 28 ++--- .../core/integrations/telescope/module.lua | 100 +++++------------- lua/telescope/_extensions/neorg.lua | 4 +- .../_extensions/neorg/insert_file_link.lua | 3 +- 4 files changed, 42 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index b6d6d61..6c604fc 100644 --- a/README.md +++ b/README.md @@ -192,25 +192,19 @@ This module accepts the following configuration with the shown defaults: You can define keybindings like this: ```lua -local neorg_callbacks = require("neorg.core.callbacks") - -neorg_callbacks.on_event("core.keybinds.events.enable_keybinds", function(_, keybinds) - -- Map all the below keybinds only when the "norg" mode is active - keybinds.map_event_to_mode("norg", { - n = { -- Bind keys in normal mode - { "", "core.integrations.telescope.find_linkable" }, - }, - - i = { -- Bind in insert mode - { "", "core.integrations.telescope.insert_link" }, - }, - }, { - silent = true, - noremap = true, - }) -end) +vim.keymap.set("n", "", "(neorg.telescope.search_headings)") ``` +List of all available plug mappings: +- `neorg.telescope.backlinks.file_backlinks` +- `neorg.telescope.backlinks.header_backlinks` +- `neorg.telescope.find_linkable` +- `neorg.telescope.find_norg_files` +- `neorg.telescope.insert_file_link` +- `neorg.telescope.insert_link` +- `neorg.telescope.search_headings` +- `neorg.telescope.switch_workspace` + # Support Welcome If it's not clear by the code already, I'm a solid noob at telescope related things :) diff --git a/lua/neorg/modules/core/integrations/telescope/module.lua b/lua/neorg/modules/core/integrations/telescope/module.lua index 2d77b7a..359b4e4 100644 --- a/lua/neorg/modules/core/integrations/telescope/module.lua +++ b/lua/neorg/modules/core/integrations/telescope/module.lua @@ -7,9 +7,30 @@ local neorg = require("neorg.core") local module = neorg.modules.create("core.integrations.telescope") module.setup = function() - return { success = true, requires = { "core.keybinds", "core.dirman" } } + return { success = true, requires = { "core.dirman" } } end +-- To add a new picker: +-- - Choose a name to add to this list (eg. ) +-- - Create a file in `lua/telescope/_extensions/neorg/.lua` +-- - Add the picker to `lua/telescope/_extensions/neorg.lua` +-- - Add it to the list in the README + +local pickers = { + "find_linkable", + "find_norg_files", + "insert_link", + "insert_file_link", + "search_headings", + "find_project_tasks", + "find_aof_project_tasks", + "find_aof_tasks", + "find_context_tasks", + "switch_workspace", + "backlinks.file_backlinks", + "backlinks.header_backlinks", +} + module.load = function() local telescope_loaded, telescope = pcall(require, "telescope") @@ -17,20 +38,9 @@ module.load = function() telescope.load_extension("neorg") - module.required["core.keybinds"].register_keybinds(module.name, { - "find_linkable", - "find_norg_files", - "insert_link", - "insert_file_link", - "search_headings", - "find_project_tasks", - "find_aof_project_tasks", - "find_aof_tasks", - "find_context_tasks", - "switch_workspace", - "find_backlinks", - "find_header_backlinks", - }) + for _, picker in ipairs(pickers) do + vim.keymap.set("", ("(neorg.telescope.%s)"):format(picker), module.public[picker]) + end end module.config.public = { @@ -39,64 +49,10 @@ module.config.public = { }, } -module.public = { - find_linkable = require("telescope._extensions.neorg.find_linkable"), - find_norg_files = require("telescope._extensions.neorg.find_norg_files"), - insert_link = require("telescope._extensions.neorg.insert_link"), - insert_file_link = require("telescope._extensions.neorg.insert_file_link"), - search_headings = require("telescope._extensions.neorg.search_headings"), - find_project_tasks = require("telescope._extensions.neorg.find_project_tasks"), - find_context_tasks = require("telescope._extensions.neorg.find_context_tasks"), - find_aof_tasks = require("telescope._extensions.neorg.find_aof_tasks"), - find_aof_project_tasks = require("telescope._extensions.neorg.find_aof_project_tasks"), - switch_workspace = require("telescope._extensions.neorg.switch_workspace"), - find_backlinks = require("telescope._extensions.neorg.backlinks.file_backlinks"), - find_header_backlinks = require("telescope._extensions.neorg.backlinks.header_backlinks"), -} +module.public = {} -module.on_event = function(event) - if event.split_type[2] == "core.integrations.telescope.find_linkable" then - module.public.find_linkable() - elseif event.split_type[2] == "core.integrations.telescope.find_norg_files" then - module.public.find_norg_files() - elseif event.split_type[2] == "core.integrations.telescope.insert_link" then - module.public.insert_link() - elseif event.split_type[2] == "core.integrations.telescope.insert_file_link" then - module.public.insert_file_link() - elseif event.split_type[2] == "core.integrations.telescope.search_headings" then - module.public.search_headings() - elseif event.split_type[2] == "core.integrations.telescope.find_project_tasks" then - module.public.find_project_tasks() - elseif event.split_type[2] == "core.integrations.telescope.find_aof_tasks" then - module.public.find_aof_tasks() - elseif event.split_type[2] == "core.integrations.telescope.find_aof_project_tasks" then - module.public.find_aof_project_tasks() - elseif event.split_type[2] == "core.integrations.telescope.find_context_tasks" then - module.public.find_context_tasks() - elseif event.split_type[2] == "core.integrations.telescope.switch_workspace" then - module.public.switch_workspace() - elseif event.split_type[2] == "core.integrations.telescope.find_backlinks" then - module.public.find_backlinks() - elseif event.split_type[2] == "core.integrations.telescope.find_header_backlinks" then - module.public.find_header_backlinks() - end +for _, picker in ipairs(pickers) do + module.public[picker] = require(("telescope._extensions.neorg.%s"):format(picker)) end -module.events.subscribed = { - ["core.keybinds"] = { - ["core.integrations.telescope.find_linkable"] = true, - ["core.integrations.telescope.find_norg_files"] = true, - ["core.integrations.telescope.insert_link"] = true, - ["core.integrations.telescope.insert_file_link"] = true, - ["core.integrations.telescope.search_headings"] = true, - ["core.integrations.telescope.find_project_tasks"] = true, - ["core.integrations.telescope.find_context_tasks"] = true, - ["core.integrations.telescope.find_aof_tasks"] = true, - ["core.integrations.telescope.find_aof_project_tasks"] = true, - ["core.integrations.telescope.switch_workspace"] = true, - ["core.integrations.telescope.find_backlinks"] = true, - ["core.integrations.telescope.find_header_backlinks"] = true, - }, -} - return module diff --git a/lua/telescope/_extensions/neorg.lua b/lua/telescope/_extensions/neorg.lua index 5861243..254fca1 100644 --- a/lua/telescope/_extensions/neorg.lua +++ b/lua/telescope/_extensions/neorg.lua @@ -10,7 +10,7 @@ return require("telescope").register_extension({ find_aof_tasks = require("neorg.modules.core.integrations.telescope.module").public.find_aof_tasks, find_aof_project_tasks = require("neorg.modules.core.integrations.telescope.module").public.find_aof_project_tasks, switch_workspace = require("neorg.modules.core.integrations.telescope.module").public.switch_workspace, - find_backlinks = require("neorg.modules.core.integrations.telescope.module").public.find_backlinks, - find_header_backlinks = require("neorg.modules.core.integrations.telescope.module").public.find_header_backlinks, + find_backlinks = require("neorg.modules.core.integrations.telescope.module").public["backlinks.file_backlinks"], + find_header_backlinks = require("neorg.modules.core.integrations.telescope.module").public["backlinks.header_backlinks"], }, }) diff --git a/lua/telescope/_extensions/neorg/insert_file_link.lua b/lua/telescope/_extensions/neorg/insert_file_link.lua index 0d1ff05..4d3774b 100644 --- a/lua/telescope/_extensions/neorg/insert_file_link.lua +++ b/lua/telescope/_extensions/neorg/insert_file_link.lua @@ -39,8 +39,7 @@ local function get_file_title(file) return nil end - local bufnr = dirman.get_file_bufnr(tostring(file)) - local metadata = ts.get_document_metadata(bufnr) + local metadata = ts.get_document_metadata(file) if not metadata or not metadata.title then return nil end From e85ec3d9306e72b28aceaa8cf82686d892419da2 Mon Sep 17 00:00:00 2001 From: max397574 <81827001+max397574@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:05:07 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c604fc..d286b50 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ This module accepts the following configuration with the shown defaults: You can define keybindings like this: ```lua -vim.keymap.set("n", "", "(neorg.telescope.search_headings)") +vim.keymap.set("n", "", "(neorg.telescope.search_headings)") ``` List of all available plug mappings: