From b714c229e2d24f13e5a2888cbd5c1d8765b8bb16 Mon Sep 17 00:00:00 2001
From: Juanma Barranquero <lekktu@gmail.com>
Date: Sat, 5 Oct 2019 00:36:49 +0200
Subject: [PATCH] Allow highlighting line numbers that are multiple of given
 values

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

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

* etc/NEWS (value): Announce new feature.
* doc/emacs/display.texi (Display Custom): Describe it.  Wording by
Robert Pluim <rpluim@gmail.com>
---
 doc/emacs/display.texi |  7 ++++++-
 etc/NEWS               |  7 +++++++
 lisp/cus-start.el      | 12 ++++++++++++
 lisp/faces.el          | 34 ++++++++++++++++++++++++++++++++++
 src/xdisp.c            | 26 ++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 84363d0f0d..406feb8c12 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1871,7 +1871,12 @@ 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-major-tick} and
+@code{line-number-minor-tick} can be used to highlight the line numbers
+of lines which are a multiple of certain numbers.  Customize
+@code{display-line-numbers-major-tick} and
+@code{display-line-numbers-minor-tick} respectively to set those
+numbers.
 
 @vindex visible-bell
   If the variable @code{visible-bell} is non-@code{nil}, Emacs attempts
diff --git a/etc/NEWS b/etc/NEWS
index db90e8e5c5..617482b262 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -558,6 +558,13 @@ 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-major-tick' and 'line-number-minor-tick',
+and customizable variables 'display-line-numbers-major-tick' and
+'display-line-numbers-minor-tick' can be used to highlight the line
+numbers of lines multiple of certain numbers.
+
 +++
 ** 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..2e37f095bb 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-major-tick
+              display-line-numbers
+              (choice
+               (const :tag "No line" 0)
+               (integer :tag "Multiples of" 10))
+              "27.1")
+             (display-line-numbers-minor-tick
+              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..58b6349ccf 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2390,6 +2390,40 @@ line-number-current-line
   :group 'basic-faces
   :group 'display-line-numbers)
 
+(defface line-number-major-tick
+  '((t :inherit line-number))
+  "Face for highlighting \"major ticks\" (as in a ruler).
+When `display-line-numbers-major-tick' is positive, highlight
+the line numbers of lines which are a multiple of its value.
+This face is used when `display-line-numbers' is non-nil.
+
+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-minor-tick
+  '((t :inherit line-number))
+  "Face for highlighting \"minor ticks\" (as in a ruler).
+When `display-line-numbers-minor-tick' is positive, highlight
+the line numbers of lines which are a multiple of its value.
+This face is used when `display-line-numbers' is non-nil.
+
+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 9d1fdecaff..423615c054 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22567,6 +22567,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_major_tick, INT_MAX)
+	       && (lnum_to_display % XFIXNUM (Vdisplay_line_numbers_major_tick) == 0))
+	tem_it.face_id = merge_faces (it->w, Qline_number_major_tick,
+				      0, DEFAULT_FACE_ID);
+      else if (RANGED_FIXNUMP (1, Vdisplay_line_numbers_minor_tick, INT_MAX)
+	       && (lnum_to_display % XFIXNUM (Vdisplay_line_numbers_minor_tick) == 0))
+	tem_it.face_id = merge_faces (it->w, Qline_number_minor_tick,
+				      0, DEFAULT_FACE_ID);
       else
 	tem_it.face_id = lnum_face_id;
       if (beyond_zv
@@ -34007,6 +34015,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_major_tick, "line-number-major-tick");
+  DEFSYM (Qline_number_minor_tick, "line-number-minor-tick");
   /* Name of a text property which disables line-number display.  */
   DEFSYM (Qdisplay_line_numbers_disable, "display-line-numbers-disable");
 
@@ -34642,6 +34652,22 @@ 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-major-tick", Vdisplay_line_numbers_major_tick,
+    doc: /* If an integer N > 0, highlight line number of every Nth line.
+The line number is shown with the `line-number-major-tick' face.
+Otherwise, no special highlighting is done every Nth line.
+Note that major ticks take precedence over minor ticks.  */);
+  Vdisplay_line_numbers_major_tick = make_fixnum (0);
+  DEFSYM (Qdisplay_line_numbers_major_tick, "display-line-numbers-major-tick");
+
+  DEFVAR_LISP ("display-line-numbers-minor-tick", Vdisplay_line_numbers_minor_tick,
+    doc: /* If an integer N > 0, highlight line number of every Nth line.
+The line number is shown with the `line-number-minor-tick' face.
+Otherwise, no special highlighting is done every Mth line.
+Note that major ticks take precedence over minor ticks.  */);
+  Vdisplay_line_numbers_minor_tick = make_fixnum (0);
+  DEFSYM (Qdisplay_line_numbers_minor_tick, "display-line-numbers-minor-tick");
+
   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

