From c83c8bdd49b8639a2824e489698c70e36d54fe42 Mon Sep 17 00:00:00 2001
From: Juanma Barranquero <lekktu@gmail.com>
Date: Thu, 3 Oct 2019 06:04:53 +0200
Subject: [PATCH] Allow highlighting line numbers that are multiple of given
 values

* lisp/faces.el (line-number-Nth-line, line-number-Mth-line):
New faces.
* lisp/cus-start.el (display-line-numbers-Nth-line)
(display-line-numbers-Mth-line): Add customization info.

* src/xdisp.c (syms_of_xdisp) <display-line-numbers-Nth-line>
<display-line-numbers-Mth-line>: Defvar new options.
(syms_of_xdisp) <line-number-Nth-line, line-number-Mth-line>:
Defsym new faces.
(maybe_produce_line_number): Use new faces for line numbers
that are multiple of `display-line-numbers-Nth-line' and
`display-line-numbers-Mth-line'.

* etc/NEWS (value): Announce new feature.
* doc/emacs/display.texi (Display Custom): Describe it.
---
 doc/emacs/display.texi |  6 +++++-
 etc/NEWS               | 10 ++++++++++
 lisp/cus-start.el      | 12 ++++++++++++
 lisp/faces.el          | 32 ++++++++++++++++++++++++++++++++
 src/xdisp.c            | 27 +++++++++++++++++++++++++++
 5 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 84363d0f0d..0bd3ae85e3 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1871,7 +1871,11 @@ Display Custom
 The current line number is displayed in a different face,
 @code{line-number-current-line}, so you can make the current line's
 number have a distinct appearance, which will help locating the line
-showing point.
+showing point. Additional faces @code{line-number-Nth-line} and
+@code{line-number-Mth-line} can be used to highlight the line number
+of lines multiple of certain numbers which can be customized via the
+variables @code{display-line-numbers-Nth-line} and
+@code{display-line-numbers-Mth-line} respectively.
 
 @vindex visible-bell
   If the variable @code{visible-bell} is non-@code{nil}, Emacs attempts
diff --git a/etc/NEWS b/etc/NEWS
index 00a01999a7..f14d73ef91 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -553,6 +553,16 @@ network connection information (in addition to the host name).
 *** When called interactively with a prefix arg 'C-u', 'desktop-read'
 now prompts the user for the directory containing the desktop file.
 
++++
+** display-line-numbers-mode
+*** New faces 'line-number-Nth-line' and 'line-number-Mth-line',
+and customizable variables 'display-line-numbers-Nth-line' and
+'display-line-numbers-Mth-line', can be used to highlight the line
+numbers of lines multiple of N and M.
+
+*** New faces 'line-number-fifth-line' and 'line-number-tenth-line'
+can be used to highlight the line number of every fifth or tenth line.
+
 +++
 ** winner
 *** A new variable, 'winner-boring-buffers-regexp', has been added.
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index e61c1954a1..8ff1bd33ec 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -655,6 +655,18 @@ minibuffer-prompt-properties--setter
                (const :tag "Count lines from beginning of narrowed region"
                       :value nil))
               "26.1")
+             (display-line-numbers-Nth-line
+              display-line-numbers
+              (choice
+               (const :tag "No line" 0)
+               (integer :tag "Multiples of" 10))
+              "27.1")
+             (display-line-numbers-Mth-line
+              display-line-numbers
+              (choice
+               (const :tag "No line" 0)
+               (integer :tag "Multiples of" 5))
+              "27.1")
 
              (display-fill-column-indicator
               display-fill-column-indicator
diff --git a/lisp/faces.el b/lisp/faces.el
index 9c5ffe1e59..cb0b8b77af 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2390,6 +2390,38 @@ line-number-current-line
   :group 'basic-faces
   :group 'display-line-numbers)
 
+(defface line-number-Nth-line
+  '((t :inherit line-number))
+  "Face for highlighting the line number of every Nth line.
+This face is used when `display-line-numbers' is non-nil and
+variable `display-line-numbers-Nth-line' has a positive value.
+
+If you customize the font of this face, make sure it is a
+monospaced font, otherwise line numbers will not line up,
+and text lines might move horizontally as you move through
+the buffer.  Similarly, making this face's font different
+from that of the `line-number' face could produce such
+unwanted effects."
+  :version "27.1"
+  :group 'basic-faces
+  :group 'display-line-numbers)
+
+(defface line-number-Mth-line
+  '((t :inherit line-number))
+  "Face for highlighting the line number of every Mth line.
+This face is used when `display-line-numbers' is non-nil and
+variable `display-line-numbers-Mth-line' has a positive value.
+
+If you customize the font of this face, make sure it is a
+monospaced font, otherwise line numbers will not line up,
+and text lines might move horizontally as you move through
+the buffer.  Similarly, making this face's font different
+from that of the `line-number' face could produce such
+unwanted effects."
+  :version "27.1"
+  :group 'basic-faces
+  :group 'display-line-numbers)
+
 ;; Definition stolen from display-line-numbers.
 (defface fill-column-indicator
   '((t :inherit shadow :weight normal :slant normal
diff --git a/src/xdisp.c b/src/xdisp.c
index 89a72ff751..225fb02576 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22566,6 +22566,14 @@ maybe_produce_line_number (struct it *it)
 	     empty lines beyond EOB.  */
 	  && it->what != IT_EOB)
 	tem_it.face_id = current_lnum_face_id;
+      else if (RANGED_FIXNUMP (1, Vdisplay_line_numbers_Nth_line, INT_MAX)
+	       && (lnum_to_display % XFIXNUM (Vdisplay_line_numbers_Nth_line) == 0))
+	tem_it.face_id = merge_faces (it->w, Qline_number_Nth_line,
+				      0, DEFAULT_FACE_ID);
+      else if (RANGED_FIXNUMP (1, Vdisplay_line_numbers_Mth_line, INT_MAX)
+	       && (lnum_to_display % XFIXNUM (Vdisplay_line_numbers_Mth_line) == 0))
+	tem_it.face_id = merge_faces (it->w, Qline_number_Mth_line,
+				      0, DEFAULT_FACE_ID);
       else
 	tem_it.face_id = lnum_face_id;
       if (beyond_zv
@@ -34006,6 +34014,8 @@ syms_of_xdisp (void)
   /* Names of the faces used to display line numbers.  */
   DEFSYM (Qline_number, "line-number");
   DEFSYM (Qline_number_current_line, "line-number-current-line");
+  DEFSYM (Qline_number_Nth_line, "line-number-Nth-line");
+  DEFSYM (Qline_number_Mth_line, "line-number-Mth-line");
   /* Name of a text property which disables line-number display.  */
   DEFSYM (Qdisplay_line_numbers_disable, "display-line-numbers-disable");
 
@@ -34641,6 +34651,23 @@ syms_of_xdisp (void)
   DEFSYM (Qdisplay_fill_column_indicator_character, "display-fill-column-indicator-character");
   Fmake_variable_buffer_local (Qdisplay_fill_column_indicator_character);
 
+  DEFVAR_LISP ("display-line-numbers-Nth-line", Vdisplay_line_numbers_Nth_line,
+    doc: /* If an integer N > 0, highlight line number of every Nth line.
+The line number is shown with the `line-number-Nth-line' face.
+Otherwise, no special highlighting is done every Nth lines.  */);
+  Vdisplay_line_numbers_Nth_line = make_fixnum (0);
+  DEFSYM (Qdisplay_line_numbers_Nth_line, "display-line-numbers-Nth-line");
+  Fmake_variable_buffer_local (Qdisplay_line_numbers_Nth_line);
+
+  DEFVAR_LISP ("display-line-numbers-Mth-line", Vdisplay_line_numbers_Mth_line,
+    doc: /* If an integer M > 0, highlight line number of every Mth line.
+The line number is shown with the `line-number-Mth-line' face.
+Otherwise, no special highlighting is done every Mth lines.
+Note that `display-line-numbers-Nth-line' takes precedence.  */);
+  Vdisplay_line_numbers_Mth_line = make_fixnum (0);
+  DEFSYM (Qdisplay_line_numbers_Mth_line, "display-line-numbers-Mth-line");
+  Fmake_variable_buffer_local (Qdisplay_line_numbers_Mth_line);
+
   DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay,
     doc: /* Non-nil means don't eval Lisp during redisplay.  */);
   inhibit_eval_during_redisplay = false;
-- 
2.23.0.windows.1

