Skip to content

Commit

Permalink
feat(tempus): add insert mode <M-d> keybind to insert a date
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed May 15, 2023
1 parent c37a104 commit b420f69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions lua/neorg/modules/core/keybinds/keybinds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.config.public = {
{ "<C-t>", "core.promo.promote" },
{ "<C-d>", "core.promo.demote" },
{ "<M-CR>", "core.itero.next-iteration" },
{ "<M-d>", "core.tempus.insert-date-insert-mode" },
},

-- TODO: Readd these
Expand Down
16 changes: 11 additions & 5 deletions lua/neorg/modules/core/tempus/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ module.public = {
.. tostring(string.format("%02d", osdate.min))
.. (osdate.sec ~= 0 and ("." .. tostring(osdate.sec)) or "")
end,
}),
}) or nil,
})
end,

Expand Down Expand Up @@ -408,12 +408,12 @@ module.private = {

module.load = function()
neorg.modules.await("core.keybinds", function(keybinds)
keybinds.register_keybind(module.name, "insert-date")
keybinds.register_keybinds(module.name, { "insert-date", "insert-date-insert-mode" })
end)
end

module.on_event = function(event)
if event.split_type[2] ~= "core.tempus.insert-date" then
if event.split_type[2] ~= "core.tempus.insert-date" and event.split_type[2] ~= "core.tempus.insert-date-insert-mode" then
return
end

Expand Down Expand Up @@ -443,11 +443,16 @@ module.on_event = function(event)
output = tostring(output)
end

vim.api.nvim_paste("{@ " .. output .. "}", false, -1)
vim.api.nvim_put({ "{@ " .. output .. "}" }, "c", false, true)

if vim.endswith(event.split_type[2], "insert-mode") then
vim.cmd.startinsert()
end
end

if neorg.modules.is_module_loaded("core.ui.calendar") then
neorg.modules.get_module("core.ui.calendar").select_date({ callback = callback })
vim.cmd.stopinsert()
neorg.modules.get_module("core.ui.calendar").select_date({ callback = vim.schedule_wrap(callback)})
else
vim.ui.input({
prompt = "Date: ",
Expand All @@ -458,6 +463,7 @@ end
module.events.subscribed = {
["core.keybinds"] = {
[module.name .. ".insert-date"] = true,
[module.name .. ".insert-date-insert-mode"] = true,
},
}

Expand Down

0 comments on commit b420f69

Please sign in to comment.