Function: doc-view-fit-window-to-page
doc-view-fit-window-to-page is an interactive and byte-compiled
function defined in doc-view.el.gz.
Signature
(doc-view-fit-window-to-page)
Documentation
Resize selected window so it just fits the current page.
Resize the containing frame if needed.
Probably introduced at or before Emacs version 27.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/doc-view.el.gz
(defun doc-view-fit-window-to-page ()
"Resize selected window so it just fits the current page.
Resize the containing frame if needed."
(interactive)
(let* ((slice (doc-view-current-slice))
(img-width (if slice (nth 2 slice)
(car (image-display-size
(image-get-display-property) t))))
(img-height (if slice (nth 3 slice)
(cdr (image-display-size
(image-get-display-property) t))))
(win-width (- (nth 2 (window-inside-pixel-edges))
(nth 0 (window-inside-pixel-edges))))
(win-height (- (nth 3 (window-inside-pixel-edges))
(nth 1 (window-inside-pixel-edges))))
(width-diff (- img-width win-width))
(height-diff (- img-height win-height))
(new-frame-params
;; If we can't resize the window, try and resize the frame.
;; We used to compare the `window-width/height` and the
;; `frame-width/height` instead of catching the errors, but
;; it's too fiddly (e.g. in the presence of the miniwindow,
;; the height the frame should be equal to the height of the
;; root window +1).
(append
(condition-case nil
(progn
(enlarge-window (/ width-diff (frame-char-width)) 'horiz)
nil)
(error
`((width . (text-pixels
. ,(+ (frame-text-width) width-diff))))))
(condition-case nil
(progn
(enlarge-window (/ height-diff (frame-char-height)) nil)
nil)
(error
`((height . (text-pixels
. ,(+ (frame-text-height) height-diff)))))))))
(when new-frame-params
(modify-frame-parameters (selected-frame) new-frame-params))))