Skip to content

Commit

Permalink
README: Add get_bufnrs function for buffers under current git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rish987 authored and Rishikesh Hirendu Vaishnav committed Nov 18, 2023
1 parent 3022dbc commit c933638
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c933638

Please sign in to comment.