aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2021-10-13 09:51:27 +0200
committerMartin Rudalics2021-10-13 09:51:27 +0200
commit2223c519a5b6c8f437ec4ece9028c9555cc98ea9 (patch)
treeac5f27ab220beec20af73dbc090bc4c2b249b60a
parentdec613d1e727b94fc3b672134d3a75063bd6b618 (diff)
downloademacs-2223c519a5b6c8f437ec4ece9028c9555cc98ea9.tar.gz
emacs-2223c519a5b6c8f437ec4ece9028c9555cc98ea9.zip
Improve 'display-buffer' 'temp-buffer-resize-mode' cohabitation (Bug#51062)
* doc/lispref/display.texi (Temporary Displays): Explain how to override the effect of 'temp-buffer-resize-mode' with a suitable 'display-buffer' action alist entry. * doc/lispref/windows.texi (Buffer Display Action Alists): Mention that an 'inhibit-switch-frame' entry might not work with every WM. Describe the 'window-size' entry. Describe how automatic window resizing can be overridden. * lisp/help.el (resize-temp-buffer-window-inhibit): New variable. (resize-temp-buffer-window): Handle case where user overrides automatic resizing. * lisp/window.el (temp-buffer-window-show): Bind 'resize-temp-buffer-window-inhibit' to nil around 'display-buffer'. Do not raise frame automatically to avoid defeating 'inhibit-switch-frame'. (window--display-buffer): Set 'resize-temp-buffer-window-inhibit' to t when the action alist contains a 'window-height', 'window-width' or 'window-size' entry. Use 'modify-frame-parameters' instead of 'set-frame-height' and 'set-frame-width' to avoid that the latter step on each others toes. (display-buffer): Fix 'inhibit-switch-frame' part in and add 'window-size' part to doc-string.
-rw-r--r--doc/lispref/display.texi5
-rw-r--r--doc/lispref/windows.texi48
-rw-r--r--lisp/help.el40
-rw-r--r--lisp/window.el71
4 files changed, 116 insertions, 48 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 2ae04a85218..52fe97b2993 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1334,6 +1334,11 @@ are not resized. By default, this mode uses @code{fit-window-to-buffer}
1334(@pxref{Resizing Windows}) for resizing. You can specify a different 1334(@pxref{Resizing Windows}) for resizing. You can specify a different
1335function by customizing the options @code{temp-buffer-max-height} and 1335function by customizing the options @code{temp-buffer-max-height} and
1336@code{temp-buffer-max-width} below. 1336@code{temp-buffer-max-width} below.
1337
1338The effect of this option can be overridden by providing a suitable
1339@code{window-height}, @code{window-width} or @code{window-size} action
1340alist entry for @code{display-buffer} (@pxref{Buffer Display Action
1341Alists}).
1337@end defopt 1342@end defopt
1338 1343
1339@defopt temp-buffer-max-height 1344@defopt temp-buffer-max-height
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 679744884a3..d015ac1844f 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -2924,9 +2924,9 @@ A non-@code{nil} value prevents another frame from being raised or
2924selected, if the window chosen by @code{display-buffer} is displayed 2924selected, if the window chosen by @code{display-buffer} is displayed
2925there. Primarily affected by this are 2925there. Primarily affected by this are
2926@code{display-buffer-use-some-frame} and 2926@code{display-buffer-use-some-frame} and
2927@code{display-buffer-reuse-window}. 2927@code{display-buffer-reuse-window}. Ideally,
2928@code{display-buffer-pop-up-frame} should be affected as well, but 2928@code{display-buffer-pop-up-frame} should be affected as well, but there
2929there is no guarantee that the window manager will comply. 2929is no guarantee that the window manager will comply.
2930 2930
2931@vindex window-parameters@r{, a buffer display action alist entry} 2931@vindex window-parameters@r{, a buffer display action alist entry}
2932@item window-parameters 2932@item window-parameters
@@ -2972,8 +2972,8 @@ root window.
2972If the value specifies a function, that function is called with one 2972If the value specifies a function, that function is called with one
2973argument---the chosen window. The function is supposed to adjust the 2973argument---the chosen window. The function is supposed to adjust the
2974height of the window; its return value is ignored. Suitable functions 2974height of the window; its return value is ignored. Suitable functions
2975are @code{shrink-window-if-larger-than-buffer} and 2975are @code{fit-window-to-buffer} and
2976@code{fit-window-to-buffer}, see @ref{Resizing Windows}. 2976@code{shrink-window-if-larger-than-buffer}, see @ref{Resizing Windows}.
2977@end itemize 2977@end itemize
2978 2978
2979By convention, the height of the chosen window is adjusted only if the 2979By convention, the height of the chosen window is adjusted only if the
@@ -3007,11 +3007,31 @@ argument---the chosen window. The function is supposed to adjust the
3007width of the window; its return value is ignored. 3007width of the window; its return value is ignored.
3008@end itemize 3008@end itemize
3009 3009
3010By convention, the width of the chosen window is adjusted only if the 3010@vindex window-size@r{, a buffer display action alist entry}
3011window is part of a horizontal combination (@pxref{Windows and 3011@item window-size
3012Frames}) to avoid changing the width of other, unrelated windows. 3012This entry is a combination of the two preceding ones and can be used to
3013Also, this entry should be processed under only certain conditions 3013adjust the chosen window's height and width. Since windows can be
3014which are specified right below this list. 3014resized in one direction only without affecting other windows,
3015@code{window-size} is effective only to set up the size of a window
3016appearing alone on a frame. The value can be one of the following:
3017
3018@itemize @bullet
3019@item
3020@code{nil} means to leave the size of the chosen window alone.
3021
3022@item
3023A cons cell of two integers specifies the desired total width and height
3024of the chosen window in lines and columns. It's effect is to adjust the
3025size of the frame accordingly.
3026
3027@item
3028If the value specifies a function, that function is called with one
3029argument---the chosen window. The function is supposed to adjust the
3030size of the window's frame; its return value is ignored.
3031@end itemize
3032
3033This entry should be processed under only certain conditions which are
3034specified right below this list.
3015 3035
3016@vindex dedicated@r{, a buffer display action alist entry} 3036@vindex dedicated@r{, a buffer display action alist entry}
3017@item dedicated 3037@item dedicated
@@ -3112,6 +3132,14 @@ the window was created earlier by @code{display-buffer} to show the
3112buffer and never was used to show another buffer until it was reused 3132buffer and never was used to show another buffer until it was reused
3113by the current invocation of @code{display-buffer}. 3133by the current invocation of @code{display-buffer}.
3114 3134
3135If no @code{window-height}, @code{window-width} or @code{window-size}
3136entry was specified, the window may still be resized automatically when
3137the buffer is temporary and @code{temp-buffer-resize-mode} has been
3138enabled, @ref{Temporary Displays}. In that case, the @sc{cdr} of a
3139@code{window-height}, @code{window-width} or @code{window-size} entry
3140can be used to inhibit or override the default behavior of
3141@code{temp-buffer-resize-mode} for specific buffers or invocations of
3142@code{display-buffer}.
3115 3143
3116@node Choosing Window Options 3144@node Choosing Window Options
3117@subsection Additional Options for Displaying Buffers 3145@subsection Additional Options for Displaying Buffers
diff --git a/lisp/help.el b/lisp/help.el
index eaca33795ae..fa4eaee417d 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1596,10 +1596,16 @@ and some others."
1596 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append) 1596 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1597 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window))) 1597 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1598 1598
1599(defvar resize-temp-buffer-window-inhibit nil
1600 "Non-nil means `resize-temp-buffer-window' should not resize.")
1601
1599(defun resize-temp-buffer-window (&optional window) 1602(defun resize-temp-buffer-window (&optional window)
1600 "Resize WINDOW to fit its contents. 1603 "Resize WINDOW to fit its contents.
1601WINDOW must be a live window and defaults to the selected one. 1604WINDOW must be a live window and defaults to the selected one.
1602Do not resize if WINDOW was not created by `display-buffer'. 1605Do not resize if WINDOW was not created by `display-buffer'. Do
1606not resize either if a `window-height', `window-width' or
1607`window-size' entry in `display-buffer-alist' prescribes some
1608alternative resizing for WINDOW's buffer.
1603 1609
1604If WINDOW is part of a vertical combination, restrain its new 1610If WINDOW is part of a vertical combination, restrain its new
1605size by `temp-buffer-max-height' and do not resize if its minimum 1611size by `temp-buffer-max-height' and do not resize if its minimum
@@ -1614,27 +1620,33 @@ provided `fit-frame-to-buffer' is non-nil.
1614This function may call `preserve-window-size' to preserve the 1620This function may call `preserve-window-size' to preserve the
1615size of WINDOW." 1621size of WINDOW."
1616 (setq window (window-normalize-window window t)) 1622 (setq window (window-normalize-window window t))
1617 (let ((height (if (functionp temp-buffer-max-height) 1623 (let* ((buffer (window-buffer window))
1624 (height (if (functionp temp-buffer-max-height)
1625 (with-selected-window window
1626 (funcall temp-buffer-max-height buffer))
1627 temp-buffer-max-height))
1628 (width (if (functionp temp-buffer-max-width)
1618 (with-selected-window window 1629 (with-selected-window window
1619 (funcall temp-buffer-max-height (window-buffer))) 1630 (funcall temp-buffer-max-width buffer))
1620 temp-buffer-max-height)) 1631 temp-buffer-max-width))
1621 (width (if (functionp temp-buffer-max-width) 1632 (quit-cadr (cadr (window-parameter window 'quit-restore))))
1622 (with-selected-window window 1633 ;; Resize WINDOW only if it was made by `display-buffer'.
1623 (funcall temp-buffer-max-width (window-buffer)))
1624 temp-buffer-max-width))
1625 (quit-cadr (cadr (window-parameter window 'quit-restore))))
1626 ;; Resize WINDOW iff it was made by `display-buffer'.
1627 (when (or (and (eq quit-cadr 'window) 1634 (when (or (and (eq quit-cadr 'window)
1628 (or (and (window-combined-p window) 1635 (or (and (window-combined-p window)
1629 (not (eq fit-window-to-buffer-horizontally 1636 (not (eq fit-window-to-buffer-horizontally
1630 'only)) 1637 'only))
1631 (pos-visible-in-window-p (point-min) window)) 1638 (pos-visible-in-window-p
1639 (with-current-buffer buffer (point-min))
1640 window)
1641 (not resize-temp-buffer-window-inhibit))
1632 (and (window-combined-p window t) 1642 (and (window-combined-p window t)
1633 fit-window-to-buffer-horizontally))) 1643 fit-window-to-buffer-horizontally
1644 (not resize-temp-buffer-window-inhibit))))
1634 (and (eq quit-cadr 'frame) 1645 (and (eq quit-cadr 'frame)
1635 fit-frame-to-buffer 1646 fit-frame-to-buffer
1636 (eq window (frame-root-window window)))) 1647 (eq window (frame-root-window window))
1637 (fit-window-to-buffer window height nil width nil t)))) 1648 (not resize-temp-buffer-window-inhibit)))
1649 (fit-window-to-buffer window height nil width nil t))))
1638 1650
1639;;; Help windows. 1651;;; Help windows.
1640(defcustom help-window-select nil 1652(defcustom help-window-select nil
diff --git a/lisp/window.el b/lisp/window.el
index 971264b6344..1a5f2d40067 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -108,11 +108,14 @@ Return the buffer."
108 ;; Return the buffer. 108 ;; Return the buffer.
109 buffer))) 109 buffer)))
110 110
111;; Defined in help.el.
112(defvar resize-temp-buffer-window-inhibit)
113
111(defun temp-buffer-window-show (buffer &optional action) 114(defun temp-buffer-window-show (buffer &optional action)
112 "Show temporary buffer BUFFER in a window. 115 "Show temporary buffer BUFFER in a window.
113Return the window showing BUFFER. Pass ACTION as action argument 116Return the window showing BUFFER. Pass ACTION as action argument
114to `display-buffer'." 117to `display-buffer'."
115 (let (window frame) 118 (let (resize-temp-buffer-window-inhibit window)
116 (with-current-buffer buffer 119 (with-current-buffer buffer
117 (set-buffer-modified-p nil) 120 (set-buffer-modified-p nil)
118 (setq buffer-read-only t) 121 (setq buffer-read-only t)
@@ -130,9 +133,9 @@ to `display-buffer'."
130 t 133 t
131 window-combination-limit))) 134 window-combination-limit)))
132 (setq window (display-buffer buffer action))) 135 (setq window (display-buffer buffer action)))
133 (setq frame (window-frame window)) 136 ;; We used to raise the window's frame here. Do not do that
134 (unless (eq frame (selected-frame)) 137 ;; since it would override an `inhibit-switch-frame' entry
135 (raise-frame frame)) 138 ;; specified for the action alist used by `display-buffer'.
136 (setq minibuffer-scroll-window window) 139 (setq minibuffer-scroll-window window)
137 (set-window-hscroll window 0) 140 (set-window-hscroll window 0)
138 (with-selected-window window 141 (with-selected-window window
@@ -7246,11 +7249,14 @@ Return WINDOW if BUFFER and WINDOW are live."
7246 (inhibit-modification-hooks t)) 7249 (inhibit-modification-hooks t))
7247 (funcall (cdr (assq 'body-function alist)) window))) 7250 (funcall (cdr (assq 'body-function alist)) window)))
7248 7251
7249 (let ((quit-restore (window-parameter window 'quit-restore)) 7252 (let* ((quit-restore (window-parameter window 'quit-restore))
7250 (height (cdr (assq 'window-height alist))) 7253 (window-height (assq 'window-height alist))
7251 (width (cdr (assq 'window-width alist))) 7254 (height (cdr window-height))
7252 (size (cdr (assq 'window-size alist))) 7255 (window-width (assq 'window-width alist))
7253 (preserve-size (cdr (assq 'preserve-size alist)))) 7256 (width (cdr window-width))
7257 (window-size (assq 'window-size alist))
7258 (size (cdr window-size))
7259 (preserve-size (cdr (assq 'preserve-size alist))))
7254 (cond 7260 (cond
7255 ((or (eq type 'frame) 7261 ((or (eq type 'frame)
7256 (and (eq (car quit-restore) 'same) 7262 (and (eq (car quit-restore) 'same)
@@ -7267,14 +7273,18 @@ Return WINDOW if BUFFER and WINDOW are live."
7267 (height (cdr size)) 7273 (height (cdr size))
7268 (frame (window-frame window))) 7274 (frame (window-frame window)))
7269 (when (and (numberp width) (numberp height)) 7275 (when (and (numberp width) (numberp height))
7270 (set-frame-height 7276 ;; Modifying the parameters of a newly created frame might
7271 frame (+ (frame-height frame) 7277 ;; not work everywhere, but then `temp-buffer-resize-mode'
7272 (- height (window-total-height window)))) 7278 ;; will certainly fail in a similar fashion.
7273 (set-frame-width 7279 (modify-frame-parameters
7274 frame (+ (frame-width frame) 7280 frame `((height . ,(+ (frame-height frame)
7275 (- width (window-total-width window))))))) 7281 (- height (window-total-height window))))
7282 (width . ,(+ (frame-width frame)
7283 (- width (window-total-width window))))))))
7284 (setq resize-temp-buffer-window-inhibit t))
7276 ((functionp size) 7285 ((functionp size)
7277 (ignore-errors (funcall size window))))) 7286 (ignore-errors (funcall size window))
7287 (setq resize-temp-buffer-window-inhibit t))))
7278 ((or (eq type 'window) 7288 ((or (eq type 'window)
7279 (and (eq (car quit-restore) 'same) 7289 (and (eq (car quit-restore) 'same)
7280 (eq (nth 1 quit-restore) 'window))) 7290 (eq (nth 1 quit-restore) 'window)))
@@ -7294,9 +7304,11 @@ Return WINDOW if BUFFER and WINDOW are live."
7294 (delta (- new-height (window-total-height window)))) 7304 (delta (- new-height (window-total-height window))))
7295 (when (and (window--resizable-p window delta nil 'safe) 7305 (when (and (window--resizable-p window delta nil 'safe)
7296 (window-combined-p window)) 7306 (window-combined-p window))
7297 (window-resize window delta nil 'safe)))) 7307 (window-resize window delta nil 'safe)))
7308 (setq resize-temp-buffer-window-inhibit 'vertical))
7298 ((functionp height) 7309 ((functionp height)
7299 (ignore-errors (funcall height window)))) 7310 (ignore-errors (funcall height window))
7311 (setq resize-temp-buffer-window-inhibit 'vertical)))
7300 ;; Adjust width of window if asked for. 7312 ;; Adjust width of window if asked for.
7301 (cond 7313 (cond
7302 ((not width)) 7314 ((not width))
@@ -7310,9 +7322,11 @@ Return WINDOW if BUFFER and WINDOW are live."
7310 (delta (- new-width (window-total-width window)))) 7322 (delta (- new-width (window-total-width window))))
7311 (when (and (window--resizable-p window delta t 'safe) 7323 (when (and (window--resizable-p window delta t 'safe)
7312 (window-combined-p window t)) 7324 (window-combined-p window t))
7313 (window-resize window delta t 'safe)))) 7325 (window-resize window delta t 'safe)))
7326 (setq resize-temp-buffer-window-inhibit 'horizontal))
7314 ((functionp width) 7327 ((functionp width)
7315 (ignore-errors (funcall width window)))) 7328 (ignore-errors (funcall width window))
7329 (setq resize-temp-buffer-window-inhibit 'horizontal)))
7316 ;; Preserve window size if asked for. 7330 ;; Preserve window size if asked for.
7317 (when (consp preserve-size) 7331 (when (consp preserve-size)
7318 (window-preserve-size window t (car preserve-size)) 7332 (window-preserve-size window t (car preserve-size))
@@ -7557,9 +7571,11 @@ perform.
7557Action alist entries are: 7571Action alist entries are:
7558 `inhibit-same-window' -- A non-nil value prevents the same 7572 `inhibit-same-window' -- A non-nil value prevents the same
7559 window from being used for display. 7573 window from being used for display.
7560 `inhibit-switch-frame' -- A non-nil value prevents any frame 7574`inhibit-switch-frame' -- A non-nil value prevents any frame used
7561 used for showing the buffer from being raised or selected. 7575 for showing the buffer from being raised or selected. Note
7562 `reusable-frames' -- The value specifies the set of frames to 7576 that a window manager may still raise a new frame and give it
7577 focus, effectively overriding the value specified here.
7578`reusable-frames' -- The value specifies the set of frames to
7563 search for a window that already displays the buffer. 7579 search for a window that already displays the buffer.
7564 Possible values are nil (the selected frame), t (any live 7580 Possible values are nil (the selected frame), t (any live
7565 frame), visible (any visible frame), 0 (any visible or 7581 frame), visible (any visible frame), 0 (any visible or
@@ -7582,7 +7598,14 @@ Action alist entries are:
7582 window) or a function to be called with one argument - the 7598 window) or a function to be called with one argument - the
7583 chosen window. The function is supposed to adjust the width 7599 chosen window. The function is supposed to adjust the width
7584 of the window; its return value is ignored. 7600 of the window; its return value is ignored.
7585 `preserve-size' -- The value should be either (t . nil) to 7601 `window-size' -- This entry is only useful for windows appearing
7602 alone on their frame and specifies the desired size of that
7603 window either as a cons of integers (the total width and
7604 height of the window on that frame), or a function to be
7605 called with one argument - the chosen window. The function
7606 is supposed to adjust the size of the frame; its return value
7607 is ignored.
7608`preserve-size' -- The value should be either (t . nil) to
7586 preserve the width of the chosen window, (nil . t) to 7609 preserve the width of the chosen window, (nil . t) to
7587 preserve its height or (t . t) to preserve its height and 7610 preserve its height or (t . t) to preserve its height and
7588 width in future changes of the window configuration. 7611 width in future changes of the window configuration.