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: Sat, 20 Dec 2014 15:51:27 +0100 Message-ID: <87oaqyz85s.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> <87a92lmxy3.fsf@posteo.de> <837fxpue6v.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 1419087149 2931 80.91.229.3 (20 Dec 2014 14:52:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Dec 2014 14:52:29 +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 Sat Dec 20 15:52:20 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 1Y2LOF-0001H6-NH for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Dec 2014 15:52:19 +0100 Original-Received: from localhost ([::1]:34608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2LOE-0000Ve-TE for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Dec 2014 09:52:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2LO7-0000VQ-1S for bug-gnu-emacs@gnu.org; Sat, 20 Dec 2014 09:52:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2LNz-0005HI-Ca for bug-gnu-emacs@gnu.org; Sat, 20 Dec 2014 09:52:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2LNz-0005HE-98 for bug-gnu-emacs@gnu.org; Sat, 20 Dec 2014 09:52:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y2LNz-0007zG-4Y for bug-gnu-emacs@gnu.org; Sat, 20 Dec 2014 09:52:03 -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: Sat, 20 Dec 2014 14:52:03 +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.141908709630649 (code B ref 19395); Sat, 20 Dec 2014 14:52:03 +0000 Original-Received: (at 19395) by debbugs.gnu.org; 20 Dec 2014 14:51:36 +0000 Original-Received: from localhost ([127.0.0.1]:52259 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y2LNX-0007yG-Bn for submit@debbugs.gnu.org; Sat, 20 Dec 2014 09:51:35 -0500 Original-Received: from mx02.posteo.de ([89.146.194.165]:58650) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y2LNU-0007y7-FE for 19395@debbugs.gnu.org; Sat, 20 Dec 2014 09:51:33 -0500 Original-Received: from dovecot03.posteo.de (unknown [185.67.36.28]) by mx02.posteo.de (Postfix) with ESMTPS id 5B60625A3DD3; Sat, 20 Dec 2014 15:51:31 +0100 (CET) Original-Received: from mail.posteo.de (localhost [127.0.0.1]) by dovecot03.posteo.de (Postfix) with ESMTPSA id 3k4VJM0sD5z5vN8; Sat, 20 Dec 2014 15:51:30 +0100 (CET) In-reply-to: <837fxpue6v.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:97609 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 2014-12-18 Thu 17:15, Eli Zaretskii wrote: >> From: Titus von der Malsburg >> Cc: 19395@debbugs.gnu.org >> Date: Wed, 17 Dec 2014 19:36:04 -0800 >>=20 >> > 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. >>=20 >> 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. >>=20 >> 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. > > Given the changes I pushed in commit b197822, you will no longer need > all this complexity. Just > > (aref (font-info (face-font 'default)) 11) Great, thanks for adding this. Below the updated version of my solution to the original problem: (defun window-char-width (&optional window face) "Return character width for WINDOW. WINDOW must be a live window and defaults to the selected one. FACE is the face for which character width should be returned. Buffer-local face remappings are applied. If nil, the default face is used." (with-selected-window (window-normalize-window window t) (let* ((face (if face face 'default)) (info (font-info (face-font face))) (width (aref info 11))) (if (> width 0) width (aref info 10))))) (defun window-max-characters-per-line (&optional window face) "Return the number of characters that can be displayed on one line. WINDOW must be a live window and defaults to the selected one. FACE is the face whose character width should be used for the calculation. Buffer-local face remappings are applied. If nil, the default face is used. 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')." (with-selected-window (window-normalize-window window t) (let* ((window-width (window-body-width window t)) (font-width (window-char-width window face)) (ncols (/ window-width font-width))) (if (and (display-graphic-p) overflow-newline-into-fringe (/=3D (frame-parameter nil 'left-fringe) 0) (/=3D (frame-parameter nil 'right-fringe) 0)) ncols (1- ncols))))) Note that the first function is a variant of Martin's version which had a bug: if the buffer in the specified window is displayed in two frames, the returned character width was always the one used in the current frame which is not necessarily the character width in the specified window (the window may be in the other frame). This is a problem because character width can be different, if the two frames use different default fonts. For completeness, it probably also makes sense to include the following function in simple.el, which already has a function `default-font-height'. (defun default-font-width ()=20 "Return the width in pixels of the current buffer's default face font. Buffer-local face remappings are applied." (let* ((info (font-info (face-font 'default))) (width (aref info 11))) (if (> width 0) width (aref info 10)))) > (For bullet-proof code, check that this is not zero, and if it is, use > the 10th member instead; see the docs.) This is checked. > If we are going to put this in simple.el or subr.el, I don't think we > need to worry about XEmacs. I removed that part of the condition. I also added the bonus feature which lets you specify a specific face that should be used for the calculations. Titus --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUlYzwAAoJEK40WfPGE2idG7cIAIaSGHFatqgwpcM9x2he9tCX bOofykFl+C1HmK4q8YJka1MLJdEV97e8LJqugnr8S1rXV78UMm2P1l7ofMroIvLk EebNFrvEuwbqdlXKeN8SCRQdrPUCiKNoHVP75Elf2XmJkmt6F0SxCyZYOBvKW2bF yQC2xxDEgE5OeYlIsmc7IOlc0MslG/Vq2blwDO6VphbG/ta2VeFcjkWMPSHUH0Zg sdaEBAG5dzgxTrZJqKBsW/MH0ItgY9MNf2LDKYwt3uzvWAPxgnCGjTKQwa7SSb3b xukK/d8+Bk4l515P8BF9GTtFGM6YbxPuHgftSZA/EHAcPEntCvKJbfC5D/j7zx4= =9iLG -----END PGP SIGNATURE----- --=-=-=--