]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve eww-search-words
authorEshel Yaron <me@eshelyaron.com>
Fri, 8 Nov 2024 08:54:05 +0000 (09:54 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 8 Nov 2024 08:54:05 +0000 (09:54 +0100)
lisp/net/eww.el

index 6559c7e5eb9734d9c04720fce38aded7b9ef232f..869fe869fffaac08a901643af7488cde4322624d 100644 (file)
@@ -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."