Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide current buffer #28

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lua/unclutter/tabline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,26 @@ function tabline.get_tab_label(buf)
end

--- Get all buffers to be displayed in the tabline
---@param hide_current boolean?
---@return table<number, number>
function tabline.list()
function tabline.list(hide_current)
hide_current = hide_current or false
local buffers = {}
local all_buffers = buffer.all()
local current_buffer = buffer.current()

for _, buf in ipairs(all_buffers) do
if
buffer.current() == buf -- keep current buffer
local is_current_buf = buf == current_buffer
local should_keep = is_current_buf -- keep current buffer
or tabline.is_buffer_kept(buf) -- keep buffers that are marked
or buffer.is_visible(buf) -- keep visible buffers
or not buffer.is_file(buf) -- keep non-file buffers
or #buffers < config.clean_after -- keep first n buffers (config)
then
table.insert(buffers, buf)

if should_keep then
if not is_current_buf or not hide_current then
table.insert(buffers, buf)
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion lua/unclutter/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ telescope.open = function(opts)
opts = opts or {}
opts = {
format = opts.format or "compact",
hide_current = opts.hide_current or false,
}

if not pcall(require, "telescope") then
print "You need to install telescope.nvim if you want to use this integration"
return
end

local tabline_buffers = require("unclutter.tabline").list()
local tabline_buffers = require("unclutter.tabline").list(opts.hide_current)

-- Sort the buffers by last used
table.sort(tabline_buffers, function(a, b)
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ unclutter.telescope { format = "cwd" } -- path/folder/file.js
unclutter.telescope { format = "filename" } -- file.js
```

You can also hide the current buffer in the list:

```lua
unclutter.telescope { hide_current = true } -- default: false
```

If you want to use the telescope integration without the tabline, you can disable it:

```lua
Expand Down
Loading