I tend to organise my notes into files related to a specific topic or project, so I find org-mode with org-capture very useful to add quick notes to a specific file, like adding a TODO item or an idea for a blog post (I will post lots more about org-mode in due course, but there is an overview on my tutorial page). However, if I want to make a more general note that doesn’t fit into a category (say notes from a meeting), then deft is a nice alternative.
This post is a short introduction to deft, and I will describe some tweaks I have made in subsequent posts.
Deft is an emacs package (available through package-list-packages
) that lets you quickly create, search and add to files containing notes. It is inspired by the Mac programme Notational Velocity.
My use case is that I launch deft, start typing a search string to very quickly find the file I want to add notes to, or create a new file on the fly, and then add my notes, quit deft and be back to where I was before.
Deft works simply by having all of your note files in a single directory, and the files themselves are simple text (org-mode if you like) files that can be viewed and edited anywhere else as well as via deft. Deft is really just a nice quick interface for finding/creating and opening the right file for editing.
To use deft, launch it with M-x deft
and you will see a list of the files in your deft directory with short summaries. Start typing a search string and the list will dynamically filter down to files that match the string in their file name or body text. Use arrow keys to move up and down through the list of files and hit return to open that file for editing.
If no files match the search string then hitting enter creates a new file with a name taken from the search string. If you want to create a new file with a specific name, use C-c C-n
.
You can also rename C-c C-r
and delete C-c C-d
files from the deft buffer.
Use C-c C-q
to quit deft.
This is best illustrated with a couple of examples. In the first example I launch deft and type a search string to find an existing file and then open that file for editing. In this case I am looking for the file about an open day in 2014.
In the second example I launch deft and type a search string that doesn’t match any files and so create a new file with a name based on the search string. In this case, my search string “open day 2015” doesn’t match anything so deft creates a new file for me.
Once you have installed deft, add the following to your emacs config file to get the behaviour described above
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; deft ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'deft)
(setq deft-directory "~/docs/deft")
(setq deft-extensions '("org"))
(setq deft-default-extension "org")
(setq deft-text-mode 'org-mode)
(setq deft-use-filename-as-title t)
(setq deft-use-filter-string-for-filename t)
(setq deft-auto-save-interval 0)
;;key to launch deft
(global-set-key (kbd "C-c d") 'deft)
With this setup, my deft files are all stored in ~/docs/deft/
and have .org
file extensions, and deft will open them for editing in org-mode.
The option (setq deft-use-filename-as-title t)
tells deft to use the search string to generate the filename for a new file if the string does not match an existing file.
Those are the basics of deft, but stay tuned for some tweaks that (for me at least) make the experience even smoother.
Update
An update to deft introduced a new way to tell deft to use the filter to create the filename
(setq deft-use-filter-string-for-filename t)
I have added that to the deft setup code above. This solves an issue raised in the comments below.