]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve calculation of indent prefixes when using text scaling
authorJim Porter <jporterbugs@gmail.com>
Tue, 4 Feb 2025 17:25:17 +0000 (09:25 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Feb 2025 08:34:57 +0000 (09:34 +0100)
Previously, the display spec for the "average space" was wrong.  It used
a plain number for the width of the specified space, which means "N
times the normal character width for the buffer", but we want "N times
the normal character width for the *current face*" (bug#76008).

* lisp/visual-wrap.el (visual-wrap--content-prefix): Specify the width
of the "average space" in terms of the average width of the current
face.

* lisp/net/shr.el (shr-indent): As above, and call 'string-pixel-width'
without specifying the buffer, to match 'shr-string-pixel-width'.

(cherry picked from commit 6842415577405adafcba16f8cbff02f35b5583f9)

lisp/net/shr.el
lisp/visual-wrap.el

index a732e25a560a04cf683b0f630539efd92068847e..7521860db09826ea6be2cce038b8f584fae6242c 100644 (file)
@@ -1052,15 +1052,15 @@ When `shr-fill-text' is nil, only indent."
           (insert-char ?\s shr-indentation)
         (insert ?\s)
         ;; Set the specified space width in units of the average-width
-        ;; of the current font, like (N . width).  That way, the
+        ;; of the current face, like (N . width).  That way, the
         ;; indentation is calculated correctly when using
         ;; `text-scale-adjust'.
         (let ((avg-space (propertize (buffer-substring (1- (point)) (point))
-                                     'display '(space :width 1))))
+                                     'display '(space :width (1 . width)))))
           (put-text-property
            (1- (point)) (point) 'display
            `(space :width (,(/ (float shr-indentation)
-                               (string-pixel-width avg-space (current-buffer)))
+                               (string-pixel-width avg-space))
                            . width)))))
       (put-text-property start (+ (point) prefix)
                          'shr-prefix-length (+ prefix (- (point) start))))))
index cceb694cfcce05229b5a4c610d50e953e2a103a8..50879cc30c9e2e423a7ba5eec1b0b19dc52c13d8 100644 (file)
@@ -164,7 +164,7 @@ PREFIX was empty."
     ;; units of the font's average-width) large enough to fit the
     ;; first-line prefix.
     (let ((avg-space (propertize (buffer-substring position (1+ position))
-                                 'display '(space :width 1))))
+                                 'display '(space :width (1 . width)))))
       ;; Remove any `min-width' display specs since we'll replace with
       ;; our own later in `visual-wrap--apply-to-line' (bug#73882).
       (add-display-text-property 0 (length prefix) 'min-width nil prefix)