From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.bugs Subject: bug#7822: 24.0.50; `fit-window-to-buffer': take display artefacts into account Date: Wed, 12 Jan 2011 03:14:51 +0100 Message-ID: References: <7A4D04DE08AE47B8B59F98C7D0215CAD@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1294799069 28172 80.91.229.12 (12 Jan 2011 02:24:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 12 Jan 2011 02:24:29 +0000 (UTC) Cc: 7822@debbugs.gnu.org To: Drew Adams , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 12 03:24:24 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PcqNr-0004Sq-RF for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Jan 2011 03:24:24 +0100 Original-Received: from localhost ([127.0.0.1]:59365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcqNr-00009N-5B for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Jan 2011 21:24:23 -0500 Original-Received: from [140.186.70.92] (port=59972 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcqNi-00008z-Jk for bug-gnu-emacs@gnu.org; Tue, 11 Jan 2011 21:24:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PcqNh-0000qJ-6h for bug-gnu-emacs@gnu.org; Tue, 11 Jan 2011 21:24:14 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PcqNh-0000q7-4K for bug-gnu-emacs@gnu.org; Tue, 11 Jan 2011 21:24:13 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Pcq81-0005Gx-OE; Tue, 11 Jan 2011 21:08:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lennart Borgman Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Jan 2011 02:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7822 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 7822-submit@debbugs.gnu.org id=B7822.129479806720247 (code B ref 7822); Wed, 12 Jan 2011 02:08:01 +0000 Original-Received: (at 7822) by debbugs.gnu.org; 12 Jan 2011 02:07:47 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Pcq7m-0005GV-QS for submit@debbugs.gnu.org; Tue, 11 Jan 2011 21:07:47 -0500 Original-Received: from mail-ey0-f172.google.com ([209.85.215.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Pcq7k-0005GJ-C3 for 7822@debbugs.gnu.org; Tue, 11 Jan 2011 21:07:45 -0500 Original-Received: by eyd10 with SMTP id 10so44135eyd.3 for <7822@debbugs.gnu.org>; Tue, 11 Jan 2011 18:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=QgP3YDV5UXRPpDmmA+hrYz4jT/niRjYwVhggR2vYN7k=; b=X/jO1ItRz0T2y8Ht8H552+nzlW1G5uaMOM1JYmnh3G3RTGZXa1ZlQzryUo8B+Ulwnx m+ur/7sw1OVhb+P/KIYSiU+lxRZAsSFMRMpqgiTydF9qSV1vmn70bKWsQg/WnB5tw8rU 3Goy2SFZ+HEN1nMMpIlfU6U5mjW77uPJebYk4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=MKlFCxQnS9QiSWj4NO35srUrAaHf7NAILQ4jKsk23KP2BNwAXwLZ7rDInS+FbuG84P QKSb9p6IqxPj7CMmLXdNxttxjLQ1oBxcINuf0m0gh45fx2OBy6gthFm3/4lWo5BmDi7D nI8RlCJQNNGfIl9U7+wU5fYljCuh0W4h860BY= Original-Received: by 10.213.29.16 with SMTP id o16mr621333ebc.58.1294798512693; Tue, 11 Jan 2011 18:15:12 -0800 (PST) Original-Received: by 10.213.20.148 with HTTP; Tue, 11 Jan 2011 18:14:51 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 11 Jan 2011 21:08:01 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:43273 Archived-At: I started writing a solution for this (could we please move the discussion here?). It is not ready, but I paste it here for comments. The part currently fails because window-line-height returns nil - which I think is another Emacs bug. Anyway here is what I have written so far: (defun winsize-fit-window-to-buffer (&optional window max-height min-height) "A more complete `fit-window-to-buffer'. Fix-me: not ready, bug# 7822. Find through an iterative search minimal height to display whole buffer \(narrowed part if narrowed) and set window height to that height. Or, if that can not be done then set the height to the best possible height for fit. Try first to adjust window below and if that is not enough window above. " (let* ((window (or window (selected-window))) (frm (window-frame window)) (frm-height (frame-height frm)) here (above (windmove-find-other-window 'up nil window)) (below (windmove-find-other-window 'down nil window)) ;;(wcfg (current-window-configuration frm)) window-configuration-change-hook (eob-in-win (= (window-end window t) (point-max))) (curh (window-height window)) (minh (if (not eob-in-win) curh (or min-height window-min-height))) (orig-minh minh) (maxh (if eob-in-win curh (or max-height frm-height))) (orig-maxh maxh) midh done) (when (window-minibuffer-p below) (setq below nil)) (when (or above below) (with-current-buffer (window-buffer window) (setq here (point)) ;; First try resizing window below. (when below (while (and (not done) (> maxh minh)) (setq midh (+ minh (/ (- maxh minh) 2))) (let* ((winh (window-height window)) (delta (- midh winh)) did-it) (condition-case err (progn (adjust-window-trailing-edge window delta nil) (setq did-it t)) (error (message "%S" err))) (if did-it (progn (goto-char (point-min)) ;; Fix-me: This unfortunately returns t even if ;; the last line is partly hidden (test example ;; help for posn-at-x-y): (setq eob-in-win (= (window-end window t) (point-max))) ;; So let us try another way to check if eob is in window: (let* ((edges (window-inside-pixel-edges)) (left (1+ (nth 0 edges))) (bottom (1- (nth 3 edges)))) (setq eob-in-win (= (point-max) (posn-point (posn-at-x-y left bottom frm))))) (if eob-in-win ;; Fix-me: This assumes that posn-at-point is ;; relative to window text area. (let* ((loc (event-end (posn-at-point (point-max) window))) (loc-bottom (cdr loc)) (edges (window-inside-pixel-edges window)) (win-top (nth 1 edges)) (win-bottom (nth 3 edges)) (win-rel-bottom (- win-bottom win-top)) ;; Fix-me: This returns nil even though ;; we have updated above with ;; (window-end window t) and also after ;; (redisplay t) or (sit-for 0). (dummy (redisplay t)) (dummy2 (sit-for 0)) (bottom-line-height (window-line-height (line-number-at-pos (1- (point-max))) window))) ;; Make a guess if we are ready. (when (> bottom-line-height (- win-rel-bottom loc-bottom)) (setq done t)) (setq maxh midh)) (setq minh midh))) (if (< 0 delta) (setq maxh (1- maxh)) (setq minh (1+ minh)))) ))) ;; If we are not done try window above. (when above (while (and (not done) (> maxh minh)) (setq midh (+ minh (/ (- maxh minh) 2))) (let* ((winh (window-height window)) (delta (- winh midh)) did-it) ;; (when (> 0 delta) ;; Check window above min height ;; (setq delta (max delta ;; (- window-min-height ;; (window-height above)))) ;; (setq midh (- delta winh))) (condition-case err (progn (adjust-window-trailing-edge above delta nil) (setq did-it t)) (error (message "%S" err))) (if did-it (progn (goto-char (point-min)) (setq eob-in-win (= (window-end window t) (point-max))) (if eob-in-win (setq maxh midh) (setq minh midh))) (if (> 0 delta) (setq maxh (1- maxh)) (setq minh (1+ minh)))) ))) (goto-char here)) )))