unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Kan-Ru Chen" <kanru@kanru.info>
To: 18498@debbugs.gnu.org
Subject: bug#18498: 24.3.93; [PATCH] Fix fit-window-to-buffer's buffer width calculation
Date: Thu, 18 Sep 2014 17:46:55 +0800	[thread overview]
Message-ID: <87k351uupc.fsf@kanru-mozilla.corp.tpe1.mozilla.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 625 bytes --]


To reproduce:

emacs -Q --eval '(progn (setq fit-window-to-buffer-horizontally t)
                        (set-frame-size nil 120 20)
                        (with-current-buffer-window "*scratch*" nil nil
                          (insert (make-string 20 ?x))
                          (insert (make-string 10 ?\n))
                          (insert (make-string 90 ?x))
                          (split-window-horizontally)
                          (fit-window-to-buffer)
                          (message "window width: %d" (window-width))))'

Expected result: window width: 90
Actual result: window width: 20

Patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-fit-window-to-buffer-s-buffer-width-calculation.patch --]
[-- Type: text/x-diff, Size: 1862 bytes --]

From 3bcdeb847e579981229b065b8dbd01722a94fc18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kan-Ru=20Chen=20=28=E9=99=B3=E4=BE=83=E5=A6=82=29?=
 <kanru@kanru.info>
Date: Thu, 18 Sep 2014 17:36:54 +0800
Subject: Fix fit-window-to-buffer's buffer width calculation

 * window.el (fit-window-to-buffer): When counting buffer width,
 count the whole visible buffer.  Correctly convert the body-height
 to pixel size for window-text-pixel-size.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c82b6f7..9096b92 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,8 +1,14 @@
+2014-09-18  Kan-Ru Chen  <kanru@kanru.info>
+
+	* window.el (fit-window-to-buffer): When counting buffer width,
+	count the whole visible buffer.  Correctly convert the body-height
+	to pixel size for window-text-pixel-size.
+
 2014-09-14  Glenn Morris  <rgm@gnu.org>
 
 	* image.el (image-multi-frame-p): Fix thinko - do not force
 	a delay if none was specified.  (Bug#18334)
 
 2014-09-12  Kan-Ru Chen  <kanru@kanru.info>
 
 	* window.el (fit-window-to-buffer): Doc fix.
diff --git a/lisp/window.el b/lisp/window.el
index 4dc30ff..c547725 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7296,17 +7296,17 @@ accessible position."
 		 (width (+ (car (window-text-pixel-size
 				 nil (window-start) (point-max)
 				 (frame-pixel-width)
 				 ;; Add one char-height to assure that
 				 ;; we're on the safe side.  This
 				 ;; overshoots when the first line below
 				 ;; the bottom is wider than the window.
 				 (* body-height
-				    (if pixelwise char-height 1))))
+				    (if pixelwise 1 char-height))))
 			   (window-right-divider-width))))
 	    (unless pixelwise
 	      (setq width (/ (+ width char-width -1) char-width)))
 	    (unless (= width body-width)
 	      (window-resize-no-error
 	       window
 	       (- (max min-width
 		       (min max-width
-- 
1.9.1


             reply	other threads:[~2014-09-18  9:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  9:46 Kan-Ru Chen [this message]
2014-09-18 12:08 ` bug#18498: 24.3.93; [PATCH] Fix fit-window-to-buffer's buffer width calculation martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k351uupc.fsf@kanru-mozilla.corp.tpe1.mozilla.com \
    --to=kanru@kanru.info \
    --cc=18498@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).