From: Stefan Kangas Date: Wed, 29 Sep 2021 01:24:10 +0000 (+0200) Subject: Add bookmark.el support to eww X-Git-Tag: emacs-28.0.90~539 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=da89bdde2e3aa941594a112db884ede1beaac658;p=emacs.git 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. --- diff --git a/etc/NEWS b/etc/NEWS index 21cc3c50cd1..38a8f3015d9 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 e9b31858073..bb6583c2a9a 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