From 3919e3f88f0d1d3109ee33b538c3ebeb7b36cf71 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 24 Feb 2026 19:48:41 -0500 Subject: [PATCH] fix(buffer): replace indentexpr with dedicated o/O mappings Problem: setup_indentexpr always returned 0 because no task line starts with whitespace (the /ID/ prefix begins with /), so the return 2 branch was dead code. Pressing o or O opened a blank line at column 0 with no ID prefix, which the diff parser cannot recognise as a task. Solution: remove setup_indentexpr and M.get_indent() entirely; add M.open_line(above) which inserts a two-space stub line and enters insert mode at the end so the user types directly into the new task body. The diff layer already handles lines matching ^ .+ as new tasks. Add o and O buffer-local mappings in init.lua. --- lua/pending/buffer.lua | 26 +++++++++++--------------- lua/pending/init.lua | 6 ++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lua/pending/buffer.lua b/lua/pending/buffer.lua index bf598fc..93c0fd3 100644 --- a/lua/pending/buffer.lua +++ b/lua/pending/buffer.lua @@ -63,22 +63,19 @@ local function setup_syntax(bufnr) end) end ----@param bufnr integer -local function setup_indentexpr(bufnr) - vim.bo[bufnr].indentexpr = 'v:lua.require("pending.buffer").get_indent()' -end ----@return integer -function M.get_indent() - local lnum = vim.v.lnum - if lnum <= 1 then - return 0 +---@param above boolean +function M.open_line(above) + local bufnr = task_bufnr + if not bufnr or not vim.api.nvim_buf_is_valid(bufnr) then + return end - local prev = vim.fn.getline(lnum - 1) - if prev == '' or prev:match('^%S') then - return 0 - end - return 2 + local row = vim.api.nvim_win_get_cursor(0)[1] + local insert_row = above and (row - 1) or row + vim.bo[bufnr].modifiable = true + vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { ' ' }) + vim.api.nvim_win_set_cursor(0, { insert_row + 1, 2 }) + vim.cmd('startinsert!') end ---@return string @@ -222,7 +219,6 @@ function M.open() vim.api.nvim_buf_set_name(task_bufnr, 'pending://') set_buf_options(task_bufnr) - setup_indentexpr(task_bufnr) vim.api.nvim_set_current_buf(task_bufnr) set_win_options(vim.api.nvim_get_current_win()) diff --git a/lua/pending/init.lua b/lua/pending/init.lua index d03e454..86c1971 100644 --- a/lua/pending/init.lua +++ b/lua/pending/init.lua @@ -61,6 +61,12 @@ function M._setup_buf_mappings(bufnr) vim.keymap.set('n', 'U', function() M.undo_write() end, opts) + vim.keymap.set('n', 'o', function() + buffer.open_line(false) + end, opts) + vim.keymap.set('n', 'O', function() + buffer.open_line(true) + end, opts) end ---@param bufnr integer