Skip to content
New issue

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

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

Already on GitHub? # to your account

Mixed project buffer in the tabline #1

Closed
nicodebo opened this issue Oct 20, 2022 · 7 comments
Closed

Mixed project buffer in the tabline #1

nicodebo opened this issue Oct 20, 2022 · 7 comments

Comments

@nicodebo
Copy link

Hello,
Thank you for this package.
I'm not sure if this is an issue.
When opening a new project file (C-x p p f) the previous buffer from the project I switch from appears in the new project tabline.
Consequently, the tabline contains buffer from both projects.

@fritzgrabo
Copy link
Owner

Hi @nicodebo, thanks for reporting this!

I'm not using Emacs' tab-line package myself, so didn't notice this until now.

The issue seems to be that the new tab is created after selecting the project, but before executing a command within that project (project-find-file in your example).

I looked into the related code briefly, but no obvious solution re. how to handle this in a generic way popped up.

I'll continue to look at this once I have more time on my hands, then report back here.

Thanks!

@fritzgrabo
Copy link
Owner

@nicodebo I think I might have found a way to solve the issue you reported.

The tab-line allows to customize how the list of tabs to display in the tab line is generated. See the "Window Tab Line" manual, which states that

You can customize the variable tab-line-tabs-function to define the preferred contents of the tab line. By default, it displays all buffers previously visited in the window, as described above.

I came up with a function that uses the default behavior (all buffers previously visited in the window), then filters out every buffer that doesn't belong to the current buffer's project (if any).

Here's that function's definition and how to apply it:

(defun project-tab-groups-tab-line-tabs-window-project-buffers ()
  "Return a list of tabs that should be displayed in the tab line.
Same as `tab-line-tabs-window-buffers', but if the current buffer
belongs to a project, all other buffers that don't belong to that
project are filtered out."
  (let ((window-buffers (tab-line-tabs-window-buffers)))
    (if-let* ((pr (project-current))
              (project-buffers (project--buffers-to-kill pr)))
        (seq-filter (lambda (buf) (member buf project-buffers)) window-buffers)
      window-buffers)))

(setq tab-line-tabs-function #'project-tab-groups-tab-line-tabs-window-project-buffers)

Add this snippet to your Emacs config if you want and give it a try yourself.

A quick first test seems promising, but I want to test-drive this for a week or so before I add it to the package, or its README at least.

Note that previous-buffer (C-x left) and next-buffer (C-x right) might behave a little unexpected at the tab line's edges now: they use the unfiltered list of windows, so you can move past the shown tabs in the tab-line, to buffers that don't belong to the project.

Let me know if you find anything that's odd or unexpected. Thanks!

@nicodebo
Copy link
Author

Thank you very much.
I will try this for a week or so and report back here.

@nicodebo
Copy link
Author

nicodebo commented Nov 5, 2022

It looks good to me after trying it for a week.
I don't use previous-buffer and next-buffer so I didn't test this.
Thank you.

@fritzgrabo
Copy link
Owner

Awesome, thanks for the update!

I'll add a note about this to the project's README, so others can benefit from what we found out.

Thanks for your contribution! 🙌

@adamcstephens
Copy link

It doesn't appear that snippet was ever added to the README. It helps fix the issue for me though, so thanks. :)

@fritzgrabo
Copy link
Owner

@adamcstephens thanks for the nudge. I added a short description of the problem and a link to this issue / fix in the README's "Limitations" section now. 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants