unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20032: eww: access bookmarks right from the URI prompt
@ 2015-03-07 19:45 Ivan Shmakov
  2015-03-08 10:25 ` Ivan Shmakov
  2015-12-25  6:25 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 11+ messages in thread
From: Ivan Shmakov @ 2015-03-07 19:45 UTC (permalink / raw)
  To: 20032

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

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

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

--- 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)

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-01-24 22:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-07 19:45 bug#20032: eww: access bookmarks right from the URI prompt Ivan Shmakov
2015-03-08 10:25 ` Ivan Shmakov
2015-12-25  6:35   ` Lars Ingebrigtsen
2015-12-26  8:57     ` Ivan Shmakov
2015-12-26 13:05       ` Lars Ingebrigtsen
2015-12-26 16:48         ` Ivan Shmakov
2015-12-26 17:00           ` Lars Ingebrigtsen
2016-02-02  4:33             ` Lars Ingebrigtsen
2017-01-24 22:44               ` Lars Ingebrigtsen
2015-12-25  6:25 ` Lars Ingebrigtsen
2015-12-26  9:42   ` Ivan Shmakov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).