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: use the current URI as the default; be bound to a key Date: Wed, 19 Nov 2014 14:37:14 +0000 Message-ID: <87d28j5k9x.fsf@violet.siamics.net> References: <87r3wz5rgr.fsf@violet.siamics.net> <87r3wzbd0c.fsf@thinkpad-t440p.tsdh.org> <87k32r5nbd.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1416407902 15264 80.91.229.3 (19 Nov 2014 14:38:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Nov 2014 14:38:22 +0000 (UTC) To: 19106@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 19 15:38:18 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 1Xr6Od-0006ci-Te for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 15:38:16 +0100 Original-Received: from localhost ([::1]:58784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr6Od-0000gm-Dq for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 09:38:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr6OV-0000gY-Q2 for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 09:38:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr6OR-0002bf-Lc for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 09:38:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40757) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr6OR-0002bY-9j for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 09:38:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Xr6OQ-00057T-Jd for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 09:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Nov 2014 14:38:02 +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.141640785019629 (code B ref 19106); Wed, 19 Nov 2014 14:38:02 +0000 Original-Received: (at 19106) by debbugs.gnu.org; 19 Nov 2014 14:37:30 +0000 Original-Received: from localhost ([127.0.0.1]:37970 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xr6Nu-00056X-2a for submit@debbugs.gnu.org; Wed, 19 Nov 2014 09:37:30 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:41395) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xr6Nq-00056N-SB for 19106@debbugs.gnu.org; Wed, 19 Nov 2014 09:37:27 -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=ZBx8jnWcl2vpym3dQKopOrod+SC0TViZDyxB5D3PSQQ=; b=jHoOuoNnmGzH1q/ZWMcebRO1aiPZ4J+Xgg5hnxc7Q0rgRcECx5J32Yx7WpqYawMaItTrJGtrCKn1lMWUG3ajp4uDy4j+NaivbBAbVrD5oCbunbp3+qpVV+nGP8Wsu/NujzOmrnZq+sbIt6nKdgyzaUWby+1Tv57YLRp5SSZGh1Y=; 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 1Xr6No-0004hb-4W for 19106@debbugs.gnu.org; Wed, 19 Nov 2014 14:37:24 +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 1Xr6Nf-0006O7-Cs for 19106@debbugs.gnu.org; Wed, 19 Nov 2014 21:37:15 +0700 In-Reply-To: <87k32r5nbd.fsf@violet.siamics.net> (Ivan Shmakov's message of "Wed, 19 Nov 2014 13:31:34 +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:96238 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Ivan Shmakov writes: [=E2=80=A6] > 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. --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/diff Content-Disposition: inline --- 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) --=-=-= Content-Type: text/emacs-lisp Content-Disposition: inline (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))) --=-=-=--