-
Notifications
You must be signed in to change notification settings - Fork 1
Recipes
dharmx edited this page May 9, 2024
·
11 revisions
Select the next Mark
in the marks list.
local index = 0
vim.api.nvim_create_user_command("CycleMarkP", function()
local _, bundle = require("track.util").root_and_bundle()
if not bundle then return end
index = math.max(index, math.min(#bundle.views, index)) % #bundle.views + 1
vim.cmd.SelectMark(index)
end, {})
vim.api.nvim_create_user_command("CycleMarkN", function()
local _, bundle = require("track.util").root_and_bundle()
if not bundle then return end
index = (index - 2 + #bundle.views) % #bundle.views + 1
vim.cmd.SelectMark(index)
end, {})
Global mark selection mappings similar to harpoons. Depends on xdg-open.
for serial = 1, 9 do
local key = tostring(serial)
vim.keymap.set("n", "<space>" .. key, "<cmd>SelectMark " .. key .. "<cr>")
end
Open PDFs, audio files, video files, etc.
local media = {
["jpeg"] = true,
["jpg"] = true,
["png"] = true,
["mp3"] = true,
["mp4"] = true,
["flac"] = true,
["mkv"] = true,
["pdf"] = true,
}
local function open(mark)
if mark.type == "file" and media[mark.path:match(".+%.(.+)$")] then
vim.fn.jobstart({ "xdg-open", mark:absolute() }, { detach = true })
else
require("track.util").open_entry(mark)
end
end
require("track").setup({
pickers = {
pad = {
hooks = { on_choose = open },
},
views = {
hooks = {
on_choose = function(self)
local entries = vim.F.if_nil(self:get_multi_selection(), {})
if #entries == 0 then table.insert(entries, self:get_selection()) end
for _, entry in ipairs(entries) do open(entry.value) end
end,
},
},
},
})