Function: tab-bar-rename-tab

tab-bar-rename-tab is an interactive and byte-compiled function defined in tab-bar.el.gz.

Signature

(tab-bar-rename-tab NAME &optional TAB-NUMBER)

Documentation

Give the tab specified by its absolute position TAB-NUMBER a new NAME.

If no TAB-NUMBER is specified, then rename the current tab. Interactively, TAB-NUMBER is the prefix numeric argument, and defaults to the current tab. TAB-NUMBER counts from 1. Interactively, prompt for the new NAME. If NAME is the empty string, then use the automatic name function tab-bar-tab-name-function.

Key Bindings

Aliases

tab-rename

Source Code

;; Defined in /usr/src/emacs/lisp/tab-bar.el.gz
(defun tab-bar-rename-tab (name &optional tab-number)
  "Give the tab specified by its absolute position TAB-NUMBER a new NAME.
If no TAB-NUMBER is specified, then rename the current tab.
Interactively, TAB-NUMBER is the prefix numeric argument, and defaults
to the current tab.
TAB-NUMBER counts from 1.
Interactively, prompt for the new NAME.
If NAME is the empty string, then use the automatic name
function `tab-bar-tab-name-function'."
  (interactive
   (let* ((tabs (funcall tab-bar-tabs-function))
          (tab-number (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs))))
          (tab-name (alist-get 'name (nth (1- tab-number) tabs))))
     (list (read-from-minibuffer
            "New name for tab (leave blank for automatic naming): "
            nil nil nil nil tab-name)
           current-prefix-arg)))
  (let* ((tabs (funcall tab-bar-tabs-function))
         (tab-index (if (integerp tab-number)
                        (1- (max 0 (min tab-number (length tabs))))
                      (tab-bar--current-tab-index tabs)))
         (tab-to-rename (nth tab-index tabs))
         (tab-explicit-name (> (length name) 0))
         (tab-new-name (if tab-explicit-name
                           name
                         (funcall tab-bar-tab-name-function))))
    (setf (alist-get 'name tab-to-rename) tab-new-name
          (alist-get 'explicit-name tab-to-rename) tab-explicit-name)

    (force-mode-line-update)
    (unless tab-bar-mode
      (message "Renamed tab to '%s'" tab-new-name))))