emacs: provide eww and bookmark.el integration

This commit is contained in:
Protesilaos Stavrou 2024-06-22 13:44:41 +03:00
parent 2fd4e7e57d
commit 438f9549c1
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
3 changed files with 54 additions and 0 deletions

View file

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

View file

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

View file

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