Emacs bookmarks are used to keep track of where you read in a file. It’s kind of like a register, just like a register, because it can also record positions. There are two differences with register: 1. It has a longer name; 2. 2. When Emacs is off, it will persist to disk automatically.
Set up a bookmark
When we read a long document and don’t finish it all in one sitting. We want to remember where the current document was last read so we can quickly locate it the next time we use Emacs to read it. So, let’s set up a bookmark with the bookmark-set shortcut c-x r M
Lists the bookmarks saved
Bookmark-bmenu-list corresponds to c-x r L, which opens a * bookmark list * buffer and lists all saved bookmarks.
Bookmark List*
In the *Bookmark List* buffer, there are the following shortcuts to use:
- A Displays the annotation information of the current bookmark;
- A Displays all the annotation information of all bookmarks in the other buffer;
- D marks bookmarks for deletion (x – perform deletion);
- E Edit the annotation information of the current bookmark.
- M marks bookmarks for further display and other operations (v – access this bookmark);
- O Select the current bookmark and display it in another window;
- C-o switches to the current bookmark in another window;
- R Renames the current bookmark;
- W displays the current bookmark position in the minibuffer.
Jump to a bookmark
Use the bookmark-jump function to jump to a particular bookmark, which is bound to a shortcut key c-x r b. If you have helm installed in your Emacs, you can also use helm-bookmarks to quickly find and jump to bookmarks.
helm-bookmarks
Use the helm-bookmarks command to find and jump bookmarks as shown below:
Bookmark find and jump
Changing the Default Sort
The default bookmarks sorting is alphabetical for bookmarks lookup and jump. If you want to put recently accessed bookmarks first, add the following code to your Emacs profile.
(defadvice bookmark-jump (after bookmark-jump activate)
(let ((latest (bookmark-get-bookmark bookmark)))
(setq bookmark-alist (delq latest bookmark-alist))
(add-to-list 'bookmark-alist latest)))Copy the code
Delete a bookmark
The command for deleting a bookmark is bookmark-delete.
Save the bookmark
The latest version of Emacs (old bookmarks are saved in ~/.emacs.bmk) will save bookmarks automatically upon exit. If you want to save your bookmarks manually, you can use the bookmark-save function. By default, Emacs saves bookmarks in the file corresponding to the bookmark-default-file variable. On my machine, the corresponding file is as follows:
ELISP> bookmark-default-file
"/Users/aborn/.emacs.d/.cache/bookmarks"
ELISP>Copy the code
Other Settings
There is a variable bookmark-save-flag. If the value of this variable is a number, it indicates how many times a bookmark has been modified (or added) before Emacs automatically saves the bookmark to disk. When this variable is set to 1, Emacs automatically saves the contents to the appropriate location on disk every time the bookmark is changed (this prevents the loss of the Bookmark if Emacs crashes). If this value is set to nil, emacs will not actively save the bookmark unless the user manually calls M-x bookmark-save.
bookmark+
Bookmark + is an extension to Bookmark. It has more features:
- The original bookmark can only record file locations, and Bookmark + can save bookmarks for isolated buffers (buffers with no associated files).
- Support bookmarks to tag;
- Save an area of the document as a bookmark, not just a location;
- Records the number of visits to each bookmark, and the last visit time, can be sorted based on them;
- [Fixed] Multiple bookmarks can have the same name
- You can bookmark functions, variables, and so on.
More features refer to: www.emacswiki.org/emacs/Bookm…