Git Product home page Git Product logo

Comments (11)

akinsho avatar akinsho commented on May 20, 2024 1

@siduck76 I've already started some work over in #179 I'm probably not going to go with the structure above since that is way more work/complexity i.e. hiding buffers and then trying to add a new secondary UI. The main way this is probably going to work will be different highlighting/icons for grouped buffers and just as a visual indicator, I might also allow some custom separator e.g. a space or divider between groups or a sort of header tab.

Anyway I'm trying to keep the initial implementation lean so won't be adding a bunch of complexity otherwise chances are I'll never finish anyway. You can have a look at that PR to see where it's at. It's not fully documented yet though

from bufferline.nvim.

G-Rowell avatar G-Rowell commented on May 20, 2024 1

Hi @akinsho & @siduck76,

I thought I might explain my implementation a little, though mine clearly has flaws with it's implementation as it is currently. (I intend to improve it after my exams soon!)

On Terminal creation,

  • set a local terminal variable term_type to indicate that this is a managed term & what kind of window the user created the term as
    • Eg: map("n", "<leader>w", ":execute 'terminal' | let b:term_type = 'wind' | startinsert <CR>", opt)
    • Eg: map("n", "<leader>v", ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert <CR>", opt)
  • This could probably be done with an autocommand instead

This code is an edited excerpt from here


Closing buffers

There are several implementation choices to make:

  1. Re-map locally (in any term buffer), the normal close buffer keybind, to instead hide a term
  2. Re-map globally your close buffer keybind to a function, part of this function hide the term
  3. There is likely some way to hijack :bd! or similar with an autocommand?

We implemented # 2

map("n", "<leader>x", ":lua require('utils').close_buffer() <CR>", opt) -- close buffer
This code is an edited excerpt from here
This code is an edited excerpt from here


What hiding a term means

close_buffer()

      local chad_term, type = pcall(function()
         -- try to get our special buffer variable
         return vim.api.nvim_buf_get_var(buf, "term_type")
      end)

      if chad_term then
         -- this is a managed terminal!
         if type == "wind" then
            -- hide from bufferline
            vim.cmd(string.format("%d bufdo setlocal nobl", buf))
            -- swtich to another buff
            vim.cmd "BufferLineCycleNext"
         else
            -- this is instead a split window term
            local cur_win = vim.fn.winnr()
            -- we can close this window
            vim.cmd(string.format("%d wincmd c", cur_win))
            return
         end
      else
         -- normally close this buffer
         vim.cmd(string.format("bd! %d", buf))
      end

This code is an edited excerpt from here


How to bring back / show a term

As this implementation is designed to created many terms (instead of toggleterm.nvim's approach),
we now need some kind of selector to choose what term to show again.

I've decided to use a Telescope picker, as that already has many in-built tools and can live-preview buffers.

The general idea behind the picker:

  • only show our managed terminal buffers
  • only show hidden buffers
  • on selection, checks local buffer var term_type to see how best to re-show the terminal in a window
    -- for a window term, create a new window and set it to listed to show on the bufferline
    -- for a split term, create a split with the selected term
            if chad_term then
               if type == "wind" then
                  -- swtich to term buff & show in bufferline
                  vim.cmd(string.format("b %d | setlocal bl", buf))
               elseif type == "vert" then
                  vim.cmd(string.format("vsp #%d", buf))
               elseif type == "hori" then
                  vim.cmd(string.format("15 sp #%d ", buf))
               end

This code is an edited excerpt from here


I hope this helps, or is at least curious.
I'm more than happy to explain more, and it's totally understandable if you completely disagree with my implementation 😆

I am by all means new to plugin & proper NeoVim modification!

G

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024 1

closed by #179

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

@CooperAnderson potentially the filtering you had in your PR could be done on top of this e.g. certain groups could be assigned to specific tabs etc., thoughts?

from bufferline.nvim.

ahmed-rezk-dev avatar ahmed-rezk-dev commented on May 20, 2024

Is there any updates on buffer groups?

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

Nope. Haven't looked into it properly. A big part of the way centaur-tabs does it is that it can render the UI in a way that can't really be achieved in nvim so not super clear how this would look.

It's also a non-trivial amount of work I don't currently have time for.

from bufferline.nvim.

siduck avatar siduck commented on May 20, 2024

Nope. Haven't looked into it properly. A big part of the way centaur-tabs does it is that it can render the UI in a way that can't really be achieved in nvim so not super clear how this would look.

It's also a non-trivial amount of work I don't currently have time for.

Idk if this sounds dumb lol , maybe you can use one buffer for grouping multiple buffers and pressing a mapping when you're in the group buffer will open a lil popup over the bottom of the grouped buffer and cycling within the popup ( of grouped buffer ) with a mapping.

image

from bufferline.nvim.

siduck avatar siduck commented on May 20, 2024

@akinsho My friend has added a PR to NvChad (my config) which lets me hide/unhide specific terminal buffers through telescope.Idk if this would be useful but you could implement the same with hiding buffers and unhiding them through telescope or any other floating window like thing

image

image

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

I'm sure I understand tbh or if it relates to this particular functionality at all really.

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

@G-Rowell thanks for explaining the terminal functionality referenced above. Just to clarify, I think there's generally a bit of confusion about what this issue is about and what the related PR will do. It doesn't have anything to do with hiding buffers or toggling things or secondary UI's. The buffer group logic is a mechanism for users to specify how buffers get grouped, things like highlights and icons for a group and exposes functionality for interacting with a group e.g. all test files are grouped or all files matching some other criteria can be grouped and then closed together, or opened in splits all at once.

I don't think most of the recent comments really relate to this issue, just to be clear.

from bufferline.nvim.

G-Rowell avatar G-Rowell commented on May 20, 2024

@akinsho

Yeah, my apologies, I barely got any sleep last night 😢

I was mainly trying to supplement SiDuck's answer.

I'm slightly more awake now and agree, it's quite irrelevant.
Sorry, my bad 😆

Let me know if you want me to ping you if I do get bufferline grouping working

from bufferline.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.