BookMarks

This page is about Emacs bookmarks. Bookmarks record locations so you can return to them later.

Introduction

Emacs bookmarking makes use of three things that are related but different: a bookmark list, a bookmark file, and a bookmark-list display. Understanding these is important to using Emacs bookmarks. They are explained at Bookmark Basics.

Some bookmarking commands to get you started:

Your personal bookmark file is defined by option ‘bookmark-default-file’, which defaults to `~/.emacs.bmk’. The file is maintained automatically by Emacs as you create, change, and delete bookmarks.

(Bookmark+ makes it easy to have multiple bookmark files – different sets of bookmarks for different uses.)

`*Bookmark List*'

The bookmark list (buffer ‘*Bookmark List*’) is like Dired or BufferMenu for bookmarks. You access it using ‘C-x r l’. (Emacs sometimes calls it the “bookmark menu list”, which is a misnomer.)

Some keys in ‘*Bookmark List*’:

Info Bookmarks and Virtual Books

You can bookmark Info nodes also – just use ‘C-x r m’, as usual. Command ‘bookmark-bmenu-list’, bound to ‘C-x r l’, provides a convenient menu to access bookmarks.

Access File Bookmarks from `C-x C-f'

If you hit ‘C-x C-f’ and then realize that you want a file that is bookmarked, you can get to the bookmark this way:

 From: MatthiasMeulien Subject: Re: bookmarks and abbrevs
 Newsgroups: gnu.emacs.help Date: 17 Jun 2002 20:20:59 +0200
 (defun bookmark-to-abbrevs ()
   "Create abbrevs based on `bookmark-alist'."
   (dolist (bookmark bookmark-alist)
   (let* ((name (car bookmark))
          (file (bookmark-get-filename name)))
     (define-abbrev global-abbrev-table name file))))

I did not realize how to use this until I googled and found the original post where the poster mentioned using C-x a e (expand-abbrev) and RET on the find-file prompt. Now, if we could make find-file grok this more or less automatically too… ☺ – MathiasDahl

You can do the same thing (access a file bookmark from ‘C-x C-f’ etc.) with Icicles – just hit ‘C-x m’. See Icicles - File-Name Input. – DrewAdams

bookmark-add.el

Lisp:bookmark-add.el creates a buffer for working with bookmarks. Written by EugeneMarkov

Put Last-Selected Bookmark on Top

Using this method you’ll find frequently used bookmarks easily (cho-seiri-hou in Japanese). – rubikitch

(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)))

Org Mode as a Bookmark Manager

I like to use OrgMode and RememberMode to keep my bookmarks for me. Just visit a file/web page/email and then do ‘M-x remember’ and add the item to a bookmarks.org file. With it’s clever hierarchy handling you can keep bookmarks well organised for different projects.

Syncing Bookmarks with zsh

zsh has a feature called ‘cd-able-vars’ which is similar to bookmarks but limited to directories on the local machine. Here’s some code to convert emacs’ bookmarks into code for zsh. First add this to your .zshrc:

    setopt cd_able_vars
    [[ -r ~/.zsh.bmk ]] && source ~/.zsh.bmk

Add this to your .emacs:

    (defadvice bookmark-write-file 
      (after local-directory-bookmarks-to-zsh-advice activate)
      (local-directory-bookmarks-to-zsh))
    (defun local-directory-bookmarks-to-zsh () 
      (interactive)
      (when (and (require 'tramp nil t)
                 (require 'bookmark nil t))
        (set-buffer (find-file-noselect "~/.zsh.bmk" t t))
        (delete-region (point-min) (point-max))
        (insert "# -*- mode:sh -*-\n")
        (let (collect-names)
          (mapc (lambda (item)
                  (let ((name (replace-regexp-in-string "-" "_" (car item)))
                        (file (cdr (assoc 'filename 
                                           (if (cddr item) item (cadr item))))))
                    (when (and (not (tramp-tramp-file-p file))
                               (file-directory-p file))
                      (setq collect-names (cons (concat "~" name) collect-names))
                      (insert (format "%s=\"%s\"\n" name (expand-file-name file) name)))))
                bookmark-alist)
          (insert ": " (mapconcat 'identity collect-names " ") "\n"))
        (let ((backup-inhibited t)) (save-buffer))
        (kill-buffer (current-buffer))))

Info Bookmarks

You can bookmark Info nodes. As an alternative, you can use Info+ to create a virtual Info book and use Info to navigate its nodes. If you also use Icicles you can have any number of persistent virtual Info books.

Cycling Among Bookmarks

See Also


CategoryBookmarking CategoryHypermedia CategoryPersistence CategoryGlossary CategoryNavigation