aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2014-01-13 08:47:15 +0100
committerMartin Rudalics2014-01-13 08:47:15 +0100
commit25a700d0fd5ef89458259ebc5f3c2aa117557c29 (patch)
tree5347bf16b65f545b10ff7b5d788f1732d429fa0e
parent6ae948d87e16588cd1c2a08d41331923e9786109 (diff)
downloademacs-25a700d0fd5ef89458259ebc5f3c2aa117557c29.tar.gz
emacs-25a700d0fd5ef89458259ebc5f3c2aa117557c29.zip
fit-frame/window-to-buffer code fixes including one for Bug#14096.
* window.el (fit-frame-to-buffer): Fix doc-string. Respect window-min-height/-width. Fit pixelwise when frame-resize-pixelwise is non-nil. Adjust right/bottom edge when avoiding that frame goes partially off-screen. (fit-window-to-buffer): Respect window-min-height/-width (Bug#14096).
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/window.el51
2 files changed, 40 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 241e4ed242b..8508ca7b357 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12014-01-13 Martin Rudalics <rudalics@gmx.at>
2
3 fit-frame/window-to-buffer code fixes including one for Bug#14096.
4 * window.el (fit-frame-to-buffer): Fix doc-string. Respect
5 window-min-height/-width. Fit pixelwise when
6 frame-resize-pixelwise is non-nil. Adjust right/bottom edge
7 when avoiding that frame goes partially off-screen.
8 (fit-window-to-buffer): Respect window-min-height/-width
9 (Bug#14096).
10
12014-01-13 Stefan Monnier <monnier@iro.umontreal.ca> 112014-01-13 Stefan Monnier <monnier@iro.umontreal.ca>
2 12
3 * indent.el (indent-according-to-mode): Flush to column 0 in text-mode 13 * indent.el (indent-according-to-mode): Flush to column 0 in text-mode
diff --git a/lisp/window.el b/lisp/window.el
index d1d8a5ea79c..29f38538855 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6824,7 +6824,8 @@ See also `fit-frame-to-buffer-margins'."
6824FRAME can be any live frame and defaults to the selected one. 6824FRAME can be any live frame and defaults to the selected one.
6825Fit only if FRAME's root window is live. MAX-HEIGHT, MIN-HEIGHT, 6825Fit only if FRAME's root window is live. MAX-HEIGHT, MIN-HEIGHT,
6826MAX-WIDTH and MIN-WIDTH specify bounds on the new total size of 6826MAX-WIDTH and MIN-WIDTH specify bounds on the new total size of
6827FRAME's root window. 6827FRAME's root window. MIN-HEIGHT and MIN-WIDTH default to the values of
6828`window-min-height' and `window-min-width' respectively.
6828 6829
6829The option `fit-frame-to-buffer' controls whether this function 6830The option `fit-frame-to-buffer' controls whether this function
6830has any effect. New position and size of FRAME are additionally 6831has any effect. New position and size of FRAME are additionally
@@ -6832,8 +6833,10 @@ determined by the options `fit-frame-to-buffer-sizes' and
6832`fit-frame-to-buffer-margins' or the corresponding parameters of 6833`fit-frame-to-buffer-margins' or the corresponding parameters of
6833FRAME." 6834FRAME."
6834 (interactive) 6835 (interactive)
6835 (or (fboundp 'x-display-pixel-height) 6836 (unless (and (fboundp 'x-display-pixel-height)
6836 (user-error "Cannot resize frame in non-graphic Emacs")) 6837 ;; We need the respective sizes now.
6838 (fboundp 'display-monitor-attributes-list))
6839 (user-error "Cannot resize frame in non-graphic Emacs"))
6837 (setq frame (window-normalize-frame frame)) 6840 (setq frame (window-normalize-frame frame))
6838 (when (and (window-live-p (frame-root-window frame)) 6841 (when (and (window-live-p (frame-root-window frame))
6839 fit-frame-to-buffer 6842 fit-frame-to-buffer
@@ -6938,7 +6941,8 @@ FRAME."
6938 (min-height 6941 (min-height
6939 (cond 6942 (cond
6940 ((numberp (nth 1 sizes)) (* (nth 1 sizes) char-height)) 6943 ((numberp (nth 1 sizes)) (* (nth 1 sizes) char-height))
6941 ((numberp min-height) (* min-height char-height)))) 6944 ((numberp min-height) (* min-height char-height))
6945 (t (* window-min-height char-height))))
6942 (max-width 6946 (max-width
6943 (cond 6947 (cond
6944 ((numberp (nth 2 sizes)) 6948 ((numberp (nth 2 sizes))
@@ -6950,7 +6954,8 @@ FRAME."
6950 ((numberp (nth 3 sizes)) 6954 ((numberp (nth 3 sizes))
6951 (- (* (nth 3 sizes) char-width) window-extra-width)) 6955 (- (* (nth 3 sizes) char-width) window-extra-width))
6952 ((numberp min-width) 6956 ((numberp min-width)
6953 (- (* min-width char-width) window-extra-width)))) 6957 (- (* min-width char-width) window-extra-width))
6958 (t (* window-min-width char-width))))
6954 ;; Note: Currently, for a new frame the sizes of the header 6959 ;; Note: Currently, for a new frame the sizes of the header
6955 ;; and mode line may be estimated incorrectly 6960 ;; and mode line may be estimated incorrectly
6956 (value (window-text-pixel-size 6961 (value (window-text-pixel-size
@@ -6958,7 +6963,7 @@ FRAME."
6958 (width (+ (car value) (window-right-divider-width))) 6963 (width (+ (car value) (window-right-divider-width)))
6959 (height (+ (cdr value) (window-bottom-divider-width))) 6964 (height (+ (cdr value) (window-bottom-divider-width)))
6960 remainder) 6965 remainder)
6961 (unless window-resize-pixelwise 6966 (unless frame-resize-pixelwise
6962 ;; Round sizes to character sizes. 6967 ;; Round sizes to character sizes.
6963 (setq remainder (% width char-width)) 6968 (setq remainder (% width char-width))
6964 (unless (zerop remainder) 6969 (unless (zerop remainder)
@@ -6987,12 +6992,11 @@ FRAME."
6987 ;; Add extra width. 6992 ;; Add extra width.
6988 (setq width (+ width extra-width)) 6993 (setq width (+ width extra-width))
6989 ;; Preserve right margin. 6994 ;; Preserve right margin.
6990 (let ((right (+ left width extra-width)) 6995 (let ((right (+ left width extra-width)))
6991 (max-right (- workarea-width right-margin)))
6992 (cond 6996 (cond
6993 ((> right max-right) 6997 ((> right right-margin)
6994 ;; Move FRAME to left. 6998 ;; Move frame to left (we don't know its real width).
6995 (setq left (max 0 (- left (- right max-right))))) 6999 (setq left (min (- right-margin display-width) -1)))
6996 ((< left left-margin) 7000 ((< left left-margin)
6997 ;; Move frame to right. 7001 ;; Move frame to right.
6998 (setq left left-margin))))) 7002 (setq left left-margin)))))
@@ -7005,12 +7009,11 @@ FRAME."
7005 ;; Add extra height. 7009 ;; Add extra height.
7006 (setq height (+ height extra-height)) 7010 (setq height (+ height extra-height))
7007 ;; Preserve bottom and top margins. 7011 ;; Preserve bottom and top margins.
7008 (let ((bottom (+ top height extra-height)) 7012 (let ((bottom (+ top height extra-height)))
7009 (max-bottom (- workarea-height bottom-margin)))
7010 (cond 7013 (cond
7011 ((> bottom max-bottom) 7014 ((> bottom bottom-margin)
7012 ;; Move FRAME to left. 7015 ;; Move frame up (we don't know its real height).
7013 (setq top (max 0 (- top (- bottom max-bottom))))) 7016 (setq top (min (- bottom-margin display-height) -1)))
7014 ((< top top-margin) 7017 ((< top top-margin)
7015 ;; Move frame down. 7018 ;; Move frame down.
7016 (setq top top-margin))))) 7019 (setq top top-margin)))))
@@ -7027,16 +7030,16 @@ FRAME."
7027 (set-frame-size 7030 (set-frame-size
7028 frame 7031 frame
7029 (if width 7032 (if width
7030 (if window-resize-pixelwise 7033 (if frame-resize-pixelwise
7031 width 7034 width
7032 (/ width char-width)) 7035 (/ width char-width))
7033 (frame-text-width)) 7036 (frame-text-width))
7034 (if height 7037 (if height
7035 (if window-resize-pixelwise 7038 (if frame-resize-pixelwise
7036 height 7039 height
7037 (/ height char-height)) 7040 (/ height char-height))
7038 (frame-text-height)) 7041 (frame-text-height))
7039 window-resize-pixelwise))))) 7042 frame-resize-pixelwise)))))
7040 7043
7041(defun fit-window-to-buffer (&optional window max-height min-height max-width min-width) 7044(defun fit-window-to-buffer (&optional window max-height min-height max-width min-width)
7042 "Adjust size of WINDOW to display its buffer's contents exactly. 7045 "Adjust size of WINDOW to display its buffer's contents exactly.
@@ -7098,7 +7101,10 @@ accessible position."
7098 (window-safe-min-pixel-height window) 7101 (window-safe-min-pixel-height window)
7099 window-safe-min-height)) 7102 window-safe-min-height))
7100 ;; Preserve header and mode line if present. 7103 ;; Preserve header and mode line if present.
7101 (window-min-size nil nil t pixelwise))) 7104 (max (if pixelwise
7105 (* char-height window-min-height)
7106 window-min-height)
7107 (window-min-size nil nil t pixelwise))))
7102 (max-height 7108 (max-height
7103 ;; Sanitize MAX-HEIGHT. 7109 ;; Sanitize MAX-HEIGHT.
7104 (if (numberp max-height) 7110 (if (numberp max-height)
@@ -7150,7 +7156,10 @@ accessible position."
7150 (window-safe-min-pixel-width) 7156 (window-safe-min-pixel-width)
7151 window-safe-min-width)) 7157 window-safe-min-width))
7152 ;; Preserve fringes, margins, scrollbars if present. 7158 ;; Preserve fringes, margins, scrollbars if present.
7153 (window-min-size nil nil t pixelwise))) 7159 (max (if pixelwise
7160 (* char-width window-min-width)
7161 window-min-width)
7162 (window-min-size nil nil t pixelwise))))
7154 (max-width 7163 (max-width
7155 ;; Sanitize MAX-WIDTH. 7164 ;; Sanitize MAX-WIDTH.
7156 (if (numberp max-width) 7165 (if (numberp max-width)