[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#28246: display line number width != length of line number at eob
From: |
Keith David Bershatsky |
Subject: |
bug#28246: display line number width != length of line number at eob |
Date: |
Mon, 28 Aug 2017 11:50:40 -0700 |
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);
}