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 buffer, set it again.
Works only if the buffer was opened via bookmarks."
(interactive)
(when bookmark-current-bookmark
(bookmark-set bookmark-current-bookmark)))
(add-hook 'before-save-hook 'rebookmark)
The workflow idea for this code is:
- When saving (e.g. by default keybind
C-x C-s
), automatically check if the current file is already bookmarked. - 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.