From: Stefan Monnier Date: Sat, 17 May 2025 16:34:33 +0000 (-0400) Subject: (eww-switch-to-buffer): Don't let-bind `completion-extra-properties` X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=81d4e7aeb2d5afc05c72d610eb93891c50c217ce;p=emacs.git (eww-switch-to-buffer): Don't let-bind `completion-extra-properties` * lisp/net/eww.el (eww--buffer-p): New function. (eww-switch-to-buffer): Use it. And set `completion-extra-properties` buffer-locally rather than let-binding it. (cherry picked from commit f77f464637c6ce86d5d69963543f86bc517ad14c) --- diff --git a/lisp/net/eww.el b/lisp/net/eww.el index ffcc47d8747..db13497f356 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -2292,26 +2292,31 @@ If CHARSET is nil then use UTF-8." (eww-reload nil 'utf-8) (eww-reload nil charset))) +(defun eww--buffer-p (buf) + (provided-mode-derived-p (buffer-local-value 'major-mode buf) + 'eww-mode)) + (defun eww-switch-to-buffer () "Prompt for an EWW buffer to display in the selected window." (interactive nil eww-mode) - (let ((completion-extra-properties - `(:annotation-function - ,(lambda (buf) - (with-current-buffer buf - (format " %s" (eww-current-url)))))) + (let ((list (cl-loop for buf in (nreverse (buffer-list)) + if (eww--buffer-p buf) + return buf)) (curbuf (current-buffer))) (pop-to-buffer-same-window - (read-buffer "Switch to EWW buffer: " - (cl-loop for buf in (nreverse (buffer-list)) - if (with-current-buffer buf (derived-mode-p 'eww-mode)) - return buf) - t - (lambda (bufn) - (setq bufn (if (consp bufn) (cdr bufn) (get-buffer bufn))) - (and (with-current-buffer bufn - (derived-mode-p 'eww-mode)) - (not (eq bufn curbuf)))))))) + (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))))))))) (defun eww-toggle-fonts () "Toggle whether to use monospaced or font-enabled layouts."