Skip to content

The denote-templates option

The user option denote-templates is an alist of content templates for new notes. A template is arbitrary text that Denote will add to a newly created note right below the front matter.

Templates are expressed as a ‘(KEY . VALUE)’ association.

  • The ‘KEY’ is the name which identifies the template. It is an arbitrary symbol, such as ‘report’, ‘memo’, ‘statement’.

  • The ‘VALUE’ is either a string or the symbol of a function.

    • If it is a string, it is ordinary text that Denote will insert as-is. It can contain newline characters to add spacing. The manual of Denote contains examples on how to use the concat function, beside writing a generic string.
    • If it is a function, it is called without arguments and is expected to return a string. Denote will call the function and insert the result in the buffer.

The user can choose a template either by invoking the command denote-template or by changing the user option denote-prompts to always prompt for a template when calling the denote command.

The denote-prompts option.

Convenience commands for note creation.

Templates can be written directly as one large string. For example (the ‘\n’ character is read as a newline):

emacs-lisp
(setq denote-templates
      '((report . "* Some heading\n\n* Another heading")
        (memo . "* Some heading

* Another heading

")))

Long strings may be easier to type but interpret indentation literally. Also, they do not scale well. A better way is to use some Elisp code to construct the string. This would typically be the concat function, which joins multiple strings into one. The following is the same as the previous example:

emacs-lisp
(setq denote-templates
      `((report . "* Some heading\n\n* Another heading")
        (memo . ,(concat "* Some heading"
                         "\n\n"
                         "* Another heading"
                         "\n\n"))))

Notice that to evaluate a function inside of an alist we use the backtick to quote the alist (NOT the straight quote) and then prepend a comma to the expression that should be evaluated. The concat form here is not sensitive to indentation, so it is easier to adjust for legibility.

For when the ‘VALUE’ is a function, we have this:

emacs-lisp
(setq denote-templates
      `((report . "* Some heading\n\n* Another heading")
        (blog . my-denote-template-function-for-blog) ; a function to return a string
        (memo . ,(concat "* Some heading"
                         "\n\n"
                         "* Another heading"
                         "\n\n"))))

In this example, my-denote-template-function-for-blog is a function that returns a string. Denote will take care to insert it in the buffer.

DEV NOTE: We do not provide more examples at this point, though feel welcome to ask for help if the information provided herein is not sufficient. We shall expand the manual accordingly.