Function: tab-bar-get-buffer-tab

tab-bar-get-buffer-tab is a byte-compiled function defined in tab-bar.el.gz.

Signature

(tab-bar-get-buffer-tab BUFFER-OR-NAME &optional ALL-FRAMES IGNORE-CURRENT-TAB)

Documentation

Return the tab that owns the window whose buffer is BUFFER-OR-NAME.

BUFFER-OR-NAME may be a buffer or a buffer name, and defaults to the current buffer.

The optional argument ALL-FRAMES specifies the frames to consider:

- t means consider all tabs on all existing frames.

- visible means consider all tabs on all visible frames.

- A frame means consider all tabs on that frame only.

- Any other value of ALL-FRAMES means consider all tabs on the
selected frame and no others.

When the optional argument IGNORE-CURRENT-TAB is non-nil, don't take into account the buffers in the currently selected tab. Otherwise, prefer buffers of the current tab.

Source Code

;; Defined in /usr/src/emacs/lisp/tab-bar.el.gz
(defun tab-bar-get-buffer-tab (buffer-or-name &optional all-frames ignore-current-tab)
  "Return the tab that owns the window whose buffer is BUFFER-OR-NAME.
BUFFER-OR-NAME may be a buffer or a buffer name, and defaults to
the current buffer.

The optional argument ALL-FRAMES specifies the frames to consider:

- t means consider all tabs on all existing frames.

- `visible' means consider all tabs on all visible frames.

- A frame means consider all tabs on that frame only.

- Any other value of ALL-FRAMES means consider all tabs on the
selected frame and no others.

When the optional argument IGNORE-CURRENT-TAB is non-nil,
don't take into account the buffers in the currently selected tab.
Otherwise, prefer buffers of the current tab."
  (let ((buffer (if buffer-or-name
                    (get-buffer buffer-or-name)
                  (current-buffer))))
    (when (bufferp buffer)
      (seq-some
       (lambda (frame)
         (seq-some
          (lambda (tab)
            (when (if (eq (car tab) 'current-tab)
                      (get-buffer-window buffer frame)
                    (let* ((state (alist-get 'ws tab))
                           (buffers (when state
                                      (window-state-buffers state))))
                      (or
                       ;; non-writable window-state
                       (memq buffer buffers)
                       ;; writable window-state
                       (member (buffer-name buffer) buffers))))
              (append tab `((index . ,(tab-bar--tab-index tab nil frame))
                            (frame . ,frame)))))
          (let* ((tabs (funcall tab-bar-tabs-function frame))
                 (current-tab (tab-bar--current-tab-find tabs)))
            (setq tabs (remq current-tab tabs))
            (if ignore-current-tab
                ;; Use tabs without current-tab.
                tabs
              ;; Make sure current-tab is at the beginning of tabs.
              (cons current-tab tabs)))))
       (tab-bar--reusable-frames all-frames)))))