Created
September 20, 2024 19:05
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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