mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
style: make stylua happy
This commit is contained in:
5502
lua/telekasten.lua
5502
lua/telekasten.lua
File diff suppressed because it is too large
Load Diff
0
lua/telekasten/config.lua
Normal file
0
lua/telekasten/config.lua
Normal file
0
lua/telekasten/functions.lua
Normal file
0
lua/telekasten/functions.lua
Normal file
@@ -8,37 +8,37 @@ local conf = require("telescope.config").values
|
|||||||
|
|
||||||
-- Pick between the various configured vaults
|
-- Pick between the various configured vaults
|
||||||
function M.vaults(telekasten, opts)
|
function M.vaults(telekasten, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local vaults = telekasten.vaults
|
local vaults = telekasten.vaults
|
||||||
local _vaults = {}
|
local _vaults = {}
|
||||||
for k, v in pairs(vaults) do
|
for k, v in pairs(vaults) do
|
||||||
table.insert(_vaults, { k, v })
|
table.insert(_vaults, { k, v })
|
||||||
end
|
end
|
||||||
pickers
|
pickers
|
||||||
.new(opts, {
|
.new(opts, {
|
||||||
prompt_title = "Vaults",
|
prompt_title = "Vaults",
|
||||||
finder = finders.new_table({
|
finder = finders.new_table({
|
||||||
results = _vaults,
|
results = _vaults,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
return {
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
display = entry[1],
|
display = entry[1],
|
||||||
ordinal = entry[1],
|
ordinal = entry[1],
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
}),
|
}),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr, map)
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
-- print(vim.inspect(selection))
|
-- print(vim.inspect(selection))
|
||||||
telekasten.chdir(selection.value[2])
|
telekasten.chdir(selection.value[2])
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:find()
|
:find()
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
0
lua/telekasten/syntax.lua
Normal file
0
lua/telekasten/syntax.lua
Normal file
0
lua/telekasten/templates.lua
Normal file
0
lua/telekasten/templates.lua
Normal file
@@ -5,110 +5,110 @@ local date = require("telekasten.utils.luadate")
|
|||||||
--- see https://webspace.science.uu.nl/~gent0113/calendar/isocalendar.htm
|
--- see https://webspace.science.uu.nl/~gent0113/calendar/isocalendar.htm
|
||||||
--- see https://en.wikipedia.org/wiki/ISO_week_date
|
--- see https://en.wikipedia.org/wiki/ISO_week_date
|
||||||
M.dow_for_year = function(year)
|
M.dow_for_year = function(year)
|
||||||
return (
|
return (
|
||||||
year
|
year
|
||||||
+ math.floor(year / 4)
|
+ math.floor(year / 4)
|
||||||
- math.floor(year / 100)
|
- math.floor(year / 100)
|
||||||
+ math.floor(year / 400)
|
+ math.floor(year / 400)
|
||||||
) % 7
|
) % 7
|
||||||
end
|
end
|
||||||
|
|
||||||
M.weeks_in_year = function(year)
|
M.weeks_in_year = function(year)
|
||||||
local d = 0
|
local d = 0
|
||||||
local dy = M.dow_for_year(year) == 4 -- current year ends Thursday
|
local dy = M.dow_for_year(year) == 4 -- current year ends Thursday
|
||||||
local dyy = M.dow_for_year(year - 1) == 3 -- previous year ends Wednesday
|
local dyy = M.dow_for_year(year - 1) == 3 -- previous year ends Wednesday
|
||||||
if dy or dyy then
|
if dy or dyy then
|
||||||
d = 1
|
d = 1
|
||||||
end
|
end
|
||||||
return 52 + d
|
return 52 + d
|
||||||
end
|
end
|
||||||
|
|
||||||
M.days_in_year = function(year)
|
M.days_in_year = function(year)
|
||||||
local t = os.time({ year = year, month = 12, day = 31 })
|
local t = os.time({ year = year, month = 12, day = 31 })
|
||||||
return os.date("*t", t).yday
|
return os.date("*t", t).yday
|
||||||
end
|
end
|
||||||
|
|
||||||
M.date_from_doy = function(year, doy)
|
M.date_from_doy = function(year, doy)
|
||||||
local ret = {
|
local ret = {
|
||||||
year = year,
|
year = year,
|
||||||
month = 1,
|
month = 1,
|
||||||
day = doy,
|
day = doy,
|
||||||
}
|
}
|
||||||
-- january is clear immediately
|
-- january is clear immediately
|
||||||
if doy < 32 then
|
if doy < 32 then
|
||||||
return ret
|
return ret
|
||||||
end
|
|
||||||
|
|
||||||
local dmap = {
|
|
||||||
[1] = 31,
|
|
||||||
[2] = 28, -- will be fixed further down
|
|
||||||
[3] = 31,
|
|
||||||
[4] = 30,
|
|
||||||
[5] = 31,
|
|
||||||
[6] = 30,
|
|
||||||
[7] = 31,
|
|
||||||
[8] = 31,
|
|
||||||
[9] = 30,
|
|
||||||
[10] = 31,
|
|
||||||
[11] = 30,
|
|
||||||
[12] = 31,
|
|
||||||
}
|
|
||||||
if M.days_in_year(year) == 366 then
|
|
||||||
dmap[2] = 29
|
|
||||||
end
|
|
||||||
|
|
||||||
for month, d in pairs(dmap) do
|
|
||||||
doy = doy - d
|
|
||||||
if doy < 0 then
|
|
||||||
ret.day = doy + d
|
|
||||||
ret.month = month
|
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return ret -- unreachable if input values are sane
|
local dmap = {
|
||||||
|
[1] = 31,
|
||||||
|
[2] = 28, -- will be fixed further down
|
||||||
|
[3] = 31,
|
||||||
|
[4] = 30,
|
||||||
|
[5] = 31,
|
||||||
|
[6] = 30,
|
||||||
|
[7] = 31,
|
||||||
|
[8] = 31,
|
||||||
|
[9] = 30,
|
||||||
|
[10] = 31,
|
||||||
|
[11] = 30,
|
||||||
|
[12] = 31,
|
||||||
|
}
|
||||||
|
if M.days_in_year(year) == 366 then
|
||||||
|
dmap[2] = 29
|
||||||
|
end
|
||||||
|
|
||||||
|
for month, d in pairs(dmap) do
|
||||||
|
doy = doy - d
|
||||||
|
if doy < 0 then
|
||||||
|
ret.day = doy + d
|
||||||
|
ret.month = month
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret -- unreachable if input values are sane
|
||||||
end
|
end
|
||||||
|
|
||||||
-- the algo on wikipedia seems wrong, so we opt for full-blown luadate
|
-- the algo on wikipedia seems wrong, so we opt for full-blown luadate
|
||||||
M.isoweek_to_date = function(year, isoweek)
|
M.isoweek_to_date = function(year, isoweek)
|
||||||
local ret = date(year .. "-W" .. string.format("%02d", isoweek) .. "-1")
|
local ret = date(year .. "-W" .. string.format("%02d", isoweek) .. "-1")
|
||||||
return {
|
return {
|
||||||
year = ret:getyear(),
|
year = ret:getyear(),
|
||||||
month = ret:getmonth(),
|
month = ret:getmonth(),
|
||||||
day = ret:getday(),
|
day = ret:getday(),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_isoweek(year, isoweek, ydate)
|
local function check_isoweek(year, isoweek, ydate)
|
||||||
print("*********** KW " .. isoweek .. " " .. year .. ": ")
|
print("*********** KW " .. isoweek .. " " .. year .. ": ")
|
||||||
-- local ret = M.weeknumber_to_date(year, isoweek)
|
-- local ret = M.weeknumber_to_date(year, isoweek)
|
||||||
local ret = M.isoweek_to_date(year, isoweek)
|
local ret = M.isoweek_to_date(year, isoweek)
|
||||||
local result = ret.year == ydate.year
|
local result = ret.year == ydate.year
|
||||||
and ret.month == ydate.month
|
and ret.month == ydate.month
|
||||||
and ret.day == ydate.day
|
and ret.day == ydate.day
|
||||||
print(
|
print(
|
||||||
ret.year
|
ret.year
|
||||||
.. "-"
|
.. "-"
|
||||||
.. ret.month
|
.. ret.month
|
||||||
.. "-"
|
.. "-"
|
||||||
.. ret.day
|
.. ret.day
|
||||||
.. " == "
|
.. " == "
|
||||||
.. ydate.year
|
.. ydate.year
|
||||||
.. "-"
|
.. "-"
|
||||||
.. ydate.month
|
.. ydate.month
|
||||||
.. "-"
|
.. "-"
|
||||||
.. ydate.day
|
.. ydate.day
|
||||||
.. " : "
|
.. " : "
|
||||||
.. tostring(result)
|
.. tostring(result)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run_tests = function()
|
M.run_tests = function()
|
||||||
print(check_isoweek(2020, 1, { year = 2019, month = 12, day = 30 })) -- 30.12.2019
|
print(check_isoweek(2020, 1, { year = 2019, month = 12, day = 30 })) -- 30.12.2019
|
||||||
print(check_isoweek(2020, 52, { year = 2020, month = 12, day = 21 })) -- 21.12.2020
|
print(check_isoweek(2020, 52, { year = 2020, month = 12, day = 21 })) -- 21.12.2020
|
||||||
print(check_isoweek(2020, 53, { year = 2020, month = 12, day = 28 })) -- 28.12.2020
|
print(check_isoweek(2020, 53, { year = 2020, month = 12, day = 28 })) -- 28.12.2020
|
||||||
print(check_isoweek(2021, 1, { year = 2021, month = 1, day = 4 })) -- 4.1.2020
|
print(check_isoweek(2021, 1, { year = 2021, month = 1, day = 4 })) -- 4.1.2020
|
||||||
print(check_isoweek(2021, 52, { year = 2021, month = 12, day = 27 })) -- 27.12.2021
|
print(check_isoweek(2021, 52, { year = 2021, month = 12, day = 27 })) -- 27.12.2021
|
||||||
print(check_isoweek(2022, 1, { year = 2022, month = 1, day = 3 })) -- 3.1.2022
|
print(check_isoweek(2022, 1, { year = 2022, month = 1, day = 3 })) -- 3.1.2022
|
||||||
end
|
end
|
||||||
|
|
||||||
-- M.run_tests()
|
-- M.run_tests()
|
||||||
|
|||||||
Reference in New Issue
Block a user