--- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -29,6 +29,7 @@ (require 'shr) (require 'url) (require 'url-queue) +(require 'url-util) ; for url-get-url-at-point (require 'mm-url) (eval-when-compile (require 'subr-x)) ;; for string-trim @@ -158,12 +159,29 @@ (define-key map "\r" 'eww-follow-link) map)) +(defun eww-suggested-uris nil + "Return the list of URIs to suggest at the `eww' prompt." + ;; FIXME: allow for customization? + (remq nil + (list ;; in the shr-copy-url order + (get-text-property (point) 'shr-url) + (get-text-property (point) 'image-url) + ;; check the text itself + (url-get-url-at-point) + ;; fallback to the URI of the visited page + (plist-get eww-data :url))) + ;;;###autoload -(defun eww (url) +(defun eww (url &optional no-save-history) "Fetch URL and render the page. If the input doesn't look like an URL or a domain name, the word(s) will be searched for via `eww-search-prefix'." - (interactive "sEnter URL or keywords: ") + (interactive + (let* ((uris (eww-suggested-uris)) + (prompt (concat "Enter URL or keywords" + (if uris (format " (default %s)" (car uris) "")) + ": "))) + (list (read-string prompt nil nil uris)))) (setq url (string-trim url)) (cond ((string-match-p "\\`file:/" url)) ;; Don't mangle file: URLs at all. @@ -513,6 +526,7 @@ the like." (suppress-keymap map) (define-key map "q" 'quit-window) (define-key map "g" 'eww-reload) + (define-key map "G" 'eww) (define-key map [?\t] 'shr-next-link) (define-key map [?\M-\t] 'shr-previous-link) (define-key map [delete] 'scroll-down-command)