all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ivan Shmakov <ivan@siamics.net>
To: 19106@debbugs.gnu.org
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	[thread overview]
Message-ID: <87d28j5k9x.fsf@violet.siamics.net> (raw)
In-Reply-To: <87k32r5nbd.fsf@violet.siamics.net> (Ivan Shmakov's message of "Wed, 19 Nov 2014 13:31:34 +0000")

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

>>>>> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/diff, Size: 1664 bytes --]

--- 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)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: Type: text/emacs-lisp, Size: 1064 bytes --]

(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	other threads:[~2014-11-19 14:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19 12:01 bug#19106: M-x eww: use the current URI as the default; be bound to a key Ivan Shmakov
2014-11-19 12:17 ` Tassilo Horn
2014-11-19 13:31   ` Ivan Shmakov
2014-11-19 14:37     ` Ivan Shmakov [this message]
2014-11-19 17:31       ` Lars Magne Ingebrigtsen
2014-11-19 20:07         ` Ivan Shmakov
2014-11-19 20:27           ` Lars Magne Ingebrigtsen
2014-11-19 20:40             ` Ivan Shmakov
2014-11-22 19:20       ` bug#19106: M-x eww: provide default URIs; " Ivan Shmakov
2014-11-23 15:55         ` Lars Magne Ingebrigtsen
2014-11-19 17:09 ` bug#19106: M-x eww: use the current URI as the default; " Mark Oteiza
2014-11-20 13:45   ` Ivan Shmakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d28j5k9x.fsf@violet.siamics.net \
    --to=ivan@siamics.net \
    --cc=19106@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.