all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christophe Rhodes <csr21@cantab.net>
To: 26552@debbugs.gnu.org
Subject: bug#26552: [patch] nlinum margin width calculation (emacs <25)
Date: Tue, 18 Apr 2017 19:04:34 +0100	[thread overview]
Message-ID: <87lgqxoaml.fsf@cantab.net> (raw)
In-Reply-To: <8737d6pvxb.fsf@cantab.net>

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Christophe Rhodes <csr21@cantab.net>
>> Date: Mon, 17 Apr 2017 22:26:56 +0100
>> 
>> I think the calculation that nlinum-mode does to guess the margin size
>> in the absence of font width information (in emacs versions less than
>> 25) uses the wrong bit of font information: the pixel size, rather than
>> the font height.  Trivial patch below, which fixes the problem for me.
>
> Isn't it a mere coincidence that this fixes your problem?

I don't think so.

The calculation is trying to compute how many characters should be
reserved in the margin, which will on a graphical display (I presume)
reserve space in units of frame-char-width.

In the case that the face for linum/nlinum is the same as the face for
everything else (in particular, the face used for frame-char-height), we
want to reserve the number of character cells that is equal to the
length of the strings we will need to format, nlinum--width.  But
frame-char-height is the height (in pixels) of the lines in the frame,
not the height of the characters in the font -- it includes leading.
So, when computing the number of characters to reserve, the inclusion of
leading in the denominator but not the numerator eventually leads to an
underestimate in the number of characters to reserve.

> How can height be a better approximation for width than size?

It's not, but the ratio of one height (the font height) to another
height (frame-char-height) is a better approximation to the scaling
ratio between widths, which is what really matters, than the ratio of
the font pixel size to the frame-char-height (which are two quantities
without a direct relationship).

> What are the actual numbers in your case?

My font is Source Code Pro 10, which has pixel size 13 and height 17;
frame-char-height is 17.  So once nlinum--width is 5, the current
computation underestimates the space needed; with my patch, the
calculation is correct for all values of nlinum--width.  I haven't
tested with different sizes for the linum face and the normal face; I
expect my patched calculation to approximate better than the existing
one in essentially all cases.

Best wishes,

Christophe






  reply	other threads:[~2017-04-18 18:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-17 21:26 bug#26552: [patch] nlinum margin width calculation (emacs <25) Christophe Rhodes
2017-04-18 16:14 ` Eli Zaretskii
2017-04-18 18:04   ` Christophe Rhodes [this message]
2017-04-22  8:33     ` Christophe Rhodes
2017-04-22 10:19       ` Eli Zaretskii
2017-04-23 13:38         ` Stefan Monnier
2017-11-04 14:39           ` Noam Postavsky

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

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

  git send-email \
    --in-reply-to=87lgqxoaml.fsf@cantab.net \
    --to=csr21@cantab.net \
    --cc=26552@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.