Add bookmark support and keybindings to EWW in Emacs

This commit adds the ability to access EWW bookmarks. It modifies the init-eww.el configuration file by introducing a function to visit bookmarks and updating the keybindings to include commands for accessing and listing bookmarks.
This commit is contained in:
Jeremy Dormitzer 2024-07-24 11:41:07 -04:00
parent 4a7ccb378d
commit 8ad4c70070

View File

@ -7,6 +7,7 @@
(interactive
(let* ((uris (eww-suggested-uris))
(browser-history (mapcar (lambda (h) (plist-get h :url)) eww-history))
(bookmarks (mapcar (lambda (b) (plist-get b :url)) eww-bookmarks))
(suggestions (delete-dups (append uris eww-prompt-history browser-history)))
(current-uri (plist-get eww-data :url)))
(list (completing-read "URL or keywords: " suggestions nil nil current-uri 'eww-prompt-history)
@ -74,10 +75,24 @@ new EWW buffer."
(position (replace-regexp-in-string "^.*(\\([0-9]+\\))[\s\t]+~" "\\1" selection))
(point (string-to-number position)))
(goto-char point))))
(defun eww-visit-bookmark (bookmark &optional arg)
"Visit BOOKMARK in EWW."
(interactive (list (let* ((bookmarks (mapcar (lambda (b)
(cons (format "%s | %s"
(plist-get b :title)
(plist-get b :url))
(plist-get b :url)))
eww-bookmarks))
(bookmark (completing-read "Bookmark: " bookmarks)))
(cdr (assoc bookmark bookmarks)))
current-prefix-arg))
(eww bookmark arg))
:general
(leader-map "E" #'eww)
(normal eww-mode-map
"go" #'eww
"gb" #'eww-visit-bookmark
"gB" #'eww-list-bookmarks
"gJ"#'eww-jump-to-url-on-page
"gV" #'eww-visit-url-on-page))