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: provide default URIs; be bound to a key
Date: Sat, 22 Nov 2014 19:20:34 +0000	[thread overview]
Message-ID: <87ppcfujnh.fsf_-_@violet.siamics.net> (raw)
In-Reply-To: <87d28j5k9x.fsf@violet.siamics.net> (Ivan Shmakov's message of "Wed, 19 Nov 2014 14:37:14 +0000")

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

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

	Please consider 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.

	I’ve found that I myself prefer a different order for the
	default URIs than my previous patch suggested.  Therefore, I’ve
	ended up making it fully customizable.

-- 
FSF associate member #7257  np. Following My Father’s Song — Jami Sieber

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

--- a/lisp/net/eww.el	2014-11-21 09:21:50 +0000 
+++ b/lisp/net/eww.el	2014-11-22 19:05:15 +0000
@@ -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
 
@@ -59,6 +60,21 @@
   :group 'eww
   :type 'string)
 
+(defcustom eww-suggest-uris
+  '(eww-links-at-point
+    url-get-url-at-point
+    eww-current-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
+  :options '(eww-links-at-point
+	     url-get-url-at-point
+	     eww-current-url))
+
 (defcustom eww-bookmarks-directory user-emacs-directory
   "Directory where bookmark files will be stored."
   :version "25.1"
@@ -101,6 +123,7 @@
   :group 'eww
   :type '(choice (const :tag "Unlimited" nil)
                  integer))
+
 (defcustom eww-use-external-browser-for-content-type
   "\\`\\(video/\\|audio/\\|application/ogg\\)"
   "Always use external browser for specified content-type."
@@ -194,12 +218,31 @@
     (define-key map "\r" 'eww-follow-link)
     map))
 
+(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))
+	(uris nil))
+    (dolist (fun eww-suggest-uris)
+      (let ((ret (funcall fun)))
+	(dolist (uri (if (stringp ret) (list ret) ret))
+	  (when (and uri (not (intern-soft uri obseen)))
+	    (intern uri obseen)
+	    (push   uri uris)))))
+    ;; .
+    (nreverse uris)))
+
 ;;;###autoload
 (defun eww (url)
   "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.
@@ -454,6 +504,16 @@
   (unless (eq major-mode 'eww-mode)
     (eww-mode)))
 
+(defun eww-current-url nil
+  "Return URI of the Web page the current EWW buffer is visiting."
+  (plist-get eww-data :url))
+
+(defun eww-links-at-point (&optional pt)
+  "Return list of URIs, if any, linked at point."
+  (remq nil
+	(list (get-text-property (point) 'shr-url)
+	      (get-text-property (point) 'image-url))))
+
 (defun eww-view-source ()
   "View the HTML source code of the current page."
   (interactive)
@@ -548,6 +608,7 @@
     (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)

  parent reply	other threads:[~2014-11-22 19:20 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
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       ` Ivan Shmakov [this message]
2014-11-23 15:55         ` bug#19106: M-x eww: provide default URIs; " 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=87ppcfujnh.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.