Using Denote with Subdirectories
2022-12-08 #emacs #org-mode #pkm
My last post mentioned the out-of-the-box experience of Denote is not so great, especially when having notes across many subdirectories. By default, Denote searches and creates notes from the root
denote-directory. I need to know the exact file location before searching for a note. I need to move note from the root directory to subdirectories after creating the note.
The good news is that, these issues are now fixed and this post talks about how.
#1 Search by Filename in Subdirectories
By default, Denote searches only in the
denote-directory. To find a note hidden inside a subdirectory, the user needs to know the path to that file and navigate there. Needing to know the exact directory to be able to search for a file is counter-intuitive.
However, thanks to a recent (2022-11-18) refactoring by nobiot@, it is no longer the case! The commit makes notes inside subdirectories searchable with common Denote commands like
denote-link-*. This greatly improves the out-of-the-box experience of Denote. Update Denote to a newer version including this new change!
#2 Full-Text Search in Subdirectories
By default, Denote does not come with any command for full-text search.
However, it could be done easily with
(defun consult-denote-ripgrep () "Search with ‘rg’ for files in denote-directory where the content matches a regexp." (interactive) (consult-ripgrep denote-directory ""))
#3 Create Notes in Subdirectories
By default, Denote creates notes in the root
denote-directory. Every time after creating a note, I need to move them manually to the right subdirectory. This is cumbersome.
However, it turned out to be my fault of not reading the official documentation, which has already suggested two ways to select a specific directory when creating a new note:
I go with (1) because it works with all Denote commands that could create a note, like
denote-link-or-create. It also allows other customizations to
denote-prompts. For example, I prefer setting “subdirectory” before “title” (reorder
subdirectory) and updating keyword later with
(setq denote-prompts '(subdirectory title))
If you have too much subdirectories, use
denote-excluded-directories-regexp to exclude some of them.
Comparing with Org-roam Again
With these tweaks, I can now use Denote as my primary note-taking package.
I mentioned a concern with the link type
denote: in my last post. It turns out to be not concerning because it is easy to migrate to or away from this link type with some elisp. I don’t use other features like org-roam-daily, org-roam-bibtex, or org-roam-ui at all. The last step before removing Org-roam is probably migrating the existing links.