From 5cd39589ebd47ccc8f53b8921fadd566df316d21 Mon Sep 17 00:00:00 2001 From: Jim Porter 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