summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2025-05-29 22:40:00 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2025-05-30 11:36:54 +0200
commit2c284f61a24e0df3927620aa93d509a251287078 (patch)
tree22bd25576c8dfc35cce3e6451bff0ad9e59df86f
parent36cbf084808b79c31219d7915d32a177c0372c66 (diff)
nvim: Add support for ledger and timetracking
-rw-r--r--nvim/nvim/init.lua4
-rw-r--r--nvim/nvim/lua/ledger.lua48
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..b8f273a
--- /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 pattern = "^[iIoO] %d%d%d%d/%d%d/%d%d %d%d:%d%d:%d%d (%S+)%s?.*$"
+ function table.contains(table, element)
+ for _, value in pairs(table) do
+ if value == element then
+ return true
+ end
+ end
+ return false
+ end
+
+
+ local lines = {}
+ for _,v in pairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
+ i, j, account = string.find(v, pattern)
+ if account and string.sub(account, 1, #arglead) == arglead then
+ if not table.contains(lines, account) then
+ table.insert(lines, account)
+ end
+ end
+ end
+ return lines
+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
+ }
+)