Function: frameset--reuse-frame

frameset--reuse-frame is a byte-compiled function defined in frameset.el.gz.

Signature

(frameset--reuse-frame DISPLAY PARAMETERS)

Documentation

Return an existing frame to reuse, or nil if none found.

DISPLAY is the display where the frame will be shown, and PARAMETERS is the parameter alist of the frame being restored. Internal use only.

Source Code

;; Defined in /usr/src/emacs/lisp/frameset.el.gz
(defun frameset--reuse-frame (display parameters)
  "Return an existing frame to reuse, or nil if none found.
DISPLAY is the display where the frame will be shown, and PARAMETERS
is the parameter alist of the frame being restored.  Internal use only."
  (let ((frame nil)
	mini)
    ;; There are no fancy heuristics there.  We could implement some
    ;; based on frame size and/or position, etc., but it is not clear
    ;; that any "gain" (in the sense of reduced flickering, etc.) is
    ;; worth the added complexity.  In fact, the code below mainly
    ;; tries to work nicely when M-x desktop-read is used after a
    ;; desktop session has already been loaded.  The other main use
    ;; case, which is the initial desktop-read upon starting Emacs,
    ;; will usually have only one frame, and should already work.
    (cond ((null display)
	   ;; When the target is tty, every existing frame is reusable.
	   (setq frame (frameset--find-frame-if nil display)))
	  ((car (setq mini (cdr (assq 'frameset--mini parameters))))
	   ;; If the frame has its own minibuffer, let's see whether
	   ;; that frame has already been loaded (which can happen after
	   ;; M-x desktop-read).
	   (setq frame (frameset--find-frame-if
			#'frameset-frame-id-equal-p
			display (frameset-cfg-id parameters)))
	   ;; If it has not been loaded, and it is not a minibuffer-only frame,
	   ;; let's look for an existing non-minibuffer-only frame to reuse.
	   (unless (or frame (eq (cdr (assq 'minibuffer parameters)) 'only))
           ;; "Fix semantics of 'minibuffer' frame parameter" change:
           ;; The 'minibuffer' frame parameter of a non-minibuffer-only
           ;; frame is t instead of that frame's minibuffer window.
	     (setq frame (frameset--find-frame-if
			  (lambda (f)
			    (eq (frame-parameter f 'minibuffer) t))
			  display))))
	  (mini
	   ;; For minibufferless frames, check whether they already exist,
	   ;; and that they are linked to the right minibuffer frame.
	   (setq frame (frameset--find-frame-if
			(lambda (f id mini-id)
			  (and (frameset-frame-id-equal-p f id)
			       (or (null mini-id) ; minibuffer frame not saved
				   (frameset-frame-id-equal-p
				    (window-frame (minibuffer-window f))
				    mini-id))))
			display (frameset-cfg-id parameters) (cdr mini))))
	  (t
	   ;; Default to just finding a frame in the same display.
	   (setq frame (frameset--find-frame-if nil display))))
    ;; If found, remove from the list.
    (when frame
      (setq frameset--reuse-list (delq frame frameset--reuse-list)))
    frame))