From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Titus von der Malsburg Newsgroups: gmane.emacs.bugs Subject: bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width Date: Wed, 17 Dec 2014 19:36:04 -0800 Message-ID: <87a92lmxy3.fsf@posteo.de> References: <87vblbnz2u.fsf@posteo.de> <83k31rwe55.fsf@gnu.org> <87lhm772o2.fsf@posteo.de> <83h9wvwbux.fsf@gnu.org> <87bnn39cpe.fsf@posteo.de> <83a92mwau9.fsf@gnu.org> <874msu9out.fsf@posteo.de> <83vblauoh6.fsf@gnu.org> <87wq5q864m.fsf@posteo.de> <83tx0uum88.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1418873844 29401 80.91.229.3 (18 Dec 2014 03:37:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 18 Dec 2014 03:37:24 +0000 (UTC) Cc: 19395@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 04:37:17 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y1Rts-00017T-Mr for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Dec 2014 04:37:16 +0100 Original-Received: from localhost ([::1]:52360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Rtr-0000Jx-UV for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 22:37:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Rtk-0000Ii-1W for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 22:37:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1Rte-00078s-Hy for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 22:37:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40053) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Rte-00078o-F6 for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 22:37:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y1Rte-0007iB-1M for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 22:37:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Titus von der Malsburg Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Dec 2014 03:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19395 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19395-submit@debbugs.gnu.org id=B19395.141887377529583 (code B ref 19395); Thu, 18 Dec 2014 03:37:01 +0000 Original-Received: (at 19395) by debbugs.gnu.org; 18 Dec 2014 03:36:15 +0000 Original-Received: from localhost ([127.0.0.1]:49419 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Rss-0007h4-DC for submit@debbugs.gnu.org; Wed, 17 Dec 2014 22:36:14 -0500 Original-Received: from mx02.posteo.de ([89.146.194.165]:42000) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Rso-0007gt-Ts for 19395@debbugs.gnu.org; Wed, 17 Dec 2014 22:36:12 -0500 Original-Received: from dovecot03.posteo.de (unknown [185.67.36.28]) by mx02.posteo.de (Postfix) with ESMTPS id D0AE925A3DD1; Thu, 18 Dec 2014 04:36:09 +0100 (CET) Original-Received: from mail.posteo.de (localhost [127.0.0.1]) by dovecot03.posteo.de (Postfix) with ESMTPSA id 3k2zQ06NBNz5vMw; Thu, 18 Dec 2014 04:36:08 +0100 (CET) In-reply-to: <83tx0uum88.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97481 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2014-12-17 Wed 11:09, Eli Zaretskii wrote: >> From: Titus von der Malsburg >> Cc: 19395@debbugs.gnu.org >> Date: Wed, 17 Dec 2014 10:48:25 -0800 >>=20 >> The problem is that there may not be a clean solution to that >> problem. A buffer can contain text is several font sizes and as far as >> I know there is no notion of a default size for a buffer, or is there? > > Yes, there is: the 'default' face. > >> In my special case, I have the font size under control and >> `term-window-width' would be good enough. > > But if we want this function to be more generally useful, it > shouldn't be limited to the frame's canonical character size, and > should at least take the face-remapping into account. Bonus points > for accepting a face as an argument and using that face's font > dimensions. This is more difficult than I thought. Below is a first sketch. Let me know if you think this is going in the right direction and I'll polish it and add the bonus feature. It appears that a font has to be rendered before Emacs can tell how wide a character is. That's why we need the temporary buffer. Not elegant, but I couldn't find a better way. `default-font-width' complements `default-font-height' in simple.el. The other function would go into window.el. Titus (defun default-font-width ()=20 "Return the width in pixels of the current buffer's default face font. More precisely, this returns the width of the letter =E2=80=98m=E2=80=99. If the font is mono-spaced, this will also be the wid= th of all other printable characters." (let ((window (selected-window)) (remapping face-remapping-alist)) (with-temp-buffer (make-local-variable 'face-remapping-alist) (setq face-remapping-alist remapping) (set-window-buffer window (current-buffer)) (insert "m") (aref (aref (font-get-glyphs (font-at 1) 1 2) 0) 4)))) (defun window-available-columns () "Return the maximal number of characters that can be displayed on one line. This function is different from `window-body-width' in that it accounts for fringes (when at least one fringe has zero width, one column is reserved for continuation characters) and for the size of the default font (which may have been adjusted using, e.g., `text-scale-increase')." (let* ((window-width (window-body-width nil t)) (font-width (default-font-width)) (ncols (/ window-width font-width))) (if (and (not (featurep 'xemacs)) (display-graphic-p) overflow-newline-into-fringe (/=3D (frame-parameter nil 'left-fringe) 0) (/=3D (frame-parameter nil 'right-fringe) 0)) ncols (1- (ncols))))) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUkkulAAoJEK40WfPGE2iddfcH+gO4yYXf10UiAy63sG+rky4F IkMzHa7N0VftlryQRL8bdss4wx9QoXpC5XphVzeD+dsYd3/QDOLKvdazXFFts1Gg dDyPFU/hPKgd3GKdiDEtoV+f8iOgkWmDd6tXSiuUn5RD8Y+cM73w+t+43vcaNyOL SA+1+1GQCka4iE109rbXRBkHHu96ef9b+pUHyg0RPvljF8ZSDIURtEO/kQVNhn2H oCILUjZiJVri1kP9jQvnxVB7pBgjVW72NyMukcPyY1ifEP4shpkqQvf66APyZAoe qEPG4/zbPQzPf/y0VJ5/QleZmo9o35IOPWRWCmXRuWNRmnktis8GqP7zNgHga74= =Yq4y -----END PGP SIGNATURE----- --=-=-=--