]> git.eshelyaron.com Git - emacs.git/commitdiff
eww.el: Misc changes
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 18 May 2025 19:48:54 +0000 (15:48 -0400)
committerEshel Yaron <me@eshelyaron.com>
Wed, 21 May 2025 06:12:23 +0000 (08:12 +0200)
* 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

index ae4c32481531327d18d5fcc0f1d35ce8cf5a926d..34f58fd89f0a90f745b8bec4680c1c12965eafa7 100644 (file)
@@ -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 &#0; before parsing.
     (while (re-search-forward "\\(\r$\\)\\|\0" nil t)
       (replace-match (if (match-beginning 1) "" "&#0;") 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."