Ads by Google

Saturday, June 16, 2012

Bookmarking in Emacs

This little feature in Emacs should be among the first things you should learn when you're trying out Emacs.

The thing is, you have to consciously keep at it for sometime before you start using it in a fashion that suits your workflow. In fact, I didn't use bookmarks at all for quite a few years; doing the same C-x d, scrolling to a folder, repeat scrolling till I reached my usual nested directory.  If you're doing something repetitively, it's a good bet to check out the manual about it or ask in the Emacs mailing list, someone's been through your pain before.

Anyways, if you want to bookmark a location(think man, info pages, specific directories), hit C-x r m and it will prompt you for a name.  Give one and you're set. C-x r b will give a promptable(tab completable) list that you type in to jump to the specific directory or file location.  The bookmarks can be saved for the next sessions by issuing a M-x bookmark-save.

That's all there is to it and you'll soon find it nifty when you're working on a coding project with large number of folders and files. People get lost in the humongous manual and this is the quickest way to get back to where you were when trying out things in the scratch buffer.

This thread might be useful for some and there are some improvements to it which can be found in the Emacswiki bookmarks link.


Anonymous said...

I wrote some elisp to do that!


Anonymous said...

Errors with "Buffer not visiting a file or directory" when I try to set a bookmark inside a man page.

Anonymous said...

You can get automatic bookmarking of all your visited files with ido:

'(ido-use-virtual-buffers t)

if you want automatic bookmarking for folders you visit, add:

(defun recentf-track-dired-buffers ()
"I want the dired buffers to be tracked by recentf"
(let ((cur-dir-no-slash (substring ; removes trailing slash
(expand-file-name default-directory)
0 -1)))
(when (file-directory-p cur-dir-no-slash) ;; just in case :-)
(recentf-add-file cur-dir-no-slash))))

(add-hook 'dired-mode-hook 'recentf-track-dired-buffers t)