Function: window--state-put-2
window--state-put-2 is a byte-compiled function defined in
window.el.gz.
Signature
(window--state-put-2 IGNORE PIXELWISE)
Documentation
Helper function for window-state-put.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window--state-put-2 (ignore pixelwise)
"Helper function for `window-state-put'."
(dolist (item window-state-put-list)
(let ((window (car item))
(combination-limit (cdr (assq 'combination-limit item)))
(parameters (cdr (assq 'parameters item)))
(state (cdr (assq 'buffer item)))
(next-buffers (cdr (assq 'next-buffers item)))
(prev-buffers (cdr (assq 'prev-buffers item))))
(when combination-limit
(set-window-combination-limit window combination-limit))
;; Reset window's parameters and assign saved ones (we might want
;; a `remove-window-parameters' function here).
(dolist (parameter (window-parameters window))
(set-window-parameter window (car parameter) nil))
(when parameters
(dolist (parameter parameters)
(set-window-parameter window (car parameter) (cdr parameter))))
;; Process buffer related state.
(when state
(let* ((old-buffer-or-name (car state))
(buffer (get-buffer old-buffer-or-name))
(state (cdr state))
(dedicated (cdr (assq 'dedicated state))))
(if (buffer-live-p buffer)
(with-current-buffer buffer
(set-window-buffer window buffer)
(set-window-hscroll window (cdr (assq 'hscroll state)))
(apply 'set-window-fringes
(cons window (cdr (assq 'fringes state))))
(let ((margins (cdr (assq 'margins state))))
(set-window-margins window (car margins) (cdr margins)))
(let ((scroll-bars (cdr (assq 'scroll-bars state))))
(set-window-scroll-bars
window (car scroll-bars) (nth 2 scroll-bars)
(nth 3 scroll-bars) (nth 5 scroll-bars) (nth 6 scroll-bars)))
(set-window-vscroll window (cdr (assq 'vscroll state)))
;; Adjust vertically.
(if (or (memq window-size-fixed '(t height))
(window-preserved-size window))
;; A fixed height window, try to restore the
;; original size.
(let ((delta
(- (cdr (assq
(if pixelwise 'pixel-height 'total-height)
item))
(window-size window nil pixelwise)))
window-size-fixed)
(when (window--resizable-p
window delta nil nil nil nil nil pixelwise)
(window-resize window delta nil nil pixelwise)))
;; Else check whether the window is not high enough.
(let* ((min-size
(window-min-size window nil ignore pixelwise))
(delta
(- min-size (window-size window nil pixelwise))))
(when (and (> delta 0)
(window--resizable-p
window delta nil ignore nil nil nil pixelwise))
(window-resize window delta nil ignore pixelwise))))
;; Adjust horizontally.
(if (or (memq window-size-fixed '(t width))
(window-preserved-size window t))
;; A fixed width window, try to restore the original
;; size.
(let ((delta
(- (cdr (assq
(if pixelwise 'pixel-width 'total-width)
item))
(window-size window t pixelwise)))
window-size-fixed)
(when (window--resizable-p
window delta t nil nil nil nil pixelwise)
(window-resize window delta t nil pixelwise)))
;; Else check whether the window is not wide enough.
(let* ((min-size (window-min-size window t ignore pixelwise))
(delta (- min-size (window-size window t pixelwise))))
(when (and (> delta 0)
(window--resizable-p
window delta t ignore nil nil nil pixelwise))
(window-resize window delta t ignore pixelwise))))
;; Set dedicated status.
(set-window-dedicated-p window dedicated)
;; Install positions (maybe we should do this after all
;; windows have been created and sized).
(ignore-errors
;; Set 'noforce argument to avoid that window start
;; overrides window point set below (Bug#24240).
(set-window-start window (cdr (assq 'start state)) 'noforce)
(set-window-point window (cdr (assq 'point state))))
;; Select window if it's the selected one.
(when (cdr (assq 'selected state))
;; This used to call 'select-window' which, however,
;; can be partially undone because the current buffer
;; may subsequently change twice: When leaving the
;; present 'with-current-buffer' and when leaving the
;; containing 'with-temp-buffer' form (Bug#69093).
;; 'window-state-put-selected-window' should now work
;; around that bug but we leave this 'select-window'
;; in since some code run before the part that fixed
;; it might still refer to this window as the selected
;; one.
(select-window window)
(setq window-state-put-selected-window window))
(set-window-next-buffers
window
(delq nil (mapcar (lambda (buffer)
(setq buffer (get-buffer buffer))
(when (buffer-live-p buffer) buffer))
next-buffers)))
(set-window-prev-buffers
window
(delq nil (mapcar (lambda (entry)
(let ((buffer (get-buffer (nth 0 entry)))
(m1 (nth 1 entry))
(m2 (nth 2 entry)))
(when (buffer-live-p buffer)
(list buffer
(if (markerp m1) m1
(set-marker (make-marker) m1
buffer))
(if (markerp m2) m2
(set-marker (make-marker) m2
buffer))))))
prev-buffers))))
(unless (window-minibuffer-p window)
;; Preferably show a buffer previously shown in this
;; window.
(switch-to-prev-buffer window)
(cond
((functionp window-restore-killed-buffer-windows)
(let* ((start (cdr (assq 'start state)))
;; Handle both - marker positions from writable
;; states and markers from non-writable states.
(start-pos (if (markerp start)
(marker-last-position start)
start))
(point (cdr (assq 'point state)))
(point-pos (if (markerp point)
(marker-last-position point)
point)))
(push (list window old-buffer-or-name
start-pos point-pos dedicated nil)
window-state-put-kept-windows)))
((or (and dedicated
(eq window-restore-killed-buffer-windows 'dedicated))
(memq window-restore-killed-buffer-windows '(nil delete)))
;; Try to delete the window.
(push window window-state-put-stale-windows)))
(set-window-dedicated-p window nil))))))))