0

I'm attempting to create a bookmark handler for eww so I can use Emacs's built-in bookmarks to save and visit urls with eww.

There's an equivenant setup for w3m here: https://github.com/TotalView/dotemacs/blob/master/.emacs.d/elpa/w3m-20140330.1933/bookmark-w3m.el

From what I can gather I need to:

  • Create a function to actually make a properly formatted bookmark entry.
  • Find a way to grab all the data you need to create the bookmark from eww.
  • Set bookmark-make-record-function to that function.
  • Make a bookmark 'handler' which launches eww with the bookmark's url.

So far I've got the following setup. However, I'm getting the error oht-eww-bookmark-make-record: Symbol’s value as variable is void: oht-eww-current-title

(defun oht-eww-current-title ()
  "Returns the title of the current eww buffer"
  (plist-get eww-data :title))

(defun oht-eww-bookmark-make-record ()
  "Return a bookmark record for the current eww buffer."
  (interactive)
  `(,oht-eww-current-title
    (location . ,eww-current-url)
    (handler . ,oht-eww-bookmark-handler)))

(defun oht-eww-set-bookmark-handler ()
  "Set local variable to call function to save eww bookmark"
  (interactive)
  (set (make-local-variable 'bookmark-make-record-function)
       #'oht-eww-bookmark-make-record))

(defun oht-eww-bookmark-handler (record)
  "Jump to an eww bookmarked location."
  (eww (bookmark-prop-get record 'location)))

1 Answer 1

0

Seems like I just got the syntax wrong for the oht-eww-bookmark-make-record function. The below is a complete working solution.

(defun oht-eww-current-title ()
  "Returns the title of the current eww buffer"
  (plist-get eww-data :title))

(defun oht-eww-bookmark-make-record ()
  "Return a bookmark record for the current eww buffer."
  (interactive)
  `(,(oht-eww-current-title)
    (location . ,(eww-current-url))
    (handler . oht-eww-bookmark-handler)))

(defun oht-eww-set-bookmark-handler ()
  "This tells Emacs which function to use to create bookmarks."
  (interactive)
  (set (make-local-variable 'bookmark-make-record-function)
       #'oht-eww-bookmark-make-record))

(defun oht-eww-bookmark-handler (record)
  "Jump to an eww bookmarked location."
  (eww (bookmark-prop-get record 'location)))

(add-hook 'eww-mode-hook 'oht-eww-set-bookmark-handler)
3
  • Hello, i tried your snippet. But nothing happens, no error, no bookmark. Saving a bookmark inside eww saves it to the eww bookmark list. Or do i not understand your effort? Please explain a little bit more. Thanks Poul
    – space_held
    Commented Jan 25, 2021 at 18:47
  • This allows you to use bookmark-set on webpages in eww. You can view them with list-bookmarks. These bookmarks are different from eww's bookmarks. Commented Jan 26, 2021 at 19:38
  • thank you for the clear answer. I thought, that the eww bookmark command is modified by this code. Now i try C-x r m or M and it works great! Thanks a lot. Regards
    – space_held
    Commented Jan 28, 2021 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.