From 438f9549c1dce33f8cc59e868ab803ccb20daa6b Mon Sep 17 00:00:00 2001 From: Protesilaos Stavrou Date: Sat, 22 Jun 2024 13:44:41 +0300 Subject: [PATCH] emacs: provide eww and bookmark.el integration --- .../prot-emacs-modules/prot-emacs-web.el | 2 ++ emacs/.emacs.d/prot-emacs.org | 27 +++++++++++++++++++ emacs/.emacs.d/prot-lisp/prot-eww.el | 25 +++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/emacs/.emacs.d/prot-emacs-modules/prot-emacs-web.el b/emacs/.emacs.d/prot-emacs-modules/prot-emacs-web.el index 05ba5b03..54f717ba 100644 --- a/emacs/.emacs.d/prot-emacs-modules/prot-emacs-web.el +++ b/emacs/.emacs.d/prot-emacs-modules/prot-emacs-web.el @@ -84,6 +84,7 @@ (use-package prot-eww :ensure nil :after eww + :hook (eww-mode . prot-eww-set-bookmark-handler) :config (setq prot-eww-save-history-file (locate-user-emacs-file "prot-eww-visited-history")) @@ -94,6 +95,7 @@ (define-prefix-command 'prot-eww-map) (define-key global-map (kbd "C-c w") 'prot-eww-map) + (prot-emacs-keybind prot-eww-map "b" #'prot-eww-visit-bookmark "e" #'prot-eww-browse-dwim diff --git a/emacs/.emacs.d/prot-emacs.org b/emacs/.emacs.d/prot-emacs.org index 2225800b..677a7bfd 100644 --- a/emacs/.emacs.d/prot-emacs.org +++ b/emacs/.emacs.d/prot-emacs.org @@ -10195,6 +10195,7 @@ account default : pub (use-package prot-eww :ensure nil :after eww + :hook (eww-mode . prot-eww-set-bookmark-handler) :config (setq prot-eww-save-history-file (locate-user-emacs-file "prot-eww-visited-history")) @@ -10205,6 +10206,7 @@ account default : pub (define-prefix-command 'prot-eww-map) (define-key global-map (kbd "C-c w") 'prot-eww-map) + (prot-emacs-keybind prot-eww-map "b" #'prot-eww-visit-bookmark "e" #'prot-eww-browse-dwim @@ -12541,6 +12543,31 @@ As a final step, save `prot-eww-visited-history' to a file (see (when (yes-or-no-p "Are you sure you want to quit eww?") (run-hooks 'prot-eww-quit-hook)))) +;;;; Bookmark support + +(declare-function bookmark-prop-get "bookmark" (bookmark prop)) + +(defun prot-eww-bookmark-name () + "Return name of bookmark based on currect directory." + (buffer-name)) + +(defun prot-eww-bookmark-make-record () + "Create a bookmark for the current Shell buffer." + `(,(prot-eww-bookmark-name) + (url . ,(prot-eww--get-current-url)) + (handler . prot-eww-bookmark-jump))) + +;;;###autoload +(defun prot-eww-bookmark-jump (bookmark) + "Default BOOKMARK handler for Shell buffers." + (eww (bookmark-prop-get bookmark 'url))) + +(put 'prot-eww-bookmark-jump 'bookmark-handler-type "EWW") + +(defun prot-eww-set-bookmark-handler () + "Set my EWW bookmark handler for integration with bookmark.el." + (setq-local bookmark-make-record-function #'prot-eww-bookmark-make-record)) + (provide 'prot-eww) ;;; prot-eww.el ends here #+end_src diff --git a/emacs/.emacs.d/prot-lisp/prot-eww.el b/emacs/.emacs.d/prot-lisp/prot-eww.el index eef092fe..bd12cc11 100644 --- a/emacs/.emacs.d/prot-lisp/prot-eww.el +++ b/emacs/.emacs.d/prot-lisp/prot-eww.el @@ -656,5 +656,30 @@ As a final step, save `prot-eww-visited-history' to a file (see (when (yes-or-no-p "Are you sure you want to quit eww?") (run-hooks 'prot-eww-quit-hook)))) +;;;; Bookmark support + +(declare-function bookmark-prop-get "bookmark" (bookmark prop)) + +(defun prot-eww-bookmark-name () + "Return name of bookmark based on currect directory." + (buffer-name)) + +(defun prot-eww-bookmark-make-record () + "Create a bookmark for the current Shell buffer." + `(,(prot-eww-bookmark-name) + (url . ,(prot-eww--get-current-url)) + (handler . prot-eww-bookmark-jump))) + +;;;###autoload +(defun prot-eww-bookmark-jump (bookmark) + "Default BOOKMARK handler for Shell buffers." + (eww (bookmark-prop-get bookmark 'url))) + +(put 'prot-eww-bookmark-jump 'bookmark-handler-type "EWW") + +(defun prot-eww-set-bookmark-handler () + "Set my EWW bookmark handler for integration with bookmark.el." + (setq-local bookmark-make-record-function #'prot-eww-bookmark-make-record)) + (provide 'prot-eww) ;;; prot-eww.el ends here