Skip to content

Commit b4ca2f2

Browse files
authored
Merge pull request #68 from benlubas/push-skskxwuyvuoq
feat!: update to new keybinding logic
2 parents fe255a3 + e85ec3d commit b4ca2f2

File tree

4 files changed

+42
-93
lines changed

4 files changed

+42
-93
lines changed

README.md

+11-17
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,19 @@ This module accepts the following configuration with the shown defaults:
192192
You can define keybindings like this:
193193

194194
```lua
195-
local neorg_callbacks = require("neorg.core.callbacks")
196-
197-
neorg_callbacks.on_event("core.keybinds.events.enable_keybinds", function(_, keybinds)
198-
-- Map all the below keybinds only when the "norg" mode is active
199-
keybinds.map_event_to_mode("norg", {
200-
n = { -- Bind keys in normal mode
201-
{ "<C-s>", "core.integrations.telescope.find_linkable" },
202-
},
203-
204-
i = { -- Bind in insert mode
205-
{ "<C-l>", "core.integrations.telescope.insert_link" },
206-
},
207-
}, {
208-
silent = true,
209-
noremap = true,
210-
})
211-
end)
195+
vim.keymap.set("n", "<lhs>", "<Plug>(neorg.telescope.search_headings)")
212196
```
213197

198+
List of all available plug mappings:
199+
- `neorg.telescope.backlinks.file_backlinks`
200+
- `neorg.telescope.backlinks.header_backlinks`
201+
- `neorg.telescope.find_linkable`
202+
- `neorg.telescope.find_norg_files`
203+
- `neorg.telescope.insert_file_link`
204+
- `neorg.telescope.insert_link`
205+
- `neorg.telescope.search_headings`
206+
- `neorg.telescope.switch_workspace`
207+
214208
# Support Welcome
215209
If it's not clear by the code already, I'm a solid noob at telescope related things :)
216210

lua/neorg/modules/core/integrations/telescope/module.lua

+28-72
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,40 @@ local neorg = require("neorg.core")
77
local module = neorg.modules.create("core.integrations.telescope")
88

99
module.setup = function()
10-
return { success = true, requires = { "core.keybinds", "core.dirman" } }
10+
return { success = true, requires = { "core.dirman" } }
1111
end
1212

13+
-- To add a new picker:
14+
-- - Choose a name to add to this list (eg. <picker>)
15+
-- - Create a file in `lua/telescope/_extensions/neorg/<picker>.lua`
16+
-- - Add the picker to `lua/telescope/_extensions/neorg.lua`
17+
-- - Add it to the list in the README
18+
19+
local pickers = {
20+
"find_linkable",
21+
"find_norg_files",
22+
"insert_link",
23+
"insert_file_link",
24+
"search_headings",
25+
"find_project_tasks",
26+
"find_aof_project_tasks",
27+
"find_aof_tasks",
28+
"find_context_tasks",
29+
"switch_workspace",
30+
"backlinks.file_backlinks",
31+
"backlinks.header_backlinks",
32+
}
33+
1334
module.load = function()
1435
local telescope_loaded, telescope = pcall(require, "telescope")
1536

1637
assert(telescope_loaded, telescope)
1738

1839
telescope.load_extension("neorg")
1940

20-
module.required["core.keybinds"].register_keybinds(module.name, {
21-
"find_linkable",
22-
"find_norg_files",
23-
"insert_link",
24-
"insert_file_link",
25-
"search_headings",
26-
"find_project_tasks",
27-
"find_aof_project_tasks",
28-
"find_aof_tasks",
29-
"find_context_tasks",
30-
"switch_workspace",
31-
"find_backlinks",
32-
"find_header_backlinks",
33-
})
41+
for _, picker in ipairs(pickers) do
42+
vim.keymap.set("", ("<Plug>(neorg.telescope.%s)"):format(picker), module.public[picker])
43+
end
3444
end
3545

3646
module.config.public = {
@@ -39,64 +49,10 @@ module.config.public = {
3949
},
4050
}
4151

42-
module.public = {
43-
find_linkable = require("telescope._extensions.neorg.find_linkable"),
44-
find_norg_files = require("telescope._extensions.neorg.find_norg_files"),
45-
insert_link = require("telescope._extensions.neorg.insert_link"),
46-
insert_file_link = require("telescope._extensions.neorg.insert_file_link"),
47-
search_headings = require("telescope._extensions.neorg.search_headings"),
48-
find_project_tasks = require("telescope._extensions.neorg.find_project_tasks"),
49-
find_context_tasks = require("telescope._extensions.neorg.find_context_tasks"),
50-
find_aof_tasks = require("telescope._extensions.neorg.find_aof_tasks"),
51-
find_aof_project_tasks = require("telescope._extensions.neorg.find_aof_project_tasks"),
52-
switch_workspace = require("telescope._extensions.neorg.switch_workspace"),
53-
find_backlinks = require("telescope._extensions.neorg.backlinks.file_backlinks"),
54-
find_header_backlinks = require("telescope._extensions.neorg.backlinks.header_backlinks"),
55-
}
52+
module.public = {}
5653

57-
module.on_event = function(event)
58-
if event.split_type[2] == "core.integrations.telescope.find_linkable" then
59-
module.public.find_linkable()
60-
elseif event.split_type[2] == "core.integrations.telescope.find_norg_files" then
61-
module.public.find_norg_files()
62-
elseif event.split_type[2] == "core.integrations.telescope.insert_link" then
63-
module.public.insert_link()
64-
elseif event.split_type[2] == "core.integrations.telescope.insert_file_link" then
65-
module.public.insert_file_link()
66-
elseif event.split_type[2] == "core.integrations.telescope.search_headings" then
67-
module.public.search_headings()
68-
elseif event.split_type[2] == "core.integrations.telescope.find_project_tasks" then
69-
module.public.find_project_tasks()
70-
elseif event.split_type[2] == "core.integrations.telescope.find_aof_tasks" then
71-
module.public.find_aof_tasks()
72-
elseif event.split_type[2] == "core.integrations.telescope.find_aof_project_tasks" then
73-
module.public.find_aof_project_tasks()
74-
elseif event.split_type[2] == "core.integrations.telescope.find_context_tasks" then
75-
module.public.find_context_tasks()
76-
elseif event.split_type[2] == "core.integrations.telescope.switch_workspace" then
77-
module.public.switch_workspace()
78-
elseif event.split_type[2] == "core.integrations.telescope.find_backlinks" then
79-
module.public.find_backlinks()
80-
elseif event.split_type[2] == "core.integrations.telescope.find_header_backlinks" then
81-
module.public.find_header_backlinks()
82-
end
54+
for _, picker in ipairs(pickers) do
55+
module.public[picker] = require(("telescope._extensions.neorg.%s"):format(picker))
8356
end
8457

85-
module.events.subscribed = {
86-
["core.keybinds"] = {
87-
["core.integrations.telescope.find_linkable"] = true,
88-
["core.integrations.telescope.find_norg_files"] = true,
89-
["core.integrations.telescope.insert_link"] = true,
90-
["core.integrations.telescope.insert_file_link"] = true,
91-
["core.integrations.telescope.search_headings"] = true,
92-
["core.integrations.telescope.find_project_tasks"] = true,
93-
["core.integrations.telescope.find_context_tasks"] = true,
94-
["core.integrations.telescope.find_aof_tasks"] = true,
95-
["core.integrations.telescope.find_aof_project_tasks"] = true,
96-
["core.integrations.telescope.switch_workspace"] = true,
97-
["core.integrations.telescope.find_backlinks"] = true,
98-
["core.integrations.telescope.find_header_backlinks"] = true,
99-
},
100-
}
101-
10258
return module

lua/telescope/_extensions/neorg.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ return require("telescope").register_extension({
1010
find_aof_tasks = require("neorg.modules.core.integrations.telescope.module").public.find_aof_tasks,
1111
find_aof_project_tasks = require("neorg.modules.core.integrations.telescope.module").public.find_aof_project_tasks,
1212
switch_workspace = require("neorg.modules.core.integrations.telescope.module").public.switch_workspace,
13-
find_backlinks = require("neorg.modules.core.integrations.telescope.module").public.find_backlinks,
14-
find_header_backlinks = require("neorg.modules.core.integrations.telescope.module").public.find_header_backlinks,
13+
find_backlinks = require("neorg.modules.core.integrations.telescope.module").public["backlinks.file_backlinks"],
14+
find_header_backlinks = require("neorg.modules.core.integrations.telescope.module").public["backlinks.header_backlinks"],
1515
},
1616
})

lua/telescope/_extensions/neorg/insert_file_link.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ local function get_file_title(file)
3939
return nil
4040
end
4141

42-
local bufnr = dirman.get_file_bufnr(tostring(file))
43-
local metadata = ts.get_document_metadata(bufnr)
42+
local metadata = ts.get_document_metadata(file)
4443
if not metadata or not metadata.title then
4544
return nil
4645
end

0 commit comments

Comments
 (0)