summaryrefslogtreecommitdiff
path: root/lisp/window.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/window.el')
-rw-r--r--lisp/window.el33
1 files changed, 27 insertions, 6 deletions
diff --git a/lisp/window.el b/lisp/window.el
index bb34a6d7b4c..865f6fdd5cc 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2172,7 +2172,8 @@ the font."
(with-selected-window (window-normalize-window window t)
(let* ((window-width (window-body-width window t))
(font-width (window-font-width window face))
- (ncols (/ window-width font-width)))
+ (ncols (- (/ window-width font-width)
+ (ceiling (line-number-display-width 'columns)))))
(if (and (display-graphic-p)
overflow-newline-into-fringe
(not
@@ -3431,7 +3432,7 @@ routines."
"Resize minibuffer-only frame FRAME."
(if (functionp resize-mini-frames)
(funcall resize-mini-frames frame)
- (fit-frame-to-buffer frame)))
+ (fit-mini-frame-to-buffer frame)))
(defun window--sanitize-window-sizes (horizontal)
"Assert that all windows on selected frame are large enough.
@@ -5479,7 +5480,7 @@ frame. The selected window is not changed by this function."
(set-window-parameter
(window-parent new) 'window-side window-side))))
((eq window-combination-resize 'atom)
- ;; Make sure `window--check-frame' won't destroy an existing
+ ;; Make sure `window--check' won't destroy an existing
;; atomic window in case the new window gets nested inside.
(unless (window-parameter window 'window-atom)
(set-window-parameter window 'window-atom t))
@@ -7711,7 +7712,7 @@ indirectly called by the latter."
(with-current-buffer (window-buffer window)
(cond ((memq major-mode allowed-modes)
'same)
- ((derived-mode-p allowed-modes)
+ ((apply #'derived-mode-p allowed-modes)
'derived)))))
(when (and mode?
(not (and inhibit-same-window-p
@@ -8924,6 +8925,14 @@ Return 0 otherwise."
(declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise))
+(defun fit-mini-frame-to-buffer (&optional frame)
+ "Adjust size of minibuffer FRAME to display its contents.
+FRAME should be a minibuffer-only frame and defaults to the
+selected one. Unlike `fit-frame-to-buffer' FRAME will fit to the
+contents of its buffer with any leading or trailing empty lines
+included."
+ (fit-frame-to-buffer-1 frame))
+
(defun fit-frame-to-buffer (&optional frame max-height min-height max-width min-width only)
"Adjust size of FRAME to display the contents of its buffer exactly.
FRAME can be any live frame and defaults to the selected one.
@@ -8942,8 +8951,18 @@ horizontally only.
The new position and size of FRAME can be additionally determined
by customizing the options `fit-frame-to-buffer-sizes' and
`fit-frame-to-buffer-margins' or setting the corresponding
-parameters of FRAME."
+parameters of FRAME.
+
+Any leading or trailing empty lines of the buffer content are not
+considered."
(interactive)
+ (fit-frame-to-buffer-1 frame max-height min-height max-width min-width only t t))
+
+(defun fit-frame-to-buffer-1 (&optional frame max-height min-height max-width min-width only from to)
+ "Helper function for `fit-frame-to-buffer'.
+FROM and TO are the buffer positions to determine the size to fit
+to, see `window-text-pixel-size'. The remaining arguments are as
+for `fit-frame-to-buffer'."
(unless (fboundp 'display-monitor-attributes-list)
(user-error "Cannot resize frame in non-graphic Emacs"))
(setq frame (window-normalize-frame frame))
@@ -9078,7 +9097,7 @@ parameters of FRAME."
;; Note: Currently, for a new frame the sizes of the header
;; and mode line may be estimated incorrectly
(size
- (window-text-pixel-size window t t max-width max-height))
+ (window-text-pixel-size window from to max-width max-height))
(width (max (car size) min-width))
(height (max (cdr size) min-height)))
;; Don't change height or width when the window's size is fixed
@@ -10184,4 +10203,6 @@ displaying that processes's buffer."
(define-key ctl-x-4-map "1" 'same-window-prefix)
(define-key ctl-x-4-map "4" 'other-window-prefix)
+(provide 'window)
+
;;; window.el ends here