From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#19106: M-x eww: provide default URIs; be bound to a key Date: Sat, 22 Nov 2014 19:20:34 +0000 Message-ID: <87ppcfujnh.fsf_-_@violet.siamics.net> References: <87r3wz5rgr.fsf@violet.siamics.net> <87r3wzbd0c.fsf@thinkpad-t440p.tsdh.org> <87k32r5nbd.fsf@violet.siamics.net> <87d28j5k9x.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1416684081 11779 80.91.229.3 (22 Nov 2014 19:21:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 22 Nov 2014 19:21:21 +0000 (UTC) To: 19106@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Nov 22 20:21:15 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XsGF8-0008Dy-GK for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Nov 2014 20:21:14 +0100 Original-Received: from localhost ([::1]:46528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsGF7-0006se-QM for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Nov 2014 14:21:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsGF0-0006sX-TN for bug-gnu-emacs@gnu.org; Sat, 22 Nov 2014 14:21:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XsGEw-0000ok-JB for bug-gnu-emacs@gnu.org; Sat, 22 Nov 2014 14:21:06 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsGEw-0000of-4N for bug-gnu-emacs@gnu.org; Sat, 22 Nov 2014 14:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XsGEv-00034Z-RQ for bug-gnu-emacs@gnu.org; Sat, 22 Nov 2014 14:21:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Nov 2014 19:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19106 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19106-submit@debbugs.gnu.org id=B19106.141668404811786 (code B ref 19106); Sat, 22 Nov 2014 19:21:01 +0000 Original-Received: (at 19106) by debbugs.gnu.org; 22 Nov 2014 19:20:48 +0000 Original-Received: from localhost ([127.0.0.1]:41960 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XsGEi-000341-43 for submit@debbugs.gnu.org; Sat, 22 Nov 2014 14:20:48 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:41915) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XsGEf-00033q-NO for 19106@debbugs.gnu.org; Sat, 22 Nov 2014 14:20:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:Sender:References:Subject:To:From; bh=vHqjUlkzEBbQvhdv/BNV2HjSLIIyjuxnykVIrDl6Njg=; b=LZifa8jfaXWa6kciZpbDM4WLgLI5jOVXqc2qGz1h+Yg1dF9T1TzmcIL+KXAgcMF1Ix9oyQq3VcOyO1HWWzE7TryIgajgIja9yCg5aGuWLnZ9scRdgwtRpivE5uejLGh5gkyaocPYoxl7ra47W6WYome0VYvU8y7760oFmmFTOgA=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XsGEc-0006JJ-IQ for 19106@debbugs.gnu.org; Sat, 22 Nov 2014 19:20:43 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XsGEV-0002gA-B0 for 19106@debbugs.gnu.org; Sun, 23 Nov 2014 02:20:35 +0700 In-Reply-To: <87d28j5k9x.fsf@violet.siamics.net> (Ivan Shmakov's message of "Wed, 19 Nov 2014 14:37:14 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:96432 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Ivan Shmakov writes: Please consider the revised patch MIMEd. [=E2=80=A6] > 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=E2=80=99ve found that I myself prefer a different order for the default URIs than my previous patch suggested. Therefore, I=E2=80=99ve ended up making it fully customizable. --=20 FSF associate member #7257 np. Following My Father=E2=80=99s Song =E2=80= =94 Jami Sieber --=-=-= Content-Type: text/diff Content-Disposition: inline --- 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) --=-=-=--