A nvim-cmp source for turning natural dates into ISO dates.
https://github.com/Gelio/cmp-natdat/assets/889383/1d6d388d-2a10-4923-9156-b99764c5a342
@now
-> 2023-10-13 12:38
@tomorrow
-> 2023-10-14
@last Friday 2pm
-> 2023-10-06 14:00
@Oct 8 2021
-> 2021-10-08
@today 14:20
-> 2023-10-13 14:20
now
yesterday
, today
, tomorrow
with optional timelast
/next
modifier and
timeInstall the plugin
Using lazy.nvim:
{ "Gelio/cmp-natdat", config = true }
config = true
is necessary so lazy.nvim calls
require("cmp_natdat").setup()
to register the source.
Using packer.nvim:
use {
"Gelio/cmp-natdat",
config = function()
require("cmp_natdat").setup()
end
}
Add the source to the list in your nvim-cmp configuration
sources = {
{ name = "natdat" },
--- other sources...
}
cmp-natdat
accepts the following optional configuration, passed as a table to
the setup()
method:
cmp_kind_text
- the text to use as the completion item's label in the
nvim-cmp completions popup.
Default: Text
highlight_group
- the name of an existing highlight group to use for that
completion item's label in the nvim-cmp completions popup.
Default: CmpItemKindText
Example:
{
"Gelio/cmp-natdat",
config = function()
require("cmp_natdat").setup({
cmp_kind_text = "NatDat",
highlight_group = "Red",
})
end,
}
To get the most out of the custom cmp kind text, you can also use lspkind.nvim to show the calendar icon (📆) for cmp-natdat completions:
require("lspkind").init({
symbol_map = {
NatDat = "📅",
},
})
Parsing the dates is done using pcomb, a Lua parser combinator library. Its API is inspired by Rust's nom crate.
pcomb
can also be used in other plugins to parse other text input into a more
structured format. It is flexible and makes it easy to build parsers from the
bottom-up:
---@type pcomb.Parser<{ [1]: integer, [2]: pcomb.NIL | integer }>
local day_of_month_and_opt_year = psequence.sequence({
-- Day of month
pcharacter.integer,
pcombinator.opt(psequence.preceded(
pcharacter.multispace1,
-- Year
pcharacter.integer,
))
})
See CONTRIBUTING.md.