diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-05-29 22:40:00 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-06-01 00:48:38 +0200 |
commit | 55577c7aa06b0d7e3e92d6a7c8f9de45557230e5 (patch) | |
tree | 844e6857e4cc0fcdbe76d97cca373f70eb579739 | |
parent | 36cbf084808b79c31219d7915d32a177c0372c66 (diff) |
nvim: Add support for ledger and timetrackingguix
-rw-r--r-- | nvim/nvim/init.lua | 4 | ||||
-rw-r--r-- | nvim/nvim/lua/ledger.lua | 48 |
2 files changed, 51 insertions, 1 deletions
diff --git a/nvim/nvim/init.lua b/nvim/nvim/init.lua index 672ea11..fd6d1eb 100644 --- a/nvim/nvim/init.lua +++ b/nvim/nvim/init.lua @@ -119,7 +119,8 @@ vim.api.nvim_create_autocmd({ "BufEnter" }, { require'nvim-treesitter.configs'.setup { -- A list of parser names, or "all" ensure_installed = { "c", "cpp", "python", "scheme", "javascript", "fennel", - "zig", "clojure", "vimdoc", "vim", "bash", "markdown", "markdown_inline" }, + "zig", "clojure", "vimdoc", "vim", "bash", "markdown", "markdown_inline", + "ledger"}, -- Install parsers synchronously (only applied to `ensure_installed`) sync_install = false, @@ -159,3 +160,4 @@ require 'highlight' require 'colors' require 'parens' require 'git' +require 'ledger' diff --git a/nvim/nvim/lua/ledger.lua b/nvim/nvim/lua/ledger.lua new file mode 100644 index 0000000..a6a5cd4 --- /dev/null +++ b/nvim/nvim/lua/ledger.lua @@ -0,0 +1,48 @@ +function clock (start_end, text) + -- start_end: is "i" or "o" + -- text: is the account + local entry = os.date (start_end .. " %Y/%m/%d %H:%M:%S " .. text) + vim.api.nvim_put ({entry}, "l", true, true) +end + + +function complete (arglead, cmdline, cursorpos) + local account_pattern = "^account (%S+)%s*$" + local entry_pattern = "^[iIoO] %d+/%d%d/%d%d %d%d:%d%d:%d%d (%S+)%s?.*$" + + local found = {} + for _,v in pairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do + _, _, account = string.find(v, account_pattern) + if not account then + _, _, account = string.find(v, entry_pattern) + end + if account and string.sub(account, 1, #arglead) == arglead then + if not found[account] then + found[account] = true + end + end + end + local suggestions = {} + for i,_ in pairs(found) do + table.insert(suggestions, i) + end + table.sort(suggestions) + return suggestions +end + +vim.api.nvim_create_user_command ('TimerStart', + function (opts) clock ("i", opts.fargs[1]) end, + { + desc="Start a ledger time entry", + nargs=1, + complete=complete + } +) +vim.api.nvim_create_user_command ('TimerStop', + function (opts) clock ("o", opts.fargs[1]) end, + { + desc="Stop a ledger time entry", + nargs=1, + complete=complete + } +) |