unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Titus von der Malsburg <malsburg@posteo.de>,
	Eli Zaretskii <eliz@gnu.org>
Cc: 19395@debbugs.gnu.org
Subject: bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width
Date: Sat, 20 Dec 2014 16:06:21 +0100	[thread overview]
Message-ID: <5495906D.7030800@gmx.at> (raw)
In-Reply-To: <87oaqyz85s.fsf@posteo.de>

 > (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
 >                 (/= (frame-parameter nil 'left-fringe) 0)
 >                 (/= (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.

So this what I've been trying to find out all the time.  The faces
apparently _get_ merged dependent on the buffer _and_ the frame.

I need a corresponding `window-char-height' as well, probably also with
a FACE argument.

 > 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 ()
 >    "Return the width in pixels of the current buffer's default face font.

I profoundly dislike the "default-" prefix here.  `buffer-font-height'
and `buffer-font-width' would be much better IMHO.

 > I also added the bonus feature which lets you specify a specific face
 > that should be used for the calculations.

So are you now sure that we don't need a specific character ("M") any
more?

martin





  reply	other threads:[~2014-12-20 15:06 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-16 20:01 bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width Titus von der Malsburg
2014-12-16 20:09 ` Eli Zaretskii
2014-12-16 20:36   ` Titus von der Malsburg
2014-12-16 20:58     ` Eli Zaretskii
2014-12-16 23:12       ` Stefan Monnier
2014-12-17  3:39         ` Eli Zaretskii
2014-12-17 14:16           ` Stefan Monnier
2014-12-17 15:47             ` Eli Zaretskii
2014-12-17 21:31               ` Stefan Monnier
2014-12-17 22:57                 ` Drew Adams
2014-12-18  3:37                 ` Eli Zaretskii
2014-12-18 14:24                   ` Stefan Monnier
2014-12-18 15:51                     ` Eli Zaretskii
2014-12-20 10:09                       ` martin rudalics
2014-12-20 11:00                         ` Eli Zaretskii
2014-12-17  3:46         ` Titus von der Malsburg
2014-12-17 15:29           ` Eli Zaretskii
2014-12-17 21:34             ` Stefan Monnier
2014-12-18  3:40               ` Eli Zaretskii
2014-12-18 14:25                 ` Stefan Monnier
2014-12-18 15:52                   ` Eli Zaretskii
2014-12-17  3:28       ` Titus von der Malsburg
2014-12-17 15:32         ` Eli Zaretskii
2014-12-17 17:18           ` Titus von der Malsburg
2014-12-17 18:21             ` Eli Zaretskii
2014-12-17 18:48               ` Titus von der Malsburg
2014-12-17 19:09                 ` Eli Zaretskii
2014-12-18  3:36                   ` Titus von der Malsburg
2014-12-18 16:15                     ` Eli Zaretskii
2014-12-19 17:09                       ` martin rudalics
2014-12-19 19:35                         ` Eli Zaretskii
2014-12-20 10:09                           ` martin rudalics
2014-12-20 10:59                             ` Eli Zaretskii
2014-12-20 11:42                               ` martin rudalics
2014-12-20 12:45                                 ` Eli Zaretskii
2014-12-20 14:51                                   ` martin rudalics
2014-12-20 16:36                                     ` Eli Zaretskii
2014-12-20 17:50                                       ` martin rudalics
2014-12-20 18:16                                         ` Eli Zaretskii
2014-12-20 18:58                                           ` martin rudalics
2014-12-20 19:52                                             ` Eli Zaretskii
2014-12-21 12:14                                               ` Titus von der Malsburg
2014-12-21 16:43                                                 ` Eli Zaretskii
2014-12-20 14:51                       ` Titus von der Malsburg
2014-12-20 15:06                         ` martin rudalics [this message]
2014-12-20 15:21                           ` Titus von der Malsburg
2014-12-20 16:03                             ` martin rudalics
2014-12-20 16:40                               ` Eli Zaretskii
2014-12-20 15:45                           ` Titus von der Malsburg
2014-12-20 16:38                           ` Eli Zaretskii
2014-12-20 17:51                             ` martin rudalics
2014-12-20 18:19                               ` Eli Zaretskii
2014-12-20 16:31                         ` Eli Zaretskii
2014-12-21 22:04                           ` Titus von der Malsburg
2014-12-22 16:00                             ` Eli Zaretskii
2022-04-29 13:14                               ` Lars Ingebrigtsen
2022-06-02 21:41                                 ` Jim Porter
     [not found]                                 ` <a54d35b0-7ed6-374c-2a14-e7d97cf6c0a2@gmail.com>
2022-06-03  3:21                                   ` Lars Ingebrigtsen
2014-12-18 17:16         ` Eli Zaretskii

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=5495906D.7030800@gmx.at \
    --to=rudalics@gmx.at \
    --cc=19395@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=malsburg@posteo.de \
    /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).