[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master beaddd8: Allow 'display-buffer' to set up body size of chosen win
From: |
Martin Rudalics |
Subject: |
master beaddd8: Allow 'display-buffer' to set up body size of chosen window (Bug#17065) |
Date: |
Mon, 25 Oct 2021 04:43:10 -0400 (EDT) |
branch: master
commit beaddd87f79b69fe2723206c9cbb2efacf34620d
Author: Martin Rudalics <rudalics@gmx.at>
Commit: Martin Rudalics <rudalics@gmx.at>
Allow 'display-buffer' to set up body size of chosen window (Bug#17065)
* doc/lispref/windows.texi (Buffer Display Action Alists):
Describe new possible values for 'window-height', 'window-width'
and 'window-size' action alist entries.
* lisp/window.el (window--display-buffer): Handle new values for
'window-height', 'window-width' and 'window-size' ALIST entries.
(display-buffer): Update doc-string for new values of some
action alist entries.
* etc/NEWS: Mention new values of some action alist entries.
---
doc/lispref/windows.texi | 20 ++++++-
etc/NEWS | 6 +++
lisp/window.el | 132 ++++++++++++++++++++++++++++-------------------
3 files changed, 104 insertions(+), 54 deletions(-)
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 2625160..9ce185a 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -3036,6 +3036,11 @@ desired total height with respect to the total height of
its frame's
root window.
@item
+A cons cell whose @sc{car} is @code{body-lines} and whose @sc{cdr} is an
+integer that specifies the height of the chosen window's body in frame
+lines.
+
+@item
If the value specifies a function, that function is called with one
argument---the chosen window. The function is supposed to adjust the
height of the window; its return value is ignored. Suitable functions
@@ -3069,6 +3074,11 @@ desired total width with respect to the total width of
the frame's
root window.
@item
+A cons cell whose @sc{car} is @code{body-columns} and whose @sc{cdr} is
+an integer that specifies the width of the chosen window's body in frame
+columns.
+
+@item
If the value specifies a function, that function is called with one
argument---the chosen window. The function is supposed to adjust the
width of the window; its return value is ignored.
@@ -3077,8 +3087,8 @@ width of the window; its return value is ignored.
@vindex window-size@r{, a buffer display action alist entry}
@item window-size
This entry is a combination of the two preceding ones and can be used to
-adjust the chosen window's height and width. Since windows can be
-resized in one direction only without affecting other windows,
+adjust the chosen window's height @emph{and} width. Since windows can
+be resized in one direction only without affecting other windows,
@code{window-size} is effective only to set up the size of a window
appearing alone on a frame. The value can be one of the following:
@@ -3092,6 +3102,12 @@ of the chosen window in lines and columns. It's effect
is to adjust the
size of the frame accordingly.
@item
+A cons cell whose @sc{car} equals @code{body-chars} and whose @sc{cdr}
+is a cons cell of two integers---the desired body width and height of
+the chosen window in frame columns and lines. It's effect is to adjust
+the size of the frame accordingly.
+
+@item
If the value specifies a function, that function is called with one
argument---the chosen window. The function is supposed to adjust the
size of the window's frame; its return value is ignored.
diff --git a/etc/NEWS b/etc/NEWS
index f6d36f1..90ad8d3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -67,6 +67,12 @@ This support is built by default when the libwebp library is
available. To disable it, use the '--without-webp' configure flag.
Image specifiers can now use ':type webp'.
+** Windows
+
++++
+*** 'display-buffer' now can set up the body size of the chosen window.
+For example, an alist entry as '(window-width . (body-columns . 40))'
+will make the body of the chosen window 40 columns wide.
* Editing Changes in Emacs 29.1
diff --git a/lisp/window.el b/lisp/window.el
index 132f093..848e618 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7234,7 +7234,8 @@ Return WINDOW if BUFFER and WINDOW are live."
(inhibit-modification-hooks t))
(funcall (cdr (assq 'body-function alist)) window)))
- (let* ((quit-restore (window-parameter window 'quit-restore))
+ (let* ((frame (window-frame window))
+ (quit-restore (window-parameter window 'quit-restore))
(window-height (assq 'window-height alist))
(height (cdr window-height))
(window-width (assq 'window-width alist))
@@ -7256,29 +7257,35 @@ Return WINDOW if BUFFER and WINDOW are live."
(when window-size
(setq resize-temp-buffer-window-inhibit t)))
((consp size)
- (let ((width (car size))
- (height (cdr size))
- (frame (window-frame window)))
- (when (and (numberp width) (numberp height))
- ;; Modifying the parameters of a newly created frame might
- ;; not work everywhere, but then `temp-buffer-resize-mode'
- ;; will certainly fail in a similar fashion.
+ ;; Modifying the parameters of a newly created frame might
+ ;; not work everywhere, but then `temp-buffer-resize-mode'
+ ;; will certainly fail in a similar fashion.
+ (if (eq (car size) 'body-chars)
+ (let ((width (+ (frame-text-width frame)
+ (* (frame-char-width frame) (cadr size))
+ (- (window-body-width window t))))
+ (height (+ (frame-text-height frame)
+ (* (frame-char-height frame) (cddr size))
+ (- (window-body-height window t)))))
+ (modify-frame-parameters
+ frame `((height . (text-pixels . ,height))
+ (width . (text-pixels . ,width)))))
+ (let ((width (- (+ (frame-width frame) (car size))
+ (window-total-width window)))
+ (height (- (+ (frame-height frame) (cdr size))
+ (window-total-height window))))
(modify-frame-parameters
- frame `((height . ,(+ (frame-height frame)
- (- height (window-total-height window))))
- (width . ,(+ (frame-width frame)
- (- width (window-total-width window))))))))
+ frame `((height . ,height) (width . ,width)))))
(setq resize-temp-buffer-window-inhibit t))
- ((functionp size)
+ ((functionp size)
(ignore-errors (funcall size window))
(setq resize-temp-buffer-window-inhibit t))))
((or (eq type 'window)
(and (eq (car quit-restore) 'same)
(eq (nth 1 quit-restore) 'window)))
;; A window that never showed another buffer but BUFFER ever
- ;; since it was created on an existing frame.
- ;;
- ;; Adjust width and/or height of window if asked for.
+ ;; since it was created on an existing frame. Adjust its width
+ ;; and/or height if asked for.
(cond
((not height)
(when window-height
@@ -7295,7 +7302,14 @@ Return WINDOW if BUFFER and WINDOW are live."
(window-combined-p window))
(window-resize window delta nil 'safe)))
(setq resize-temp-buffer-window-inhibit 'vertical))
- ((functionp height)
+ ((and (consp height) (eq (car height) 'body-lines))
+ (let* ((delta (- (* (frame-char-height frame) (cdr height))
+ (window-body-height window t))))
+ (and (window--resizable-p window delta nil 'safe nil nil nil t)
+ (window-combined-p window)
+ (window-resize window delta nil 'safe t)))
+ (setq resize-temp-buffer-window-inhibit 'vertical))
+ ((functionp height)
(ignore-errors (funcall height window))
(setq resize-temp-buffer-window-inhibit 'vertical)))
;; Adjust width of window if asked for.
@@ -7315,6 +7329,13 @@ Return WINDOW if BUFFER and WINDOW are live."
(window-combined-p window t))
(window-resize window delta t 'safe)))
(setq resize-temp-buffer-window-inhibit 'horizontal))
+ ((and (consp width) (eq (car width) 'body-columns))
+ (let* ((delta (- (* (frame-char-width frame) (cdr width))
+ (window-body-width window t))))
+ (and (window--resizable-p window delta t 'safe nil nil nil t)
+ (window-combined-p window t)
+ (window-resize window delta t 'safe t)))
+ (setq resize-temp-buffer-window-inhibit 'horizontal))
((functionp width)
(ignore-errors (funcall width window))
(setq resize-temp-buffer-window-inhibit 'horizontal)))
@@ -7564,11 +7585,12 @@ perform.
Action alist entries are:
`inhibit-same-window' -- A non-nil value prevents the same
window from being used for display.
-`inhibit-switch-frame' -- A non-nil value prevents any frame used
- for showing the buffer from being raised or selected. Note
- that a window manager may still raise a new frame and give it
- focus, effectively overriding the value specified here.
-`reusable-frames' -- The value specifies the set of frames to
+ `inhibit-switch-frame' -- A non-nil value prevents any frame
+ used for showing the buffer from being raised or selected.
+ Note that a window manager may still raise a new frame and
+ give it focus, effectively overriding the value specified
+ here.
+ `reusable-frames' -- The value specifies the set of frames to
search for a window that already displays the buffer.
Possible values are nil (the selected frame), t (any live
frame), visible (any visible frame), 0 (any visible or
@@ -7577,45 +7599,51 @@ Action alist entries are:
frame parameters to give a new frame, if one is created.
`window-height' -- The value specifies the desired height of the
window chosen and is either an integer (the total height of
- the window), a floating point number (the fraction of its
- total height with respect to the total height of the frame's
- root window) or a function to be called with one argument -
- the chosen window. The function is supposed to adjust the
- height of the window; its return value is ignored. Suitable
- functions are `shrink-window-if-larger-than-buffer' and
- `fit-window-to-buffer'.
+ the window specified in frame lines), a floating point
+ number (the fraction of its total height with respect to the
+ total height of the frame's root window), a cons cell whose
+ car is 'body-lines' and whose cdr is an integer that
+ specifies the height of the window's body in frame lines, or
+ a function to be called with one argument - the chosen
+ window. That function is supposed to adjust the height of
+ the window. Suitable functions are `fit-window-to-buffer'
+ and `shrink-window-if-larger-than-buffer'.
`window-width' -- The value specifies the desired width of the
window chosen and is either an integer (the total width of
- the window), a floating point number (the fraction of its
- total width with respect to the width of the frame's root
- window) or a function to be called with one argument - the
- chosen window. The function is supposed to adjust the width
- of the window; its return value is ignored.
+ the window specified in frame lines), a floating point
+ number (the fraction of its total width with respect to the
+ width of the frame's root window), a cons cell whose car is
+ 'body-columns' and whose cdr is an integer that specifies the
+ width of the window's body in frame columns, or a function to
+ be called with one argument - the chosen window. That
+ function is supposed to adjust the width of the window.
`window-size' -- This entry is only useful for windows appearing
alone on their frame and specifies the desired size of that
window either as a cons of integers (the total width and
- height of the window on that frame), or a function to be
- called with one argument - the chosen window. The function
- is supposed to adjust the size of the frame; its return value
- is ignored.
-`preserve-size' -- The value should be either (t . nil) to
+ height of the window on that frame), a cons cell whose car is
+ 'body-chars' and whose cdr is a cons of integers (the desired
+ width and height of the window's body in columns and lines of
+ its frame), or a function to be called with one argument -
+ the chosen window. That function is supposed to adjust the
+ size of the frame.
+ `preserve-size' -- The value should be either (t . nil) to
preserve the width of the chosen window, (nil . t) to
preserve its height or (t . t) to preserve its height and
width in future changes of the window configuration.
`window-parameters' -- The value specifies an alist of window
- parameters to give the chosen window.
- `allow-no-window' -- A non-nil value means that `display-buffer'
- may not display the buffer and return nil immediately.
- `body-function' -- A function called with one argument - the
- displayed window. It is called after the buffer is
- displayed, and before `window-height', `window-width'
- and `preserve-size' are applied. The function is supposed
- to fill the window body with some contents that might depend
- on dimensions of the displayed window.
-
-The entries `window-height', `window-width' and `preserve-size'
-are applied only when the window used for displaying the buffer
-never showed another buffer before.
+ parameters to give the chosen window. `allow-no-window' -- A
+ non-nil value means that `display-buffer' may not display the
+ buffer and return nil immediately. `body-function' -- A
+ function called with one argument - the displayed window. It
+ is called after the buffer is displayed, and before
+ `window-height', `window-width' and `preserve-size' are
+ applied. The function is supposed to fill the window body
+ with some contents that might depend on dimensions of the
+ displayed window.
+
+The entries `window-height', `window-width', `window-size' and
+`preserve-size' are applied only when the window used for
+displaying the buffer never showed another buffer before.
The ACTION argument can also have a non-nil and non-list value.
This means to display the buffer in a window other than the
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master beaddd8: Allow 'display-buffer' to set up body size of chosen window (Bug#17065),
Martin Rudalics <=