emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master da89bdd 1/2: Add bookmark.el support to eww


From: Stefan Kangas
Subject: master da89bdd 1/2: Add bookmark.el support to eww
Date: Tue, 28 Sep 2021 21:53:14 -0400 (EDT)

branch: master
commit da89bdde2e3aa941594a112db884ede1beaac658
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Add bookmark.el support to eww
    
    * lisp/net/eww.el (eww-bookmark-name, eww-bookmark-make-record)
    (eww-bookmark-jump): New defuns.
    (eww-mode): Set up bookmark handler.
---
 etc/NEWS        |  5 +++++
 lisp/net/eww.el | 23 +++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 21cc3c5..38a8f30 100644
--- 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
 
 ---
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index e9b3185..bb6583c 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]