Function: window--display-buffer

window--display-buffer is a byte-compiled function defined in window.el.gz.

Signature

(window--display-buffer BUFFER WINDOW TYPE &optional ALIST)

Documentation

Display BUFFER in WINDOW.

WINDOW must be a live window chosen by a buffer display action function for showing BUFFER. TYPE tells whether WINDOW existed already before that action function was called or is a new window created by that function. ALIST is a buffer display action alist as compiled by display-buffer.

TYPE must be one of the following symbols: reuse (which means WINDOW existed before the call of display-buffer and may already show BUFFER or not), window (WINDOW was created on an existing frame) or frame (WINDOW was created on a new frame). TYPE is passed unaltered to display-buffer-record-window.

Handle WINDOW's dedicated flag as follows: If WINDOW already shows BUFFER, leave it alone. Otherwise, if ALIST contains a dedicated entry and WINDOW is either new or that entry's value equals side, set WINDOW's dedicated flag to the value of that entry. Otherwise, if WINDOW is new and the value of display-buffer-mark-dedicated is non-nil, set WINDOW's dedicated flag to that value. In any other case, reset WINDOW's dedicated flag to nil.

Return WINDOW if BUFFER and WINDOW are live.

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window--display-buffer (buffer window type &optional alist)
  "Display BUFFER in WINDOW.
WINDOW must be a live window chosen by a buffer display action
function for showing BUFFER.  TYPE tells whether WINDOW existed
already before that action function was called or is a new window
created by that function.  ALIST is a buffer display action alist
as compiled by `display-buffer'.

TYPE must be one of the following symbols: `reuse' (which means
WINDOW existed before the call of `display-buffer' and may
already show BUFFER or not), `window' (WINDOW was created on an
existing frame) or `frame' (WINDOW was created on a new frame).
TYPE is passed unaltered to `display-buffer-record-window'.

Handle WINDOW's dedicated flag as follows: If WINDOW already
shows BUFFER, leave it alone.  Otherwise, if ALIST contains a
`dedicated' entry and WINDOW is either new or that entry's value
equals `side', set WINDOW's dedicated flag to the value of that
entry.  Otherwise, if WINDOW is new and the value of
`display-buffer-mark-dedicated' is non-nil, set WINDOW's
dedicated flag to that value.  In any other case, reset WINDOW's
dedicated flag to nil.

Return WINDOW if BUFFER and WINDOW are live."
  (when (and (buffer-live-p buffer) (window-live-p window))
    (display-buffer-record-window type window buffer)
    (unless (eq buffer (window-buffer window))
      ;; Unless WINDOW already shows BUFFER reset its dedicated flag.
      (set-window-dedicated-p window nil)
      (set-window-buffer window buffer))
    (let ((alist-dedicated (assq 'dedicated alist)))
      ;; Maybe dedicate WINDOW to BUFFER if asked for.
      (cond
       ;; Don't dedicate WINDOW if it is dedicated because it shows
       ;; BUFFER already or it is reused and is not a side window.
       ((or (window-dedicated-p window)
            (and (eq type 'reuse) (not (eq (cdr alist-dedicated) 'side)))))
       ;; Otherwise, if ALIST contains a 'dedicated' entry, use that
       ;; entry's value (which may be nil).
       (alist-dedicated
        (set-window-dedicated-p window (cdr alist-dedicated)))
       ;; Otherwise, if 'display-buffer-mark-dedicated' is non-nil,
       ;; use that.
       (display-buffer-mark-dedicated
        (set-window-dedicated-p window display-buffer-mark-dedicated))))
    (when (memq type '(window frame tab))
      (set-window-prev-buffers window nil))

    (when (functionp (cdr (assq 'body-function alist)))
      (let ((inhibit-read-only t)
            (inhibit-modification-hooks t))
        (funcall (cdr (assq 'body-function alist)) window)))

    (let ((quit-restore (window-parameter window 'quit-restore))
	  (height (cdr (assq 'window-height alist)))
	  (width (cdr (assq 'window-width alist)))
	  (size (cdr (assq 'window-size alist)))
	  (preserve-size (cdr (assq 'preserve-size alist))))
      (cond
       ((or (eq type 'frame)
	    (and (eq (car quit-restore) 'same)
		 (eq (nth 1 quit-restore) 'frame)))
	;; A window that never showed another buffer but BUFFER ever
        ;; since it was created on a new frame.
        ;;
        ;; Adjust size of frame if asked for.  We probably should do
        ;; that only for a single window frame.
	(cond
	 ((not size))
	 ((consp size)
	  (let ((width (car size))
		(height (cdr size))
		(frame (window-frame window)))
	    (when (and (numberp width) (numberp height))
	      (set-frame-height
	       frame (+ (frame-height frame)
			(- height (window-total-height window))))
	      (set-frame-width
	       frame (+ (frame-width frame)
			(- width (window-total-width window)))))))
	 ((functionp size)
	  (ignore-errors (funcall size window)))))
       ((or (eq type 'window)
	    (and (eq (car quit-restore) 'same)
		 (eq (nth 1 quit-restore) 'window)))
	;; A window that never showed another buffer but BUFFER ever
        ;; since it was created on an existing frame.
        ;;
        ;; Adjust width and/or height of window if asked for.
	(cond
	 ((not height))
	 ((numberp height)
	  (let* ((new-height
		  (if (integerp height)
		      height
		    (round
		     (* (window-total-height (frame-root-window window))
			height))))
		 (delta (- new-height (window-total-height window))))
	    (when (and (window--resizable-p window delta nil 'safe)
		       (window-combined-p window))
	      (window-resize window delta nil 'safe))))
	 ((functionp height)
	  (ignore-errors (funcall height window))))
	;; Adjust width of window if asked for.
	(cond
	 ((not width))
	 ((numberp width)
	  (let* ((new-width
		  (if (integerp width)
		      width
		    (round
		     (* (window-total-width (frame-root-window window))
			width))))
		 (delta (- new-width (window-total-width window))))
	    (when (and (window--resizable-p window delta t 'safe)
		       (window-combined-p window t))
	      (window-resize window delta t 'safe))))
	 ((functionp width)
	  (ignore-errors (funcall width window))))
	;; Preserve window size if asked for.
	(when (consp preserve-size)
	  (window-preserve-size window t (car preserve-size))
	  (window-preserve-size window nil (cdr preserve-size)))))
      ;; Assign any window parameters specified.
      (let ((parameters (cdr (assq 'window-parameters alist))))
        (dolist (parameter parameters)
          (set-window-parameter
           window (car parameter) (cdr parameter)))))
    window))