GNU bug report logs -
#55169
Can't combine window-min-height with window-height
Previous Next
To reply to this bug, email your comments to 55169 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 28 Apr 2022 18:04:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Juri Linkov <juri <at> linkov.net>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 28 Apr 2022 18:04:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
As bug#33007 revealed, window-min-height doesn't prevent
from too narrow window height when using such call:
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-min-height . 10)
(window-height . fit-window-to-buffer)))
Shouldn't the order of processing these parameters be rather like this:
1. first set window-height with fit-window-to-buffer;
2. then check if the constraint of window-min-height is fulfilled,
and shrink too high window.
Then the caller could insert the initial string, and
'fit-window-to-buffer' will fit the window. If the window height
is less than 10 lines, it will enlarge to 10 lines. But in case of
too many lines, the window height should not be more than
half of the original window.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 29 Apr 2022 10:28:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 55169 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> Shouldn't the order of processing these parameters be rather like this:
>
> 1. first set window-height with fit-window-to-buffer;
> 2. then check if the constraint of window-min-height is fulfilled,
> and shrink too high window.
The original example looks odd to me, but I may just be misunderstanding
the window machinery (not for the first time).
But:
(display-buffer-below-selected
(current-buffer)
'((window-min-height . 10)
(window-height . fit-window-to-buffer)))
I'd expect that to work as you describe (or perhaps with the alist in
opposite order), and it doesn't. Perhaps Martin has some comments;
added to the CCs.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Sat, 30 Apr 2022 08:04:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> I'd expect that to work as you describe (or perhaps with the alist in
> opposite order), and it doesn't. Perhaps Martin has some comments;
> added to the CCs.
Ideally, a 'window-min-height' entry should be applied when an existing
window is used via 'display-buffer-use-some-window'. Just that in such
case we (i) don't even look at that entry and (ii) we would not apply a
'window-height' entry in the first place because that one is only used
for new windows or windows that always showed one and the same buffer.
Now
>> 1. first set window-height with fit-window-to-buffer;
>> 2. then check if the constraint of window-min-height is fulfilled,
>> and shrink too high window.
is in general non-trivial because "1." constitutes a fait accompli: We
need a _real_ window to calculate its desired size and whether it is
'window-resizable' to that size. So we may have to split some window
first to make "1." work. But what would we do then if "2." were not
satisfied? Restore the frame to a window configuration saved before
splitting?
Which means that the strategy proposed above would work seamlessly with
'display-buffer-reuse-window' only. But then would we really reject a
window showing a buffer already only because it's not large enough?
As usual we are caught in between long established conveniences and more
rigorous guide lines for how 'display-buffer' should behave.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Sun, 01 May 2022 17:49:03 GMT)
Full text and
rfc822 format available.
Message #14 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Ideally, a 'window-min-height' entry should be applied when an existing
> window is used via 'display-buffer-use-some-window'. Just that in such
> case we (i) don't even look at that entry and (ii) we would not apply a
> 'window-height' entry in the first place because that one is only used
> for new windows or windows that always showed one and the same buffer.
>
> Now
>
>>> 1. first set window-height with fit-window-to-buffer;
>>> 2. then check if the constraint of window-min-height is fulfilled,
>>> and shrink too high window.
>
> is in general non-trivial because "1." constitutes a fait accompli: We
> need a _real_ window to calculate its desired size and whether it is
> 'window-resizable' to that size. So we may have to split some window
> first to make "1." work. But what would we do then if "2." were not
> satisfied? Restore the frame to a window configuration saved before
> splitting?
>
> Which means that the strategy proposed above would work seamlessly with
> 'display-buffer-reuse-window' only. But then would we really reject a
> window showing a buffer already only because it's not large enough?
>
> As usual we are caught in between long established conveniences and more
> rigorous guide lines for how 'display-buffer' should behave.
Maybe as a workaround two calls of display-buffer would do the trick?
The first call display-buffer-below-selected will split the window,
then the second call display-buffer-use-some-window will adjust the height.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Mon, 02 May 2022 07:38:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Maybe as a workaround two calls of display-buffer would do the trick?
> The first call display-buffer-below-selected will split the window,
> then the second call display-buffer-use-some-window will adjust the height.
There would be no benefit in doing such a thing. The first call might
not be able to produce a window that satisfies the 'window-min-height'
constraint.
A correct solution would be to, before splitting, check whether the
split off window can be made as high as wanted. For that, we would have
to investigate all possible splittings over all actions allowed by the
ALIST argument to check whether the emanating split would satisfy the
height constraint (where the maximum possible height of a split off
window would be the sum of the total sizes minus their minimum sizes of
all windows in the same combination as the split one).
Our current strategy to usually split just the largest or LRU window is
much too naive in this regard. The problem with a new approach is that
we would have to tell people that when a 'window-min-height' entry is
present, the display strategy they got used to may change - the new
window might appear in a non-standard position. Who's to blame? The
one who bona fides added the 'window-min-height' constraint in a call or
the people who changed the semantics of 'display-buffer'?
BTW I do not understand well in which sense your original scenario
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-min-height . 10)
(window-height . fit-window-to-buffer)))
fails. Do you mean that the window should be at least ten lines high
despite of the fact that it's fit to an empty buffer?
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Mon, 02 May 2022 19:24:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> BTW I do not understand well in which sense your original scenario
>
> (pop-to-buffer (generate-new-buffer "*edit string*")
> '(display-buffer-below-selected
> (window-min-height . 10)
> (window-height . fit-window-to-buffer)))
>
> fails. Do you mean that the window should be at least ten lines high
> despite of the fact that it's fit to an empty buffer?
Exactly. I expected that window-min-height takes precedence over window-height.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Tue, 03 May 2022 09:22:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 55169 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> BTW I do not understand well in which sense your original scenario
>>
>> (pop-to-buffer (generate-new-buffer "*edit string*")
>> '(display-buffer-below-selected
>> (window-min-height . 10)
>> (window-height . fit-window-to-buffer)))
>>
>> fails. Do you mean that the window should be at least ten lines high
>> despite of the fact that it's fit to an empty buffer?
>
> Exactly. I expected that window-min-height takes precedence over window-height.
We could do something like the untested attached .diff. But we really
should install it only if at least two or three people confirm that it's
the expected behavior.
Note: ‘shrink-window-if-larger-than-buffer’ does not re-enlarge a window
that already shows the buffer if its height is less than the specified
'window-min-height'.
martin
[window--display-buffer.diff (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Tue, 03 May 2022 18:01:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>>> BTW I do not understand well in which sense your original scenario
>>>
>>> (pop-to-buffer (generate-new-buffer "*edit string*")
>>> '(display-buffer-below-selected
>>> (window-min-height . 10)
>>> (window-height . fit-window-to-buffer)))
>>>
>>> fails. Do you mean that the window should be at least ten lines high
>>> despite of the fact that it's fit to an empty buffer?
>>
>> Exactly. I expected that window-min-height takes precedence over window-height.
>
> We could do something like the untested attached .diff.
Thanks, I confirm that it works correctly.
> But we really should install it only if at least two or three people
> confirm that it's the expected behavior.
Do you think it's a too big change in behavior that might break some
existing configs?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 04 May 2022 07:55:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Do you think it's a too big change in behavior that might break some
> existing configs?
It introduces a certain inconsistency. So far, 'window-min-height' is
obeyed by 'display-buffer-below-selected' only. My patch would have
other clients obey it as well - but to a certain extent only. For
example, 'split-window-sensibly' will never care whether a window it
splits off can be made 'window-min-height' lines high. How would we
document that fact?
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 04 May 2022 19:34:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> Do you think it's a too big change in behavior that might break some
>> existing configs?
>
> It introduces a certain inconsistency. So far, 'window-min-height' is
> obeyed by 'display-buffer-below-selected' only. My patch would have
> other clients obey it as well - but to a certain extent only. For
> example, 'split-window-sensibly' will never care whether a window it
> splits off can be made 'window-min-height' lines high. How would we
> document that fact?
I didn't expect that 'split-window-sensibly' should pay attention
to 'window-min-height'. I though only 'display-buffer-*' are affected.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 05 May 2022 07:48:01 GMT)
Full text and
rfc822 format available.
Message #35 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> I didn't expect that 'split-window-sensibly' should pay attention
> to 'window-min-height'. I though only 'display-buffer-*' are affected.
'split-window-sensibly' is the function 'display-buffer-pop-up-window'
runs by default to make a new window. The dilemma is the following:
'display-buffer-below-selected', before it tries to split the selected
window, asserts that
(or (not (numberp min-height))
(window-sizable-p nil (- min-height)))
where 'min-height' is (cdr (assq 'window-min-height alist)).
'split-window-sensibly', however, may split off a window that is less
than 'min-height' lines high and cannot be enlarged afterwards either.
So far, this is OK because in the manual, in wise foresight, we say for
‘window-min-height’ that "The only client of this entry is presently
‘display-buffer-below-selected’". But if we obey 'window-min-height' in
'window--display-buffer', then 'display-buffer-pop-up-window' becomes a
client of 'window-min-height' without, however, fulfilling its premise
which says that "If ALIST contains a `window-min-height' entry, this
function ensures that the window used is or can become at least as high
as specified by that entry's value.".
We obviously could call 'split-window-sensibly' with an extra ALIST
argument and have it obey the 'window-min-height' constraint. But
'split-window-sensibly' is just the default value of the option
'split-window-preferred-function' (all these were invented some time
before 'display-buffer-alist') and that function accepts only one
argument. So we would have to amend 'window--try-to-split-window' as
(or (condition-case nil
(funcall split-window-preferred-function window alist)
(error nil))
(condition-case nil
(funcall split-window-preferred-function window)
(error nil)))))
No great deal but spilling out the details in the manual will inevitably
increase the mythical confusion around 'display-buffer-alist'.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 05 May 2022 08:31:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> No great deal but spilling out the details in the manual will inevitably
> increase the mythical confusion around 'display-buffer-alist'.
Also this increases the likelihood of regressions.
For example, with your latest patch, *Completions*
are no more fit into a small window, e.g.
'C-h f car TAB TAB' pops up too high window.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 05 May 2022 09:50:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Also this increases the likelihood of regressions.
> For example, with your latest patch, *Completions*
> are no more fit into a small window, e.g.
> 'C-h f car TAB TAB' pops up too high window.
Likely because the *Completions* window would become smaller than
'window-min-height'. Either decrease that or provide an explicit
'window-min-height' alist entry of 0 in the 'display-buffer' call.
It's a can or worms we'd open here.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 05 May 2022 16:39:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> Also this increases the likelihood of regressions.
>> For example, with your latest patch, *Completions*
>> are no more fit into a small window, e.g.
>> 'C-h f car TAB TAB' pops up too high window.
>
> Likely because the *Completions* window would become smaller than
> 'window-min-height'. Either decrease that or provide an explicit
> 'window-min-height' alist entry of 0 in the 'display-buffer' call.
>
> It's a can or worms we'd open here.
Do you think it would be simpler and thus more reliable
to enforce height constraints such as min-height
in fit-window-to-buffer?
This will be very clear to users to see how it works:
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-height (fit-window-to-buffer 10))))
where 10 is min-height.
Because it should be the task of fit-window-to-buffer,
and it already has the argument MIN-HEIGHT.
Also other arguments of fit-window-to-buffer
could be allowed to use in display-buffer-alist.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 06 May 2022 07:04:02 GMT)
Full text and
rfc822 format available.
Message #47 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Do you think it would be simpler and thus more reliable
> to enforce height constraints such as min-height
> in fit-window-to-buffer?
>
> This will be very clear to users to see how it works:
>
> (pop-to-buffer (generate-new-buffer "*edit string*")
> '(display-buffer-below-selected
> (window-height (fit-window-to-buffer 10))))
>
> where 10 is min-height.
>
> Because it should be the task of fit-window-to-buffer,
> and it already has the argument MIN-HEIGHT.
> Also other arguments of fit-window-to-buffer
> could be allowed to use in display-buffer-alist.
You mean the value of a 'window-height' entry could also be a
• A list whose CAR is a function and whose remaining elements
are the arguments passed to that function.
so we'd run
(ignore-errors (funcall (car height) window (nth 1 height) ...))
in 'window--display-buffer'? Which means the caller has to know the
function and which arguments it needs in which order. Sounds fragile.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 06 May 2022 08:00:03 GMT)
Full text and
rfc822 format available.
Message #50 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> Because it should be the task of fit-window-to-buffer,
>> and it already has the argument MIN-HEIGHT.
>> Also other arguments of fit-window-to-buffer
>> could be allowed to use in display-buffer-alist.
>
> You mean the value of a 'window-height' entry could also be a
>
> • A list whose CAR is a function and whose remaining elements
> are the arguments passed to that function.
>
> so we'd run
>
> (ignore-errors (funcall (car height) window (nth 1 height) ...))
>
> in 'window--display-buffer'? Which means the caller has to know the
> function and which arguments it needs in which order. Sounds fragile.
It is intended only for special handling of 'fit-window-to-buffer'.
If 'fit-window-to-buffer' with MIN-HEIGHT will really fix this problem,
then details of the entry format could be adapted later.
And indeed this works exactly as should with
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-height . fit-window-to-buffer)))
and an experimental patch:
diff --git a/lisp/window.el b/lisp/window.el
index 9f78784612..a21cf109a4 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7336,7 +7336,9 @@ window--display-buffer
(window-resize window delta nil 'safe t)))
(setq resize-temp-buffer-window-inhibit 'vertical))
((functionp height)
- (ignore-errors (funcall height window))
+ (if (eq height 'fit-window-to-buffer)
+ (ignore-errors (funcall height window nil 10))
+ (ignore-errors (funcall height window)))
(setq resize-temp-buffer-window-inhibit 'vertical)))
;; Adjust width of window if asked for.
(cond
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 06 May 2022 14:11:01 GMT)
Full text and
rfc822 format available.
Message #53 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> You mean the value of a 'window-height' entry could also be a
>>
>> • A list whose CAR is a function and whose remaining elements
>> are the arguments passed to that function.
>>
>> so we'd run
>>
>> (ignore-errors (funcall (car height) window (nth 1 height) ...))
>>
>> in 'window--display-buffer'? Which means the caller has to know the
>> function and which arguments it needs in which order. Sounds fragile.
>
> It is intended only for special handling of 'fit-window-to-buffer'.
> If 'fit-window-to-buffer' with MIN-HEIGHT will really fix this problem,
> then details of the entry format could be adapted later.
> And indeed this works exactly as should with
>
> (pop-to-buffer (generate-new-buffer "*edit string*")
> '(display-buffer-below-selected
> (window-height . fit-window-to-buffer)))
>
> and an experimental patch:
>
> diff --git a/lisp/window.el b/lisp/window.el
> index 9f78784612..a21cf109a4 100644
> --- a/lisp/window.el
> +++ b/lisp/window.el
> @@ -7336,7 +7336,9 @@ window--display-buffer
> (window-resize window delta nil 'safe t)))
> (setq resize-temp-buffer-window-inhibit 'vertical))
> ((functionp height)
> - (ignore-errors (funcall height window))
> + (if (eq height 'fit-window-to-buffer)
> + (ignore-errors (funcall height window nil 10))
> + (ignore-errors (funcall height window)))
> (setq resize-temp-buffer-window-inhibit 'vertical)))
> ;; Adjust width of window if asked for.
> (cond
This boils down to what I sketched above: ALIST must supply a list whose
car is 'fit-window-to-buffer' and 'window--display-buffer' supplies the
window used as first argument in its call to 'fit-window-to-buffer' and
the rest of the list as the remaining arguments.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 06 May 2022 15:36:02 GMT)
Full text and
rfc822 format available.
Message #56 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>>> You mean the value of a 'window-height' entry could also be a
>>>
>>> • A list whose CAR is a function and whose remaining elements
>>> are the arguments passed to that function.
>>>
>>> so we'd run
>>>
>>> (ignore-errors (funcall (car height) window (nth 1 height) ...))
>> ...
> This boils down to what I sketched above: ALIST must supply a list whose
> car is 'fit-window-to-buffer' and 'window--display-buffer' supplies the
> window used as first argument in its call to 'fit-window-to-buffer' and
> the rest of the list as the remaining arguments.
Then this could be an easy to explain rule. I'm only unsure about the
WINDOW argument. What if another function has a WINDOW argument in
another position, not the first? Maybe better to allow a lambda like this:
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-height . (lambda (window)
(fit-window-to-buffer window nil 10)))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Sat, 07 May 2022 07:59:02 GMT)
Full text and
rfc822 format available.
Message #59 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Then this could be an easy to explain rule. I'm only unsure about the
> WINDOW argument. What if another function has a WINDOW argument in
> another position, not the first? Maybe better to allow a lambda like this:
>
> (pop-to-buffer (generate-new-buffer "*edit string*")
> '(display-buffer-below-selected
> (window-height . (lambda (window)
> (fit-window-to-buffer window nil 10)))))
Sounds too complicated IMO. Let's stick to your earlier proposal as
(ignore-errors
(if (eq height 'fit-window-to-buffer)
(fit-window-to-buffer
window nil (cdr (assq 'window-min-height alist)))
(funcall height window)))
say something like "As a special case, if `window-height' specifies
`fit-window-to-buffer' and ALIST contains a `window-min-height' entry,
pass the value of that entry as MIN-HEIGHT argument to
`fit-window-to-buffer'." and do a similar thing for `window-min-width'.
And if we really want to, we can always add a MIN-HEIGHT argument to
'shrink-window-if-larger-than-buffer' and handle it the same way.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Sun, 08 May 2022 18:26:02 GMT)
Full text and
rfc822 format available.
Message #62 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> (pop-to-buffer (generate-new-buffer "*edit string*")
>> '(display-buffer-below-selected
>> (window-height . (lambda (window)
>> (fit-window-to-buffer window nil 10)))))
>
> Sounds too complicated IMO.
Actually a lambda is already supported, so no changes are required.
> Let's stick to your earlier proposal as
>
> (ignore-errors
> (if (eq height 'fit-window-to-buffer)
> (fit-window-to-buffer
> window nil (cdr (assq 'window-min-height alist)))
> (funcall height window)))
>
> say something like "As a special case, if `window-height' specifies
> `fit-window-to-buffer' and ALIST contains a `window-min-height' entry,
> pass the value of that entry as MIN-HEIGHT argument to
> `fit-window-to-buffer'." and do a similar thing for `window-min-width'.
A special case for fit-window-to-buffer, shrink-window-* and other similar
could be implemented only when you are sure that a `window-min-height' entry
is not going to be used for other purposes besides of using it as an argument
of a window-height entry.
BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
Would they be useful for a window-width entry?
> And if we really want to, we can always add a MIN-HEIGHT argument to
> 'shrink-window-if-larger-than-buffer' and handle it the same way.
This is very much needed, thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Mon, 09 May 2022 07:26:02 GMT)
Full text and
rfc822 format available.
Message #65 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>>> (pop-to-buffer (generate-new-buffer "*edit string*")
>>> '(display-buffer-below-selected
>>> (window-height . (lambda (window)
>>> (fit-window-to-buffer window nil 10)))))
>>
>> Sounds too complicated IMO.
>
> Actually a lambda is already supported, so no changes are required.
We have to find a suitable way to explain that in the manual.
> A special case for fit-window-to-buffer, shrink-window-* and other similar
> could be implemented only when you are sure that a `window-min-height' entry
> is not going to be used for other purposes besides of using it as an argument
> of a window-height entry.
You said that this is the case for 'fit-window-to-buffer' and that
function is the canonical client for a 'window-height' function. So why
bother about the rest?
> BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
> Would they be useful for a window-width entry?
Maybe. But let's talk about MAX-HEIGHT first.
>> And if we really want to, we can always add a MIN-HEIGHT argument to
>> 'shrink-window-if-larger-than-buffer' and handle it the same way.
>
> This is very much needed, thanks.
See below (this should also fix the lie about the return value).
martin
(defun shrink-window-if-larger-than-buffer (&optional window min-height)
"Shrink height of WINDOW if its buffer doesn't need so many lines.
More precisely, shrink WINDOW vertically to be as small as
possible, while still showing the full contents of its buffer.
WINDOW must be a live window and defaults to the selected one.
The optional argument MIN-HEIGHT specifies the minimum number of
lines to which WINDOW may be shrunk and defaults to
`window-min-height'.
Do nothing if the buffer contains more lines than the present
height of WINDOW, some of WINDOW's contents are scrolled out of
view, shrinking WINDOW would also shrink another window, or
WINDOW is the root window of its frame.
Return non-nil if WINDOW was shrunk, nil otherwise."
(interactive)
(setq window (window-normalize-window window t))
;; Make sure that WINDOW is vertically combined and `point-min' is
;; visible (for whatever reason that's needed). The remaining issues
;; should be taken care of by `fit-window-to-buffer'.
(when (and (window-combined-p window)
(pos-visible-in-window-p (point-min) window))
(let ((old-height (window-pixel-height window)))
(fit-window-to-buffer
window (window-total-height window) nil min-height)
(/= old-height (window-pixel-height window)))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Mon, 09 May 2022 07:40:01 GMT)
Full text and
rfc822 format available.
Message #68 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> (/= old-height (window-pixel-height window)))))
Better
(> old-height (window-pixel-height window)))))
since in some corner cases 'fit-window-to-buffer' might have grown
WINDOW by a few pixels here.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Mon, 09 May 2022 19:02:03 GMT)
Full text and
rfc822 format available.
Message #71 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>>>> (pop-to-buffer (generate-new-buffer "*edit string*")
>>>> '(display-buffer-below-selected
>>>> (window-height . (lambda (window)
>>>> (fit-window-to-buffer window nil 10)))))
>>>
>>> Sounds too complicated IMO.
>>
>> Actually a lambda is already supported, so no changes are required.
>
> We have to find a suitable way to explain that in the manual.
It's already documented in the manual:
• 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 are ‘fit-window-to-buffer’ and
‘shrink-window-if-larger-than-buffer’, see *note Resizing
Windows::.
It would be nice to add just a small example of a lambda with more args
for fit-window-to-buffer or shrink-window-if-larger-than-buffer.
>> A special case for fit-window-to-buffer, shrink-window-* and other similar
>> could be implemented only when you are sure that a `window-min-height' entry
>> is not going to be used for other purposes besides of using it as an argument
>> of a window-height entry.
>
> You said that this is the case for 'fit-window-to-buffer' and that
> function is the canonical client for a 'window-height' function. So why
> bother about the rest?
You found another function shrink-window-if-larger-than-buffer.
Then it would be better not to limit only to these two.
>> BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
>> Would they be useful for a window-width entry?
>
> Maybe. But let's talk about MAX-HEIGHT first.
Maybe MAX-WIDTH is not needed after all, as much as MAX-HEIGHT.
>>> And if we really want to, we can always add a MIN-HEIGHT argument to
>>> 'shrink-window-if-larger-than-buffer' and handle it the same way.
>>
>> This is very much needed, thanks.
>
> See below (this should also fix the lie about the return value).
Thanks, I'll test it. Does it need more args from fit-window-to-buffer?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Tue, 10 May 2022 07:42:02 GMT)
Full text and
rfc822 format available.
Message #74 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> It would be nice to add just a small example of a lambda with more args
> for fit-window-to-buffer or shrink-window-if-larger-than-buffer.
Maybe show the code you intend to use and how the user could override it
with 'shrink-window-if-larger-than-buffer' in 'display-buffer-alist'.
> You found another function shrink-window-if-larger-than-buffer.
> Then it would be better not to limit only to these two.
OK.
>>> BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
>>> Would they be useful for a window-width entry?
>>
>> Maybe. But let's talk about MAX-HEIGHT first.
>
> Maybe MAX-WIDTH is not needed after all, as much as MAX-HEIGHT.
Currently, we don't have to bother anyway. The only client of this is
'display-buffer-below-selected' and that hardly produces a horizontal
combination.
> Thanks, I'll test it. Does it need more args from fit-window-to-buffer?
None that I know of.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 11 May 2022 07:26:03 GMT)
Full text and
rfc822 format available.
Message #77 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> It would be nice to add just a small example of a lambda with more args
>> for fit-window-to-buffer or shrink-window-if-larger-than-buffer.
>
> Maybe show the code you intend to use and how the user could override it
> with 'shrink-window-if-larger-than-buffer' in 'display-buffer-alist'.
I have an example only for 'fit-window-to-buffer':
(pop-to-buffer (generate-new-buffer "*edit string*")
'(display-buffer-below-selected
(window-height . (lambda (window)
(fit-window-to-buffer window nil 10)))))
>>>> BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
>>>> Would they be useful for a window-width entry?
>>>
>>> Maybe. But let's talk about MAX-HEIGHT first.
>>
>> Maybe MAX-WIDTH is not needed after all, as much as MAX-HEIGHT.
>
> Currently, we don't have to bother anyway. The only client of this is
> 'display-buffer-below-selected' and that hardly produces a horizontal
> combination.
I wonder why other 'display-buffer-*' function wouldn't need the same?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 11 May 2022 08:20:02 GMT)
Full text and
rfc822 format available.
Message #80 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> I have an example only for 'fit-window-to-buffer':
>
> (pop-to-buffer (generate-new-buffer "*edit string*")
> '(display-buffer-below-selected
> (window-height . (lambda (window)
> (fit-window-to-buffer window nil 10)))))
I meant an example for how to put a lambda into 'display-buffer-alist'.
In either case, I still think we should provide an option where we pass
the window _and_ the alist to that function. Your example illustrates
well that we cannot integrate a user supplied 'window-min-height' entry
say into the application provided lambda. Vice versa, user supplied
functions cannot interact with application provided 'window-min-height'
entries.
Think of an application suggesting 'fit-window-to-buffer' with some
'window-min-height' value and a user who wants to use
'shrink-window-if-larger-than-buffer' instead but still use the
'window-min-height' value proposed by the application. How would we do
that?
> I wonder why other 'display-buffer-*' function wouldn't need the same?
All of 'display-buffer-same-window', 'display-buffer-reuse-window' and
'display-buffer-pop-up-window' should get the same treatment, probably.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 11 May 2022 09:04:01 GMT)
Full text and
rfc822 format available.
Message #83 received at 55169 <at> debbugs.gnu.org (full text, mbox):
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
> • 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 are ‘fit-window-to-buffer’ and
> ‘shrink-window-if-larger-than-buffer’, see *note Resizing
> Windows::.
That text is hard to read due to use of "that function" rather than
some sort of name. Would someone please improve this by using a
metasyntactic variable to refer to it? It could be
"@var{size-action}", perhaps.
--
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 12 May 2022 17:09:03 GMT)
Full text and
rfc822 format available.
Message #86 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> > • 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 are ‘fit-window-to-buffer’ and
> > ‘shrink-window-if-larger-than-buffer’, see *note Resizing
> > Windows::.
>
> That text is hard to read due to use of "that function" rather than
> some sort of name. Would someone please improve this by using a
> metasyntactic variable to refer to it? It could be
> "@var{size-action}", perhaps.
This excerpt was shown out of context. In the manual this
metasyntactic variable is named ‘window-height’.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 12 May 2022 17:09:03 GMT)
Full text and
rfc822 format available.
Message #89 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> I have an example only for 'fit-window-to-buffer':
>>
>> (pop-to-buffer (generate-new-buffer "*edit string*")
>> '(display-buffer-below-selected
>> (window-height . (lambda (window)
>> (fit-window-to-buffer window nil 10)))))
>
> I meant an example for how to put a lambda into 'display-buffer-alist'.
>
> In either case, I still think we should provide an option where we pass
> the window _and_ the alist to that function. Your example illustrates
> well that we cannot integrate a user supplied 'window-min-height' entry
> say into the application provided lambda. Vice versa, user supplied
> functions cannot interact with application provided 'window-min-height'
> entries.
Adding an alist is a good idea, but unfortunately it's not backwards-compatible.
> Think of an application suggesting 'fit-window-to-buffer' with some
> 'window-min-height' value and a user who wants to use
> 'shrink-window-if-larger-than-buffer' instead but still use the
> 'window-min-height' value proposed by the application. How would we do
> that?
I have no idea how to make this backwards-compatible.
>> I wonder why other 'display-buffer-*' function wouldn't need the same?
>
> All of 'display-buffer-same-window', 'display-buffer-reuse-window' and
> 'display-buffer-pop-up-window' should get the same treatment, probably.
Definitively the functions that create a new window
should take into account height constraints.
But not sure about functions that select the existing window.
Should they resize the existing window?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 13 May 2022 07:02:01 GMT)
Full text and
rfc822 format available.
Message #92 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Adding an alist is a good idea, but unfortunately it's not backwards-compatible.
That's what I'm trying to bring up ever since we started this thread.
AFAICT we'd need two new functions at least - an action function say
'display-buffer-split-window' and a 'dislay-buffer-fit-window' function
- both accepting the ALIST as (additional) argument.
>> Think of an application suggesting 'fit-window-to-buffer' with some
>> 'window-min-height' value and a user who wants to use
>> 'shrink-window-if-larger-than-buffer' instead but still use the
>> 'window-min-height' value proposed by the application. How would we do
>> that?
>
> I have no idea how to make this backwards-compatible.
It can be done with global variables but the resulting code will be
neither elegant nor comprehensible. IMO any such information must be
inevitably passed on through the ALIST argument.
> Definitively the functions that create a new window
> should take into account height constraints.
> But not sure about functions that select the existing window.
> Should they resize the existing window?
They do so already. With emacs -Q do
(pop-to-buffer (get-buffer-create "*edit string*")
'(display-buffer-below-selected
(window-height . (lambda (window)
(fit-window-to-buffer window nil 10)))))
followed by
(pop-to-buffer (get-buffer-create "*edit string*")
'(display-buffer-below-selected
(window-height . (lambda (window)
(fit-window-to-buffer window nil 20)))))
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Fri, 13 May 2022 17:07:02 GMT)
Full text and
rfc822 format available.
Message #95 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> Adding an alist is a good idea, but unfortunately it's not backwards-compatible.
>
> That's what I'm trying to bring up ever since we started this thread.
> AFAICT we'd need two new functions at least - an action function say
> 'display-buffer-split-window'
Can the existing 'display-buffer-in-direction' be used to split window?
Or a new action 'display-buffer-split-in-direction' is needed?
> and a 'dislay-buffer-fit-window' function
> - both accepting the ALIST as (additional) argument.
But they can't be used simultaneously? When 'display-buffer-split-window'
splits the window, then the next 'dislay-buffer-fit-window' is not called?
>>> Think of an application suggesting 'fit-window-to-buffer' with some
>>> 'window-min-height' value and a user who wants to use
>>> 'shrink-window-if-larger-than-buffer' instead but still use the
>>> 'window-min-height' value proposed by the application. How would we do
>>> that?
>>
>> I have no idea how to make this backwards-compatible.
>
> It can be done with global variables but the resulting code will be
> neither elegant nor comprehensible. IMO any such information must be
> inevitably passed on through the ALIST argument.
Maybe a new alist key could be added, e.g. 'window-fit',
that is like 'window-height' but also adds the new arg 'alist'?
>> Definitively the functions that create a new window
>> should take into account height constraints.
>> But not sure about functions that select the existing window.
>> Should they resize the existing window?
>
> They do so already. With emacs -Q do
>
> (pop-to-buffer (get-buffer-create "*edit string*")
> '(display-buffer-below-selected
> (window-height . (lambda (window)
> (fit-window-to-buffer window nil 10)))))
>
> followed by
>
> (pop-to-buffer (get-buffer-create "*edit string*")
> '(display-buffer-below-selected
> (window-height . (lambda (window)
> (fit-window-to-buffer window nil 20)))))
Nice!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Sat, 14 May 2022 07:50:01 GMT)
Full text and
rfc822 format available.
Message #98 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> That's what I'm trying to bring up ever since we started this thread.
>> AFAICT we'd need two new functions at least - an action function say
>> 'display-buffer-split-window'
>
> Can the existing 'display-buffer-in-direction' be used to split window?
Yes. I've rewritten it long ago but it now contains references to
functions based on scaling the body sizes of windows and implementing
these has stalled. Eventually, 'display-buffer-in-direction' should
replace 'display-buffer-pop-up-window' and its heuristics ...
> Or a new action 'display-buffer-split-in-direction' is needed?
No. The "-direction" suffix should tell enough about where the window
should go (incidentally, nowadays many people use side windows for that
purpose).
>> and a 'dislay-buffer-fit-window' function
>> - both accepting the ALIST as (additional) argument.
>
> But they can't be used simultaneously? When 'display-buffer-split-window'
> splits the window, then the next 'dislay-buffer-fit-window' is not called?
Sorry, I meant 'dislay-buffer--fit-window'. Not an action function but
one that would fit or shrink the window and accept the ALIST as extra
argument. So it could process all sorts of minimum or maximum heights
the user or application wants.
> Maybe a new alist key could be added, e.g. 'window-fit',
> that is like 'window-height' but also adds the new arg 'alist'?
Something like that, yes. It would end up calling the
'dislay-buffer--fit-window' function mentioned above.
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Wed, 18 May 2022 18:23:02 GMT)
Full text and
rfc822 format available.
Message #101 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> (defun shrink-window-if-larger-than-buffer (&optional window min-height)
> "Shrink height of WINDOW if its buffer doesn't need so many lines.
> More precisely, shrink WINDOW vertically to be as small as
> possible, while still showing the full contents of its buffer.
> WINDOW must be a live window and defaults to the selected one.
>
> The optional argument MIN-HEIGHT specifies the minimum number of
> lines to which WINDOW may be shrunk and defaults to
> `window-min-height'.
>
> Do nothing if the buffer contains more lines than the present
> height of WINDOW, some of WINDOW's contents are scrolled out of
> view, shrinking WINDOW would also shrink another window, or
> WINDOW is the root window of its frame.
>
> Return non-nil if WINDOW was shrunk, nil otherwise."
> (interactive)
> (setq window (window-normalize-window window t))
> ;; Make sure that WINDOW is vertically combined and `point-min' is
> ;; visible (for whatever reason that's needed). The remaining issues
> ;; should be taken care of by `fit-window-to-buffer'.
> (when (and (window-combined-p window)
> (pos-visible-in-window-p (point-min) window))
> (let ((old-height (window-pixel-height window)))
> (fit-window-to-buffer
> window (window-total-height window) nil min-height)
Thanks, this works fine, after removing nil above.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 19 May 2022 07:19:02 GMT)
Full text and
rfc822 format available.
Message #104 received at 55169 <at> debbugs.gnu.org (full text, mbox):
> Thanks, this works fine, after removing nil above.
Thanks for catching it.
So what shall I do? Check it in?
martin
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#55169
; Package
emacs
.
(Thu, 19 May 2022 16:34:01 GMT)
Full text and
rfc822 format available.
Message #107 received at 55169 <at> debbugs.gnu.org (full text, mbox):
>> Thanks, this works fine, after removing nil above.
>
> Thanks for catching it.
>
> So what shall I do? Check it in?
It looks safe to check in since it's a backward-compatible change.
This bug report was last modified 3 years and 27 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.