Skip to content

Commit

Permalink
feat(esupports.hop): Add tab drop as option for open_mode (#1580)
Browse files Browse the repository at this point in the history
* feat(esupports.hop): Add tab drop as option for open_mode

* docs(esupports.hop): Document keybinds for tab-drop

* feat(esupports.hop): Add drop as option for open_mode
  • Loading branch information
devansh08 authored Nov 16, 2024
1 parent 488507b commit c7ada78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ mapping them):
- `neorg.esupports.hop.hop-link` - Follow the link under the cursor, seeks forward
- `neorg.esupports.hop.hop-link.vsplit` - Same, but open the link in a vertical split
- `neorg.esupports.hop.hop-link.tab-drop` - Same as hop-link, but open the link in a new tab; if the destination is already
open in an existing tab then just navigate to that tab (check :help :drop)
- `neorg.esupports.hop.hop-link.drop` - Same as hop-link, but navigate to the buffer if the destination is already open
in an existing buffer (check :help :drop)
--]]

local neorg = require("neorg.core")
Expand All @@ -42,6 +46,8 @@ module.load = function()
dirman_utils = module.required["core.dirman.utils"]
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link)", module.public.hop_link)
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.vsplit)", lib.wrap(module.public.hop_link, "vsplit"))
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.drop)", lib.wrap(module.public.hop_link, "drop"))
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.tab-drop)", lib.wrap(module.public.hop_link, "tab-drop"))
end

module.config.public = {
Expand Down Expand Up @@ -216,11 +222,19 @@ module.public = {
end,

buffer = function()
open_split()
if open_mode ~= "tab-drop" and open_mode ~= "drop" then
open_split()
end

if located_link_information.buffer ~= vim.api.nvim_get_current_buf() then
vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true)
vim.api.nvim_set_current_buf(located_link_information.buffer)
if open_mode == "tab-drop" then
vim.cmd("tab drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer))
elseif open_mode == "drop" then
vim.cmd("drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer))
else
vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true)
vim.api.nvim_set_current_buf(located_link_information.buffer)
end
end

if located_link_information.line then
Expand Down
8 changes: 8 additions & 0 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ module.private = {
opts = { desc = "[neorg] Jump to Link (Vertical Split)" },
},

-- Same as `<CR>`, except open the destination in a new tab
-- If destination is already open in an existing tab, just navigate to it
{
"<M-t>",
"<Plug>(neorg.esupports.hop.hop-link.tab-drop)",
opts = { desc = "[neorg] Jump to Link (Tab Drop)" },
},

-- Promote an object non-recursively
{
">.",
Expand Down

0 comments on commit c7ada78

Please sign in to comment.