diff --git a/src/dispextern.h b/src/dispextern.h index 08e5caa893b..84a27169ea1 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -2667,9 +2667,10 @@ struct it /* The byte position corresponding to lnum. */ ptrdiff_t lnum_bytepos; - /* The width in columns needed for display of the line numbers, or - zero if not computed. */ + /* The width, in columns and in pixels, needed for display of the + line numbers, or zero if not computed. */ int lnum_width; + int lnum_pixel_width; /* The line number of point's line, or zero if not computed yet. */ ptrdiff_t pt_lnum; diff --git a/src/xdisp.c b/src/xdisp.c index bbf30504844..3fc5f29d0c4 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -20938,6 +20938,8 @@ maybe_produce_line_number (struct it *it) } } + /* Record the width in pixels we need for the line number display. */ + it->lnum_pixel_width = tem_it.current_x; /* Copy the produced glyphs into IT's glyph_row. */ struct glyph *g = scratch_glyph_row.glyphs[TEXT_AREA]; struct glyph *e = g + scratch_glyph_row.used[TEXT_AREA]; @@ -27997,13 +27999,12 @@ x_produce_glyphs (struct it *it) int tab_width = it->tab_width * font->space_width; int x = it->current_x + it->continuation_lines_width; int x0 = x; - /* Adjust for line numbers. Kludge alert: the "2" below - is because we add 2 blanks to the actual line number. */ + /* Adjust for line numbers, if needed. */ if (!NILP (Vdisplay_line_numbers)) - x -= (it->lnum_width + 2) * font->space_width; + x -= it->lnum_pixel_width; int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; if (!NILP (Vdisplay_line_numbers)) - next_tab_x += (it->lnum_width + 2) * font->space_width; + next_tab_x += it->lnum_pixel_width; /* If the distance from the current position to the next tab stop is less than a space character width, use the