Remove unused personal modules: zk, journal, taskwarrior, TLA+
These aren't being actively used. Zk and journal are vault-specific (~/Documents/Dane's Vault paths hardcoded). Taskwarrior was already commented out. TLA+ is research tooling that belongs in the FRET project, not the base editor config.
This commit is contained in:
parent
e1915f2d7b
commit
611def5b2c
@ -1,5 +1,4 @@
|
||||
vim.g.dap_virtual_text = false
|
||||
vim.g.tlaplus_mappings_enable = true
|
||||
vim.env.PATH = vim.env.PATH .. ":/Users/danesabo/.ghcup/bin"
|
||||
vim.g.loaded_python3_provider = 1
|
||||
vim.g.python3_host_prog = vim.fn.expand "~/.config/nvim/nvim_venv/bin/python"
|
||||
@ -8,8 +7,5 @@ vim.opt.updatetime = 1000 -- 1 second delay for CursorHold events
|
||||
vim.o.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions"
|
||||
|
||||
require "custom.language_specific_commands.cadquery"
|
||||
require "custom.zk"
|
||||
require "custom.git_quickpush"
|
||||
require "custom.journal"
|
||||
-- require "custom.taskwarrior" -- replaced by openclaw agent
|
||||
print "Custom init settings loaded."
|
||||
|
||||
@ -1,151 +0,0 @@
|
||||
-- === Journal helpers ===
|
||||
local journal_dir = vim.fn.expand "~/Documents/Dane's Vault/Writing/Journal"
|
||||
|
||||
-- ---------- utilities ----------
|
||||
local function ensure_dir(path)
|
||||
vim.fn.mkdir(path, "p")
|
||||
end
|
||||
|
||||
local function iso_utc()
|
||||
return os.date "!%Y-%m-%dT%H:%M:%SZ"
|
||||
end
|
||||
|
||||
local function write_if_missing(path, lines)
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
local fh = io.open(path, "w")
|
||||
if not fh then
|
||||
vim.notify("Failed to create file at " .. path, vim.log.levels.ERROR)
|
||||
return false
|
||||
end
|
||||
fh:write(table.concat(lines, "\n"))
|
||||
fh:close()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- ---------- :JrnlNew ----------
|
||||
local function new_journal_note()
|
||||
local timestamp = os.date "%Y%m%d-%H%M%S"
|
||||
local date_title = os.date "%A, %B %d, %Y - %I:%M %p"
|
||||
local filename = "JRNL-" .. timestamp .. ".md"
|
||||
|
||||
ensure_dir(journal_dir)
|
||||
local path = journal_dir .. "/" .. filename
|
||||
|
||||
local created = iso_utc()
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: JRNL-" .. timestamp,
|
||||
"title: " .. date_title,
|
||||
"type: journal",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"tags: [journal]",
|
||||
"---",
|
||||
"",
|
||||
"# " .. date_title,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
vim.cmd "normal! Go"
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------- :JrnlCompile ----------
|
||||
local function compile_journal()
|
||||
-- Change to journal directory
|
||||
local original_dir = vim.fn.getcwd()
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(journal_dir))
|
||||
|
||||
-- Find journal files using simple glob in current directory
|
||||
local journal_files = vim.fn.glob("JRNL-*.md", false, true)
|
||||
|
||||
if #journal_files == 0 then
|
||||
vim.notify("No journal entries found", vim.log.levels.WARN)
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(original_dir))
|
||||
return
|
||||
end
|
||||
|
||||
-- Read config
|
||||
local config_file = "journal_config.txt"
|
||||
if vim.fn.filereadable(config_file) == 0 then
|
||||
local default_config = {
|
||||
"# Journal Config",
|
||||
"pdf-engine=xelatex",
|
||||
"V geometry:margin=1in",
|
||||
"V fontsize=11pt",
|
||||
"toc",
|
||||
"V title=My Journal",
|
||||
"V author=Dane",
|
||||
"V date=" .. os.date "%B %Y",
|
||||
}
|
||||
local fh = io.open(config_file, "w")
|
||||
if fh then
|
||||
fh:write(table.concat(default_config, "\n"))
|
||||
fh:close()
|
||||
vim.notify("Created journal config file", vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
|
||||
-- Parse config
|
||||
local config_args = {}
|
||||
local fh = io.open(config_file, "r")
|
||||
if fh then
|
||||
for line in fh:lines() do
|
||||
local trimmed = line:match "^%s*(.-)%s*$"
|
||||
if trimmed ~= "" and not trimmed:match "^#" then
|
||||
if trimmed:match "^V " then
|
||||
local var_content = trimmed:match "^V (.+)"
|
||||
table.insert(config_args, "-V")
|
||||
table.insert(config_args, var_content)
|
||||
else
|
||||
table.insert(config_args, "--" .. trimmed)
|
||||
end
|
||||
end
|
||||
end
|
||||
fh:close()
|
||||
end
|
||||
|
||||
-- Sort files
|
||||
table.sort(journal_files)
|
||||
|
||||
-- Build command as table to avoid shell escaping issues
|
||||
local cmd_parts = { "pandoc" }
|
||||
|
||||
-- Add input files
|
||||
for _, file in ipairs(journal_files) do
|
||||
table.insert(cmd_parts, file)
|
||||
end
|
||||
|
||||
-- Add config args
|
||||
for _, arg in ipairs(config_args) do
|
||||
table.insert(cmd_parts, arg)
|
||||
end
|
||||
|
||||
-- Add output
|
||||
table.insert(cmd_parts, "-o")
|
||||
table.insert(cmd_parts, "compiled_journal.pdf")
|
||||
|
||||
vim.notify("Compiling " .. #journal_files .. " journal entries...", vim.log.levels.INFO)
|
||||
|
||||
-- Run pandoc using vim.system (avoids shell entirely)
|
||||
local result = vim.system(cmd_parts):wait()
|
||||
|
||||
-- Return to original directory
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(original_dir))
|
||||
|
||||
if result.code == 0 then
|
||||
vim.notify("Journal compiled successfully!", vim.log.levels.INFO)
|
||||
else
|
||||
local error_msg = result.stderr or "Unknown error"
|
||||
vim.notify("Compilation failed: " .. error_msg, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("JrnlNew", new_journal_note, { desc = "Create new journal entry" })
|
||||
vim.api.nvim_create_user_command("JrnlCompile", compile_journal, { desc = "Compile journal to PDF" })
|
||||
|
||||
vim.keymap.set("n", "<leader>jn", ":JrnlNew<CR>", { desc = "Journal: New entry" })
|
||||
vim.keymap.set("n", "<leader>jc", ":JrnlCompile<CR>", { desc = "Journal: Compile to PDF" })
|
||||
@ -89,23 +89,6 @@ local plugins = {
|
||||
return M
|
||||
end,
|
||||
},
|
||||
{
|
||||
"susliko/tla.nvim",
|
||||
ft = { "tla" },
|
||||
config = function()
|
||||
require("tla").setup {
|
||||
java_executable = "/usr/bin/java",
|
||||
java_opts = { "-XX:+UseParallelGC" },
|
||||
}
|
||||
end,
|
||||
},
|
||||
{
|
||||
"florentc/vim-tla",
|
||||
ft = { "tla" },
|
||||
-- Optional: specify events or commands for lazy loading
|
||||
event = "BufRead",
|
||||
cmd = { "TLAPlusCommand" },
|
||||
},
|
||||
{
|
||||
"rmagatti/auto-session",
|
||||
lazy = false,
|
||||
|
||||
@ -1,280 +0,0 @@
|
||||
-- Taskwarrior integration for Neovim with clean notifications
|
||||
-- Add this to your ~/.config/nvim/init.lua or create a separate plugin file
|
||||
|
||||
-- Helper function for clean error handling with notifications
|
||||
local function run_task_command(cmd, success_msg, error_prefix)
|
||||
local result = vim.fn.system(cmd)
|
||||
if vim.v.shell_error == 0 then
|
||||
if success_msg then
|
||||
vim.notify(success_msg, vim.log.levels.INFO)
|
||||
end
|
||||
return true, result
|
||||
else
|
||||
vim.notify((error_prefix or "Error") .. ": " .. vim.trim(result), vim.log.levels.ERROR)
|
||||
return false, result
|
||||
end
|
||||
end
|
||||
|
||||
-- Basic task management commands
|
||||
vim.api.nvim_create_user_command("TaskAdd", function(opts)
|
||||
local task_desc = opts.args
|
||||
if task_desc == "" then
|
||||
task_desc = vim.fn.input "Task description: "
|
||||
end
|
||||
if task_desc ~= "" then
|
||||
run_task_command("task add " .. task_desc, "Task added successfully", "Error adding task")
|
||||
end
|
||||
end, { nargs = "*", desc = "Add a new task" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskList", function()
|
||||
local success, output = run_task_command("task list", nil, "Error listing tasks")
|
||||
if success then
|
||||
vim.cmd "new"
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(output, "\n"))
|
||||
vim.bo.buftype = "nofile"
|
||||
vim.bo.bufhidden = "wipe"
|
||||
vim.bo.modifiable = false
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
-- Set a descriptive buffer name
|
||||
vim.api.nvim_buf_set_name(0, "TaskWarrior List (All)")
|
||||
end
|
||||
end, { desc = "Show all pending tasks in new buffer" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskNext", function()
|
||||
local success, output = run_task_command("task next limit:10", nil, "Error getting next tasks")
|
||||
if success then
|
||||
local lines = vim.split(vim.trim(output), "\n")
|
||||
-- Filter out empty lines
|
||||
local clean_lines = {}
|
||||
for _, line in ipairs(lines) do
|
||||
if line ~= "" and not line:match "^%s*$" then
|
||||
table.insert(clean_lines, line)
|
||||
end
|
||||
end
|
||||
|
||||
if #clean_lines > 0 then
|
||||
-- Create floating window for next tasks
|
||||
local width = math.min(math.max(80, vim.o.columns - 20), 120)
|
||||
local height = math.min(#clean_lines + 2, 25)
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, clean_lines)
|
||||
|
||||
local opts = {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
title = " Next Tasks ",
|
||||
title_pos = "center",
|
||||
}
|
||||
|
||||
vim.api.nvim_open_win(buf, true, opts)
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = buf })
|
||||
vim.keymap.set("n", "<Esc>", "<cmd>close<cr>", { buffer = buf })
|
||||
else
|
||||
vim.notify("No pending tasks", vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
end, { desc = "Show next 10 highest priority tasks in floating window" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskEdit", function(opts)
|
||||
local task_id = opts.args
|
||||
if task_id == "" then
|
||||
task_id = vim.fn.input "Task ID to edit: "
|
||||
end
|
||||
if task_id ~= "" then
|
||||
run_task_command("task " .. task_id .. " edit", "Edited task " .. task_id, "Error editing task")
|
||||
end
|
||||
end, { nargs = "?", desc = "Edit a task by ID" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskDone", function(opts)
|
||||
local task_id = opts.args
|
||||
if task_id == "" then
|
||||
task_id = vim.fn.input "Task ID to complete: "
|
||||
end
|
||||
if task_id ~= "" then
|
||||
run_task_command("task " .. task_id .. " done", "Task " .. task_id .. " completed!", "Error completing task")
|
||||
end
|
||||
end, { nargs = "?", desc = "Mark task as done" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskModify", function(opts)
|
||||
local args = vim.split(opts.args, " ", { trimempty = true })
|
||||
if #args < 2 then
|
||||
local task_id = vim.fn.input "Task ID: "
|
||||
local modification = vim.fn.input "Modification (e.g., 'priority:H', '+urgent'): "
|
||||
if task_id ~= "" and modification ~= "" then
|
||||
run_task_command(
|
||||
"task " .. task_id .. " modify " .. modification,
|
||||
"Modified task " .. task_id,
|
||||
"Error modifying task"
|
||||
)
|
||||
end
|
||||
else
|
||||
local task_id = args[1]
|
||||
local modification = table.concat(args, " ", 2)
|
||||
run_task_command(
|
||||
"task " .. task_id .. " modify " .. modification,
|
||||
"Modified task " .. task_id,
|
||||
"Error modifying task"
|
||||
)
|
||||
end
|
||||
end, { nargs = "*", desc = "Modify a task" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskStart", function(opts)
|
||||
local task_id = opts.args
|
||||
if task_id == "" then
|
||||
task_id = vim.fn.input "Task ID to start: "
|
||||
end
|
||||
if task_id ~= "" then
|
||||
run_task_command("task " .. task_id .. " start", "Started task " .. task_id, "Error starting task")
|
||||
end
|
||||
end, { nargs = "?", desc = "Start working on a task" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskStop", function(opts)
|
||||
local task_id = opts.args
|
||||
if task_id == "" then
|
||||
-- If no ID provided, stop the active task
|
||||
local success, active_output = run_task_command("task +ACTIVE ids", nil, "Error finding active tasks")
|
||||
if success then
|
||||
local active_id = vim.trim(active_output)
|
||||
if active_id ~= "" then
|
||||
run_task_command("task " .. active_id .. " stop", "Stopped active task " .. active_id, "Error stopping task")
|
||||
else
|
||||
vim.notify("No active task to stop", vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
else
|
||||
run_task_command("task " .. task_id .. " stop", "Stopped task " .. task_id, "Error stopping task")
|
||||
end
|
||||
end, { nargs = "?", desc = "Stop working on a task" })
|
||||
|
||||
vim.api.nvim_create_user_command("TaskActive", function()
|
||||
local success, output = run_task_command("task +ACTIVE list", nil, "Error getting active tasks")
|
||||
if success then
|
||||
if vim.trim(output) == "" or output:match "No matches" then
|
||||
vim.notify("No active tasks", vim.log.levels.WARN)
|
||||
else
|
||||
vim.cmd "new"
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(output, "\n"))
|
||||
vim.bo.buftype = "nofile"
|
||||
vim.bo.bufhidden = "wipe"
|
||||
vim.bo.modifiable = false
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
end
|
||||
end
|
||||
end, { desc = "Show active tasks" })
|
||||
|
||||
-- Project and context commands
|
||||
vim.api.nvim_create_user_command("TaskProject", function(opts)
|
||||
local project = opts.args
|
||||
if project == "" then
|
||||
local success, output = run_task_command("task projects", nil, "Error listing projects")
|
||||
if success then
|
||||
vim.notify(output, vim.log.levels.INFO)
|
||||
end
|
||||
else
|
||||
local success, output = run_task_command("task project:" .. project .. " list", nil, "Error filtering by project")
|
||||
if success then
|
||||
vim.cmd "new"
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(output, "\n"))
|
||||
vim.bo.buftype = "nofile"
|
||||
vim.bo.bufhidden = "wipe"
|
||||
vim.bo.modifiable = false
|
||||
end
|
||||
end
|
||||
end, { nargs = "?", desc = "Show projects or filter by project" })
|
||||
|
||||
-- Advanced: Add task from visual selection
|
||||
vim.keymap.set("v", "<leader>ta", function()
|
||||
local start_pos = vim.fn.getpos "'<"
|
||||
local end_pos = vim.fn.getpos "'>"
|
||||
local lines = vim.api.nvim_buf_get_lines(0, start_pos[2] - 1, end_pos[2], false)
|
||||
local selected_text = table.concat(lines, " "):gsub("%s+", " ")
|
||||
if selected_text ~= "" then
|
||||
run_task_command("task add " .. selected_text, "Task added from selection", "Error adding task from selection")
|
||||
end
|
||||
end, { desc = "Add task from visual selection" })
|
||||
|
||||
-- Key mappings (using <leader>t prefix for taskwarrior)
|
||||
vim.keymap.set("n", "<leader>ta", ":TaskAdd<CR>", { desc = "Add task" })
|
||||
vim.keymap.set("n", "<leader>tl", ":TaskList<CR>", { desc = "List all tasks" })
|
||||
vim.keymap.set("n", "<leader>tn", ":TaskNext<CR>", { desc = "Show next 10 tasks" })
|
||||
vim.keymap.set("n", "<leader>te", ":TaskEdit<CR>", { desc = "Edit task" })
|
||||
vim.keymap.set("n", "<leader>td", ":TaskDone<CR>", { desc = "Mark task done" })
|
||||
vim.keymap.set("n", "<leader>tm", ":TaskModify<CR>", { desc = "Modify task" })
|
||||
vim.keymap.set("n", "<leader>tp", ":TaskProject<CR>", { desc = "Show projects" })
|
||||
vim.keymap.set("n", "<leader>tS", ":TaskStart<CR>", { desc = "Start task" })
|
||||
vim.keymap.set("n", "<leader>tT", ":TaskStop<CR>", { desc = "Stop task" })
|
||||
vim.keymap.set("n", "<leader>tA", ":TaskActive<CR>", { desc = "Show active tasks" })
|
||||
|
||||
-- Quick shortcuts for common modifications
|
||||
vim.keymap.set("n", "<leader>tH", function()
|
||||
local task_id = vim.fn.input "Task ID for high priority: "
|
||||
if task_id ~= "" then
|
||||
run_task_command(
|
||||
"task " .. task_id .. " modify priority:H",
|
||||
"Set task " .. task_id .. " to high priority",
|
||||
"Error setting priority"
|
||||
)
|
||||
end
|
||||
end, { desc = "Set task to high priority" })
|
||||
|
||||
vim.keymap.set("n", "<leader>tu", function()
|
||||
local task_id = vim.fn.input "Task ID to add urgent tag: "
|
||||
if task_id ~= "" then
|
||||
run_task_command(
|
||||
"task " .. task_id .. " modify +urgent",
|
||||
"Added urgent tag to task " .. task_id,
|
||||
"Error adding urgent tag"
|
||||
)
|
||||
end
|
||||
end, { desc = "Add urgent tag to task" })
|
||||
|
||||
-- Show task summary in floating window
|
||||
vim.api.nvim_create_user_command("TaskSummary", function()
|
||||
local success, output = run_task_command("task summary", nil, "Error getting task summary")
|
||||
if success then
|
||||
local lines = vim.split(output, "\n")
|
||||
|
||||
-- Create floating window
|
||||
local width = 60
|
||||
local height = math.min(#lines + 2, 20)
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
|
||||
local opts = {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
title = " Task Summary ",
|
||||
title_pos = "center",
|
||||
}
|
||||
|
||||
vim.api.nvim_open_win(buf, true, opts)
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = buf })
|
||||
end
|
||||
end, { desc = "Show task summary in floating window" })
|
||||
|
||||
vim.keymap.set("n", "<leader>ts", ":TaskSummary<CR>", { desc = "Show task summary" })
|
||||
|
||||
-- Use a timer to show the load message after everything initializes
|
||||
vim.defer_fn(function()
|
||||
vim.notify("Taskwarrior integration loaded! Use <leader>t* commands", vim.log.levels.INFO)
|
||||
end, 100)
|
||||
@ -1,385 +0,0 @@
|
||||
-- === Zettelkasten helpers (custom.zk) ===
|
||||
-- Root + folder layout (with spaces, as requested)
|
||||
local zk_root = vim.fn.expand "~/Documents/Dane's Vault/Zettelkasten"
|
||||
local fleeting_dir = zk_root .. "/Fleeting Notes"
|
||||
local hub_dir = zk_root .. "/Hub Notes"
|
||||
local permanent_dir = zk_root .. "/Permanent Notes"
|
||||
local daily_dir = fleeting_dir .. "/Daily" -- assumption: dailies live under Fleeting Notes/Daily
|
||||
|
||||
-- ---------- utilities ----------
|
||||
local function slugify(s)
|
||||
s = (s or ""):lower()
|
||||
s = s
|
||||
:gsub("[^%w%s%-]", "") -- keep letters, digits, space, dash
|
||||
:gsub("%s+", "-") -- spaces -> dash
|
||||
:gsub("%-+", "-") -- collapse dashes
|
||||
:gsub("^%-", "")
|
||||
:gsub("%-$", "")
|
||||
return s
|
||||
end
|
||||
|
||||
local function iso_utc()
|
||||
return os.date "!%Y-%m-%dT%H:%M:%SZ"
|
||||
end
|
||||
local function ensure_dir(path)
|
||||
vim.fn.mkdir(path, "p")
|
||||
end
|
||||
local function starts_with(s, prefix)
|
||||
return s:sub(1, #prefix) == prefix
|
||||
end
|
||||
|
||||
-- ---------- front-matter: update `modified:` on save ----------
|
||||
local function update_modified_in_buffer()
|
||||
local api, buf = vim.api, vim.api.nvim_get_current_buf()
|
||||
local path = vim.fn.expand "%:p"
|
||||
|
||||
-- Only touch Markdown in your ZK root
|
||||
if vim.bo[buf].filetype ~= "markdown" and not path:lower():match "%.md$" then
|
||||
return
|
||||
end
|
||||
if not starts_with(path, zk_root) then
|
||||
return
|
||||
end
|
||||
|
||||
local lines = api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
if #lines < 1 or lines[1] ~= "---" then
|
||||
return
|
||||
end
|
||||
|
||||
-- find closing '---'
|
||||
local fm_end
|
||||
for i = 2, math.min(#lines, 200) do
|
||||
if lines[i] == "---" then
|
||||
fm_end = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if not fm_end then
|
||||
return
|
||||
end
|
||||
|
||||
-- find or insert modified:
|
||||
local modified_idx
|
||||
for i = 2, fm_end - 1 do
|
||||
if lines[i]:match "^modified:%s" then
|
||||
modified_idx = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local now = "modified: " .. iso_utc()
|
||||
if modified_idx then
|
||||
if lines[modified_idx] ~= now then
|
||||
lines[modified_idx] = now
|
||||
api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
end
|
||||
else
|
||||
table.insert(lines, fm_end, now)
|
||||
api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*.md",
|
||||
callback = update_modified_in_buffer,
|
||||
desc = "ZK: auto-update YAML modified: on save",
|
||||
})
|
||||
|
||||
-- ---------- create file helper ----------
|
||||
local function write_if_missing(path, lines)
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
local fh = io.open(path, "w")
|
||||
if not fh then
|
||||
vim.notify("Failed to create file at " .. path, vim.log.levels.ERROR)
|
||||
return false
|
||||
end
|
||||
fh:write(table.concat(lines, "\n"))
|
||||
fh:close()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- ---------- :ZkNewPermanent ----------
|
||||
local function new_permanent_note(opts)
|
||||
local title = table.concat(opts.fargs or {}, " ")
|
||||
if title == "" then
|
||||
title = vim.fn.input "Permanent note title: "
|
||||
end
|
||||
if not title or title == "" then
|
||||
vim.notify("Aborted: empty title.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local id = os.date "%Y%m%d%H%M%S"
|
||||
local slug = slugify(title)
|
||||
local filename = string.format("%s-%s.md", id, slug)
|
||||
|
||||
ensure_dir(permanent_dir)
|
||||
local path = permanent_dir .. "/" .. filename
|
||||
|
||||
local created = iso_utc()
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: " .. id,
|
||||
"title: " .. title,
|
||||
"type: permanent",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"tags: []",
|
||||
"---",
|
||||
"",
|
||||
"# " .. title,
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command(
|
||||
"ZkNewPermanent",
|
||||
new_permanent_note,
|
||||
{ nargs = "*", desc = "Create a new permanent ZK note and open it" }
|
||||
)
|
||||
|
||||
-- ---------- :ZkNewDaily ----------
|
||||
-- Opens today's daily note if it exists; otherwise creates it (under Fleeting Notes/Daily).
|
||||
local function new_daily_note()
|
||||
local today = os.date "%Y-%m-%d"
|
||||
local title = "Daily — " .. today
|
||||
local fname = today .. ".md"
|
||||
|
||||
ensure_dir(daily_dir)
|
||||
local path = daily_dir .. "/" .. fname
|
||||
|
||||
local created = iso_utc()
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: " .. today, -- simple id for dailies
|
||||
"title: " .. title,
|
||||
"type: daily",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"tags: [daily]",
|
||||
"---",
|
||||
"",
|
||||
"# " .. title,
|
||||
"",
|
||||
"## Quick capture",
|
||||
"",
|
||||
"- ",
|
||||
"",
|
||||
"## Tasks",
|
||||
"",
|
||||
"- [ ] ",
|
||||
"",
|
||||
"## Notes",
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("ZkNewDaily", new_daily_note, { desc = "Open or create today's ZK daily note" })
|
||||
|
||||
-- ---------- :ZkNewHub ----------
|
||||
-- Hub/Structure note (MOC): great as an index/overview for a topic or project.
|
||||
-- File naming: HUB-YYYYMMDDHHMMSS-<slug>.md (easy to spot + sortable)
|
||||
local function new_hub_note(opts)
|
||||
local title = table.concat(opts.fargs or {}, " ")
|
||||
if title == "" then
|
||||
title = vim.fn.input "Hub note title: "
|
||||
end
|
||||
if not title or title == "" then
|
||||
vim.notify("Aborted: empty title.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local id = "HUB-" .. os.date "%Y%m%d%H%M%S"
|
||||
local slug = slugify(title)
|
||||
local filename = string.format("%s-%s.md", id, slug)
|
||||
|
||||
ensure_dir(hub_dir)
|
||||
local path = hub_dir .. "/" .. filename
|
||||
|
||||
local created = iso_utc()
|
||||
-- A practical hub template: overview, TOC, backlinks/related, and open questions.
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: " .. id,
|
||||
"title: " .. title,
|
||||
"type: hub",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"tags: [hub]",
|
||||
"aliases: []",
|
||||
"---",
|
||||
"",
|
||||
"# " .. title,
|
||||
"",
|
||||
"> Brief purpose/definition of this hub.",
|
||||
"",
|
||||
"## Overview",
|
||||
"",
|
||||
"- ",
|
||||
"",
|
||||
"## Contents (map of notes)",
|
||||
"",
|
||||
"- [[ ]] ",
|
||||
"- [[ ]] ",
|
||||
"- [[ ]] ",
|
||||
"",
|
||||
"## Permanent seeds (key ideas)",
|
||||
"",
|
||||
"- [[ ]] ",
|
||||
"",
|
||||
"## Related hubs",
|
||||
"",
|
||||
"- [[ ]] ",
|
||||
"",
|
||||
"## Sources / Literature",
|
||||
"",
|
||||
"- ",
|
||||
"",
|
||||
"## Open questions / Next actions",
|
||||
"",
|
||||
"- [ ] ",
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
end
|
||||
end
|
||||
-- ---------- :ZkNewLit ----------
|
||||
-- Lightweight Literature (three-pass) note creator.
|
||||
-- Files live under: Permanent Notes/Literature
|
||||
-- Naming: LIT-YYYYMMDDHHMMSS-<slug>.md
|
||||
local literature_dir = permanent_dir .. "/Literature Notes"
|
||||
|
||||
local function new_literature_note(opts)
|
||||
local title = table.concat(opts.fargs or {}, " ")
|
||||
if title == "" then
|
||||
title = vim.fn.input "Literature note title (paper title or handle): "
|
||||
end
|
||||
if not title or title == "" then
|
||||
vim.notify("Aborted: empty title.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local id = "LIT-" .. os.date "%Y%m%d%H%M%S"
|
||||
local slug = slugify(title)
|
||||
local filename = string.format("%s-%s.md", id, slug)
|
||||
|
||||
ensure_dir(literature_dir)
|
||||
local path = literature_dir .. "/" .. filename
|
||||
|
||||
local created = iso_utc()
|
||||
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: " .. id,
|
||||
"title: " .. title,
|
||||
"type: literature",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"citekey: ", -- just paste your Zotero citekey here
|
||||
"---",
|
||||
"",
|
||||
"# " .. title,
|
||||
"",
|
||||
"## First Pass",
|
||||
"**Category:** ",
|
||||
"",
|
||||
"**Context:** ",
|
||||
"",
|
||||
"**Correctness:** ",
|
||||
"",
|
||||
"**Contributions:** ",
|
||||
"",
|
||||
"**Clarity:** ",
|
||||
"",
|
||||
"## Second Pass",
|
||||
"**What is the main thrust?**",
|
||||
"",
|
||||
"**What is the supporting evidence?**",
|
||||
"",
|
||||
"**What are the key findings?**",
|
||||
"",
|
||||
"## Third Pass",
|
||||
"**Recreation Notes:**",
|
||||
"",
|
||||
"**Hidden Findings:**",
|
||||
"",
|
||||
"**Weak Points? Strong Points?**",
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command(
|
||||
"ZkNewLit",
|
||||
new_literature_note,
|
||||
{ nargs = "*", desc = "Create a new literature ZK note (three-pass template) and open it" }
|
||||
)
|
||||
|
||||
-- Keymap (optional): <leader>zl
|
||||
|
||||
vim.api.nvim_create_user_command(
|
||||
"ZkNewHub",
|
||||
new_hub_note,
|
||||
{ nargs = "*", desc = "Create a new hub (structure) note and open it" }
|
||||
)
|
||||
local thesis_dir = permanent_dir .. "/Thesis"
|
||||
|
||||
local function new_thesis_note(opts)
|
||||
local title = table.concat(opts.fargs or {}, " ")
|
||||
if title == "" then
|
||||
title = vim.fn.input "Thesis note title: "
|
||||
end
|
||||
if not title or title == "" then
|
||||
vim.notify("Aborted: empty title.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local id = "DR-" .. os.date "%Y%m%d%H%M%S"
|
||||
local slug = slugify(title)
|
||||
local filename = string.format("%s-%s.md", id, slug)
|
||||
|
||||
ensure_dir(thesis_dir)
|
||||
local path = thesis_dir .. "/" .. filename
|
||||
|
||||
local created = iso_utc()
|
||||
|
||||
local ok = write_if_missing(path, {
|
||||
"---",
|
||||
"id: " .. id,
|
||||
"title: " .. title,
|
||||
"type: thesis",
|
||||
"created: " .. created,
|
||||
"modified: " .. created,
|
||||
"tags: []",
|
||||
"---",
|
||||
"",
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command(
|
||||
"ZkNewThesis",
|
||||
new_thesis_note,
|
||||
{ nargs = "*", desc = "Create a new thesis ZK note and open it" }
|
||||
)
|
||||
-- ---------- keymaps ----------
|
||||
-- <leader>zn : new permanent
|
||||
-- <leader>zd : today's daily
|
||||
-- <leader>zh : new hub
|
||||
vim.keymap.set("n", "<leader>zn", ":ZkNewPermanent ", { desc = "ZK: New permanent note" })
|
||||
vim.keymap.set("n", "<leader>zd", ":ZkNewDaily<CR>", { desc = "ZK: Open/create today's daily" })
|
||||
vim.keymap.set("n", "<leader>zh", ":ZkNewHub ", { desc = "ZK: New hub (structure) note" })
|
||||
vim.keymap.set("n", "<leader>zl", ":ZkNewLit ", { desc = "ZK: New literature note" })
|
||||
vim.keymap.set("n", "<leader>zt", ":ZkNewThesis ", { desc = "ZK: New thesis note" })
|
||||
Loading…
x
Reference in New Issue
Block a user