Skip to content

Create note with specific prompts using Org capture

This section assumes knowledge of how Denote+org-capture work, as explained in the previous section (Create note using Org capture).

The previous section shows how to define an Org capture template that always prompts for whatever is set in the user option denote-prompts (title and keywords, by default). There are, however, cases where the user wants more control over what kind of input Denote will prompt for. To this end, we provide the function denote-org-capture-with-prompts. Below we explain it and then show some examples of how to use it.

The denote-org-capture-with-prompts is like denote-org-capture but with optional prompt parameters.

When called without arguments, it does not prompt for anything. It just returns the front matter with title and keyword fields empty and the date and identifier fields specified. It also makes the file name consist of only the identifier plus the Org file name extension (The file-naming scheme).

Otherwise, it produces a minibuffer prompt for every non-nil value that corresponds to the ‘TITLE’, ‘KEYWORDS’, ‘SUBDIRECTORY’, ‘DATE’, ‘TEMPLATE’, and ‘SIGNATURE’ arguments. The prompts are those used by the standard denote command and all of its utility commands (Points of entry).

When returning the contents that fill in the Org capture template, the sequence is as follows: front matter, ‘TEMPLATE’, and then the value of the user option denote-org-capture-specifiers.

Important note: in the case of ‘SUBDIRECTORY’ actual subdirectories must exist—Denote does not create them. Same principle for ‘TEMPLATE’ as templates must exist and are specified in the user option denote-templates.

This is how one can incorporate denote-org-capture-with-prompts in their Org capture templates. Instead of passing a generic t which makes it hard to remember what the argument means, we use semantic keywords like ‘:title’ for our convenience (internally this does not matter as the value still counts as non-nil, so ‘:foo’ for ‘TITLE’ is treated the same as ‘:title’ or t).

emacs-lisp
;; This prompts for TITLE, KEYWORDS, and SUBDIRECTORY
(add-to-list 'org-capture-templates
             '("N" "New note with prompts (with denote.el)" plain
               (file denote-last-path)
               (function
                (lambda ()
                  (denote-org-capture-with-prompts :title :keywords :subdirectory)))
               :no-save t
               :immediate-finish nil
               :kill-buffer t
               :jump-to-captured t))

;; This prompts only for SUBDIRECTORY
(add-to-list 'org-capture-templates
             '("N" "New note with prompts (with denote.el)" plain
               (file denote-last-path)
               (function
                (lambda ()
                  (denote-org-capture-with-prompts nil nil :subdirectory)))
               :no-save t
               :immediate-finish nil
               :kill-buffer t
               :jump-to-captured t))

;; This prompts for TITLE and SUBDIRECTORY
(add-to-list 'org-capture-templates
             '("N" "New note with prompts (with denote.el)" plain
               (file denote-last-path)
               (function
                (lambda ()
                  (denote-org-capture-with-prompts :title nil :subdirectory)))
               :no-save t
               :immediate-finish nil
               :kill-buffer t
               :jump-to-captured t))

[ You may not need org-capture to do what you want (Write your own convenience commands). ]