Выбрать главу

Inserting text works the same way. Bookmarks point to a position in a file, not to text. If you insert a new line before the third line, the bookmark remains at the point in the file where you set it, in this case, the beginning of the new line. If you move text around, the bookmark points to the same location in the file, the line and column where you set it.

What happens if you delete a file that has a bookmark in it? If you delete the whole file or even rename it and then try to access a bookmark attached to the file, Emacs gives you the following error message:

filename nonexistent. Relocate "bookmark name"? (y or n)

If you press y, you can give a new path to the file, which works well if you really just renamed or moved the file but didn't delete it. If you press n, however, Emacs gives you a message, along with some advice:

Bookmark not relocated, consider removing it

In other words, Emacs argues that no one needs bookmarks to nonexistent files, and we're inclined to agree.

4.7.4 Working with a List of Bookmarks

Remember the buffer list we discussed earlier in this chapter? Bookmarks have a similar list with one-letter commands that allow you to work with all your bookmarks at once.

To work with a list of bookmarks, type C-x r l (the lowercase letter "L"). The *Bookmark List* buffer appears.

Type: C-x r l

Emacs displays a list of bookmarks and the path to the associated files.

If you press Enter, f, or j, Emacs displays the bookmarked file with the cursor in the bookmarked location. From the bookmark list, press d to mark bookmarks for deletion, then x to delete them (unlike in the buffer list, in the bookmark list, deleting is the only reason you need the x command). If you change your mind, press Del to remove the d before you press x. Pressing r renames a bookmark, and Emacs prompts you for the new name. To save all the bookmarks, press s. You can mark several bookmarks and then display their associated files by typing m next to the bookmarks. A > appears beside bookmarks you've marked. When you've marked all you want, type v (for view) and Emacs pulls up the files associated with the bookmarks and displays them in multiple windows (with the cursor at the bookmarked location, of course). If you just want to move to one bookmarked file, you can press v without marking the bookmark first.

You can change the display of the bookmark list slightly by pressing t. By default, the list shows a bookmark's name, followed by the complete path to the file with which it is associated. If you press t (for toggle), only the bookmark names appear.

Table 4-5 summarizes the bookmark list commands. It includes a few commands relating to annotations; we'll cover these in the next section.

Table 4-5. Commands for editing the bookmark list

Command Action
Enter, f, or j Go to the bookmark on the current line.
C-o or o Open the bookmark on the current line in another window; o moves the cursor to that window; C-o keeps the cursor in the current window.
d, C-d, or k Flag bookmark for deletion.
r Rename bookmark.
s Save all bookmarks listed.
m Mark bookmarks to be displayed in multiple windows.
v Display marked bookmarks or the one the cursor is on if none are marked.
t Toggle display of paths to files associated with bookmarks.
w In the minibuffer, display location of file associated with bookmark.
x Delete bookmarks flagged for deletion.
u Remove mark from bookmark.
Del Remove mark from bookmark on previous line or move to the previous line (if there is no mark).
q Exit bookmark list.
Space or n Move down a line.
p Move up a line.
l Load a bookmark file (other than the default).
A Display all annotations.
a Display annotation for current bookmark.
e Edit (or create) annotation for the current bookmark.

4.7.5 Annotating Bookmarks

You can add annotations to your bookmarks. These annotations can provide any type of information you want: details about the file in question, what you are doing with it, documentation for someone else on your project to review when looking at your files, or really anything you want.