Skip to content

Commit

Permalink
feat(hop): allow users to jump to timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed May 15, 2023
1 parent 7368a8a commit 22b12fb
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ module.public = {
(link_target_generic)
(link_target_external_file)
(link_target_definition)
(link_target_timestamp)
(link_target_footnote)
(link_target_heading1)
(link_target_heading2)
Expand Down Expand Up @@ -321,6 +322,7 @@ module.public = {
(link_target_generic)
(link_target_external_file)
(link_target_definition)
(link_target_timestamp)
(link_target_footnote)
(link_target_heading1)
(link_target_heading2)
Expand All @@ -344,7 +346,9 @@ module.public = {
local query = neorg.utils.ts_parse_query("norg", query_text)
local range = module.required["core.integrations.treesitter"].get_node_range(link_node)

local parsed_link_information = {}
local parsed_link_information = {
link_node = link_node,
}

for id, node in query:iter_captures(document_root, buf, range.row_start, range.row_end + 1) do
local capture = query.captures[id]
Expand Down Expand Up @@ -453,6 +457,46 @@ module.public = {
return {}
end,

timestamp = function()
local tempus = neorg.modules.get_module("core.tempus")

if not tempus then
log.error("`core.tempus` is not loaded! Unable to parse timestamp.")
return {}
end

local parsed_date = tempus.parse_date(parsed_link_information.link_location_text)

if type(parsed_date) == "string" then
log.error("[ERROR]:", parsed_date)
return {}
end

local calendar = neorg.modules.get_module("core.ui.calendar")

if not calendar then
log.error("`core.ui.calendar` is not loaded! Unable to open timestamp.")
return {}
end

calendar.select_date({
date = tempus.to_lua_date(parsed_date),
callback = function(input)
local start_row, start_col, end_row, end_col = parsed_link_information.link_node:range()
vim.api.nvim_buf_set_text(
buf_pointer,
start_row,
start_col,
end_row,
end_col,
{ "{@ " .. tostring(tempus.to_date(input, false)) .. "}" }
)
end,
})

return {}
end,

_ = function()
local query_str = neorg.lib.match(parsed_link_information.link_type)({
generic = [[
Expand Down

0 comments on commit 22b12fb

Please sign in to comment.