Skip to content

Instantly share code, notes, and snippets.

@belkarx
Created September 20, 2024 19:05
Show Gist options
  • Select an option

  • Save belkarx/dc4e346092cef9249f4fffb8c90a965e to your computer and use it in GitHub Desktop.

Select an option

Save belkarx/dc4e346092cef9249f4fffb8c90a965e to your computer and use it in GitHub Desktop.
create timestamps of every new line when journalling (for tracking the development of symptoms over time for example, or a low friction timestamped journal)
-- plugin/finished_line_logger.lua
local journal_file = os.getenv("HOME") .. "/nvim-journal.txt"
local function append_to_journal(line, timestamp)
local file = io.open(journal_file, "a")
if file then
file:write(string.format("%s|%s\n", line, timestamp))
file:close()
else
print("Error: Could not open journal file")
end
end
local last_line = ""
local last_line_num = 0
vim.api.nvim_create_autocmd({"CursorMovedI"}, {
pattern = {"*.tmd"},
callback = function()
local current_line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(0)
local current_line_num = cursor[1]
if current_line_num ~= last_line_num and last_line ~= "" then
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
append_to_journal(last_line, timestamp)
last_line = ""
end
last_line = current_line
last_line_num = current_line_num
end,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment