Skip to content

Commit

Permalink
fixing cmd, scaffolds
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 15, 2024
1 parent f0cbf8a commit e027062
Show file tree
Hide file tree
Showing 20 changed files with 553 additions and 536 deletions.
4 changes: 2 additions & 2 deletions lua/down/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ end
--- @param cfg? table A config that reflects the structure of down.config.user.setup["init.name"].config
function Mod.load_mod_as_dependency(modn, parent_mod, cfg)
if Mod.load_mod(modn, cfg) and Mod.is_mod_loaded(parent_mod) then
Mod.loaded_mod[parent_mod].required[modn] = Mod.get_mod_config(modn)
Mod.loaded_mod[parent_mod].required[modn] = Mod.mod_config(modn)
end
end

Expand All @@ -461,7 +461,7 @@ end
--- Returns the init.config table if the init is loaded
--- @param modn string The name of the init to retrieve (init must be loaded)
--- @return table?
function Mod.get_mod_config(modn)
function Mod.mod_config(modn)
if not Mod.is_mod_loaded(modn) then
log.trace(
"Attempt to get init config with name"
Expand Down
4 changes: 2 additions & 2 deletions lua/down/mod/cmd/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ M.data = {
if #args == 0 or argument_count < ref.min_args then
local completions = M.data.data.generate_completions(
_,
table.concat({ "down ", data.args, " " })
table.concat({ "Down ", data.args, " " })
)
M.data.data.select_next_cmd_arg(data.args, completions)
return
Expand Down Expand Up @@ -230,7 +230,7 @@ M.data = {
---@param qargs table #A string of arguments previously supplied to the down command
---@param choices table #all possible choices for the next argument
select_next_cmd_arg = function(qargs, choices)
local current = table.concat({ "down ", qargs })
local current = table.concat({ "Down ", qargs })

local query

Expand Down
158 changes: 79 additions & 79 deletions lua/down/mod/data/log/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local M = mod.create("data.log")
M.setup = function()
if M.config.strategies[M.config.strategy] then
M.config.strategy =
M.config.strategies[M.config.strategy]
M.config.strategies[M.config.strategy]
end

-- mod.await("cmd", function(cmd)
Expand Down Expand Up @@ -102,7 +102,7 @@ M.data = {
open_log = function(time, custom_date)
-- TODO(vhyrro): Change this to use down dates!
local workspace = M.config.workspace
or M.required["workspace"].get_current_workspace()[1]
or M.required["workspace"].get_current_workspace()[1]
local workspace_path = M.required["workspace"].get_workspace(workspace)
local folder_name = M.config.log_folder
local template_name = M.config.template_name
Expand All @@ -124,8 +124,8 @@ M.data = {

local path = os.date(
type(M.config.strategy) == "function"
and M.config.strategy(os.date("*t", time))
or M.config.strategy,
and M.config.strategy(os.date("*t", time))
or M.config.strategy,
time
)

Expand All @@ -144,20 +144,20 @@ M.data = {
)

if
not log_file_exists
and M.config.use_template
and M.required["workspace"].file_exists(
workspace_path .. "/" .. folder_name .. "/" .. template_name
)
not log_file_exists
and M.config.use_template
and M.required["workspace"].file_exists(
workspace_path .. "/" .. folder_name .. "/" .. template_name
)
then
vim.cmd(
"$read "
.. workspace_path
.. "/"
.. folder_name
.. "/"
.. template_name
.. "| silent! w"
.. workspace_path
.. "/"
.. folder_name
.. "/"
.. template_name
.. "| silent! w"
)
end
end,
Expand Down Expand Up @@ -201,15 +201,15 @@ M.data = {
--- Opens the toc file
open_toc = function()
local workspace = M.config.workspace
or M.required["workspace"].get_current_workspace()[1]
local index = mod.get_mod_config("workspace").index
or M.required["workspace"].get_current_workspace()[1]
local index = mod.mod_config("workspace").index
local folder_name = M.config.log_folder

-- If the toc exists, open it, if not, create it
if
M.required["workspace"].file_exists(
folder_name .. config.pathsep .. index
)
M.required["workspace"].file_exists(
folder_name .. config.pathsep .. index
)
then
M.required["workspace"].open_file(
workspace,
Expand All @@ -223,8 +223,8 @@ M.data = {
--- Creates or updates the toc file
create_toc = function()
local workspace = M.config.workspace
or M.required["workspace"].get_current_workspace()[1]
local index = mod.get_mod_config("workspace").index
or M.required["workspace"].get_current_workspace()[1]
local index = mod.mod_config("workspace").index
local workspace_path = M.required["workspace"].get_workspace(workspace)
local workspace_name_for_link = M.config.workspace or ""
local folder_name = M.config.log_folder
Expand All @@ -238,10 +238,10 @@ M.data = {
path = path or ""
local handle = vim.loop.fs_scandir(
workspace_path
.. config.pathsep
.. folder_name
.. config.pathsep
.. path
.. config.pathsep
.. folder_name
.. config.pathsep
.. path
)

if type(handle) ~= "userdata" then
Expand All @@ -263,10 +263,10 @@ M.data = {
local get_title = function(file)
local buffer = vim.fn.bufadd(
workspace_path
.. config.pathsep
.. folder_name
.. config.pathsep
.. file
.. config.pathsep
.. folder_name
.. config.pathsep
.. file
)
local meta = M.required["workspace"].get_document_metadata(buffer)
return meta.title
Expand Down Expand Up @@ -306,7 +306,7 @@ M.data = {

if mtype == "directory" then
local months_handle =
get_fs_handle(name .. config.pathsep .. mname)
get_fs_handle(name .. config.pathsep .. mname)
while true do
-- dname is the day
local dname, dtype = vim.loop.fs_scandir_next(months_handle)
Expand All @@ -324,10 +324,10 @@ M.data = {
-- Get the title from the metadata, else, it just base to the name of the file
local title = get_title(
name
.. config.pathsep
.. mname
.. config.pathsep
.. dname
.. config.pathsep
.. mname
.. config.pathsep
.. dname
) or file[1]

-- Insert a new entry
Expand All @@ -336,16 +336,16 @@ M.data = {
tonumber(mname),
tonumber(file[1]),
"{:$"
.. workspace_name_for_link
.. config.pathsep
.. M.config.log_folder
.. config.pathsep
.. name
.. config.pathsep
.. mname
.. config.pathsep
.. file[1]
.. ":}",
.. workspace_name_for_link
.. config.pathsep
.. M.config.log_folder
.. config.pathsep
.. name
.. config.pathsep
.. mname
.. config.pathsep
.. file[1]
.. ":}",
title,
})
end)
Expand Down Expand Up @@ -379,12 +379,12 @@ M.data = {
parts[2],
parts[3],
"{:$"
.. workspace_name_for_link
.. config.pathsep
.. M.config.log_folder
.. config.pathsep
.. file[1]
.. ":}",
.. workspace_name_for_link
.. config.pathsep
.. M.config.log_folder
.. config.pathsep
.. file[1]
.. ":}",
title,
})
end)
Expand All @@ -394,34 +394,34 @@ M.data = {
vim.schedule(function()
-- Gets a base format for the entries
local format = M.config.toc_format
or function(entries)
local months_text = M.data.months
-- Convert the entries into a certain format to be written
local output = {}
local current_year
local current_month
for _, entry in ipairs(entries) do
-- Don't print the year and month if they haven't changed
if not current_year or current_year < entry[1] then
current_year = entry[1]
current_month = nil
table.insert(output, "* " .. current_year)
end
if not current_month or current_month < entry[2] then
current_month = entry[2]
table.insert(output, "** " .. months_text[current_month])
or function(entries)
local months_text = M.data.months
-- Convert the entries into a certain format to be written
local output = {}
local current_year
local current_month
for _, entry in ipairs(entries) do
-- Don't print the year and month if they haven't changed
if not current_year or current_year < entry[1] then
current_year = entry[1]
current_month = nil
table.insert(output, "* " .. current_year)
end
if not current_month or current_month < entry[2] then
current_month = entry[2]
table.insert(output, "** " .. months_text[current_month])
end

-- Prints the file link
table.insert(
output,
" " .. entry[4] .. string.format("[%s]", entry[5])
)
end

-- Prints the file link
table.insert(
output,
" " .. entry[4] .. string.format("[%s]", entry[5])
)
return output
end

return output
end

M.required["workspace"].create_file(
folder_name .. config.pathsep .. index,
workspace or M.required["workspace"].get_current_workspace()[1]
Expand Down Expand Up @@ -463,10 +463,10 @@ M.on = function(event)
M.data.open_log(
nil,
string.format("%04d", osdate.year)
.. "-"
.. string.format("%02d", osdate.month)
.. "-"
.. string.format("%02d", osdate.day)
.. "-"
.. string.format("%02d", osdate.month)
.. "-"
.. string.format("%02d", osdate.day)
)
end),
})
Expand Down
Loading

0 comments on commit e027062

Please sign in to comment.