aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Rudalics2021-10-13 09:51:27 +0200
committerMartin Rudalics2021-10-13 09:51:27 +0200
commit2223c519a5b6c8f437ec4ece9028c9555cc98ea9 (patch)
treeac5f27ab220beec20af73dbc090bc4c2b249b60a /lisp
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/help.el40
-rw-r--r--lisp/window.el71
2 files changed, 73 insertions, 38 deletions
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.