I think my proposed patch is more natural for implied-open tabs (with the tab bar showing or not, doesn't really matter) or explicitly opened ones. Just invoke when the tabs are created seems the best route and the one that people would expect reading the code. I'll have a look at the close hooks again in a bit. I do know the behavior of the pre-close hook is good for my uses. On Tue, Oct 29, 2024 at 2:54 PM Juri Linkov wrote: > >> I'm trying to align all tab creation behavior with > >> tab-bar-tab-post-open-functions. Even the first tab should be > >> considered "opened" by the system and call people's functions on the > >> hook. That tab, if you close it, does call the close hooks correctly > >> and that's aligned, at least. > > Calling the close hooks currently doesn't look correct: > > (run-hook-with-args 'tab-bar-tab-pre-close-functions > (nth close-index tabs) > last-tab-p) > (if last-tab-p > (pcase tab-bar-close-last-tab-choice > ('nil > (user-error "Attempt to delete the sole tab in a frame")) > > where first it makes an attempt to close the tab, calls the hook, > then fails with the user-error. I think the hook should be called > when the tab is really closed. > > >> If the open hook doesn't get called, then > >> those tabs have to be treated in a special way and that creates bugs > >> and burden. Not sure how relevant it is what I do in my custom hook > >> that should get called for the implied opened first frames but doesn't. > > > > If you're really curious, one use case is auto-assigning a tab group. > When > > one makes a frame, the tab bar defaults to showing the window from which > it > > was created and any custom tab-bar symbols attached to the tab have to be > > recreated. Another use case is optionally keeping tabs "pinned" to their > > user-specified positions and the post-open hook can help track the first > > and subsequent positions. I'll surely add more over time. tab-bar is > great > > and fun to use and enhance with cool productivity tools. > > Thanks, this is an interesting case. Indeed, currently > there is an inconsistency. For example, start `emacs -Q`. > Even if there is no tab-bar initially, we can say that > the first tab is already created. Later, after creating > the second tab with 'C-x t 2', we have two tabs where > the post-open hook was called only in the second tab. > > A possible solution would be to detect such situation > in 'tab-bar-new-tab-to' with the same code that > enables the tab-bar initially with: > > (when tab-bar-show > (if (not tab-bar-mode) > ;; Turn on `tab-bar-mode' since a tab was created. > ;; Note: this also updates `tab-bar-lines'. > (tab-bar-mode 1) > (tab-bar--update-tab-bar-lines))) > > then run the hook in the first tab as well. >