bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19106: M-x eww: use the current URI as the default; be bound to a ke


From: Ivan Shmakov
Subject: bug#19106: M-x eww: use the current URI as the default; be bound to a key
Date: Wed, 19 Nov 2014 14:37:14 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

>>>>> Ivan Shmakov <ivan@siamics.net> writes:

[…]

 > The eww-default-uri-hook solution seems reasonably easy to implement;
 > I hope to suggest a possible patch later.

        Better still, we can support all the options at the same time
        simply by passing a list to read-string, as per the revised
        patch MIMEd.

        One may still wish to customize the order of the entries listed,
        or perhaps to add new ones (think of recognizing, say, RFC 7154
        or RFC7154 as a link to http://tools.ietf.org/html/rfc7154, for
        instance), but to be convenient, there should probably be a
        couple of helper functions to correspond to the lambdas in the
        example code fragment also MIMEd.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
--- 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)
(require 'cl-seq)                       ; for cl-reduce

(defcustom eww-suggest-uris
  '((lambda ()
      (list (get-text-property (point) 'shr-url)
            (get-text-property (point) 'image-url)))
    'url-get-url-at-point
    (lambda ()
      (plist-get eww-data :url)))
  "List of functions called to form the list of default URIs for `eww'.
Each of the elements is a function returning either a string or a list
of strings.  The results will be joined into a single list with
duplicate entries (if any) removed."
  :version "25.1"
  :group 'eww
  :type 'hook)

(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'."
  (let ((obseen (make-vector 42 0)))
    (cl-reduce (lambda (acc elt)
                 (let ((uri (funcall elt)))
                   (if (or (not acc) (intern-soft uri obseen))
                       acc
                     (intern uri obseen)
                     (cons uri acc))))
               eww-suggest-uris
               :initial-value nil)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]