* tab-bar-mode new tab hook? @ 2022-04-25 2:07 Aaron Jensen 2022-04-25 15:44 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Aaron Jensen @ 2022-04-25 2:07 UTC (permalink / raw) To: Emacs developers Hi, I've been experimenting using tabspaces (https://github.com/mclear-tools/tabspaces) to enable each tab to have its own isolated buffer list. It provides a command, tabspaces-create-workspace that invokes tab-bar-new-tab and then sets frame parameters to isolate the buffer list space. I was curious if there has been any thought given to including a hook for when a new tab is created. This way, I could just add a hook to do this and not have to use a separate command (and replace all the other commands that use tab-bar-new-tab). I could use advice, but that seems like a last resort. Alternatively (or in addition) is the behavior to isolate buffer lists in tabs one that would make sense for Emacs to support out-of-the-box? Thanks, Aaron ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-25 2:07 tab-bar-mode new tab hook? Aaron Jensen @ 2022-04-25 15:44 ` Juri Linkov 2022-04-26 3:27 ` Aaron Jensen 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2022-04-25 15:44 UTC (permalink / raw) To: Aaron Jensen; +Cc: Emacs developers > I've been experimenting using tabspaces > (https://github.com/mclear-tools/tabspaces) to enable each tab to have > its own isolated buffer list. It provides a command, > tabspaces-create-workspace that invokes tab-bar-new-tab and then sets > frame parameters to isolate the buffer list space. > > I was curious if there has been any thought given to including a hook > for when a new tab is created. This way, I could just add a hook to do > this and not have to use a separate command (and replace all the other > commands that use tab-bar-new-tab). I could use advice, but that seems > like a last resort. You can provide own custom function for tab-bar-new-tab-choice. Then you can set an initial buffer list in it, and even to display this buffer list as the default contents of the new tab. > Alternatively (or in addition) is the behavior to isolate buffer lists > in tabs one that would make sense for Emacs to support out-of-the-box? There is already project-based buffer isolation that works nicely with tabs, so in a new tab you can set a tab group name, and just use project buffer commands: 'C-x p b' (project-switch-to-buffer), 'C-x p k' (project-kill-buffers), etc. Switching to a project buffer in a new tab is also supported with 'C-x t p b'. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-25 15:44 ` Juri Linkov @ 2022-04-26 3:27 ` Aaron Jensen 2022-04-26 7:27 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Aaron Jensen @ 2022-04-26 3:27 UTC (permalink / raw) To: Juri Linkov; +Cc: Emacs developers On Mon, Apr 25, 2022 at 11:45 AM Juri Linkov <juri@linkov.net> wrote: > > > I've been experimenting using tabspaces > > (https://github.com/mclear-tools/tabspaces) to enable each tab to have > > its own isolated buffer list. It provides a command, > > tabspaces-create-workspace that invokes tab-bar-new-tab and then sets > > frame parameters to isolate the buffer list space. > > > > I was curious if there has been any thought given to including a hook > > for when a new tab is created. This way, I could just add a hook to do > > this and not have to use a separate command (and replace all the other > > commands that use tab-bar-new-tab). I could use advice, but that seems > > like a last resort. > > You can provide own custom function for tab-bar-new-tab-choice. > Then you can set an initial buffer list in it, and even to display > this buffer list as the default contents of the new tab. This function seems like it is meant to just return the buffer to display in the new tab. It also seem like it is called before the new tab is actually created. I haven't tried it yet, but I would think that would mean that any modification of frame parameters in that function would apply to the previous tab, rather than the about to be created tab. > > Alternatively (or in addition) is the behavior to isolate buffer lists > > in tabs one that would make sense for Emacs to support out-of-the-box? > > There is already project-based buffer isolation that works nicely > with tabs, so in a new tab you can set a tab group name, and just > use project buffer commands: 'C-x p b' (project-switch-to-buffer), > 'C-x p k' (project-kill-buffers), etc. Switching to a project buffer > in a new tab is also supported with 'C-x t p b'. Yes, I used that before, but I like to be able to bring buffers in from other projects and have them in my buffer list. Sort of reference files from one project to another, so it is nice for them to actually have their own buffer lists entirely that is not limited to those in the project. Thanks, Aaron ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-26 3:27 ` Aaron Jensen @ 2022-04-26 7:27 ` Juri Linkov 2022-04-26 9:48 ` Aaron Jensen 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2022-04-26 7:27 UTC (permalink / raw) To: Aaron Jensen; +Cc: Emacs developers >> You can provide own custom function for tab-bar-new-tab-choice. >> Then you can set an initial buffer list in it, and even to display >> this buffer list as the default contents of the new tab. > > This function seems like it is meant to just return the buffer to > display in the new tab. It also seem like it is called before the new > tab is actually created. I haven't tried it yet, but I would think > that would mean that any modification of frame parameters in that tab-bar-new-tab-choice prepares the window configuration for the new tab, so it's a suitable place to modify frame parameters, e.g. (setq tab-bar-new-tab-choice (lambda () (set-frame-parameter nil 'name "tab-2") (current-buffer))) > function would apply to the previous tab, rather than the about to be > created tab. This detail is relevant only when you want to modify tab parameters. And tab parameters already include frame buffer-list and buried-buffer-list. So not only after creating a new tab, but also after switching between tabs these frame parameters get updated. >> > Alternatively (or in addition) is the behavior to isolate buffer lists >> > in tabs one that would make sense for Emacs to support out-of-the-box? >> >> There is already project-based buffer isolation that works nicely >> with tabs, so in a new tab you can set a tab group name, and just >> use project buffer commands: 'C-x p b' (project-switch-to-buffer), >> 'C-x p k' (project-kill-buffers), etc. Switching to a project buffer >> in a new tab is also supported with 'C-x t p b'. > > Yes, I used that before, but I like to be able to bring buffers in > from other projects and have them in my buffer list. Sort of reference > files from one project to another, so it is nice for them to actually > have their own buffer lists entirely that is not limited to those in > the project. Don't you think that a feature of limiting a list of buffers has only distant connection to tabs? Isn't it the purpose of project.el to define a list of buffers? So maybe it would be easier to add a new backend to project.el with a list of predefined files/buffers? There are also other packages that do something like this such as lisp/filesets.el and lisp/filecache.el. But if you want to plug such a feature into tabs, we could add more hooks to tab-bar-mode to make it easier to do this. So please help to identify these points for more customization. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-26 7:27 ` Juri Linkov @ 2022-04-26 9:48 ` Aaron Jensen 2022-04-26 15:48 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Aaron Jensen @ 2022-04-26 9:48 UTC (permalink / raw) To: Juri Linkov; +Cc: Emacs developers On Tue, Apr 26, 2022 at 3:29 AM Juri Linkov <juri@linkov.net> wrote: > > tab-bar-new-tab-choice prepares the window configuration for the new tab, > so it's a suitable place to modify frame parameters, e.g. > > (setq tab-bar-new-tab-choice > (lambda () > (set-frame-parameter nil 'name "tab-2") > (current-buffer))) > > > function would apply to the previous tab, rather than the about to be > > created tab. > > This detail is relevant only when you want to modify tab parameters. > And tab parameters already include frame buffer-list and buried-buffer-list. > So not only after creating a new tab, but also after switching between tabs > these frame parameters get updated. Ok, thank you. It does seem like I can use `tab-bar-new-tab-choice' to set the buffer list, but it only works in a subset of situations. Any command that sets it like `tab-bar-move-tab-to-window' would not be able to use it. > >> > Alternatively (or in addition) is the behavior to isolate buffer lists > >> > in tabs one that would make sense for Emacs to support out-of-the-box? > >> > >> There is already project-based buffer isolation that works nicely > >> with tabs, so in a new tab you can set a tab group name, and just > >> use project buffer commands: 'C-x p b' (project-switch-to-buffer), > >> 'C-x p k' (project-kill-buffers), etc. Switching to a project buffer > >> in a new tab is also supported with 'C-x t p b'. > > > > Yes, I used that before, but I like to be able to bring buffers in > > from other projects and have them in my buffer list. Sort of reference > > files from one project to another, so it is nice for them to actually > > have their own buffer lists entirely that is not limited to those in > > the project. > > Don't you think that a feature of limiting a list of buffers > has only distant connection to tabs? Isn't it the purpose > of project.el to define a list of buffers? So maybe it would be > easier to add a new backend to project.el with a list of predefined > files/buffers? There are also other packages that do something > like this such as lisp/filesets.el and lisp/filecache.el. I (and others I have seen) are using tabs as a way to replace persp-mode/perspective.el, i.e. workspaces. I know some in other text editors that use our equivalent of frames for this purpose. The intent is that each workspace is relatively isolated from one another. Each has its own window configuration and I think it's natural for each workspace to have its own buffer list. I think that project.el works great when there is a direct 1:1 mapping between a project and its workspace. I even use a combination of project.el and tabs (new tab from known project, for example). From there, `project-find-file' is useful for finding files in the project that would then get added to the buffer list. It's just every once in a while that I may want a custom scratch buffer or to pull a file in that is outside of a project to be in the current project's workspace, but it does happen. And when it does happen, I want the buffer list to be separate from the project specific buffer list. I want a "workspace buffer list". A project is a physical and "permanent" workspace but I am using tabs as a logical and transient workspace, which often (but not always) maps 1:1 with a project. I looked at filesets and filecache and I don't think they would work here without hooking into all of the buffer management machinery. I imagine you didn't intend for it, but the fact that tab-bar-mode manages its own buffer-list frame-parameter per tab makes it perfectly suited for the purpose of tabs being used as workspaces. > But if you want to plug such a feature into tabs, we could add > more hooks to tab-bar-mode to make it easier to do this. > So please help to identify these points for more customization. I just found `tab-bar-tab-post-open-functions', which should do exactly what I need. Thanks, Aaron ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-26 9:48 ` Aaron Jensen @ 2022-04-26 15:48 ` Juri Linkov 2022-04-26 15:56 ` Aaron Jensen 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2022-04-26 15:48 UTC (permalink / raw) To: Aaron Jensen; +Cc: Emacs developers > I imagine you didn't intend for it, but the fact that tab-bar-mode > manages its own buffer-list frame-parameter per tab makes it perfectly > suited for the purpose of tabs being used as workspaces. The intention was to make tabs as a light-weigh version of frames, so like every frame uses own frame-local buffer-list, switching tabs updates frame buffer-list to maintain a tab as a separate frame. > I just found `tab-bar-tab-post-open-functions', which should do > exactly what I need. I still don't understand why you need to run a hook only on opening a new tab, and not on switching tabs, to update frame parameters, but glad to hear that the existing hook does what you need. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: tab-bar-mode new tab hook? 2022-04-26 15:48 ` Juri Linkov @ 2022-04-26 15:56 ` Aaron Jensen 0 siblings, 0 replies; 7+ messages in thread From: Aaron Jensen @ 2022-04-26 15:56 UTC (permalink / raw) To: Juri Linkov; +Cc: Emacs developers On Tue, Apr 26, 2022 at 11:53 AM Juri Linkov <juri@linkov.net> wrote: > > > I imagine you didn't intend for it, but the fact that tab-bar-mode > > manages its own buffer-list frame-parameter per tab makes it perfectly > > suited for the purpose of tabs being used as workspaces. > > The intention was to make tabs as a light-weigh version of frames, > so like every frame uses own frame-local buffer-list, switching tabs > updates frame buffer-list to maintain a tab as a separate frame. > > > I just found `tab-bar-tab-post-open-functions', which should do > > exactly what I need. > > I still don't understand why you need to run a hook only on opening > a new tab, and not on switching tabs, to update frame parameters, > but glad to hear that the existing hook does what you need. Because the only thing I need is to set the initial buffer list and then what you described above takes care of switching tabs. This is what we are doing: (set-frame-parameter nil 'buffer-list (let ((window-buffers (mapcar #'window-buffer (window-list)))) (seq-filter (lambda (buffer) (or (member buffer window-buffers) (member (buffer-name buffer) tabspaces-include-buffers))) (frame-parameter nil 'buffer-list)))) (set-frame-parameter nil 'buried-buffer-list (seq-filter (lambda (buffer) (member (buffer-name buffer) tabspaces-include-buffers)) (frame-parameter nil 'buried-buffer-list))) tab-bar-mode takes care of the rest by doing what you describe above. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-26 15:56 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-25 2:07 tab-bar-mode new tab hook? Aaron Jensen 2022-04-25 15:44 ` Juri Linkov 2022-04-26 3:27 ` Aaron Jensen 2022-04-26 7:27 ` Juri Linkov 2022-04-26 9:48 ` Aaron Jensen 2022-04-26 15:48 ` Juri Linkov 2022-04-26 15:56 ` Aaron Jensen
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).