From 141ead3d03077401c041e86804db2ca2f3afd423 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 18 May 2025 15:48:54 -0400 Subject: [PATCH] eww.el: Misc changes * lisp/net/eww.el (eww--parse-html-region): Don't decode when it's a no-op. (eww-display-raw): Simplify. (eww-mode): Prefer #' to quote function names. (eww-switch-to-buffer): Use `completion-table-with-metadata` instead of `completion-extra-properties`. Don't prompt the user when there's only one choice. (eww-buffer-list): Use `eww--buffer-p`. (cherry picked from commit 860a6c86c5696513707f980dffbe7c58f0f52b7b) --- lisp/net/eww.el | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index ae4c3248153..34f58fd89f0 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -758,9 +758,11 @@ Use CODING-SYSTEM to decode the region; if nil, decode as UTF-8. This replaces the region with the preprocessed HTML." (setq coding-system (or coding-system 'utf-8)) (with-restriction start end - (condition-case nil - (decode-coding-region (point-min) (point-max) coding-system) - (coding-system-error nil)) + (unless (and (not enable-multibyte-characters) + (eq coding-system 'utf-8)) + (condition-case nil + (decode-coding-region (point-min) (point-max) coding-system) + (coding-system-error nil))) ;; Remove CRLF and replace NUL with � before parsing. (while (re-search-forward "\\(\r$\\)\\|\0" nil t) (replace-match (if (match-beginning 1) "" "�") t t)) @@ -1008,7 +1010,7 @@ This replaces the region with the preprocessed HTML." (erase-buffer) (insert data) (condition-case nil - (decode-coding-region (point-min) (1+ (length data)) encode) + (decode-coding-region (point-min) (point) encode) (coding-system-error nil))) (goto-char (point-min))))) @@ -1357,7 +1359,7 @@ within text input fields." (setq-local shr-url-transformer #'eww--transform-url) ;; Also rescale images when rescaling the text. (add-hook 'text-scale-mode-hook #'eww--rescale-images nil t) - (setq-local outline-search-function 'shr-outline-search + (setq-local outline-search-function #'shr-outline-search outline-level 'shr-outline-level) (add-hook 'post-command-hook #'eww-check-text-conversion nil t) (setq buffer-read-only t) @@ -2294,23 +2296,20 @@ If CHARSET is nil then use UTF-8." "Prompt for an EWW buffer to display in the selected window." (interactive nil eww-mode) (let ((list (cl-loop for buf in (nreverse (buffer-list)) - if (eww--buffer-p buf) - return buf)) - (curbuf (current-buffer))) + if (and (eww--buffer-p buf) + (not (eq buf (current-buffer)))) + collect (buffer-name buf)))) (pop-to-buffer-same-window - (minibuffer-with-setup-hook - (lambda () - (setq-local completion-extra-properties - `(:annotation-function - ,(lambda (buf) - (with-current-buffer buf - (format " %s" (eww-current-url))))))) - (read-buffer "Switch to EWW buffer: " - list t - (lambda (bufn) - (setq bufn (or (cdr-safe bufn) (get-buffer bufn))) - (and (eww--buffer-p bufn) - (not (eq bufn curbuf))))))))) + (if (length= list 1) (car list) + (completing-read "Switch to EWW buffer: " + (completion-table-with-metadata + list + `((category . buffer) + (annotation-function + . ,(lambda (buf) + (with-current-buffer buf + (format " %s" (eww-current-url))))))) + nil t))))) (defun eww-toggle-fonts () "Toggle whether to use monospaced or font-enabled layouts." @@ -2684,7 +2683,7 @@ see)." (defun eww-buffer-list () "Return a list of all live eww buffers." - (match-buffers '(derived-mode . eww-mode))) + (match-buffers #'eww--buffer-p)) (defun eww-list-buffers () "Pop a buffer with a list of eww buffers." -- 2.39.5