Rebookmark in Emacs

When working on a file from start to finish over a lifetime in Emacs, for example as in translating a lengthy text, it is good to keep the file bookmarked at the end of every day, because Emacs’ bookmarks save the cursor location. This way, whenever opening the file from bookmarks again to continue with it, it opens where it had been left off.

A working result (works if the file was opened via bookmarks):

(defun rebookmark ()
    "If a bookmark is set in the current file, set it again."
    (interactive)
    (when bookmark-current-bookmark
      (bookmark-set bookmark-current-bookmark)))
  (add-hook 'before-save-hook 'rebookmark)

The workflow idea for this code is:

  1. When saving (e.g. by default keybind C-x C-s), automatically check if the current file is already bookmarked.
  2. If the current file is indeed bookmarked, bookmark it again, which automatically saves the cursor at new location so the work is convenient to pick up again next day.

Leave a Reply

Your email address will not be published. Required fields are marked *