: Learning GNU Emacs, 3rd Edition

4.7.3 Renaming and Deleting Bookmarks

4.7.3 Renaming and Deleting Bookmarks

You may find that you made the name of your bookmark too generic; current project may be too vague if you are juggling projects and the one in your hand is the current one. To rename a bookmark, type M-x bookmark-rename. If you do the renaming from the keyboard, Emacs prompts Old bookmark name: and you type the old name and press Enter. (If you use the menus, you select the old name from a window instead.) Then Emacs asks, New name: and you type the new name and press Enter, all very straightforwardly. Renaming a bookmark does just that and nothing else: it doesn't change the bookmark's location or its contents; it simply changes its name.

To delete a bookmark, press M-x bookmark-delete. Type the name of the bookmark to delete or select it with the mouse. Deleting a bookmark doesn't in any way affect the file that was marked.

This discussion brings up an interesting question. What happens if you delete text in a file in which you've put a bookmark? Because a bookmark points to a position in a file and not to a piece of text, the bookmark stays in the same place after the text is deleted, just as the cursor remains in the same place after you delete several paragraphs. This fact is more intuitive than it sounds. You don't delete bookmarks by deleting marked text. Let's say you have a file with four lines. You bookmark the third line, then later delete lines two through four. When you jump to that bookmark again, it appears after the first line, the end of the file.

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.


: 0.312. /Cache: 3 / 1