Function: image-fit-to-window
image-fit-to-window is a byte-compiled function defined in
image-mode.el.gz.
Signature
(image-fit-to-window WINDOW)
Documentation
Adjust size of image to display it exactly in WINDOW boundaries.
Source Code
;; Defined in /usr/src/emacs/lisp/image-mode.el.gz
(defun image-fit-to-window (window)
"Adjust size of image to display it exactly in WINDOW boundaries."
(when (window-live-p window)
(with-current-buffer (window-buffer window)
(when (derived-mode-p 'image-mode)
(let ((spec (image-get-display-property)))
(when (eq (car-safe spec) 'image)
(let* ((image-width (plist-get (cdr spec) :max-width))
(image-height (plist-get (cdr spec) :max-height))
(edges (window-inside-pixel-edges window))
(window-width (- (nth 2 edges) (nth 0 edges)))
(window-height (- (nth 3 edges) (nth 1 edges))))
;; If the size has been changed manually (with `+'/`-'),
;; then :max-width/:max-height is nil. In that case, do
;; no automatic resizing.
(when (and image-width image-height
;; Don't do resizing if we have a manual
;; rotation (from the `r' command), either.
(not (plist-get (cdr spec) :rotation))
(or (not (= image-width window-width))
(not (= image-height window-height))))
(unless image-fit-to-window-lock
(unwind-protect
(progn
(setq-local image-fit-to-window-lock t)
(ignore-error 'remote-file-error
(image-toggle-display-image)))
(setq image-fit-to-window-lock nil)))))))))))