* bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text
@ 2025-02-02 12:03 Kévin Le Gouguec
2025-02-03 22:36 ` Jim Porter
0 siblings, 1 reply; 5+ messages in thread
From: Kévin Le Gouguec @ 2025-02-02 12:03 UTC (permalink / raw)
To: 76008; +Cc: Jim Porter
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
Heya!
Steps to reproduce from emacs -Q:
C-x C-f repro.rst
C-x C-+ + [+…] ; until e.g. "+6"
- words
M-x visual-wrap-prefix-mode
Expectation: no visual change.
Observation: the "- " prefix is propertized with…
There are text properties here:
display (min-width ((6 . width)))
face rst-block
fontified t
wrap-prefix (space :align-to (6 . width))
… which makes the text look like this:
- words
I believe the cause lies in visual-wrap--content-prefix; empirically the
attached patch shows good results on this reproducer, but I landed on it
more by trial-and-error than by rational analysis, so it may be
incorrect or suboptimal (e.g. there may be better text-scale or
string-width APIs to use).
Thanks for your time (& for the love & care visual-wrap has been
receiving lately).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1337 bytes --]
diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 1691ba9c500..12404127190 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -33,6 +33,8 @@
;;; Code:
+(require 'face-remap)
+
(defcustom visual-wrap-extra-indent 0
"Number of extra spaces to indent in `visual-wrap-prefix-mode'.
@@ -164,12 +166,16 @@ visual-wrap--content-prefix
;; 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)))
+ (scale (if text-scale-mode
+ (expt text-scale-mode-step text-scale-mode-amount)
+ 1)))
;; 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)
(max (string-width prefix)
- (ceiling (string-pixel-width prefix (current-buffer))
+ (ceiling (/ (string-pixel-width prefix (current-buffer))
+ scale)
(string-pixel-width avg-space (current-buffer))))))))
(defun visual-wrap-fill-context-prefix (beg end)
[-- Attachment #3: Type: text/plain, Size: 564 bytes --]
Configured using:
'configure --prefix=/home/peniblec/apps/.emacs.2025-01-18 --with-cairo
--with-native-compilation=no --with-sqlite3 --with-xinput2'
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB
Important settings:
value of $LC_TIME: en_GB.UTF-8
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text
2025-02-02 12:03 bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text Kévin Le Gouguec
@ 2025-02-03 22:36 ` Jim Porter
2025-02-04 6:50 ` Kévin Le Gouguec
0 siblings, 1 reply; 5+ messages in thread
From: Jim Porter @ 2025-02-03 22:36 UTC (permalink / raw)
To: Kévin Le Gouguec, 76008
On 2/2/2025 4:03 AM, Kévin Le Gouguec wrote:
> I believe the cause lies in visual-wrap--content-prefix; empirically the
> attached patch shows good results on this reproducer, but I landed on it
> more by trial-and-error than by rational analysis, so it may be
> incorrect or suboptimal (e.g. there may be better text-scale or
> string-width APIs to use).
Thanks. I think the issue here is actually that 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*".
Could you try this patch?
----------------------------------------
diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 1691ba9c500..f2a186ce320 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -164,7 +164,7 @@ visual-wrap--content-prefix
;; 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)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text
2025-02-03 22:36 ` Jim Porter
@ 2025-02-04 6:50 ` Kévin Le Gouguec
2025-02-04 17:30 ` Jim Porter
0 siblings, 1 reply; 5+ messages in thread
From: Kévin Le Gouguec @ 2025-02-04 6:50 UTC (permalink / raw)
To: Jim Porter; +Cc: 76008
Jim Porter <jporterbugs@gmail.com> writes:
> On 2/2/2025 4:03 AM, Kévin Le Gouguec wrote:
>> I believe the cause lies in visual-wrap--content-prefix; empirically the
>> attached patch shows good results on this reproducer, but I landed on it
>> more by trial-and-error than by rational analysis, so it may be
>> incorrect or suboptimal (e.g. there may be better text-scale or
>> string-width APIs to use).
>
> Thanks. I think the issue here is actually that 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*".
💡
> Could you try this patch?
It does fix the reproducer, thanks!
> ----------------------------------------
>
> diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
> index 1691ba9c500..f2a186ce320 100644
> --- a/lisp/visual-wrap.el
> +++ b/lisp/visual-wrap.el
> @@ -164,7 +164,7 @@ visual-wrap--content-prefix
> ;; 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)
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text
2025-02-04 6:50 ` Kévin Le Gouguec
@ 2025-02-04 17:30 ` Jim Porter
2025-02-04 18:43 ` Kévin Le Gouguec
0 siblings, 1 reply; 5+ messages in thread
From: Jim Porter @ 2025-02-04 17:30 UTC (permalink / raw)
To: Kévin Le Gouguec; +Cc: 76008-done
On 2/3/2025 10:50 PM, Kévin Le Gouguec wrote:
> It does fix the reproducer, thanks!
Thanks for checking. Merged to the master branch (with an additional bit
of cleanup for shr.el) as 68424155774. Closing this now.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text
2025-02-04 17:30 ` Jim Porter
@ 2025-02-04 18:43 ` Kévin Le Gouguec
0 siblings, 0 replies; 5+ messages in thread
From: Kévin Le Gouguec @ 2025-02-04 18:43 UTC (permalink / raw)
To: Jim Porter; +Cc: 76008-done
Jim Porter <jporterbugs@gmail.com> writes:
> On 2/3/2025 10:50 PM, Kévin Le Gouguec wrote:
>> It does fix the reproducer, thanks!
>
> Thanks for checking. Merged to the master branch (with an additional bit of cleanup for shr.el) as 68424155774. Closing this now.
Thank you for the quick fix!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-04 18:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02 12:03 bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text Kévin Le Gouguec
2025-02-03 22:36 ` Jim Porter
2025-02-04 6:50 ` Kévin Le Gouguec
2025-02-04 17:30 ` Jim Porter
2025-02-04 18:43 ` Kévin Le Gouguec
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).