From: Keith David Bershatsky <esq@lawlist.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 28246@debbugs.gnu.org
Subject: bug#28246: display line number width != length of line number at eob
Date: Mon, 28 Aug 2017 11:50:40 -0700 [thread overview]
Message-ID: <m2a82jle67.wl%esq@lawlist.com> (raw)
In-Reply-To: <m27exq56vv.wl%esq@lawlist.com>
Thank you, Eli, for having taken the time to explain the fundamentals of how Emacs calculates the width for display of native line numbers.
I have been using the point-max approach (each command loop) in my own setup since I first started using Emacs a few years ago (with a variation of linum.el for just the visible window), and I became accustomed to seeing the width decrease/increase accordingly. I instantly noticed the difference with native line numbers, and my OCDC went into action looking for a fix. :)
I created a Qprecision symbol to be used with Vdisplay_line_numbers_width, and I can turn the precision width feature on/off. The revised snippet is listed below in the event that anyone is interested in this thread in the future.
Thank you again for all your help and explanations. At your convenience, please feel free to close out bug #28246.
Keith
/* @lawlist modification -- precision width for line numbers. */
struct window *w = decode_live_window (selected_window);
Lisp_Object buf = w->contents;
CHECK_BUFFER (buf);
struct buffer *b = XBUFFER (buf);
if (!it->lnum_width
&& EQ (Vdisplay_line_numbers_width, Qprecision)
&& !EQ (Vdisplay_line_numbers, Qrelative)
&& !EQ (Vdisplay_line_numbers, Qvisual)
&& !MINI_WINDOW_P (XWINDOW (selected_window))
&& BUF_BEG (b) <= ZV
&& ZV <= BUF_Z (b))
{
/* Length of an Integer: https://stackoverflow.com/a/3068420/2112489
The log10, abs, and floor functions are provided by math.h */
it->lnum_width = floor (log10 (abs (internal_line_number_at_position (w, ZV)))) + 1;
eassert (it->lnum_width > 0);
}
/* Compute the required width if needed. */
else if (!it->lnum_width)
{
if (NATNUMP (Vdisplay_line_numbers_width))
it->lnum_width = XFASTINT (Vdisplay_line_numbers_width);
/* Max line number to be displayed cannot be more than the one
corresponding to the last row of the desired matrix. */
ptrdiff_t max_lnum;
if (NILP (Vdisplay_line_numbers_current_absolute)
&& (EQ (Vdisplay_line_numbers, Qrelative)
|| EQ (Vdisplay_line_numbers, Qvisual)))
/* We subtract one more because the current line is always zero in this mode. */
max_lnum = it->w->desired_matrix->nrows - 2;
else if (EQ (Vdisplay_line_numbers, Qvisual))
max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1;
else
max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos;
max_lnum = max (1, max_lnum);
it->lnum_width = max (it->lnum_width, log10 (max_lnum) + 1);
eassert (it->lnum_width > 0);
}
next prev parent reply other threads:[~2017-08-28 18:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-26 21:57 bug#28246: display line number width != length of line number at eob Keith David Bershatsky
2017-08-27 14:23 ` Eli Zaretskii
2017-08-28 1:46 ` Keith David Bershatsky
2017-08-28 17:27 ` Eli Zaretskii
2017-08-28 18:50 ` Keith David Bershatsky [this message]
2017-08-29 15:00 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2a82jle67.wl%esq@lawlist.com \
--to=esq@lawlist.com \
--cc=28246@debbugs.gnu.org \
--cc=eliz@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.