]> git.eshelyaron.com Git - emacs.git/commitdiff
Add bookmark.el support to eww
authorStefan Kangas <stefan@marxist.se>
Wed, 29 Sep 2021 01:24:10 +0000 (03:24 +0200)
committerStefan Kangas <stefan@marxist.se>
Wed, 29 Sep 2021 01:53:07 +0000 (03:53 +0200)
* lisp/net/eww.el (eww-bookmark-name, eww-bookmark-make-record)
(eww-bookmark-jump): New defuns.
(eww-mode): Set up bookmark handler.

etc/NEWS
lisp/net/eww.el

index 21cc3c50cd1e721e4b5bc49315a079447b68d9da..38a8f3015d9ba89c0d75e61ff297e8a82d472b31 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2391,6 +2391,11 @@ The function that is invoked when clicking on or otherwise following a
 'mailto:' link in an EWW buffer can now be customized.  For more
 information, see the related entry about 'shr-browse-url' above.
 
+---
+*** Support for bookmark.el.
+The command `bookmark-set' (bound to `C-x r m') is now supported, and
+will create a bookmark that opens the current URL in EWW.
+
 ** SHR
 
 ---
index e9b31858073266ebd3f20b6f29e2ec7042a574e4..bb6583c2a9a09371fe84524f1cd5bf17e07b0c57 100644 (file)
@@ -1101,6 +1101,7 @@ the like."
   (setq-local thing-at-point-provider-alist
               (append thing-at-point-provider-alist
                       '((url . eww--url-at-point))))
+  (setq-local bookmark-make-record-function #'eww-bookmark-make-record)
   (buffer-disable-undo)
   (setq buffer-read-only t))
 
@@ -2419,6 +2420,28 @@ Otherwise, the restored buffer will contain a prompt to do so by using
         (eww-previous-url))))
   (current-buffer))
 
+;;; bookmark.el support
+
+(declare-function bookmark-make-record-default
+                  "bookmark" (&optional no-file no-context posn))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+
+(defun eww-bookmark-name ()
+  "Create a default bookmark name for the current EWW buffer."
+  (plist-get eww-data :title))
+
+(defun eww-bookmark-make-record ()
+  "Create a bookmark for the current EWW buffer."
+  `(,(eww-bookmark-name)
+    ,@(bookmark-make-record-default t)
+    (location . ,(plist-get eww-data :url))
+    (handler . eww-bookmark-jump)))
+
+;;;###autoload
+(defun eww-bookmark-jump (bookmark)
+  "Default bookmark handler for EWW buffers."
+  (eww (bookmark-prop-get bookmark 'location)))
+
 (provide 'eww)
 
 ;;; eww.el ends here