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#20032: eww: access bookmarks right from the URI prompt Date: Sat, 07 Mar 2015 19:45:53 +0000 Message-ID: <87fv9gzj4e.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1425757647 19693 80.91.229.3 (7 Mar 2015 19:47:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Mar 2015 19:47:27 +0000 (UTC) To: 20032@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 07 20:47:14 2015 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 1YUKgr-0001uV-Lq for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Mar 2015 20:47:13 +0100 Original-Received: from localhost ([::1]:36182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YUKgr-0000LM-1L for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Mar 2015 14:47:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YUKgm-0000Kg-Jc for bug-gnu-emacs@gnu.org; Sat, 07 Mar 2015 14:47:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YUKgh-0008TE-Jy for bug-gnu-emacs@gnu.org; Sat, 07 Mar 2015 14:47:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40318) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YUKgg-0008T8-RG for bug-gnu-emacs@gnu.org; Sat, 07 Mar 2015 14:47:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YUKgg-0007Pa-Hv for bug-gnu-emacs@gnu.org; Sat, 07 Mar 2015 14:47: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: Sat, 07 Mar 2015 19:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20032 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142575756828410 (code B ref -1); Sat, 07 Mar 2015 19:47:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Mar 2015 19:46:08 +0000 Original-Received: from localhost ([127.0.0.1]:38886 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YUKfn-0007OA-NN for submit@debbugs.gnu.org; Sat, 07 Mar 2015 14:46:08 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:58440) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YUKfk-0007Nw-So for submit@debbugs.gnu.org; Sat, 07 Mar 2015 14:46:05 -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:Date:Sender:Subject:To:From; bh=BzgNs7PLs79HPYr1wuHBwh9k99XkDbUYEaFDQlHhqd8=; b=b7d2IJZv22vDkgIF0qtMdlCLH1oVkVI9tBhI5Oit5R7mtUby6JzNfBFyCRBD/NlL+zx6l8bPsfy3yrZMdsWXjgDWBHQ/0Uwgqx5RyrPl9g2hlNNPQYSwSP2x2HK7PPPClS4F9/mbvQ4pNq13IhYrvJ7A86mmcB1qhEJRPSOruKM=; 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 1YUKfi-00005E-6c for submit@debbugs.gnu.org; Sat, 07 Mar 2015 19:46:02 +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 1YUKfa-0004XI-Ti for submit@debbugs.gnu.org; Sun, 08 Mar 2015 02:45:54 +0700 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:100244 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Package: emacs Severity: wishlist Tags: patch Please consider the tentative patch MIMEd. * lisp/net/eww.el (eww-suggest-uris): Add eww-suggest-bookmarks to the default value and :options. (Bug#???) (eww-suggest-bookmarks, eww-remove-annotation): New functions. (eww-suggested-uris, eww): Use eww-remove-annotation. Somehow, I believe that eww-remove-annotation may be generalized into something worthy of subr.el. On a related note, can we please make eww-bookmarks a defcustom and thus replace eww-write-bookmarks, eww-read-bookmarks with customize-save-variable and the regular custom-set-variables mechanism, respectively? --=20 FSF associate member #7257 np. Begin Again =E2=80=94 Jami Sieber 3013 B6A0= 230E 334A --=-=-= Content-Type: text/diff Content-Disposition: inline --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -64,7 +64,8 @@ defcustom eww-download-directory "~/Downloads/" (defcustom eww-suggest-uris '(eww-links-at-point url-get-url-at-point - eww-current-url) + eww-current-url + eww-suggest-bookmarks) "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 @@ -74,7 +75,8 @@ defcustom eww-suggest-uris :type 'hook :options '(eww-links-at-point url-get-url-at-point - eww-current-url)) + eww-current-url + eww-suggest-bookmarks)) (defcustom eww-bookmarks-directory user-emacs-directory "Directory where bookmark files will be stored." @@ -234,11 +243,30 @@ defun eww-suggested-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))))) + (let ((key (and uri (eww-remove-annotation uri)))) + (when (and key (not (intern-soft key obseen))) + (intern key obseen) + (push uri uris)))))) (nreverse uris))) +(defun eww-remove-annotation (string &optional start) + (unless start + (setq start 0)) + (let ((init (get-text-property start 'annotation string)) + (chan (next-single-property-change start 'annotation string))) + (if (not chan) + (if init nil ; The whole string is an annotation. + string) + (let ((acc nil) + (from (if init chan start))) + (while from + (let ((to (next-single-property-change from 'annotation string))) + (setq acc (concat acc (substring string from to)) + from (and to + (next-single-property-change + to 'annotation string))))) + acc)))) + ;;;###autoload (defun eww (url) "Fetch URL and render the page. @@ -249,7 +277,8 @@ defun eww (url) (prompt (concat "Enter URL or keywords" (if uris (format " (default %s)" (car uris)) "") ": "))) - (list (read-string prompt nil nil uris)))) + (when-let ((uri (read-string prompt nil nil uris))) + (list (eww-remove-annotation uri))))) (setq url (string-trim url)) (cond ((string-match-p "\\`file:/" url)) ;; Don't mangle file: URLs at all. @@ -549,6 +564,22 @@ defun eww-links-at-point () (list (get-text-property (point) 'shr-url) (get-text-property (point) 'image-url)))) +(defun eww-suggest-bookmarks () + "Return list of bookmarked URIs, if any. +The URIs returned may contain arbitrary annotations. Apply +`eww-remove-annotation' on elements of the list returned to obtain the +URIs proper." + (mapcar (lambda (elt) + (let ((uri (plist-get elt :url)) + (title (plist-get elt :title))) + (when uri + (concat uri + (propertize " " + 'display (concat " (" title ")") + 'annotation t + 'face 'minibuffer-prompt))))) + eww-bookmarks)) + (defun eww-view-source () "View the HTML source code of the current page." (interactive) --=-=-=--