From c711ba3c7bcab1b0900604425283fc018257abe0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 24 Aug 2025 19:27:47 -0700 Subject: [PATCH] Prefer window-text-pixel-size in erc-fill * lisp/erc/erc-fill.el (erc-fill--wrap-measure): Using `buffer-text-pixel-size' for measuring text size in the selected window can end up triggering a scroll, which then requires imperfect countering by the scrolltobottom module, especially with regard to the option `erc-scrolltobottom-all'. Thanks to Alcor for reporting and helping with this bug, which was introduced along with fill-wrap in ERC 5.6. --- lisp/erc/erc-fill.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el index 145a4c174a8..c4c9b6da76d 100644 --- a/lisp/erc/erc-fill.el +++ b/lisp/erc/erc-fill.el @@ -618,14 +618,20 @@ message has been marked `erc--ephemeral'." Ignore any `invisible' props that may be present when figuring. Expect the target region to be free of `line-prefix' and `wrap-prefix' properties, and expect `display-line-numbers-mode' -to be disabled." +to be disabled. On Emacs 28 and below, return END minus BEG." + ;; Rely on `buffer-text-pixel-size' here even for buffers displayed in + ;; another window because temporarily selecting such windows via + ;; `with-selected-window' seems to interfere with the implementation + ;; of `erc-scrolltobottom-all' in ERC 5.6, which needs improvement. (if (fboundp 'buffer-text-pixel-size) ;; `buffer-text-pixel-size' can move point! (save-excursion (save-restriction (narrow-to-region beg end) (let* ((buffer-invisibility-spec) - (rv (car (buffer-text-pixel-size)))) + (rv (car (if (eq (selected-window) (get-buffer-window)) + (window-text-pixel-size) + (buffer-text-pixel-size))))) (if erc-fill-wrap-use-pixels (if (zerop rv) 0 (list rv)) (/ rv (frame-char-width))))))