0

I would like an Emacs bookmark that jumps to a 'today' file. This is a different file every day, so I would like to use a function.

I tried an entry in bookmark-alist in the bookmarks file at .emacs.d/bookmarks:

("Today"
  (filename . (today-file))
  ;; removed for brevity
)

(where the function today-file returns the filename)

But this give the error (wrong-type-argument stringp (today-file)) from file-readable-p.

My current workaround is a keybinding:

(define-key mode-specific-map "t" (lambda () (interactive) (find-file (today-file))))

which works.

How can I define a bookmark with a function that runs when I open the bookmark?

1 Answer 1

0

Just define your own handler:

(defun visit-today-file (bookmark)
  "bookmark handler to visit the org file for today"
  (find-file (today-file)))

and use it like

("Today"
  (filename . "Org file for today")
  (handler . visit-today-file)
  ;; removed for brevity
)

I also tried using a lambda function, but that crashed the bookmark list.

Sign up to request clarification or add additional context in comments.

3 Comments

Regarding lambdas, bookmark file (("test" . ((handler . (lambda (_bookmark) (find-file "~/.emacs.d/init.el")))))) works for me in Emacs 30.1.
Interesting... With that bookmark, I get bookmark-bmenu--revert: Wrong type argument: symbolp, (lambda (_bookmark) (find-file "~/.emacs.d/init.el")) on running C-x r l (bookmark-bmenu-list) in Emacs 30.1 on MacOS, but only the first time. It appears the error appears on reverting the bookmark file.
Sounds like insufficient testing on my part, then. At least part of the bookmark system must indeed be assuming function values will be symbols.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.