From c933638fd306122d2059fc3d3153b807036b4fa9 Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Fri, 20 Oct 2023 16:27:56 +0200 Subject: [PATCH] README: Add get_bufnrs function for buffers under current git repo --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 4d0f561..e510794 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,38 @@ cmp.setup { ``` +##### Git repository buffers + +```lua +cmp.setup { + sources = { + { + name = 'buffer', + option = { + -- all buffers for files in the current git repository + get_bufnrs = function() + local bufs = {} + local out = vim.fn.system("git rev-parse --show-toplevel") + if vim.v.shell_error ~= 0 then -- use only current buffer if not in git repo + table.insert(bufs, vim.api.nvim_get_current_buf()) + else + local rootdir = string.sub(out, 1, -2) + for _, buf in pairs(vim.api.nvim_list_bufs()) do + + local filename = vim.api.nvim_buf_get_name(buf) + if filename:find(rootdir, 1, true) == 1 then + table.insert(bufs, buf) + end + end + end + return bufs + end + } + } + } +} + +``` ### indexing_interval (type: number)