Bookmarks are one of those features that I have used, but have been on my list to learn more about. This week I decided to bump it off my list and pass along my notes. There are a number of different packages that can be used for bookmarking. I will discuss three.
This package is part of the core emacs distribution. From the emacs info,
“Bookmarks” are somewhat like registers in that they record positions you can jump to. Unlike registers, they have long names, and they persist automatically from one Emacs session to the next. The prototypical use of bookmarks is to record “where you were reading” in various files.
Bookmarks are analogous to a web browsers bookmarking facility, although I think emacs bookmarks came first. Some of the useful commands to know are (yes, options also exist under the Edit menu, but why would you want to use that):
C-x r m– set a bookmark inside a file
C-x r b– jump to a bookmark (see also GraphicalBookmarkJump)
C-x r l– list all of your bookmarks
M-x bookmark-delete– delete a bookmark by name
The bookmark tool has the ability to store annotations about the bookmarked location. Additionally, there is a great wealth of information on bookmarks and bookmark customizations on the wiki. Two of the customizations that I have tried allow for iterating through your bookmarks and for utilizing iswitchb for jumping to a bookmark.
bm.el provides a visible, buffer local bookmark, and the ability to jump forward and backward between the bookmarks. The author’s reason for creating this package was:
I missed the bookmarks from M$ Visual Studio in GNU Emacs. I think they provide an easy way to navigate in a buffer.
This package supports persistent bookmarks (both across buffer kills and emacs sessions), annotations, and viewing a list of bookmarks for the current buffer. A snippet from my .emacs file is below. My settings are based on the description provided within the package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(setq bm-restore-repository-on-load t) (require 'bm) (global-set-key (kbd "<M-f2>") 'bm-toggle) (global-set-key (kbd "<f2>") 'bm-next) (global-set-key (kbd "<S-f2>") 'bm-previous) ;; make bookmarks persistent as default (setq-default bm-buffer-persistence t) ;; Loading the repository from file when on start up. (add-hook' after-init-hook 'bm-repository-load) ;; Restoring bookmarks when on file find. (add-hook 'find-file-hooks 'bm-buffer-restore) ;; Saving bookmark data on killing a buffer (add-hook 'kill-buffer-hook 'bm-buffer-save) ;; Saving the repository to file when on exit. ;; kill-buffer-hook is not called when emacs is killed, so we ;; must save all bookmarks first. (add-hook 'kill-emacs-hook '(lambda nil (bm-buffer-save-all) (bm-repository-save)))
linemark.el comes with the eieio (Enhanced Implementation of Emacs Interpreted Objects). Bookmarks are remembered when a buffer is killed, and are restored when you return to that buffer later. Although the marks are not remembered between emacs sessions. Assuming cedet is installed correctly, then the following snippet enables linemark functionality and binds it to the F2 key in the following way.
viss-bookmark-toggle – Toggle a bookmark on this line (bound to
viss-bookmark-next-buffer – Move to the next bookmark (bound to
viss-bookmark-prev-buffer – Move to the previous bookmark (bound to
viss-bookmark-clear-all-buffer – Clear all bookmarks (bound to
(load-library "linemark") (enable-visual-studio-bookmarks)
The site notes that visual studio bookmarks are an example usage of the linemark package.
The reason this tool is useful is because cross-emacs overlay management can be a pain, and overlays are certainly needed for use with font-lock.
I see myself using the functionality of bm.el on a more frequent basis. Many days I am working on large code files, and I need to jump around between 3 or 4 locations. I think marking these locations using bm.el is more consistent with the way I work. I like the buffer local nature of the bookmarks in bm.el as compared to the bookmarks that come with emacs. I like the idea that I only need to iterate over the bookmarks for the current file, and not all bookmarks. My reason for choosing bm.el over linemark.el is that it has more functionality than the visual studio style bookmarks in linemark.el. bm.el supports persisting bookmarks across sessions and also supports annotating bookmarks.