diff --git a/src/xdisp.c b/src/xdisp.c
index 11417070804..39d8fb5894f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -24437,7 +24437,7 @@ maybe_produce_line_number (struct it *it)
/* Produce the glyphs for the line number. */
struct it tem_it;
- char lnum_buf[INT_STRLEN_BOUND (ptrdiff_t) + 1];
+ char lnum_buf[INT_STRLEN_BOUND (ptrdiff_t) + 10];
bool beyond_zv = IT_BYTEPOS (*it) >= ZV_BYTE ? true : false;
ptrdiff_t lnum_offset = -1; /* to produce 1-based line numbers */
int lnum_face_id = merge_faces (it->w, Qline_number, 0, DEFAULT_FACE_ID);
@@ -24507,7 +24507,7 @@ maybe_produce_line_number (struct it *it)
following line, so the paragraph direction might be unknown.
Therefore we cheat and add 2 blanks, one on either side. */
pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display);
- strcat (lnum_buf, " ");
+ strncat (lnum_buf, " ", max (0, min (10, line_number_extra_spaces)));
/* Setup for producing the glyphs. */
init_iterator (&tem_it, it->w, -1, -1, &scratch_glyph_row,
@@ -36781,6 +36781,11 @@ syms_of_xdisp (void)
line number may be omitted from the mode line. */);
line_number_display_limit_width = 200;
+ DEFVAR_INT ("line-number-extra-spaces",
+ line_number_extra_spaces,
+ doc: /* The number of spaces attached after the line number. */);
+ line_number_extra_spaces = 1;
+
DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows,
doc: /* Non-nil means highlight active region even in nonselected windows.
When nil (the default), the active region is only highlighted when