Function: select-frame-by-id

select-frame-by-id is an interactive and byte-compiled function defined in frame.el.gz.

Signature

(select-frame-by-id ID &optional NOERROR)

Documentation

Select the frame whose identifier is ID and raise it.

If the frame is undeletable, undelete it. Frames on the current terminal are checked first. Raise the frame and give it input focus. On a text terminal, the frame will occupy the entire terminal screen after the next redisplay. Return the selected frame or signal an error if no frame matching ID was found. If NOERROR is non-nil, return nil instead.

View in manual

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/frame.el.gz
(defun select-frame-by-id (id &optional noerror)
  "Select the frame whose identifier is ID and raise it.
If the frame is undeletable, undelete it.
Frames on the current terminal are checked first.
Raise the frame and give it input focus.  On a text terminal, the frame
will occupy the entire terminal screen after the next redisplay.
Return the selected frame or signal an error if no frame matching ID
was found.  If NOERROR is non-nil, return nil instead."
  (interactive
   (let* ((frame-ids-alist (frame--make-frame-ids-alist))
	  (default (car (car frame-ids-alist)))
	  (input (completing-read
		  (format-prompt "Select Frame by ID" default)
		  frame-ids-alist nil t)))
     (list (string-to-number
            (if (zerop (length input)) default input)))))
  ;; `undelete-frame-by-id' returns the undeleted frame, or nil.
  (unless (undelete-frame-by-id id 'noerror)
    ;; Prefer frames on the current display.
    (if-let* ((found (or (cdr (assq id (frame--make-frame-ids-alist)))
                         (catch 'done
                           (dolist (frame (frame-list))
                             (when (eq (frame-id frame) id)
                           (throw 'done frame)))))))
        (progn
          (select-frame-set-input-focus found)
          found)
      (unless noerror
        (error "There is no frame with identifier `%S'" id)))))