all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch for fit-window-to-buffer
@ 2020-03-04  3:16 Justin Burkett
  2020-03-04 17:31 ` martin rudalics
  0 siblings, 1 reply; 5+ messages in thread
From: Justin Burkett @ 2020-03-04  3:16 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 210 bytes --]

Hello,

I found a bug in the master and emacs-27 versions of fit-window-to-buffer.
Another window's data might be used to determine the new width. I'm
attaching a patch which I believe fixes the issue.

Justin

[-- Attachment #1.2: Type: text/html, Size: 292 bytes --]

[-- Attachment #2: 0001-lisp-window.el-fit-window-to-buffer-Don-t-use-wrong-.patch --]
[-- Type: application/octet-stream, Size: 931 bytes --]

From 02915c7c1b2b166d7dd0302bfac3f9ef880cbe59 Mon Sep 17 00:00:00 2001
From: Justin Burkett <justin@burkett.cc>
Date: Tue, 3 Mar 2020 22:01:29 -0500
Subject: [PATCH] * lisp/window.el (fit-window-to-buffer): Don't use wrong
 window data

---
 lisp/window.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/window.el b/lisp/window.el
index bd825c09e1..61c32ac72f 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9124,7 +9124,8 @@ fit-window-to-buffer
 	       ;; wider than its frame's pixel width, its height
 	       ;; remains unaltered.
 	       (width (+ (car (window-text-pixel-size
-			       window (window-start) (point-max)
+			       window (window-start window)
+                               (with-selected-window window (point-max))
 			       (frame-pixel-width)
 			       ;; Add one line-height to assure that
 			       ;; we're on the safe side.  This
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Patch for fit-window-to-buffer
  2020-03-04  3:16 Patch for fit-window-to-buffer Justin Burkett
@ 2020-03-04 17:31 ` martin rudalics
  2020-03-04 20:49   ` Justin Burkett
  0 siblings, 1 reply; 5+ messages in thread
From: martin rudalics @ 2020-03-04 17:31 UTC (permalink / raw)
  To: Justin Burkett, emacs-devel

 > I found a bug in the master and emacs-27 versions of fit-window-to-buffer.
 > Another window's data might be used to determine the new width. I'm
 > attaching a patch which I believe fixes the issue.

Thanks for finding these blatant bugs.  The 'window-start' fix is OK.

The 'point-max' fix could be improved: Since 'window-text-pixel-size'
has to make the buffer shown in WINDOW current before processing its
text anyway, it would IMO be more efficient to wrap the entire
'window-text-pixel-size' call into a

(with-current-buffer (window-buffer window)

form and thus avoid selecting WINDOW while providing the right buffer
for 'window-text-pixel-size' right away.  Can you try that?

Finally, the (frame-pixel-width) argument looks fishy too - it should
probably be (frame-pixel-width (window-frame window)).  Can you verify
that as well?

Thanks, martin



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Patch for fit-window-to-buffer
  2020-03-04 17:31 ` martin rudalics
@ 2020-03-04 20:49   ` Justin Burkett
  2020-03-05  9:12     ` martin rudalics
  0 siblings, 1 reply; 5+ messages in thread
From: Justin Burkett @ 2020-03-04 20:49 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 845 bytes --]

> The 'point-max' fix could be improved: Since 'window-text-pixel-size'
> has to make the buffer shown in WINDOW current before processing its
> text anyway, it would IMO be more efficient to wrap the entire
> 'window-text-pixel-size' call into a
>
> (with-current-buffer (window-buffer window)
>
> form and thus avoid selecting WINDOW while providing the right buffer
> for 'window-text-pixel-size' right away.  Can you try that?
>

I think the (point-max) is unnecessary here actually. According to the
docstring for window-text-pixel-size, nil should work here, no?

> Finally, the (frame-pixel-width) argument looks fishy too - it should
> probably be (frame-pixel-width (window-frame window)).  Can you verify
> that as well?

Yes, I made that change and the previous one in the patch attached. Both
work with my test case.

Thanks,
Justin

[-- Attachment #1.2: Type: text/html, Size: 1011 bytes --]

[-- Attachment #2: 0001-lisp-window.el-fit-window-to-buffer-Don-t-use-wrong-.patch --]
[-- Type: application/octet-stream, Size: 967 bytes --]

From 604bde6aae93934f8e67d0cda70f0e4004b50cc8 Mon Sep 17 00:00:00 2001
From: Justin Burkett <justin@burkett.cc>
Date: Tue, 3 Mar 2020 22:01:29 -0500
Subject: [PATCH] * lisp/window.el (fit-window-to-buffer): Don't use wrong
 window data

---
 lisp/window.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index bd825c09e1..039b133744 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9124,8 +9124,8 @@ fit-window-to-buffer
 	       ;; wider than its frame's pixel width, its height
 	       ;; remains unaltered.
 	       (width (+ (car (window-text-pixel-size
-			       window (window-start) (point-max)
-			       (frame-pixel-width)
+			       window (window-start window) nil
+			       (frame-pixel-width (window-frame window))
 			       ;; Add one line-height to assure that
 			       ;; we're on the safe side.  This
 			       ;; overshoots when the first line below
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Patch for fit-window-to-buffer
  2020-03-04 20:49   ` Justin Burkett
@ 2020-03-05  9:12     ` martin rudalics
  2020-03-05  9:39       ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: martin rudalics @ 2020-03-05  9:12 UTC (permalink / raw)
  To: Justin Burkett; +Cc: emacs-devel

 > I think the (point-max) is unnecessary here actually. According to the
 > docstring for window-text-pixel-size, nil should work here, no?

It should work.

 >> Finally, the (frame-pixel-width) argument looks fishy too - it should
 >> probably be (frame-pixel-width (window-frame window)).  Can you verify
 >> that as well?
 >
 > Yes, I made that change and the previous one in the patch attached. Both
 > work with my test case.

Applied to Emacs-27 (without asking for Eli's permission because the
bugs were all to obvious).

Thanks, martin



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Patch for fit-window-to-buffer
  2020-03-05  9:12     ` martin rudalics
@ 2020-03-05  9:39       ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2020-03-05  9:39 UTC (permalink / raw)
  To: martin rudalics; +Cc: justin, emacs-devel

> From: martin rudalics <rudalics@gmx.at>
> Date: Thu, 5 Mar 2020 10:12:57 +0100
> Cc: emacs-devel <emacs-devel@gnu.org>
> 
> Applied to Emacs-27 (without asking for Eli's permission because the
> bugs were all to obvious).

No need to ask questions whose answers are obvious.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-05  9:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-04  3:16 Patch for fit-window-to-buffer Justin Burkett
2020-03-04 17:31 ` martin rudalics
2020-03-04 20:49   ` Justin Burkett
2020-03-05  9:12     ` martin rudalics
2020-03-05  9:39       ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.