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