**This page has moved to http://jonathanchu.is/posts/setting-up-deft-mode-in-emacs-with-org-mode/. You will be redirected there shortly.



Setting Up Deft Mode in Emacs with Org-Mode

I've been a big fan of Notational Velocity for quite a few years now - and more recently, nValt which is a popular fork of Notational Velocity, but with a bit more features. Everyone has their own process when it comes to taking notes, and to each his own, but the one thing that really turned me on to Notational Velocity/nValt is the simplicity and unstructured process of taking and searching for notes. Coupled with Dropbox for seamless syncing, you have yourself a great note taking process that was easy to use and even easier to search. As for mobile, I used Simplenote to view my notes via Dropbox, and it made taking notes during programming meetups or business meetings even easier. Life is good!

However, over the past year, as I found myself coding more and more in my text editor of choice, Emacs - the more I found myself wanting something that didn't seem so disconnected from where I do most of my prose and coding. After a quick search, I found Jason Blevins' great little creation called Deft. To sum it up, Deft is an open source mode for Emacs to view, record, and search for notes in plain text, very much like Notational Velocity/nValt. I highly encourage you to check out Jason's project page for Deft. After trying out Deft, it made me want to switch 100% over to org-mode notes as I really only used org-mode for sporadic notes. Now, I have the power of org-mode with Emacs in a Notational Velocity-like buffer with Deft. The rest of the article will be outlining how I set it up in my Emacs config.

Setting up Deft

First, go grab deft.el and make sure it is available in your Emacs config (i.e. - ~/.emacs/vendor/deft.el path). You can grab it here or get it directly from my Emacs config, which is the original unmodified file.

Once deft.el is on your Emacs load path, you'll need to tell Emacs to use Deft. Put the following anywhere in your config (I like to keep modes separated in it's own modes.el file that gets loaded on initialization):

(require 'deft)

Since I use Org-Mode, I want *.org files to be recognized by the Deft buffer, so let's set the deft-extension to "org". I believe the default file type that Deft will look for is "txt", so omit this part or add in "txt" if you want to use plain text files.

(setq deft-extension "org")

And again, since I'm using org-mode with Deft, let's set the deft-text-mode appropriately to use org-mode:

(setq deft-text-mode 'org-mode)

Next, we need to tell Deft where to find all of my current org-mode files. In my case, I like to keep all my org-mode files in Dropbox, so that path would be ~/Dropbox/org for me. You should change this path to wherever you keep your files.

(setq deft-directory "~/Dropbox/org")

Finally, the last bit of customization is to tell Deft to use the filename as a title. By default, Deft will use the first line of the file as the filename. In my note taking preference, I normally don't lead off a note with the title of the file (it's usually a date like "2013-08-15" if it's a meeting), so I switched on the trigger for this:

(setq deft-use-filename-as-title t)

Putting it all together, and you have this in its entirety:

;; deft
(require 'deft)
(setq deft-extension "org")
(setq deft-directory "~/Dropbox/org")
(setq deft-text-mode 'org-mode)
(setq deft-use-filename-as-title t)

Using Deft

To enter the Deft buffer, simply do:

m-x deft ENTER

And you should see the Deft buffer like so, with all of your org-files (yes, I know - nothing is blurred out...I got nothing to hide :P ):

Deft buffer screenshot

Start typing and you'll see the list of notes filter out the results that do not match, just like Notational Velocity. Hit ENTER to open the note in a new buffer.

Deft filter screenshot

And there you have it! Much appreciation and thanks goes to Jason Blevins for this awesome mode that has effectively streamlined my coding and note-taking all in Emacs!