GNU bug report logs - #20032
eww: access bookmarks right from the URI prompt

Previous Next

Package: emacs;

Reported by: Ivan Shmakov <ivan <at> siamics.net>

Date: Sat, 7 Mar 2015 19:47:02 UTC

Severity: wishlist

Tags: patch, wontfix

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: submit <at> debbugs.gnu.org
Subject: eww: access bookmarks right from the URI prompt 
Date: Sat, 07 Mar 2015 19:45:53 +0000
[Message part 1 (text/plain, inline)]
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?

-- 
FSF associate member #7257  np. Begin Again — Jami Sieber 3013 B6A0 230E 334A
[Message part 2 (text/diff, 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)

This bug report was last modified 8 years and 124 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.