unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>,
	"Eli Zaretskii" <eliz@gnu.org>
Cc: Rob Stewart <R.Stewart@hw.ac.uk>, 72771@debbugs.gnu.org
Subject: bug#72771: 31.0.50; shr html renderer throwing "Specified window is not displaying the current buffer"
Date: Fri, 23 Aug 2024 15:39:00 -0700	[thread overview]
Message-ID: <3482d616-8a1c-d458-8da4-1b9d12ff32c5@gmail.com> (raw)
In-Reply-To: <875xrrcgia.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

On 8/23/2024 10:10 AM, Kévin Le Gouguec wrote:
> Thanks for opening an issue Rob!
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
>> This is being discussed here:
>>
>>    https://lists.gnu.org/archive/html/emacs-devel/2024-08/msg00788.html
> 
> (Will be traveling during the coming week, with limited time &
> connectivity, so anyone should feel free to beat me to installing the
> visual-wrap patch - AFAIU from the reported backtraces though, it won't
> fix the issues that other folks are having)

Here's a patch. I've tested this in a few configurations (in the current 
window, in a buffer that's not being displayed, in a terminal Emacs) and 
it all seems to work.

One question, Eli: is there a better way than I'm using to get the font 
that would be used for a character in the buffer? When the buffer is 
being displayed in a window, '(font-at position window)' works, but that 
doesn't address this bug, where the buffer isn't displayed. (The font 
that we get back doesn't have to be 100% accurate; just a good guess 
should be fine for this case.)

[-- Attachment #2: 0001-Improve-computation-of-indent-depth-in-SHR-and-visua.patch --]
[-- Type: text/plain, Size: 3003 bytes --]

From 5cd39589ebd47ccc8f53b8921fadd566df316d21 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Fri, 23 Aug 2024 15:11:24 -0700
Subject: [PATCH] Improve computation of indent depth in SHR and
 'visual-wrap-prefix-mode'

This method gets the font that would be used for the current window for
the text in question.  That way, there are no problems if the current
buffer isn't being displayed in a window.

* lisp/net/shr.el (shr-indent):
* lisp/visual-wrap.el (visual-wrap--content-prefix): Fix getting the
font when the buffer isn't displayed in a window.
(visual-wrap-fill-context-prefix): Fix indentation.
---
 lisp/net/shr.el     | 12 +++++++-----
 lisp/visual-wrap.el |  5 +++--
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index b9ac9f0c8c0..a55c97b1349 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1057,11 +1057,13 @@ shr-indent
          ;; 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))))
+         `(space :width
+                 (,(if-let ((text (buffer-substring (1- (point)) (point)))
+                            (font (font-at 0 nil text))
+                            (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))))))
 
diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 902a9e41c5e..52ac39513be 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 ((text (buffer-substring position (1+ position)))
+             (font (font-at 0 nil text))
              (info (query-font font)))
         (max (string-width prefix)
              (ceiling (string-pixel-width prefix (current-buffer))
@@ -189,7 +190,7 @@ visual-wrap-fill-context-prefix
           ;; make much sense (and is positively harmful in
           ;; taskpaper-mode where paragraph-start matches everything).
           (or (let ((paragraph-start regexp-unmatchable))
-                    (fill-context-prefix beg end))
+                (fill-context-prefix beg end))
                   ;; Note: fill-context-prefix may return nil; See:
                   ;; http://article.gmane.org/gmane.emacs.devel/156285
               ""))
-- 
2.25.1


  reply	other threads:[~2024-08-23 22:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23  8:15 bug#72771: 31.0.50; shr html renderer throwing "Specified window is not displaying the current buffer" Rob Stewart via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-23  9:13 ` Rob Stewart via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-23 13:12 ` Eli Zaretskii
2024-08-23 17:10   ` Kévin Le Gouguec
2024-08-23 22:39     ` Jim Porter [this message]
2024-08-24  6:08       ` Eli Zaretskii
2024-08-24 17:10         ` Jim Porter
2024-08-24 19:01           ` Eli Zaretskii
2024-08-24 19:42             ` Jim Porter
2024-08-25  5:05               ` Eli Zaretskii
2024-08-25  6:11                 ` Jim Porter
2024-08-25  6:22                   ` Eli Zaretskii
2024-08-25 17:18                     ` Jim Porter
2024-08-25 17:49                       ` Eli Zaretskii
2024-08-25 18:51                         ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3482d616-8a1c-d458-8da4-1b9d12ff32c5@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=72771@debbugs.gnu.org \
    --cc=R.Stewart@hw.ac.uk \
    --cc=eliz@gnu.org \
    --cc=kevin.legouguec@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).