You're right about tab-bar-tab-pre-close-functions being called prematurely. There seem to be almost no calls to it in the wild that I could find. Now is a good time to correct this.

On Tue, Oct 29, 2024 at 2:54 PM Juri Linkov <juri@linkov.net> wrote:

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.