From: Eshel Yaron Date: Fri, 8 Nov 2024 08:54:05 +0000 (+0100) Subject: Improve eww-search-words X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=45e0bbd0e809f991f2582ae335c4b8177120ebb8;p=emacs.git Improve eww-search-words --- diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 6559c7e5eb9..869fe869fff 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -397,12 +397,6 @@ If zero, EWW is at the newest page, which isn't yet present in :parent shr-image-map "RET" #'eww-follow-link) -(defvar-keymap eww-minibuffer-url-keymap - :doc "Keymap used in the minibuffer prompt for URLs or keywords." - :parent minibuffer-local-completion-map - "SPC" #'self-insert-command - "?" #'self-insert-command) - (defun eww-suggested-uris nil "Return the list of URIs to suggest at the `eww' prompt. This list can be customized via `eww-suggest-uris'." @@ -435,6 +429,11 @@ will start Emacs and browse the GNU web site." (user-error "No URL given")) (eww (pop command-line-args-left))) +(defun eww-read-url-or-search-string (&optional initial-input) + (let ((uris (eww-suggested-uris))) + (completing-read (format-prompt "Enter URL or keywords" uris) + (seq-uniq (append eww-prompt-history uris)) + nil nil initial-input 'eww-prompt-history uris))) ;;;###autoload (defun eww (url &optional new-buffer buffer) @@ -451,13 +450,7 @@ killed after rendering. For more information, see Info node `(eww) Top'." (interactive - (let ((uris (eww-suggested-uris)) - (minibuffer-local-completion-map eww-minibuffer-url-keymap)) - (list (completing-read (format-prompt "Enter URL or keywords" - (and uris (car uris))) - (seq-uniq (append eww-prompt-history uris)) - nil nil nil 'eww-prompt-history uris) - current-prefix-arg))) + (list (eww-read-url-or-search-string) current-prefix-arg)) (setq url (eww--dwim-expand-url url)) (pop-to-buffer-same-window (cond @@ -602,12 +595,9 @@ the text between region beginning and end. Else, prompt the user for a search string. See the variable `eww-search-prefix' for the search engine used." (interactive) - (if (use-region-p) - (let ((region-string (buffer-substring (region-beginning) (region-end)))) - (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string)) - (eww region-string) - (call-interactively #'eww))) - (call-interactively #'eww))) + (eww (eww-read-url-or-search-string + (and (use-region-p) + (string-trim (buffer-substring-no-properties (point) (mark))))))) (defun eww--open-url-in-new-buffer (url) "Open the URL in a new EWW buffer."