From 6138ff7096bc50f0b6b40b607196232e1b90d6b6 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sun, 5 Jun 2022 13:35:53 +0200 Subject: [PATCH] fix(nav-file): bufnr failure when trying to create the buffer I'm not perfectly sure if this should be upstreamed, but seems like passing true to bufnr `create` argument now fails. This fixes this issue by adding a new buffer with bufadd when the buffer does not exist in the buffer list. --- lua/harpoon/ui.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index db880b7..fcb310b 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -155,6 +155,15 @@ function M.on_menu_save() Marked.set_mark_list(get_menu_items()) end +local function get_or_create_buffer(filename) + local buf_exists = vim.fn.bufexists(filename) ~= 0 + if buf_exists then + return vim.fn.bufnr(filename) + end + + return vim.fn.bufadd(filename) +end + function M.nav_file(id) log.trace("nav_file(): Navigating to", id) local idx = Marked.get_index_of(id) @@ -168,7 +177,7 @@ function M.nav_file(id) if filename:sub(1, 1) ~= "/" then filename = vim.loop.cwd() .. "/" .. mark.filename end - local buf_id = vim.fn.bufnr(filename, true) + local buf_id = get_or_create_buffer(filename) local set_row = not vim.api.nvim_buf_is_loaded(buf_id) vim.api.nvim_set_current_buf(buf_id)