Subject: Re: bug#75168: 31.0.50; text-scale confuses ruler-mode when display-line-number-mode is active

From: Arsen Arsenović <[email-masked]>
Date: Sat, 18 Jan 2025 16:45:53 +0100

Eli Zaretskii <[email-masked]> writes:

> Seems to work well, so could you please submit a full patch with the
> commit log message, so we could then install this?
>
> Thanks.

Sure.  Attached.

From 3e24ff3da4fd423f3d2b32679e87f2fc963482f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= <[email-masked]>
Date: Sat, 18 Jan 2025 16:40:29 +0100
Subject: [PATCH] ruler-mode: Improve compatibility with text-scale (bug#75168)

* lisp/ruler-mode.el (ruler-mode-ruler): Use pixelwise line-number
display width for alignment with line numbers.
---
 lisp/ruler-mode.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el
index 003dcae560f..64568e06cc9 100644
--- a/lisp/ruler-mode.el
+++ b/lisp/ruler-mode.el
@@ -632,12 +632,7 @@ ruler-mode-ruler
   (let* ((w (ruler-mode-text-scaled-window-width))
          (m (window-margins))
          (f (window-fringes))
-         (i (if display-line-numbers
-                ;; FIXME: ruler-mode relies on I being an integer, so
-                ;; the column numbers might be slightly off if the
-                ;; line-number face is customized.
-                (round (line-number-display-width 'columns))
-              0))
+         (i 0)
          (j (ruler-mode-text-scaled-window-hscroll))
          ;; Setup the scrollbar, fringes, and margins areas.
          (lf (ruler-mode-space
@@ -745,6 +740,12 @@ ruler-mode-ruler
       (dolist (p (nreverse props))
         (add-text-properties (nth 0 p) (nth 1 p) (nthcdr 2 p) ruler-str))
 
+      ;; Attach an alignment indent.
+      (if display-line-numbers
+          (setq ruler-str
+                (concat (ruler-mode-space `(,(line-number-display-width t)))
+                        ruler-str)))
+
       ;; Return the ruler propertized string.  Using list here,
       ;; instead of concat visually separate the different areas.
       (if (nth 2 (window-fringes))
-- 
2.48.0

Have a lovely day.
-- 
Arsen Arsenović