* Re: master a876c4d7a17: Improve SHR/EWW support for 'visual-wrap-prefix-mode'
[not found] ` <20240818230855.B0A94C2BC6D@vcs2.savannah.gnu.org>
@ 2024-08-21 11:33 ` Eshel Yaron
2024-08-21 17:50 ` Kévin Le Gouguec
0 siblings, 1 reply; 3+ messages in thread
From: Eshel Yaron @ 2024-08-21 11:33 UTC (permalink / raw)
To: emacs-devel; +Cc: Jim Porter
Hello Jim,
Jim Porter <jporterbugs@gmail.com> writes:
> branch: master
> commit a876c4d7a17df152e3e78800c76ddf158f632ee5
> Author: Jim Porter <jporterbugs@gmail.com>
> Commit: Jim Porter <jporterbugs@gmail.com>
>
> Improve SHR/EWW support for 'visual-wrap-prefix-mode'
>
[...]
Thanks for this!
It seems like this change breaks Elfeed though, namely:
> (defun shr-indent ()
> (when (> shr-indentation 0)
> - (if (not shr-use-fonts)
> - (insert-char ?\s shr-indentation)
> - (insert ?\s)
> - (put-text-property (1- (point)) (point)
> - 'display `(space :width (,shr-indentation))))))
> + (let ((start (point))
> + (prefix (or (get-text-property (point) 'shr-prefix-length) 0)))
> + (if (not shr-use-fonts)
> + (insert-char ?\s shr-indentation)
> + (insert ?\s)
> + (put-text-property
> + (1- (point)) (point) 'display
> + ;; Set the specified space width in terms of the default width
> + ;; of the current face, like (N . width). That way, the
> + ;; indentation is calculated correctly when using
> + ;; `text-scale-adjust'.
> + `(space :width (,(if-let ((font (font-at (1- (point))))
> + (info (query-font font)))
> + (/ (float shr-indentation) (aref info 7))
> + shr-indentation)
> + . width))))
> + (put-text-property start (+ (point) prefix)
> + 'shr-prefix-length (+ prefix (- (point) start))))))
This call to font-at throws an error unless the current buffer happens
to be displayed in the selected window. This affects elfeed-show-entry,
for example.
Cheers,
Eshel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: master a876c4d7a17: Improve SHR/EWW support for 'visual-wrap-prefix-mode'
2024-08-21 11:33 ` master a876c4d7a17: Improve SHR/EWW support for 'visual-wrap-prefix-mode' Eshel Yaron
@ 2024-08-21 17:50 ` Kévin Le Gouguec
2024-08-21 19:01 ` Jim Porter
0 siblings, 1 reply; 3+ messages in thread
From: Kévin Le Gouguec @ 2024-08-21 17:50 UTC (permalink / raw)
To: Eshel Yaron; +Cc: emacs-devel, Jim Porter
Eshel Yaron <me@eshelyaron.com> writes:
> Hello Jim,
>
> Jim Porter <jporterbugs@gmail.com> writes:
>
>> branch: master
>> commit a876c4d7a17df152e3e78800c76ddf158f632ee5
>> Author: Jim Porter <jporterbugs@gmail.com>
>> Commit: Jim Porter <jporterbugs@gmail.com>
>>
>> Improve SHR/EWW support for 'visual-wrap-prefix-mode'
>>
> [...]
>
> Thanks for this!
>
> It seems like this change breaks Elfeed though, namely:
>
>> (defun shr-indent ()
>> (when (> shr-indentation 0)
>> - (if (not shr-use-fonts)
>> - (insert-char ?\s shr-indentation)
>> - (insert ?\s)
>> - (put-text-property (1- (point)) (point)
>> - 'display `(space :width (,shr-indentation))))))
>> + (let ((start (point))
>> + (prefix (or (get-text-property (point) 'shr-prefix-length) 0)))
>> + (if (not shr-use-fonts)
>> + (insert-char ?\s shr-indentation)
>> + (insert ?\s)
>> + (put-text-property
>> + (1- (point)) (point) 'display
>> + ;; Set the specified space width in terms of the default width
>> + ;; of the current face, like (N . width). That way, the
>> + ;; indentation is calculated correctly when using
>> + ;; `text-scale-adjust'.
>> + `(space :width (,(if-let ((font (font-at (1- (point))))
>> + (info (query-font font)))
>> + (/ (float shr-indentation) (aref info 7))
>> + shr-indentation)
>> + . width))))
>> + (put-text-property start (+ (point) prefix)
>> + 'shr-prefix-length (+ prefix (- (point) start))))))
>
> This call to font-at throws an error unless the current buffer happens
> to be displayed in the selected window. This affects elfeed-show-entry,
> for example.
Thanks for raising this; FWIW I noticed a simliar issue with Gnus, where
I add visual-wrap-prefix-mode to gnus-article-prepare-hook. Don't have
a backtrace handy, but had convinced myself that the faulty font-at was
this one in visual-wrap--content-prefix…
(if-let ((font (font-at position))
(info (query-font font)))
…)
… from 2024-08-04 "Add support for variable-pitch fonts in
'visual-wrap-prefix-mode'" (f70a6ea0ea8); and so meant to submit this…
diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 902a9e41c5e..975ccab3adb 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -164,7 +164,8 @@ visual-wrap--content-prefix
;; width of the first-line prefix in canonical-width characters.
;; This is useful if the first-line prefix uses some very-wide
;; characters.
- (if-let ((font (font-at position))
+ (if-let ((window (get-buffer-window (current-buffer)))
+ (font (font-at position window))
(info (query-font font)))
(max (string-width prefix)
(ceiling (string-pixel-width prefix (current-buffer))
… but meant to research & test more before submitting.
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: master a876c4d7a17: Improve SHR/EWW support for 'visual-wrap-prefix-mode'
2024-08-21 17:50 ` Kévin Le Gouguec
@ 2024-08-21 19:01 ` Jim Porter
0 siblings, 0 replies; 3+ messages in thread
From: Jim Porter @ 2024-08-21 19:01 UTC (permalink / raw)
To: Kévin Le Gouguec, Eshel Yaron; +Cc: emacs-devel
On 8/21/2024 10:50 AM, Kévin Le Gouguec wrote:
> Eshel Yaron <me@eshelyaron.com> writes:
>
>> Hello Jim,
>>
>> Jim Porter <jporterbugs@gmail.com> writes:
>>
>>> branch: master
>>> commit a876c4d7a17df152e3e78800c76ddf158f632ee5
>>> Author: Jim Porter <jporterbugs@gmail.com>
>>> Commit: Jim Porter <jporterbugs@gmail.com>
>>>
>>> Improve SHR/EWW support for 'visual-wrap-prefix-mode'
>>>
>> [...]
>>
>> Thanks for this!
>>
>> It seems like this change breaks Elfeed though, namely:
[snip]
>> This call to font-at throws an error unless the current buffer happens
>> to be displayed in the selected window. This affects elfeed-show-entry,
>> for example.
Thanks for noticing this. It'd be good to make the "get the average
width of the font" bit work properly in all cases.
That said, this is *also* a bug in Elfeed. SHR just works a lot better
if the buffer is displayed in a window before rendering the HTML out.
See <https://github.com/skeeto/elfeed/pull/521>.
> diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
> index 902a9e41c5e..975ccab3adb 100644
> --- a/lisp/visual-wrap.el
> +++ b/lisp/visual-wrap.el
> @@ -164,7 +164,8 @@ visual-wrap--content-prefix
> ;; width of the first-line prefix in canonical-width characters.
> ;; This is useful if the first-line prefix uses some very-wide
> ;; characters.
> - (if-let ((font (font-at position))
> + (if-let ((window (get-buffer-window (current-buffer)))
> + (font (font-at position window))
> (info (query-font font)))
> (max (string-width prefix)
> (ceiling (string-pixel-width prefix (current-buffer))
Assuming this is working for you, I think this patch makes sense and you
can feel free to merge it.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-21 19:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <172402253530.16373.1641341718329436871@vcs2.savannah.gnu.org>
[not found] ` <20240818230855.B0A94C2BC6D@vcs2.savannah.gnu.org>
2024-08-21 11:33 ` master a876c4d7a17: Improve SHR/EWW support for 'visual-wrap-prefix-mode' Eshel Yaron
2024-08-21 17:50 ` Kévin Le Gouguec
2024-08-21 19:01 ` Jim Porter
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).