#+title: denote: Simple notes with an efficient file-naming scheme
#+author: Protesilaos Stavrou
#+email: info@protesilaos.com
#+language: en
#+options: ':t toc:nil author:t email:t num:t
#+startup: content
#+macro: stable-version 3.0.0
#+macro: release-date 2024-06-30
#+macro: development-version 3.1.0-dev
#+export_file_name: denote.texi
#+texinfo_filename: denote.info
#+texinfo_dir_category: Emacs misc features
#+texinfo_dir_title: Denote: (denote)
#+texinfo_dir_desc: Simple notes with an efficient file-naming scheme
#+texinfo_header: @set MAINTAINERSITE @uref{https://protesilaos.com,maintainer webpage}
#+texinfo_header: @set MAINTAINER Protesilaos Stavrou
#+texinfo_header: @set MAINTAINEREMAIL @email{info@protesilaos.com}
#+texinfo_header: @set MAINTAINERCONTACT @uref{mailto:info@protesilaos.com,contact the maintainer}

#+texinfo: @insertcopying

This manual, written by Protesilaos Stavrou, describes the customization
options for the Emacs package called ~denote~ (or =denote.el=), and
provides every other piece of information pertinent to it.

The documentation furnished herein corresponds to stable version
{{{stable-version}}}, released on {{{release-date}}}.  Any reference to
a newer feature which does not yet form part of the latest tagged
commit, is explicitly marked as such.

Current development target is {{{development-version}}}.

+ Package name (GNU ELPA): ~denote~
+ Official manual: <https://protesilaos.com/emacs/denote>
+ Change log: <https://protesilaos.com/emacs/denote-changelog>
+ Git repositories:
  + GitHub: <https://github.com/protesilaos/denote>
  + GitLab: <https://gitlab.com/protesilaos/denote>
+ Video demo: <https://protesilaos.com/codelog/2022-06-18-denote-demo/>
+ Backronyms: Denote Everything Neatly; Omit The Excesses.  Don't Ever
  Note Only The Epiphenomenal.

If you are viewing the README.org version of this file, please note that
the GNU ELPA machinery automatically generates an Info manual out of it.

#+toc: headlines 8 insert TOC here, with eight headline levels

* COPYING
:PROPERTIES:
:COPYING: t
:CUSTOM_ID: h:40b18bb2-4dc1-4202-bd0b-6fab535b2a0f
:END:

Copyright (C) 2022-2024  Free Software Foundation, Inc.

#+begin_quote
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and
with the Back-Cover Texts as in (a) below.  A copy of the license is
included in the section entitled “GNU Free Documentation License.”

(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
modify this GNU manual.”
#+end_quote

* Overview
:PROPERTIES:
:CUSTOM_ID: h:a09b70a2-ae0b-4855-ac14-1dddfc8e3241
:END:

Denote aims to be a simple-to-use, focused-in-scope, and effective
note-taking and file-naming tool for Emacs.

Denote is based on the idea that files should follow a predictable and
descriptive file-naming scheme.  The file name must offer a clear
indication of what the contents are about, without reference to any
other metadata.  Denote basically streamlines the creation of such
files or file names while providing facilities to link between them
(where those files are editable).

Denote's file-naming scheme is not limited to "notes".  It can be used
for all types of file, including those that are not editable in Emacs,
such as videos.  Naming files in a consistent way makes their
filtering and retrieval considerably easier.  Denote provides relevant
facilities to rename files, regardless of file type.

Denote is based on the following core design principles:

+ Predictability :: File names must follow a consistent and descriptive
  naming convention ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).  The file name alone
  should offer a clear indication of what the contents are, without
  reference to any other metadatum.  This convention is not specific to
  note-taking, as it is pertinent to any form of file that is part of
  the user's long-term storage ([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]).

+ Composability :: Be a good Emacs citizen, by integrating with other
  packages or built-in functionality instead of re-inventing functions
  such as for filtering or greping.  The author of Denote (Protesilaos,
  aka "Prot") writes ordinary notes in plain text (=.txt=), switching on
  demand to an Org file only when its expanded set of functionality is
  required for the task at hand ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).

+ Portability :: Notes are plain text and should remain portable.  The
  way Denote writes file names, the front matter it includes in the
  note's header, and the links it establishes must all be adequately
  usable with standard Unix tools.  No need for a database or some
  specialised software.  As Denote develops and this manual is fully
  fleshed out, there will be concrete examples on how to do the
  Denote-equivalent on the command-line.

+ Flexibility :: Do not assume the user's preference for a note-taking
  methodology.  Denote is conceptually similar to the Zettelkasten
  Method, which you can learn more about in this detailed introduction:
  <https://zettelkasten.de/introduction/>.  Notes are atomic (one file
  per note) and have a unique identifier.  However, Denote does not
  enforce a particular methodology for knowledge management, such as a
  restricted vocabulary or mutually exclusive sets of keywords.  Denote
  also does not check if the user writes thematically atomic notes.  It
  is up to the user to apply the requisite rigor and/or creativity in
  pursuit of their preferred workflow ([[#h:6060a7e6-f179-4d42-a9de-a9968aaebecc][Writing metanotes]]).

+ Hackability :: Denote's code base consists of small and reusable
  functions.  They all have documentation strings.  The idea is to make
  it easier for users of varying levels of expertise to understand what
  is going on and make surgical interventions where necessary (e.g. to
  tweak some formatting).  In this manual, we provide concrete examples
  on such user-level configurations ([[#h:4a6d92dd-19eb-4fcc-a7b5-05ce04da3a92][Keep a journal or diary]]).

Now the important part...  "Denote" is the familiar word, though it also
is a play on the "note" concept.  Plus, we can come up with acronyms,
recursive or otherwise, of increasingly dubious utility like:

+ Don't Ever Note Only The Epiphenomenal
+ Denote Everything Neatly; Omit The Excesses

But we'll let you get back to work.  Don't Eschew or Neglect your
Obligations, Tasks, and Engagements.

* Points of entry
:PROPERTIES:
:CUSTOM_ID: h:17896c8c-d97a-4faa-abf6-31df99746ca6
:END:

#+findex: denote
#+findex: denote-type
#+findex: denote-org-capture
#+findex: denote-date
#+findex: denote-subdirectory
#+findex: denote-template
#+findex: denote-signature
There are five main ways to write a note with Denote: invoke the
~denote~, ~denote-type~, ~denote-date~, ~denote-subdirectory~,
~denote-template~, ~denote-signature~ commands, or leverage the
~org-capture-templates~ by setting up a template which calls the
function ~denote-org-capture~.  We explain all of those in the
subsequent sections.  Other more specialised commands exist as well,
which one shall learn about as they read through this manual.  We do
not want to overwhelm the user with options at this stage.

All these commands constructs the file name in accordance with the user option
~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

** Standard note creation
:PROPERTIES:
:CUSTOM_ID: h:6a92a8b5-d766-42cc-8e5b-8dc255466a23
:END:

The ~denote~ command will prompt for a title.  If a region is active,
the text of the region becomes the default at the minibuffer prompt
(meaning that typing =RET= without any input will use the default
value).  Once the title is supplied, the ~denote~ command will then ask
for keywords.  The resulting note will have a file name as already
explained: [[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file naming scheme]]

#+vindex: denote-after-new-note-hook
The ~denote~ command runs the hook ~denote-after-new-note-hook~ after
creating the new note.

The file type of the new note is determined by the user option
~denote-file-type~ ([[#h:13218826-56a5-482a-9b91-5b6de4f14261][Front matter]]).

#+vindex: denote-known-keywords
#+vindex: denote-infer-keywords
The keywords' prompt supports minibuffer completion.  Available
candidates are those defined in the user option ~denote-known-keywords~.
More candidates can be inferred from the names of existing notes, by
setting ~denote-infer-keywords~ to non-nil (which is the case by
default).

#+vindex: denote-sort-keywords
Multiple keywords can be inserted by separating them with a comma (or
whatever the value of the ~crm-separator~ is---which should be a comma).
When the user option ~denote-sort-keywords~ is non-nil (the default),
keywords are sorted alphabetically (technically, the sorting is done
with ~string-lessp~).

The interactive behaviour of the ~denote~ command is influenced by the
user option ~denote-prompts~ ([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The denote-prompts option]]).

The ~denote~ command can also be called from Lisp.  Read its doc string
for the technicalities.

#+findex: denote-create-note
In the interest of discoverability, ~denote~ is also available under the
alias ~denote-create-note~.

*** The ~denote-prompts~ option
:PROPERTIES:
:CUSTOM_ID: h:f9204f1f-fcee-49b1-8081-16a08a338099
:END:

#+vindex: denote-prompts
The user option ~denote-prompts~ determines how the ~denote~ command
will behave interactively ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).

Commands that prompt for user input to construct a Denote file name
include, but are not limited to: ~denote~, ~denote-signature~,
~denote-type~, ~denote-date~, ~denote-subdirectory~,
~denote-rename-file~, ~denote-dired-rename-files~.

- [[#h:887bdced-9686-4e80-906f-789e407f2e8f][Convenience commands for note creation]].
- [[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]].

The value of this user option is a list of symbols, which includes any
of the following:

- =title=: Prompt for the title of the new note ([[#h:403422a7-7578-494b-8f33-813874c12da3][The ~denote-history-completion-in-prompts~ option]]).

- =keywords=: Prompts with completion for the keywords of the new note.
  Available candidates are those specified in the user option
  ~denote-known-keywords~.  If the user option ~denote-infer-keywords~
  is non-nil, keywords in existing note file names are included in the
  list of candidates.  The =keywords= prompt uses
  ~completing-read-multiple~, meaning that it can accept multiple
  keywords separated by a comma (or whatever the value of ~crm-separator~
  is).

- =file-type=: Prompts with completion for the file type of the new
  note.  Available candidates are those specified in the user option
  ~denote-file-type~.  Without this prompt, ~denote~ uses the value of
  ~denote-file-type~.

- =subdirectory=: Prompts with completion for a subdirectory in which to
  create the note.  Available candidates are the value of the user
  option ~denote-directory~ and all of its subdirectories.  Any
  subdirectory must already exist: Denote will not create it.

- =date=: Prompts for the date of the new note.  It will expect an input
  like 2022-06-16 or a date plus time: 2022-06-16 14:30.  Without the
  =date= prompt, the ~denote~ command uses the ~current-time~.

  [[#h:e7ef08d6-af1b-4ab3-bb00-494a653e6d63][The denote-date-prompt-use-org-read-date option]].

- =template=: Prompts for a KEY among the ~denote-templates~.  The value
  of that KEY is used to populate the new note with content, which is
  added after the front matter ([[#h:f635a490-d29e-4608-9372-7bd13b34d56c][The denote-templates option]]).

- =signature=: - Prompts for an arbitrary string that can be used to
  establish a sequential relationship between files (e.g. 1, 1a, 1b,
  1b1, 1b2, ...).  Signatures have no strictly defined function and
  are up to the user to apply as they see fit.  One use-case is to
  implement Niklas Luhmann's Zettelkasten system for a sequence of
  notes (Folgezettel).  Signatures are not included in a file's front
  matter.  They are reserved solely for creating a sequence in a file
  listing, at least for the time being.  To insert a link that
  includes the signature, use the command ~denote-link-with-signature~
  ([[#h:066e5221-9844-474b-8858-398398646f86][Insert link to file with signature]]).

The prompts occur in the given order.

If the value of this user option is nil, no prompts are used.  The
resulting file name will consist of an identifier (i.e. the date and
time) and a supported file type extension (per ~denote-file-type~).

Recall that Denote's standard file-naming scheme is defined as follows
([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]):

: DATE--TITLE__KEYWORDS.EXT

If either or both of the =title= and =keywords= prompts are not
included in the value of this variable, file names will be any of
those permutations:

: DATE.EXT
: DATE--TITLE.EXT
: DATE__KEYWORDS.EXT

When in doubt, always include the =title= and =keywords= prompts.

Finally, this user option only affects the interactive use of the
~denote~ or other relevant commands (advanced users can call it from
Lisp). In Lisp usage, the behaviour is always what the caller
specifies, based on the supplied arguments.

*** The ~denote-history-completion-in-prompts~ option
:PROPERTIES:
:CUSTOM_ID: h:403422a7-7578-494b-8f33-813874c12da3
:END:

#+vindex: denote-history-completion-in-prompts
The user option ~denote-history-completion-in-prompts~ toggles history
completion in all ~denote-prompts-with-history-as-completion~.

When this user option is set to a non-nil value, Denote will use
minibuffer history entries as completion candidates in all of the
~denote-prompts-with-history-as-completion~. Those will show previous
inputs from their respective history as possible values to select,
either to (i) re-insert them verbatim or (ii) with the intent to edit
them further (depending on the minibuffer user interface, one can
select a candidate with =TAB= without exiting the minibuffer, as
opposed to what =RET= normally does by selecting and exiting).

When this user option is set to a nil value, all of the
~denote-prompts-with-history-as-completion~ will not use minibuffer
completion: they will just prompt for a string of characters. Their
history is still available through all the standard ways of retrieving
minibuffer history, such as with the command ~previous-history-element~.

History completion still allows arbitrary values to be provided as
input: they do not have to match the available minibuffer completion
candidates.

Note that some prompts, like ~denote-keywords-prompt~, always use
minibuffer completion, due to the specifics of their data.

[ Consider enabling the built-in ~savehist-mode~ to persist minibuffer
  histories between sessions.]

*** The ~denote-templates~ option
:PROPERTIES:
:CUSTOM_ID: h:f635a490-d29e-4608-9372-7bd13b34d56c
:END:

[ Updated as part of {{{development-version}}} to accept a function
  that returns a string. This is in addition to accepting a string. ]

#+vindex: denote-templates
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.

[[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The denote-prompts option]].

[[#h:887bdced-9686-4e80-906f-789e407f2e8f][Convenience commands for note creation]].

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

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

,* Another heading

")))
#+end_src

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:

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

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:

#+begin_src 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"))))
#+end_src

[ This is part of {{{development-version}}}. ]

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.

*** Convenience commands for note creation
:PROPERTIES:
:CUSTOM_ID: h:887bdced-9686-4e80-906f-789e407f2e8f
:END:

Sometimes the user needs to create a note that has different
requirements from those of ~denote~ ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).  While
this can be achieved globally by changing the ~denote-prompts~ user
option, there are cases where an ad-hoc method is the appropriate one
([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The denote-prompts option]]).

To this end, Denote provides the following interactive convenience
commands for note creation. They all work by appending a new prompt to
the existing ~denote-prompts~.

+ Create note by specifying file type :: The ~denote-type~ command
  creates a note while prompting for a file type.

  This is the equivalent of calling ~denote~ when ~denote-prompts~ has
  the =file-type= prompt appended to its existing prompts. In practical
  terms, this lets you produce, say, a note in Markdown even though
  you normally write in Org ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).

  #+findex: denote-create-note-using-type
  The ~denote-create-note-using-type~ is an alias of ~denote-type~.

+ Create note using a date :: Normally, Denote reads the current date
  and time to construct the unique identifier of a newly created note
  ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).  Sometimes, however, the user needs to set
  an explicit date+time value.

  This is where the ~denote-date~ command comes in.  It creates a note
  while prompting for a date.  The date can be in YEAR-MONTH-DAY
  notation like =2022-06-30= or that plus the time: =2022-06-16 14:30=.

  [[#h:e7ef08d6-af1b-4ab3-bb00-494a653e6d63][The denote-date-prompt-use-org-read-date option]].

  This is the equivalent of calling ~denote~ when ~denote-prompts~ has
  the =date= prompt appended to its existing prompts.

  #+findex: denote-create-note-using-date
  The ~denote-create-note-using-date~ is an alias of ~denote-date~.

+ Create note in a specific directory :: The ~denote-subdirectory~
  command creates a note while prompting for a subdirectory.  Available
  candidates include the value of the variable ~denote-directory~ and
  any subdirectory thereof (Denote does not create subdirectories).

  This is the equivalent of calling ~denote~ when ~denote-prompts~ has
  the =subdirectory= prompt appended to its existing prompts.

  #+findex: denote-create-note-in-subdirectory
  The ~denote-create-note-in-subdirectory~ is a more descriptive alias
  of ~denote-subdirectory~.

+ Create note and add a template :: The ~denote-template~ command
  creates a new note and inserts the specified template below the front
  matter ([[#h:f635a490-d29e-4608-9372-7bd13b34d56c][The denote-templates option]]).  Available candidates for
  templates are specified in the user option ~denote-templates~.

  This is the equivalent of calling ~denote~ when ~denote-prompts~ has
  the =template= prompt appended to its existing prompts.

  #+findex: denote-create-note-with-template
  The ~denote-create-note-with-template~ is an alias of the command
  ~denote-template~, meant to help with discoverability.

+ Create note with a signature :: The ~denote-signature~ command first
  prompts for an arbitrary string to use in the optional =SIGNATURE=
  field of the file name and then asks for a title and keywords.
  Signatures are arbitrary strings of alphanumeric characters which
  can be used to establish sequential relations between file at the
  level of their file name (e.g. 1, 1a, 1b, 1b1, 1b2, ...).

  This is the equivalent of calling ~denote~ when ~denote-prompts~ has
  the =signature= prompt appended to its existing prompts.

  The ~denote-create-note-using-signature~ is an alias of the command
  ~denote-signature~ intended to make the functionality more
  discoverable.

**** Write your own convenience commands
:PROPERTIES:
:CUSTOM_ID: h:11946562-7eb0-4925-a3b5-92d75f1f5895
:END:

The convenience commands we provide only cover some basic use-cases
([[#h:887bdced-9686-4e80-906f-789e407f2e8f][Convenience commands for note creation]]).  The user may require
combinations that are not covered, such as to prompt for a template and
for a subdirectory, instead of only one of the two.  To this end, we
show how to follow the code we use in Denote to write your own variants
of those commands.

First let's take a look at the definition of one of those commands.
They all look the same, but we use ~denote-subdirectory~ for this
example:

#+begin_src emacs-lisp
(defun denote-subdirectory ()
  "Create note while prompting for a subdirectory.

Available candidates include the value of the variable
`denote-directory' and any subdirectory thereof.

This is equivalent to calling `denote' when `denote-prompts' is
set to '(subdirectory title keywords)."
  (declare (interactive-only t))
  (interactive)
  (let ((denote-prompts '(subdirectory title keywords)))
    (call-interactively #'denote)))
#+end_src

The hyphenated word after ~defun~ is the name of the function.  It has
to be unique.  Then we have the documentation string (or "doc string")
which is for the user's convenience.

This function is ~interactive~, meaning that it can be called via =M-x=
or be assigned to a key binding.  Then we have the local binding of the
~denote-prompts~ to the desired combination ("local" means specific to
this function without affecting other contexts).  Lastly, it calls the
standard ~denote~ command interactively, so it uses all the prompts in
their specified order.

Now let's say we want to have a command that (i) asks for a template and
(ii) for a subdirectory ([[#h:f635a490-d29e-4608-9372-7bd13b34d56c][The denote-templates option]]).  All we need to
do is tweak the ~let~ bound value of ~denote-prompts~ and give our
command a unique name:

#+begin_src emacs-lisp
;; Like `denote-subdirectory' but also ask for a template
(defun denote-subdirectory-with-template ()
  "Create note while also prompting for a template and subdirectory.

This is equivalent to calling `denote' when `denote-prompts' is
set to '(template subdirectory title keywords)."
  (declare (interactive-only t))
  (interactive)
  (let ((denote-prompts '(template subdirectory title keywords)))
    (call-interactively #'denote)))
#+end_src

The tweaks to ~denote-prompts~ determine how the command will behave
([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The denote-prompts option]]). Use this paradigm to write your own
variants which you can then assign to keys, invoke with =M-x=, or add
to the list of commands available at the ~denote-command-prompt~
([[#h:98c732ac-da0e-4ebd-a0e3-5c47f9075e51][Choose which commands to prompt for]]).

*** The ~denote-save-buffers~ option
:PROPERTIES:
:CUSTOM_ID: h:bf80f4cd-6f56-4f7c-a991-8573161e4511
:END:

#+vindex: denote-save-buffers
The user option ~denote-save-buffer-after-creation~ controls whether
commands that create new notes save their buffer outright.

The default behaviour of commands such as ~denote~ (or related) is to
not save the buffer they create ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]). This gives the user
the chance to review the text before writing it to a file. The user
may choose to delete the unsaved buffer, thus not creating a new note
([[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffer-after-creation~ option]]).

This option also applies to notes affected by the renaming commands
(~denote-rename-file~ and related).

If this user option is set to a non-nil value, such buffers are saved
automatically. The assumption is that the user who opts in to this
feature is familiar with the ~denote-rename-file~ operation (or
related) and knows it is reliable ([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]).

*** The ~denote-date-prompt-use-org-read-date~ option
:PROPERTIES:
:CUSTOM_ID: h:e7ef08d6-af1b-4ab3-bb00-494a653e6d63
:END:

By default, Denote uses its own simple prompt for date or date+time
input ([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The denote-prompts option]]).  This is done when the
~denote-prompts~ option includes a =date= symbol and/or when the user
invokes the ~denote-date~ command.

#+vindex: denote-date-prompt-use-org-read-date
Users who want to benefit from the more advanced date selection method
that is common in interactions with Org mode, can set the user option
~denote-date-prompt-use-org-read-date~ to a non-nil value.

** Create a note from the current Org subtree
:PROPERTIES:
:CUSTOM_ID: h:d0c7cb79-21e5-4176-a6af-f4f68578c8dd
:END:

In Org parlance, an entry with all its subheadings and other contents
is a "subtree". Denote can operate on the subtree to extract it from
the current file and create a new file out of it. One such workflow is
to collect thoughts in a single document and produce longer standalone
notes out of them upon review.

#+findex: denote-org-extras-extract-org-subtree
The command ~denote-org-extras-extract-org-subtree~ is used for this
purpose. It creates a new Denote note using the current Org subtree.
In doing so, it removes the subtree from its current file and moves
its contents into a new file. This command is part of the optional
=denote-org-extras.el= extension, which is part of the ~denote~
package. It is loaded automatically as soon as one of its commands is
invoked.

The text of the subtree's heading becomes the =#+title= of the new
note. Everything else is inserted as-is.

If the heading has any tags, they are used as the keywords of the new
note. If the Org file has any =#+filetags= they are taken as well
(Org's =#+filetags= are inherited by the headings). If none of these
are true and the user option ~denote-prompts~ includes an entry for
keywords, then ~denote-org-extras-extract-org-subtree~ prompts for
keywords. Else the new note has no keywords ([[#h:ad4dde4a-8e88-470a-97ae-e7b9d4b41fb4][Add or remove keywords interactively]]).

If the heading has a =PROPERTIES= drawer, it is retained for further
review.

If the heading's =PROPERTIES= drawer includes a =DATE= or =CREATED=
property, or there exists a =CLOSED= statement with a timestamp value,
use that to derive the date (or date and time) of the new note (if
there is only a date, the time is taken as 00:00). If more than one of
these is present, the order of preference is =DATE=, then =CREATED=,
then =CLOSED=. If none of these is present, the current time is used.
If the ~denote-prompts~ includes an entry for a date, then the command
prompts for a date at this stage (also see ~denote-date-prompt-use-org-read-date~).

For the rest, it consults the value of the user option
~denote-prompts~ in the following scenaria:

- To optionally prompt for a subdirectory, otherwise it produces the
  new note in the ~denote-directory~.
- To optionally prompt for a file signature, otherwise to not use any.

The new note is an Org file regardless of the user option
~denote-file-type~.

** Create note using Org capture
:PROPERTIES:
:CUSTOM_ID: h:656c70cd-cf9a-4471-a0b5-4f0aaf60f881
:END:

For integration with ~org-capture~, the user must first add the relevant
template.  Such as:

#+begin_src emacs-lisp
(with-eval-after-load 'org-capture
  (add-to-list 'org-capture-templates
               '("n" "New note (with Denote)" plain
                 (file denote-last-path)
                 #'denote-org-capture
                 :no-save t
                 :immediate-finish nil
                 :kill-buffer t
                 :jump-to-captured t)))
#+end_src

[ In the future, we might develop Denote in ways which do not require such
  manual intervention.  More user feedback is required to identify the
  relevant workflows. ]

Once the template is added, it is accessed from the specified key.  If,
for instance, ~org-capture~ is bound to =C-c c=, then the note creation
is initiated with =C-c c n=, per the above snippet.  After that, the
process is the same as with invoking ~denote~ directly, namely: a prompt
for a title followed by a prompt for keywords ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).

#+vindex: denote-org-capture-specifiers
Users may prefer to leverage ~org-capture~ in order to extend file
creation with the specifiers described in the ~org-capture-templates~
documentation (such as to capture the active region and/or create a
hyperlink pointing to the given context).

IMPORTANT.  Due to the particular file-naming scheme of Denote, which is
derived dynamically, such specifiers or other arbitrary text cannot be
written directly in the template.  Instead, they have to be assigned to
the user option ~denote-org-capture-specifiers~, which is interpreted by
the function ~denote-org-capture~.  Example with our default value:

#+begin_src emacs-lisp
(setq denote-org-capture-specifiers "%l\n%i\n%?")
#+end_src

Note that ~denote-org-capture~ ignores the ~denote-file-type~: it always
sets the Org file extension for the created note to ensure that the
capture process works as intended, especially for the desired output of
the ~denote-org-capture-specifiers~.

** Create note with specific prompts using Org capture
:PROPERTIES:
:CUSTOM_ID: h:95b78582-9086-47e8-967f-62373e2369a0
:END:

This section assumes knowledge of how Denote+org-capture work, as
explained in the previous section ([[#h:656c70cd-cf9a-4471-a0b5-4f0aaf60f881][Create note using Org capture]]).

#+findex: denote-org-capture-with-prompts
The previous section shows how to define an Org capture template that
always prompts for a title and keywords.  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.

[[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]].

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

[[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][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~).

#+begin_src 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))
#+end_src

** Create a note with the region's contents
:PROPERTIES:
:CUSTOM_ID: h:2f8090f1-50af-4965-9771-d5a91a0a87bd
:END:

#+findex: denote-region
The command ~denote-region~ takes the contents of the active region
and then calls the ~denote~ command.  Once a new note is created, it
inserts the contents of the region therein.  This is useful to
quickly elaborate on some snippet of text or capture it for future
reference.

#+vindex: denote-region-after-new-note-functions
When the ~denote-region~ command is called with an active region, it
finalises its work by calling ~denote-region-after-new-note-functions~.
This is an abnormal hook, meaning that the functions added to it are
called with arguments.  The arguments are two, representing the
beginning and end positions of the newly inserted text.

A common use-case for Org mode users is to call the command
~org-insert-structure-template~ after a region is inserted.  Emacs
will thus prompt for a structure template, such as the one
corresponding to a source block.  In this case the function added to
~denote-region-after-new-note-functions~ does not actually need
aforementioned arguments: it can simply declare those as ignored by
prefixing the argument names with an underscore (an underscore is
enough, but it is better to include a name for clarity).  For example,
the following will prompt for a structure template as soon as
~denote-region~ is done:

#+begin_src emacs-lisp
(defun my-denote-region-org-structure-template (_beg _end)
  (when (derived-mode-p 'org-mode)
    (activate-mark)
    (call-interactively 'org-insert-structure-template)))

(add-hook 'denote-region-after-new-note-functions #'my-denote-region-org-structure-template)
#+end_src

Remember that ~denote-region-after-new-note-functions~ are not called
if ~denote-region~ is used without an active region.

** Open an existing note or create it if missing
:PROPERTIES:
:CUSTOM_ID: h:ad91ca39-cf10-4e16-b224-fdf78f093883
:END:

#+findex: denote-open-or-create
#+findex: denote-open-or-create-with-command
Sometimes it is necessary to briefly interrupt the ongoing writing
session to open an existing note or, if that is missing, to create it.
This happens when a new tangential thought occurs and the user wants
to confirm that an entry for it is in place.  To this end, Denote
provides the command ~denote-open-or-create~ as well as its more
flexible counterpart ~denote-open-or-create-with-command~.

The ~denote-open-or-create~ prompts to visit a file in the
~denote-directory~.  At this point, the user must type in search terms
that match a file name.  If the input does not return any matches and
the user confirms their choice to proceed (usually by typing RET
twice, depending on the minibuffer settings), ~denote-open-or-create~
will call the ~denote~ command interactively to create a new note.  It
will then use whatever prompts ~denote~ normally has, per the user
option ~denote-prompts~ ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).  If the title prompt
is involved (the default behaviour), the ~denote-open-or-create~ sets
up this prompt to have the previous input as the default title of the
note to-be-created.  This means that the user can type RET at the
empty prompt to re-use what they typed in previously.  Commands to use
previous inputs from the history are also available (=M-p= or =M-n= in
the minibuffer, which call ~previous-history-element~ and
~next-history-element~ by default).  Accessing the history is helpful
to, for example, make further edits to the available text.

The ~denote-open-or-create-with-command~ is like the above, except
when it is about to create the new note it first prompts for the
specific file-creating command to use ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).  For example,
the user may want to specify a signature for this new file, so they
can select the ~denote-signature~ command.

Denote provides similar functionality for linking to an existing note
or creating a new one ([[#h:b6056e6b-93df-4e6b-a778-eebd105bac46][Link to a note or create it if missing]]).

** Maintain separate directory silos for notes
:PROPERTIES:
:CUSTOM_ID: h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5
:END:
#+cindex: Note silos

The user option ~denote-directory~ accepts a value that represents the
path to a directory, such as =~/Documents/notes=.  Normally, the user
will have one place where they store all their notes, in which case this
arrangement shall suffice.

There is, however, the possibility to maintain separate directories of
notes.  By "separate", we mean that they do not communicate with each
other: no linking between them, no common keywords, nothing.  Think of
the scenario where one set of notes is for private use and another is
for an employer.  We call these separate directories "silos".

To create silos, the user must specify a local variable at the root of
the desired directory.  This is done by creating a =.dir-locals.el=
file, with the following contents:

#+begin_src emacs-lisp
;;; Directory Local Variables.  For more information evaluate:
;;;
;;;     (info "(emacs) Directory Variables")

((nil . ((denote-directory . "/path/to/silo/"))))
#+end_src

When inside the directory that contains this =.dir-locals.el= file,
all Denote commands/functions for note creation, linking, the
inference of available keywords, et cetera will use the silo as their
point of reference ([[#h:e0d60749-194d-4677-b943-5e98fbf9ad1d][How to switch a silo]]). They will not read the
global value of ~denote-directory~. The global value of
~denote-directory~ is read everywhere else except the silos.

[[#h:0f72e6ea-97f0-42e1-8fd4-0684af0422e0][Use custom commands to select a silo]].

In concrete terms, this is a representation of the directory structures
(notice the =.dir-locals.el= file is needed only for the silos):

#+begin_example
;; This is the global value of 'denote-directory' (no need for a .dir-locals.el)
~/Documents/notes
|-- 20210303T120534--this-is-a-test__journal_philosophy.txt
|-- 20220303T120534--another-sample__journal_testing.md
`-- 20220620T181255--the-third-test__keyword.org

;; A silo with notes for the employer
~/different/path/to/notes-for-employer
|-- .dir-locals.el
|-- 20210303T120534--this-is-a-test__conference.txt
|-- 20220303T120534--another-sample__meeting.md
`-- 20220620T181255--the-third-test__keyword.org

;; Another silo with notes for my volunteering
~/different/path/to/notes-for-volunteering
|-- .dir-locals.el
|-- 20210303T120534--this-is-a-test__activism.txt
|-- 20220303T120534--another-sample__teambuilding.md
`-- 20220620T181255--the-third-test__keyword.org
#+end_example

It is possible to configure other user options of Denote to have a
silo-specific value.  For example, this one changes the
~denote-known-keywords~ only for this particular silo:

#+begin_src emacs-lisp
;;; Directory Local Variables.  For more information evaluate:
;;;
;;;     (info "(emacs) Directory Variables")

((nil . ((denote-directory . "/path/to/silo/")
         (denote-known-keywords . ("food" "drink")))))
#+end_src

This one is like the above, but also disables ~denote-infer-keywords~:

#+begin_src emacs-lisp
;;; Directory Local Variables.  For more information evaluate:
;;;
;;;     (info "(emacs) Directory Variables")

((nil . ((denote-directory . "/path/to/silo/")
         (denote-known-keywords . ("food" "drink"))
         (denote-infer-keywords . nil))))
#+end_src

To expand the list of local variables to, say, cover specific major
modes, we can do something like this:

#+begin_src emacs-lisp
;;; Directory Local Variables.  For more information evaluate:
;;;
;;;     (info "(emacs) Directory Variables")

((nil . ((denote-directory . "/path/to/silo/")
         (denote-known-keywords . ("food" "drink"))
         (denote-infer-keywords . nil)))
 (org-mode . ((org-hide-emphasis-markers . t)
              (org-hide-macro-markers . t)
              (org-hide-leading-stars . t))))
#+end_src

As not all user options have a "safe" local value, Emacs will ask the
user to confirm their choice and to store it in the Custom code
snippet that is normally appended to init file (or added to the file
specified by the user option ~custom-file~).

Finally, it is possible to have a =.dir-locals.el= for subdirectories
of any ~denote-directory~.  Perhaps to specify a different set of
known keywords, while not making the subdirectory a silo in its own
right.  We shall not expand on such an example, as we trust the user
to experiment with the best setup for their workflow.

Feel welcome to ask for help if the information provided herein is not
sufficient.  The manual shall be expanded accordingly.

*** How to switch a silo
:PROPERTIES:
:CUSTOM_ID: h:e0d60749-194d-4677-b943-5e98fbf9ad1d
:END:

Switching to a silo directory will make all Denote commands use the
silo's path as the ~denote-directory~, instead of the global value of
that variable ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]]). There are
three ways to switch to a silo:

1. Visit a file inside of that directory.
2. Use the ~dired~ command to open the directory in a buffer.
3. Use the command ~cd~ to select the directory without moving away
   from the current buffer.

*** Use custom commands to select a silo
:PROPERTIES:
:CUSTOM_ID: h:0f72e6ea-97f0-42e1-8fd4-0684af0422e0
:END:

[ As part of version 2.1.0, the contents of this section
  are formally provided in the file =denote-silo-extras.el=.  We keep
  this here for existing users.  Otherwise consult the new entry in
  the manual ([[#h:e43baf95-f201-4fec-8620-c0eb5eaa1c85][The =denote-silo-extras.el=]]). ]

We implement silos as directory-local values of the user option
~denote-directory~.  This means that all Denote commands read from the
local value if they are invoked from that context.  For example, if
=~/Videos/recordings= is a silo and =~/Documents/notes= is the
default/global value of ~denote-directory~ all Denote commands will
read the video's path when called from there (e.g. by using Emacs'
~dired~); any other context reads the global value.

[[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]].

There are cases where the user (i) wants to maintain multiple silos
and (ii) prefers an interactive way to switch between them without
going through Dired.  Since this is specific to the user's workflow,
it is easier to have some custom code for it.  The following should be
added to the user's Denote configuration:

#+begin_src emacs-lisp
(defvar my-denote-silo-directories
  `("/home/prot/Videos/recordings"
    "/home/prot/Documents/books"
    ;; You don't actually need to include the `denote-directory' here
    ;; if you use the regular commands in their global context.  I am
    ;; including it for completeness.
    ,denote-directory)
  "List of file paths pointing to my Denote silos.
  This is a list of strings.")

(defvar my-denote-commands-for-silos
  '(denote
    denote-date
    denote-subdirectory
    denote-template
    denote-type)
  "List of Denote commands to call after selecting a silo.
  This is a list of symbols that specify the note-creating
  interactive functions that Denote provides.")

(defun my-denote-pick-silo-then-command (silo command)
  "Select SILO and run Denote COMMAND in it.
  SILO is a file path from `my-denote-silo-directories', while
  COMMAND is one among `my-denote-commands-for-silos'."
  (interactive
   (list (completing-read "Select a silo: " my-denote-silo-directories nil t)
         (intern (completing-read
                  "Run command in silo: "
                  my-denote-commands-for-silos nil t))))
  (let ((denote-directory silo))
    (call-interactively command)))
#+end_src

With this in place, =M-x my-denote-pick-silo-then-command= will use
minibuffer completion to select a silo among the predefined options
and then ask for the command to run in that context.

Note that =let= binding ~denote-directory~ can be used in custom
commands and other wrapper functions to override the global default
value of ~denote-directory~ to select silos.

To see another example of a wrapper function that =let= binds
~denote-directory~, see:

[[#h:d0c7cb79-21e5-4176-a6af-f4f68578c8dd][Extending Denote: Split an Org subtree into its own note]].

*** The =denote-silo-extras.el=
:PROPERTIES:
:CUSTOM_ID: h:e43baf95-f201-4fec-8620-c0eb5eaa1c85
:END:

The =denote-silo-extras.el= provides optional convenience functions for
working with silos ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]]).
Start by loading the relevant library:

#+begin_src emacs-lisp
(require 'denote-silo-extras)
#+end_src

#+vindex: denote-silo-extras-directories
The user option ~denote-silo-extras-directories~ specifies a list of
directories that the user has set up as ~denote-directory~ silos.

#+findex: denote-silo-extras-create-note
The command ~denote-silo-extras-create-note~ prompts for a directory
among ~denote-silo-extras-directories~ and runs the ~denote~ command
from there.

#+findex: denote-silo-extras-open-or-create
Similar to the above, the command ~denote-silo-extras-open-or-create~
prompts for a directory among ~denote-silo-extras-directories~ and runs
the ~denote-open-or-create~ command from there.

#+findex: denote-silo-extras-select-silo-then-command
The command ~denote-silo-extras-select-silo-then-command~ prompts with
minibuffer completion for a directory among ~denote-silo-extras-directories~.
Once the user selects a silo, a second prompt asks for a Denote
note-creation command to call from inside that silo ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).

*** Make Org export work with silos
:PROPERTIES:
:CUSTOM_ID: h:fed09992-7c43-4237-b48f-f654bc29d1d8
:END:

The Org export infrastructure is designed to ignore directory-local
variables. This means that Denote silos, which depend on setting the
local value of the variable ~denote-directory~, do not work as
intended ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]]). More
specifically, the Denote links do not resolve to the right file,
because their path is changed during the export process.

I brought this to the attention of the Org maintainer. The guidance
from their side is to use the =#+bind= keyword to specify a local
value for the ~denote-directory~: <https://lists.gnu.org/archive/html/emacs-orgmode/2024-06/msg00206.html>.
The prerequisite is to set ~org-export-allow-bind-keywords~ to a
non-nil value:

#+begin_src emacs-lisp
(setq org-export-allow-bind-keywords t)
#+end_src

I do not think this is an elegant solution, but here are two possible
ways to go about it, anyway:

1. Manually add the =#+bind= keyword to each file you want to export.
   It has to be like this:

   #+begin_src emacs-lisp
   ,#+bind: denote-directory "/path/to/silo/"
   #+end_src

2. Alternatively, you can make the Org front matter that Denote uses
   for new files automatically include the =#+bind= keyword with its
   desired value. Here is a complete =.dir-locals.el= which (i)
   defines the silo and (ii) modifies the ~denote-org-front-matter~
   accordingly:

   #+begin_src emacs-lisp
   ;;; Directory Local Variables.  For more information evaluate:
   ;;;
   ;;;     (info "(emacs) Directory Variables")

   ((nil . ((denote-directory . "/path/to/silo/")
            (denote-org-front-matter .
             "#+title:      %s
,#+date:       %s
,#+filetags:   %s
,#+identifier: %s
,#+bind:       denote-directory \"/path/to/silo/\"
\n"))))
   #+end_src

   [ Note that if you are reading the Org source of this manual, you
     need to use the command ~org-edit-special~ on the above code
     blocks before copying the code. This is because Org automatically
     prepends a comma to disambiguate those entries from actual
     keywords of the current file. ]

*** Make any Denote command work in a silo from anywhere
:PROPERTIES:
:CUSTOM_ID: h:547e1aac-4b48-403c-8063-ddb74b55e135
:END:

Denote silos are instantiated with a directory-local value for the
~denote-directory~ ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]]). This
means that all Denote commands will operate on the silo when the user
is inside of that directory ([[#h:e0d60749-194d-4677-b943-5e98fbf9ad1d][How to switch a silo]]). Sometimes though,
the user may not want to switch to the silo, then call a Denote
command, and finally switch away from the silo: this context change
can be done only for the duration of a command.

Here we show how easy it is to transiently bind the value of the
~denote-directory~ to the path of a silo (well, any path for that
matter).

#+begin_src emacs-lisp
(defun my-denote-journal-extras-new-or-existing-entry ()
  "Like `denote-journal-extras-new-or-existing-entry' for my silo."
  (interactive)
  (let ((denote-directory "/path/to/silo/"))
    (call-interactively 'denote-journal-extras-new-or-existing-entry)))
#+end_src

All the user needs to do here is change the exact command that is
passed to the ~call-interactively~. We use an example from the
journaling conveniences that we provide ([[#h:4a6d92dd-19eb-4fcc-a7b5-05ce04da3a92][Keep a journal or diary]]).

With this in place, the user can now call their own command, such as
the ~my-denote-journal-extras-new-or-existing-entry~ shown above, when
they need to write a note there without manually switching to the
silo. Of course, these commands can be assigned to key bindings for
greater convenience. For example:

#+begin_src emacs-lisp
(define-key global-map (kbd "C-c n j") #'my-denote-journal-extras-new-or-existing-entry)
#+end_src

** Exclude certain files from file prompts
:PROPERTIES:
:CUSTOM_ID: h:53db09de-2cec-4670-b163-5cb791f997b4
:END:

#+vindex: denote-excluded-files-regexp
The user option ~denote-excluded-files-regexp~ is a regular expression
that matches files names which should be excluded from all Denote file
prompts. Such prompts are present when linking to a file with one of
the many commands, like ~denote-link~ ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]), or when trying
to open a file that may or may not exist ([[#h:ad91ca39-cf10-4e16-b224-fdf78f093883][Open an existing note or create it if missing]]).

Functions that check for files include ~denote-directory-files~ and
~denote-file-prompt~.

The match is performed with ~string-match-p~.

[[#h:c916d8c5-540a-409f-b780-6ccbd90e088e][For developers or advanced users]].

** Exclude certain directories from all operations
:PROPERTIES:
:CUSTOM_ID: h:8458f716-f9c2-4888-824b-2bf01cc5850a
:END:

#+vindex: denote-excluded-directories-regexp
The user option ~denote-excluded-directories-regexp~ instructs all
Denote functions that read or check file/directory names to omit
directories that match the given regular expression.  The regexp needs
to match only the name of the directory, not its full path.

Affected operations include file prompts and functions that return the
available files in the value of the user option ~denote-directory~
([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directory silos for notes]]).

File prompts are used by several commands, such as ~denote-link~ and
~denote-subdirectory~.

Functions that check for files include ~denote-directory-files~ and
~denote-directory-subdirectories~.

The match is performed with ~string-match-p~.

[[#h:c916d8c5-540a-409f-b780-6ccbd90e088e][For developers or advanced users]].

** Exclude certain keywords from being inferred
:PROPERTIES:
:CUSTOM_ID: h:69e518ee-ed43-40ab-a5f4-c780a23e5358
:END:

#+vindex: denote-excluded-keywords-regexp
The user option ~denote-excluded-keywords-regexp~ omits keywords that
match a regular expression from the list of inferred keywords.

Keywords are inferred from file names and provided at relevant prompts
as completion candidates when the user option ~denote-infer-keywords~
is non-nil.

The match is performed with ~string-match-p~.

** Use Denote commands from the menu bar or context menu
:PROPERTIES:
:CUSTOM_ID: h:c4290e15-e97e-4a9b-b8db-6b9738e37e78
:END:

Denote registers a submenu for the ~menu-bar-mode~.  Users will find
the entry called "Denote".  From there they can use their pointer to
select a command.  For a sample of how this looks, read the
development log: <https://protesilaos.com/codelog/2023-03-31-emacs-denote-menu/>.

#+findex: denote-menu-bar-mode
The command ~denote-menu-bar-mode~ toggles the presentation of the
menu. It is enabled by default.

Emacs also provides support for operations through a context menu.
This is typically the set of actions that are made available via a
right mouse click.  Users who enable ~context-menu-mode~ can register
the Denote entry for it by adding the following to their configuration
file:

#+begin_src emacs-lisp
(add-hook 'context-menu-functions #'denote-context-menu)
#+end_src

* Renaming files
:PROPERTIES:
:CUSTOM_ID: h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca
:END:

Denote provides commands to rename files and update their front matter
where relevant.  For Denote to work, only the file name needs to be in
order, by following our naming conventions ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).
The linking mechanism, in particular, needs just the identifier in the
file name ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).

We write front matter in notes for the user's convenience and for other
tools to make use of that information (e.g. Org's export mechanism).
The renaming mechanism takes care to keep this data in sync with the
file name, when the user performs a change.

Renaming is useful for managing existing files created with Denote,
but also for converting older text files to Denote notes.  Denote's
file-naming scheme is not specific to notes or text files: it is
relevant for all sorts of items, such as multimedia and PDFs that form
part of the user's longer-term storage.  While Denote does not manage
such files (e.g. doesn't create links to them), it already has all the
mechanisms to facilitate the task of renaming them.

#+vindex: denote-after-rename-file-hook
All renaming commands run the ~denote-after-rename-file-hook~ after a
succesful operation. They also construct the file name in accordance
with the user option ~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

Apart from renaming files, Denote can also rename only the buffer.
The idea is that the underlying file name is correct but it can be
easier to use shorter buffer names when displaying them on the mode
line or switching between then with commands like ~switch-to-buffer~.

[[#h:3ca4db16-8f26-4d7d-b748-bac48ae32d69][Automatically rename Denote buffers]].

** Rename a single file
:PROPERTIES:
:CUSTOM_ID: h:7cc9e000-806a-48da-945c-711bbc7426b0
:END:

#+findex: denote-rename-file
The ~denote-rename-file~ command renames a file and updates existing
front matter if appropriate. It is possible to do the same with
multiple files ([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files interactively]]).

It always renames the file where it is located in the file system:
it never moves it to another directory.

If in Dired, it considers =FILE= to be the one at point, else it
prompts with minibuffer completion for one. When called from Lisp,
=FILE= is a file system path represented as a string.

If =FILE= has a Denote-compliant identifier, it retains it while
updating components of the file name referenced by the user option
~denote-prompts~ ([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The ~denote-prompts~ option]]). By default, these are
the =TITLE= and =KEYWORDS=. The =SIGNATURE= is another one. When
called from Lisp, =TITLE= and =SIGNATURE= are strings, while
=KEYWORDS= is a list of strings.

If there is no identifier, ~denote-rename-file~ creates an identifier
based on the following conditions:

1. If the ~denote-prompts~ includes an entry for date prompts, then it
   prompts for =DATE= and takes its input to produce a new identifier. For
   use in Lisp, =DATE= must conform with ~denote-valid-date-p~.

2. If =DATE= is nil (e.g. when ~denote-prompts~ does not include a
   date entry), it uses the file attributes to determine the last
   modified date of =FILE= and formats it as an identifier.

3. As a fallback, it derives an identifier from the current date and
   time.

4. At any rate, if the resulting identifier is not unique among the
   files in the variable ~denote-directory~, it increments it such
   that it becomes unique.

In interactive use, and assuming ~denote-prompts~ includes a title
entry, the ~denote-rename-file~ makes the =TITLE= prompt have
prefilled text in the minibuffer that consists of the current title of
=FILE=. The current title is either retrieved from the front matter
(such as the =#+title= in Org) or from the file name.

The command does the same for the =SIGNATURE= prompt, subject to
~denote-prompts~, by prefilling the minibuffer with the current
signature of =FILE=, if any.

Same principle for the =KEYWORDS= prompt: it converts the keywords in
the file name into a comma-separated string and prefills the minibuffer
with it (the =KEYWORDS= prompt accepts more than one keywords, each
separated by a comma, else the ~crm-separator~).

For all prompts, the ~denote-rename-file~ interprets an empty input as
an instruction to remove that file name component. For example, if a
=TITLE= prompt is available and =FILE= is =20240211T093531--some-title__keyword1.org=
then it renames =FILE= to =20240211T093531__keyword1.org=. If a file
name component is present, but there is no entry for it in
~denote-prompts~, keep it as-is.

[ NOTE: Please check with your minibuffer user interface how to
  provide an empty input. The Emacs default setup accepts the empty
  minibuffer contents as they are, though popular packages like
  ~vertico~ use the first available completion candidate instead. For
  ~vertico~, the user must either move one up to select the prompt and
  then type =RET= there with empty contents, or use the command
  ~vertico-exit-input~ with empty contents. That Vertico command is
  bound to =M-RET= as of this writing on 2024-02-13 08:08 +0200. ]

When renaming =FILE=, the command reads its file type extension (like
=.org=) and preserves it through the renaming process. Files that have
no extension are left without one.

As a final step, ask for confirmation, showing the difference
between old and new file names.  Do not ask for confirmation if
the user option ~denote-rename-confirmations~ does not contain
the symbol ~modify-file-name~ ([[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-confirmations~ option]]).

If =FILE= has front matter for =TITLE= and =KEYWORDS=, ask to rewrite
their values in order to reflect the new input, unless
~denote-rename-confirmations~ lacks ~rewrite-front-matter~. When the
~denote-save-buffers~ is nil (the default), do not save the underlying
buffer, thus giving the user the option to double-check the result,
such as by invoking the command ~diff-buffer-with-file~. The rewrite
of the =TITLE= and =KEYWORDS= in the front matter should not affect
the rest of the front matter.

If the file does not have front matter but is among the supported file
types (per ~denote-file-type~), add front matter to the top of it and
leave the buffer unsaved for further inspection ([[#h:13218826-56a5-482a-9b91-5b6de4f14261][Front matter]]). Save
the buffer if ~denote-save-buffers~ is non-nil ([[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffers~ option]]).

Construct the file name in accordance with the user option
~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

Run the ~denote-after-rename-file-hook~ after renaming =FILE=.

This command is intended to (i) rename Denote files, (ii) convert
existing supported file types to Denote notes, and (ii) rename
non-note files (e.g. =PDF=) that can benefit from Denote's file-naming
scheme.

For a version of this command that works with multiple files
one-by-one, use ~denote-dired-rename-files~ ([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files interactively]]).

*** The ~denote-rename-confirmations~ option
:PROPERTIES:
:CUSTOM_ID: h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7
:END:

#+vindex: denote-rename-confirmations
The user option ~denote-rename-confirmations~ controls what kind of
confirmation renaming commands ask for ([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]).  Its value is
a list of symbols.

The value is either nil, in which case no confirmation is ever
requested, or a list of symbols among the following:

- ~modify-file-name~ means that renaming commands will ask for
  confirmation before modifying the file name.

- ~rewrite-front-matter~ means that renaming commands will ask for
  confirmation before rewritting the front matter.

- ~add-front-matter~ means that renaming commands will ask for
  confirmation before adding new front matter to the file.

The default behaviour of the ~denote-rename-file~ command (and others
like it) is to ask for an affirmative answer as a final step before
changing the file name and, where relevant, inserting or updating the
corresponding front matter.

Specialized commands that build on top of ~denote-rename-file~ (or
related) may internally bind this user option to a non-nil value in
order to perform their operation (e.g. ~denote-dired-rename-files~
goes through each marked Dired file, prompting for the information to
use, but carries out the renaming without asking for confirmation
([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files interactively]])).

** Rename a single file based on its front matter
:PROPERTIES:
:CUSTOM_ID: h:3ab08ff4-81fa-4d24-99cb-79f97c13a373
:END:

#+findex: denote-rename-file-using-front-matter
In the previous section, we covered the more general mechanism of the
command ~denote-rename-file~ ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]).  There is also a
way to have the same outcome by making Denote read the data in the
current file's front matter and use it to construct/update the file
name.  The command for this is ~denote-rename-file-using-front-matter~.
It is only relevant for files that (i) are among the supported file
types, per ~denote-file-type~, and (ii) have the requisite front matter
in place.

Suppose you have an =.org= file with this front matter ([[#h:13218826-56a5-482a-9b91-5b6de4f14261][Front matter]]):

#+begin_example
#+title:      My sample note file
#+date:       [2022-08-05 Fri 13:10]
#+filetags:   :testing:
#+identifier: 20220805T131044
#+end_example

Its file name reflects this information:

: 20220805T131044--my-sample-note-file__testing.org

You want to change its title and keywords manually, so you modify it thus:

#+begin_example
#+title:      My modified sample note file
#+date:       [2022-08-05 Fri 13:10]
#+filetags:   :testing:denote:emacs:
#+identifier: 20220805T131044
#+end_example

At this stage, the file name still shows the old title and keywords.
You now invoke ~denote-rename-file-using-front-matter~ and it updates
the file name to:

: 20220805T131044--my-modified-sample-note-file__testing_denote_emacs.org

By default, the renaming is subject to a "yes or no" prompt that shows
the old and new names, just so the user is certain about the change.
Though this can be modified ([[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-confirmations~ option]]).

The identifier of the file, if any, is never modified even if it is
edited in the front matter: Denote considers the file name to be the
source of truth in this case, to avoid potential breakage with typos and
the like.

This command constructs the file name in accordance with the user option
~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

** Rename multiple files interactively
:PROPERTIES:
:CUSTOM_ID: h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde
:END:

#+findex: denote-dired-rename-files
#+findex: denote-dired-rename-marked-files
The command ~denote-dired-rename-files~ (alias ~denote-dired-rename-marked-files~)
renames the files that are marked in a Dired buffer. Its behaviour is
similar to the ~denote-rename-file~ in that it prompts for a title,
keywords, and signature ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]). It does so over each
marked file, renaming one after the other.

Unlike ~denote-rename-file~, the command ~denote-dired-rename-files~
does not ask to confirm the changes made to the files: it performs
them outright (same as setting ~denote-rename-confirmations~ to a nil
value). This is done to make it easier to rename multiple files
without having to confirm each step. For an even more direct approach,
check the command ~denote-dired-rename-marked-files-with-keywords~.

- [[#h:f365ff7e-2140-4e14-a92f-666ae97382a4][Rename by writing only keywords]]
- [[#h:ea5673cd-e6ca-4c42-a066-07dc6c9d57f8][Rename multiple files based on their front matter]]

** Rename multiple files at once by asking only for keywords
:PROPERTIES:
:CUSTOM_ID: h:f365ff7e-2140-4e14-a92f-666ae97382a4
:END:

#+findex: denote-dired-rename-marked-files-with-keywords
The ~denote-dired-rename-marked-files-with-keywords~ command renames
marked files in Dired to conform with our file-naming scheme. It does
so by writing keywords to them. Specifically, it does the following:

- retains the file's existing name and makes it the =TITLE= field, per
  Denote's file-naming scheme;

- sluggifies the =TITLE= and adjusts its letter casing, according to
  our conventions;

- prepends an identifier to the =TITLE=, if one is missing;

- preserves the file's extension, if any;

- prompts once for =KEYWORDS= and applies the user's input to the
  corresponding field in the file name, rewriting any keywords that
  may exist while removing keywords that do exist if =KEYWORDS= is
  empty;

- adds or rewrites existing front matter to the underlying file, if it
  is recognized as a Denote note (per the ~denote-file-type~ user
  option), such that it includes the new keywords.

[ Note that the affected buffers are not saved, unless the user option
  ~denote-rename-no-confirm~ is non-nil. Users can thus check them to
  confirm that the new front matter does not cause any problems (e.g.
  with the ~diff-buffer-with-file~ command). Multiple buffers can be
  saved in one go with the command ~save-some-buffers~ (read its doc
  string). ]

Construct the file name in accordance with the user option
~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

Run the ~denote-after-rename-file-hook~ after the renaming is done.

#+findex: denote-dired-rename-marked-files-add-keywords
#+findex: denote-dired-rename-marked-files-remove-keywords
For more specialized versions of this command that only add or remove
keywords, use ~denote-dired-rename-marked-files-add-keywords~ and
~denote-dired-rename-marked-files-remove-keywords~, respectively.

** Rename multiple files based on their front matter
:PROPERTIES:
:CUSTOM_ID: h:ea5673cd-e6ca-4c42-a066-07dc6c9d57f8
:END:

#+findex: denote-dired-rename-marked-files-using-front-matter
As already noted, Denote can rename a file based on the data in its
front matter ([[#h:3ab08ff4-81fa-4d24-99cb-79f97c13a373][Rename a single file based on its front matter]]).  The
command ~denote-dired-rename-marked-files-using-front-matter~ extends
this principle to a batch operation which applies to all marked files in
Dired.

Marked files must count as notes for the purposes of Denote, which
means that they at least have an identifier in their file name and use
a supported file type, per ~denote-file-type~. Files that do not meet
this criterion are ignored, because Denote cannot know if they have
front matter and what that may be. For such files, it is still
possible to rename them interactively ([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files interactively]]).

** Rename a file by changing only its file type
:PROPERTIES:
:CUSTOM_ID: h:85b65995-89fd-4978-bba3-7bb6c8d6f945
:END:

#+findex: denote-change-file-type-and-front-matter
The command ~denote-change-file-type-and-front-matter~ provides the
convenience of converting a note taken in one file type, say, =.txt=
into another like =.org=. It presents a choice among the
~denote-file-type~ options.

The conversion does NOT modify the existing front matter.  Instead, it
prepends new front matter to the top of the file.  We do this as a
safety precaution since the user can, in principle, add arbitrary
extras to their front matter that we would not want to touch.

If in Dired, ~denote-change-file-type-and-front-matter~ operates on the
file at point, else the current file, else it prompts with minibuffer
completion for one.

The title of the file is retrieved from a line starting with a title
field in the file's front matter, depending on the previous file type
(e.g.  =#+title= for Org).  The same process applies for keywords.

As a final step, the command asks for confirmation, showing the
difference between old and new file names.

This command constructs the file name in accordance with the user option
~denote-file-name-components-order~ ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

** Rename a file by adding or removing a title interactively
:PROPERTIES:
:CUSTOM_ID: h:a26e28c7-8222-4377-92e9-3b0a709010a5
:END:

#+findex: denote-rename-file-title
The command ~denote-rename-file-title~ streamlines the process of
interactively adding or removing a title to/from a file, while
changing its file name accordingly. It asks for a title using the
familiar minibuffer prompt ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]). It then renames
the file. The command respect the values of
~denote-rename-confirmations~ and ~denote-save-buffers~:

- [[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-confirmations~ option]].
- [[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffers~ option]].

Technically, ~denote-rename-file-title~ is a wrapper for
~denote-rename-file~, doing all the things that does ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]).

Concretely, this command can add or remove a title in one go. It
does it by prepopulating the minibuffer prompt with the existing
title. Users can then modify it. An empty input means to remove
the title altogether ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

[ NOTE: Please check with your minibuffer user interface how to
  provide an empty input. The Emacs default setup accepts the empty
  minibuffer contents as they are, though popular packages like
  ~vertico~ use the first available completion candidate instead. For
  ~vertico~, the user must either move one up to select the prompt and
  then type =RET= there with empty contents, or use the command
  ~vertico-exit-input~ with empty contents. That Vertico command is
  bound to =M-RET= as of this writing on 2024-06-30 10:37 +0300. ]

** Rename a file by adding or removing keywords interactively
:PROPERTIES:
:CUSTOM_ID: h:ad4dde4a-8e88-470a-97ae-e7b9d4b41fb4
:END:

#+findex: denote-rename-file-keywords
The command ~denote-rename-file-keywords~ streamlines the process of
interactively adding or removing keywords to a file, while changing
its file name and front matter accordingly. It asks for keywords using
the familiar minibuffer prompt ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]). It then
renames the file ([[#h:3ab08ff4-81fa-4d24-99cb-79f97c13a373][Rename a single file based on its front matter]]).
The command respect the values of ~denote-rename-confirmations~ and
~denote-save-buffers~:

- [[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-confirmations~ option]].
- [[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffers~ option]].

Technically, ~denote-rename-file-keywords~ is a wrapper for
~denote-rename-file~, doing all the things that does ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]).

Concretely, this command can add or remove keywords in one go. It does
it by prepopulating the minibuffer prompt with the existing keywords.
Users can then use the ~crm-separator~ (normally a comma), to write
new keywords or edit what is in the prompt to rewrite them
accordingly. An empty input means to remove all keywords ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

[ NOTE: Please check with your minibuffer user interface how to
  provide an empty input. The Emacs default setup accepts the empty
  minibuffer contents as they are, though popular packages like
  ~vertico~ use the first available completion candidate instead. For
  ~vertico~, the user must either move one up to select the prompt and
  then type =RET= there with empty contents, or use the command
  ~vertico-exit-input~ with empty contents. That Vertico command is
  bound to =M-RET= as of this writing on 2024-06-30 10:37 +0300. ]

** Rename a file by adding or removing a signature interactively
:PROPERTIES:
:CUSTOM_ID: h:b08a350f-b269-47ed-8c2a-b8ecf1b63c7f
:END:

#+findex: denote-rename-file-signature
The command ~denote-rename-file-signature~ streamlines the process of
interactively adding or removing a signature to/from a file, while
changing its file name accordingly. It asks for a signature using the
familiar minibuffer prompt ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]). It then renames
the file. The command respect the values of
~denote-rename-confirmations~ and ~denote-save-buffers~:

- [[#h:a2ae9090-c49e-4b32-bcf5-eb8944241fd7][The ~denote-rename-confirmations~ option]].
- [[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffers~ option]].

Technically, ~denote-rename-file-signature~ is a wrapper for
~denote-rename-file~, doing all the things that does ([[#h:7cc9e000-806a-48da-945c-711bbc7426b0][Rename a single file]]).

Concretely, this command can add or remove a signature in one go. It
does it by prepopulating the minibuffer prompt with the existing
signature. Users can then modify it. An empty input means to remove
the signature altogether ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

[ NOTE: Please check with your minibuffer user interface how to
  provide an empty input. The Emacs default setup accepts the empty
  minibuffer contents as they are, though popular packages like
  ~vertico~ use the first available completion candidate instead. For
  ~vertico~, the user must either move one up to select the prompt and
  then type =RET= there with empty contents, or use the command
  ~vertico-exit-input~ with empty contents. That Vertico command is
  bound to =M-RET= as of this writing on 2024-06-30 10:37 +0300. ]

** Faces used by rename commands
:PROPERTIES:
:CUSTOM_ID: h:ab3f355a-f763-43ae-a4c9-179d2d9265a5
:END:

These are the faces used by the various Denote rename commands to
style or highlight the old/new/current file shown in the relevant
minibuffer prompts:

- ~denote-faces-prompt-current-name~
- ~denote-faces-prompt-new-name~
- ~denote-faces-prompt-old-name~

* The file-naming scheme
:PROPERTIES:
:CUSTOM_ID: h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d
:END:

#+vindex: denote-directory
Notes are stored in the ~denote-directory~.  The default path is
=~/Documents/notes=.  The ~denote-directory~ can be a flat listing,
meaning that it has no subdirectories, or it can be a directory tree.
Either way, Denote takes care to only consider "notes" as valid
candidates in the relevant operations and will omit other files or
directories.

Every note produced by Denote follows this pattern by default
([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]):

: DATE==SIGNATURE--TITLE__KEYWORDS.EXTENSION

The =DATE= field represents the date in year-month-day format followed
by the capital letter =T= (for "time") and the current time in
hour-minute-second notation.  The presentation is compact:
=20220531T091625=.  The =DATE= serves as the unique identifier of each
note and, as such, is also known as the file's ID or identifier.

File names can include a string of alphanumeric characters in the
=SIGNATURE= field. Signatures have no clearly defined purpose and are up
to the user to define. One use-case is to use them to establish
sequential relations between files (e.g. 1, 1a, 1b, 1b1, 1b2, ...).

Signatures are an optional extension to Denote's file-naming scheme.
They can be added to newly created files on demand, with the command
~denote-signature~, or by modifying the value of the user option
~denote-prompts~.

The =TITLE= field is the title of the note, as provided by the user.
It automatically gets downcased by default and is also hyphenated
([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).  An entry about "Economics
in the Euro Area" produces an =economics-in-the-euro-area= string for
the =TITLE= of the file name.

The =KEYWORDS= field consists of one or more entries demarcated by an
underscore (the separator is inserted automatically).  Each keyword is
a string provided by the user at the relevant prompt which broadly
describes the contents of the entry.

Each of the keywords is a single word, with multiple keywords providing
the multi-dimensionality needed for advanced searches through Denote
files.  Users who need to compose a keyword out of multiple words such
as camelCase/CamelCase and are encouraged to use the
~denote-file-name-slug-functions~ user option accordingly
([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).

#+vindex: denote-file-type
The =EXTENSION= is the file type.  By default, it is =.org= (~org-mode~)
though the user option ~denote-file-type~ provides support for Markdown
with YAML or TOML variants (=.md= which runs ~markdown-mode~) and plain
text (=.txt= via ~text-mode~).  Consult its doc string for the minutiae.
While files end in the =.org= extension by default, the Denote code base
does not actually depend on org.el and/or its accoutrements.

Examples:

: 20220610T043241--initial-thoughts-on-the-zettelkasten-method__notetaking.org
: 20220610T062201--define-custom-org-hyperlink-type__denote_emacs_package.md
: 20220610T162327--on-hierarchy-and-taxis__notetaking_philosophy.txt

The different field separators, namely =--= and =__= introduce an
efficient way to anchor searches (such as with Emacs commands like
~isearch~ or from the command-line with ~find~ and related).  A query
for =_word= always matches a keyword, while a regexp in the form of,
say, ="\\([0-9T]+?\\)--\\(.*?\\)_"= captures the date in group =\1= and
the title in =\2= (test any regular expression in the current buffer by
invoking =M-x re-builder=).

[[#h:1a953736-86c2-420b-b566-fb22c97df197][Features of the file-naming scheme for searching or filtering]].

The ~denote-prompts~ can be configured in such ways to yield the
following file name permutations:

: DATE.EXT
: DATE--TITLE.EXT
: DATE__KEYWORDS.EXT
: DATE==SIGNATURE.EXT
: DATE==SIGNATURE--TITLE.EXT
: DATE==SIGNATURE--TITLE__KEYWORDS.EXT
: DATE==SIGNATURE__KEYWORDS.EXT

When in doubt, stick to the default design, which is carefully
considered and works well ([[#h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd][Change the order of file name components]]).

While Denote is an Emacs package, notes should work long-term and not
depend on the functionality of a specific program.  The file-naming
scheme we apply guarantees that a listing is readable in a variety of
contexts.  The Denote file-naming scheme is, in essence, an effective,
low-tech invention.

** Change the order of file name components
:PROPERTIES:
:CUSTOM_ID: h:dc8c40e0-233a-4991-9ad3-2cf5f05ef1cd
:END:

#+vindex: denote-file-name-components-order
Our standard file-naming scheme prescribes a specific order for the
file name components ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]). Though we provide the
user option ~denote-file-name-components-order~ to let the user
reorder them as they see fit.

The value of this user option is a list of the following symbols:

- ~identifier~: This is the combination of the date and time. When it
  is the first on the list, it looks like =20240519T073456= and does
  not have a component separator of its own due its unambiguous
  format. When it is placed anywhere else in the file name, it is
  prefixed with =@@=, so it looks like =@@20240519T073456=.

- ~signature~: This is an arbitrary string that can be used to qualify
  the file in some way, according to the user's methodology (e.g. to
  add a sequence to notes). The string is always prefixed with the
  ~==~ to remain unambiguous.

- ~title~: This is an arbitrary string which describes the file. It is
  always prefixed with =--= to be unambiguous.

- ~keywords~: This is a series of one or more words that succinctly
  group the file. Multiple keywords are separated by an underscore
  prefixed to each of them. The file name component is always prefixed
  with =__=.

All four symbols must appear exactly once. Duplicates are ignored. Any
missing symbol is added automatically.

Some examples:

#+begin_src emacs-lisp
(setq denote-file-name-components-order '(identifier signature title keywords))
;; => 20240519T07345==hello--this-is-the-title__denote_testing.org

(setq denote-file-name-components-order '(signature identifier title keywords))
;; => ==hello@@20240519T07345--this-is-the-title__denote_testing.org

(setq denote-file-name-components-order '(title signature identifier keywords))
;; => --this-is-the-title==hello@@20240519T07345__denote_testing.org

(setq denote-file-name-components-order '(keywords title signature identifier))
;; => __denote_testing--this-is-the-title==hello@@20240519T07345.org
#+end_src

Also see how to configure the Denote prompts, which affect which
components are actually used in the order specified herein ([[#h:f9204f1f-fcee-49b1-8081-16a08a338099][The ~denote-prompts~ option]]).

Before deciding on this, please consider the longer-term implications
of file names with varying patterns. Consistency makes things
predictable and thus easier to find. So pick one order and never touch
it again. When in doubt, leave the default file-naming scheme as-is.

** Sluggification of file name components
:PROPERTIES:
:CUSTOM_ID: h:ae8b19a1-7f67-4258-96b3-370a72c43f4e
:END:

Files names can contain any character that the file system
permits. Denote imposes a few additional restrictions:

+ The tokens "==", =__= and =--= are interpreted by Denote and should
  appear only once.

+ The dot character is not allowed in a note's file name, except to
  indicate the file type extension. Denote recognises two extensions
  for encrypted files, like =.txt.gpg=.

By default, Denote enforces other rules to file names through the user
option ~denote-file-name-slug-functions~. These rules are applied to
file names by default:

+ What we count as "illegal characters" are removed.  The constant
  ~denote-excluded-punctuation-regexp~ holds the relevant value.

+ Input for a file title is hyphenated.  The original value is
  preserved in the note's contents ([[#h:13218826-56a5-482a-9b91-5b6de4f14261][Front matter]]).

+ Spaces or other delimiters are removed from keywords, meaning that
  =hello-world= becomes =helloworld=.  This is because hyphens in
  keywords do not work everywhere, such as in Org. Plus, hyphens are
  word separators in the title and we want to keep distinct separators
  for each component to make search easier and semantic
  ([[#h:1a953736-86c2-420b-b566-fb22c97df197][Features of the file-naming scheme for searching or filtering]]).

+ Signatures are like the above, but use the equals sign instead of
  hyphens as a word separator.

+ All file name components are downcased. Further down we document how
  to deviate from these rules, such as to accept input of the form
  =helloWorld= or =HelloWorld= verbatim.

Denote imposes these restrictions to enforce uniformity, which is
helpful long-term as it keeps all files with the same predictable
pattern. Too many permutations make searches more difficult to express
accurately and be confident that the matches cover all files.
Nevertheless, one of the principles of Denote is its flexibility or
hackability and so users can deviate from the aforementioned
([[#h:d375c6d2-92c7-425f-9d9d-219ff47ed2a3][User-defined sluggification of file name components]]).

** User-defined sluggification of file name components
:PROPERTIES:
:CUSTOM_ID: h:d375c6d2-92c7-425f-9d9d-219ff47ed2a3
:END:

#+vindex: denote-file-name-slug-functions
The user option ~denote-file-name-slug-functions~ controls the
sluggification of file name components ([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).
The default method is outlined above and in the previous section
([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

The value of this user option is an alist where each element is a cons
cell of the form =(COMPONENT . METHOD)=. For example, here is the
default value:

#+begin_example emacs-lisp
'((title . denote-sluggify-title)
  (signature . denote-sluggify-signature)
  (keyword . denote-sluggify-keyword))
#+end_example

- The =COMPONENT= is an unquoted symbol among =title=, =signature=,
  =keyword=, which refers to the corresponding component of the file
  name.

- The =METHOD= is a function to format the given component. This
  function must take a string as its parameter and return the string
  formatted for the file name. Note that even in the case of the
  =keyword= component, the function receives one string representing a
  single keyword and returns it formatted for the file name. Joining
  the keywords together is handled internally by Denote.

One commonly requested deviation from the sluggification rules is to
not sluggify individual keywords, such that the user's input is taken
as-is. This can be done as follows:

#+begin_src emacs-lisp
(setq denote-file-name-slug-functions
      '((title . denote-sluggify-title)
        (keyword . identity)
        (signature . denote-sluggify-signature)))
#+end_src

The ~identity~ function simply returns the string it receives, thus
not altering it in any way.

Another approach is to keep the sluggification but not downcase the
string. We can do this by modifying the original functions used by
Denote. For example, we have this:

#+begin_src emacs-lisp
;; The original function for reference
(defun denote-sluggify-title (str)
  "Make STR an appropriate slug for title."
  (downcase (denote--slug-hyphenate (denote--slug-no-punct str))))

;; Our variant of the above, which does the same thing except from
;; downcasing the string.
(defun my-denote-sluggify-title (str)
  "Make STR an appropriate slug for title."
  (denote--slug-hyphenate (denote--slug-no-punct str)))

;; Now we use our function to sluggify titles without affecting their
;; letter casing.
(setq denote-file-name-slug-functions
      '((title . my-denote-sluggify-title) ; our function here
        (signature . denote-sluggify-signature)
        (keyword . denote-sluggify-keyword)))
#+end_src

Follow this principle for all the sluggification functions.

To access the source code, use either of the following built-in
methods:

1. Call the command ~find-library~ and search for ~denote~. Then
   navigate to the symbol you are searching for.

2. Invoke the command ~describe-symbol~, search for the symbol you are
   interested in, and from the resulting Help buffer either click on
   the first link or do =M-x help-view-source= (bound to =s= in Help
   buffers, by default).

Remember that deviating from the default file-naming scheme of Denote
will make things harder to use in the future, as files can/will have
permutations that create uncertainty. The sluggification scheme and
concomitant restrictions we impose by default are there for a very
good reason: they are the distillation of years of experience. Here we
give you what you wish, but bear in mind it may not be what you need.
You have been warned.

** Features of the file-naming scheme for searching or filtering
:PROPERTIES:
:CUSTOM_ID: h:1a953736-86c2-420b-b566-fb22c97df197
:END:

By default, file names have three fields and two sets of field
delimiters between them:

: DATE--TITLE__KEYWORDS.EXTENSION

When a signature is present, this becomes:

: DATE==SIGNATURE--TITLE__KEYWORDS.EXTENSION

Field delimiters practically serve as anchors for easier searching.
Consider this example:

: 20220621T062327==1a2--introduction-to-denote__denote_emacs.txt

You will notice that there are two matches for the word =denote=: one
in the title field and another in the keywords' field.  Because of the
distinct field delimiters, if we search for =-denote= we only match
the first instance while =_denote= targets the second one.  When
sorting through your notes, this kind of specificity is
invaluable---and you get it for free from the file names alone!
Similarly, a search for ==1= will show all notes that are related to
each other by virtue of their signature.

Users can get a lot of value out of this simple yet effective
arrangement, even if they have no knowledge of regular expressions.
One thing to consider, for maximum effect, is to avoid using
multi-word keywords as those can get hyphenated like the title and
will thus interfere with the above: either set the user option
~denote-allow-multi-word-keywords~ to nil or simply insert single
words at the relevant prompts.

* Front matter
:PROPERTIES:
:CUSTOM_ID: h:13218826-56a5-482a-9b91-5b6de4f14261
:END:

Notes have their own "front matter".  This is a block of data at the top
of the file, with no empty lines between the entries, which is
automatically generated at the creation of a new note.  The front matter
includes the title and keywords (aka "tags" or "filetags", depending on
the file type) which the user specified at the relevant prompt, as well
as the date and unique identifier, which are derived automatically.

This is how it looks for Org mode (when ~denote-file-type~ is nil or the
=org= symbol):

#+begin_example
#+title:      This is a sample note
#+date:       [2022-06-30 Thu 16:09]
#+filetags:   :denote:testing:
#+identifier: 20220630T160934
#+end_example

For Markdown with YAML (~denote-file-type~ has the =markdown-yaml=
value), the front matter looks like this:

#+begin_example
---
title:      "This is a sample note"
date:       2022-06-30T16:09:58+03:00
tags:       ["denote", "testing"]
identifier: "20220630T160958"
---
#+end_example

For Markdown with TOML (~denote-file-type~ has the =markdown-toml=
value), it is:

#+begin_example
+++
title      = "This is a sample note"
date       = 2022-06-30T16:10:13+03:00
tags       = ["denote", "testing"]
identifier = "20220630T161013"
+++
#+end_example

And for plain text (~denote-file-type~ has the =text= value), we have
the following:

#+begin_example
title:      This is a sample note
date:       2022-06-30
tags:       denote  testing
identifier: 20220630T161028
---------------------------
#+end_example

#+vindex: denote-date-format
The format of the date in the front matter is controlled by the user
option ~denote-date-format~.  When nil, Denote uses a file-type-specific
format:

- For Org, an inactive timestamp is used, such as
  =[2022-06-30 Wed 15:31]=.

- For Markdown, the RFC3339 standard is applied:
  =2022-06-30T15:48:00+03:00=.

- For plain text, the format is that of ISO 8601: =2022-06-30=.

If the value is a string, ignore the above and use it instead.  The
string must include format specifiers for the date.  These are described
in the doc string of ~format-time-string~..

** Change the front matter format
:PROPERTIES:
:CUSTOM_ID: h:7f918854-5ed4-4139-821f-8ee9ba06ad15
:END:

Per Denote's design principles, the code is hackable.  All front matter
is stored in variables that are intended for public use.  We do not
declare those as "user options" because (i) they expect the user to have
some degree of knowledge in Emacs Lisp and (ii) implement custom code.

[ NOTE for tinkerers: code intended for internal use includes double
  hyphens in its symbol.  "Internal use" means that it can be changed
  without warning and with no further reference in the change log.  Do
  not use any of it without understanding the consequences. ]

The variables which hold the front matter format are:

#+vindex: denote-org-front-matter
- ~denote-org-front-matter~

#+vindex: denote-text-front-matter
- ~denote-text-front-matter~

#+vindex: denote-toml-front-matter
- ~denote-toml-front-matter~

#+vindex: denote-yaml-front-matter
- ~denote-yaml-front-matter~

These variables have a string value with specifiers that are used by the
~format~ function.  The formatting operation passes four arguments which
include the values of the given entries.  If you are an advanced user
who wants to edit this variable to affect how front matter is produced,
consider using something like =%2$s= to control where the Nth argument
is placed.

When editing the value, make sure to:

1. Not use empty lines inside the front matter block.

2. Insert at least one empty line after the front matter block and do
   not use any empty line before it.

These help with consistency and might prove useful if we ever need to
operate on the front matter as a whole.

With those granted, below are some examples.  The approach is the same
for all variables.

#+begin_src emacs-lisp
;; Like the default, but upcase the entries
(setq denote-org-front-matter
  "#+TITLE:      %s
#+DATE:       %s
#+FILETAGS:   %s
#+IDENTIFIER: %s
\n")

;; Change the order (notice the %N$s notation)
(setq denote-org-front-matter
  "#+title:      %1$s
#+filetags:   %3$s
#+date:       %2$s
#+identifier: %4$s
\n")

;; Remove the date
(setq denote-org-front-matter
  "#+title:      %1$s
#+filetags:   %3$s
#+identifier: %4$s
\n")

;; Remove the date and the identifier
(setq denote-org-front-matter
  "#+title:      %1$s
#+filetags:   %3$s
\n")
#+end_src

Note that ~setq~ has a global effect: it affects the creation of all new
notes.  Depending on the workflow, it may be preferrable to have a
custom command which ~let~ binds the different format.  We shall not
provide examples at this point as this is a more advanced feature and we
are not yet sure what the user's needs are.  Please provide feedback and
we shall act accordingly.

** Regenerate front matter
:PROPERTIES:
:CUSTOM_ID: h:54b48277-e0e5-4188-ad54-ef3db3b7e772
:END:

#+findex: denote-add-front-matter
Sometimes the user needs to produce new front matter for an existing
note.  Perhaps because they accidentally deleted a line and could not
undo the operation.  The command ~denote-add-front-matter~ can be used
for this very purpose.

In interactive use, ~denote-add-front-matter~ must be invoked from a
buffer that visits a Denote note.  It prompts for a title and then for
keywords.  These are the standard prompts we already use for note
creation, so the keywords' prompt allows minibuffer completion and the
input of multiple entries, each separated by a comma ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).

The newly created front matter is added to the top of the file.

This command does not rename the file (e.g. to update the keywords).  To
rename a file by reading its front matter as input, the user can rely on
~denote-rename-file-using-front-matter~ ([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]).

Note that ~denote-add-front-matter~ is useful only for existing Denote
notes.  If the user needs to convert a generic text file to a Denote
note, they can use one of the command which first rename the file to
make it comply with our file-naming scheme and then add the relevant
front matter.

* Linking notes
:PROPERTIES:
:CUSTOM_ID: h:fc913d54-26c8-4c41-be86-999839e8ad31
:END:

Denote offers several commands for linking between notes.

All links target files which are Denote files. This means that they
have our file-naming scheme. Files need to be inside the
~denote-directory~ or one of its subdirectories. No other file is
recognised.

The following sections delve into the details ([[#h:4f354db1-aa78-47fd-ac60-c3d1e0f0b0a4][Why are some Org links opening outside Emacs?]]).

** Adding a single link
:PROPERTIES:
:CUSTOM_ID: h:5e5e3370-12ab-454f-ba09-88ff44214324
:END:

#+findex: denote-link
The ~denote-link~ command inserts a link at point to a file specified
at the minibuffer prompt. Links are formatted depending on the file
type of the current note. In Org and plain text buffers, links are
formatted thus: =[[denote:IDENTIFIER][DESCRIPTION]]=. While in
Markdown they are expressed as =[DESCRIPTION](denote:IDENTIFIER)=.

[ We optionally support links to Org headings ([[#h:d99de1fb-b1b7-4a74-8667-575636a4d6a4][The ~denote-org-store-link-to-heading~ user option]]).
  Other file types do not have the features of Org, so we cannot
  generalise this. ]

When ~denote-link~ is called with a prefix argument (=C-u= by
default), it formats links like =[[denote:IDENTIFIER]]=, regardless of
file type ([[#h:156c5ea3-147b-4f9d-a404-86a00558c60a][Fontify links in non-Org buffers]]). The user might prefer
its simplicity.

By default, the description of the link is determined thus:

- If the region is active, its text becomes the description of the
  link. In other words, the region text becomes the link.
- If the region is active but has no text, the description is empty
  and so the link is formatted the same way as if using the =C-u=
  prefix argument.
- If there is no region active, the description consists of the target
  file's signature and title ([[#h:066e5221-9844-474b-8858-398398646f86][Insert link to file with signature]]). The
  title is retrieved either from the front matter or the file name.
- If the target file has no signature, the title is used.

Links are created only for files which qualify as a "note" for our
purposes ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]). Users who need to link to Denote files from
anywhere, can write a simple command to that effect:

#+begin_src emacs-lisp
(defun my-denote-link-global (file file-type description &optional id-only)
  "Like the `denote-link', but works in any buffer.
The FILE, FILE-TYPE, DESCRIPTION, and ID-ONLY have the same meaning as
in `denote-link'."
  (interactive
   (let* ((file (denote-file-prompt nil "Link to FILE"))
          (file-type (denote-filetype-heuristics buffer-file-name))
          (description (when (file-exists-p file)
                         (denote--link-get-description file))))
     (list file file-type description current-prefix-arg)))
  (unless (file-exists-p file)
    (user-error "The linked file does not exists"))
  (let ((beg (point)))
    (denote--delete-active-region-content)
    (insert (denote-format-link file description file-type id-only))
    (unless (derived-mode-p 'org-mode)
      (make-button beg (point) 'type 'denote-link-button))))
#+end_src

#+vindex: denote-faces-link
Links are styled with the ~denote-faces-link~ face, which looks exactly
like an ordinary link by default.  This is just a convenience for the
user/theme in case they want =denote:= links to remain distinct from
other links.

** The ~denote-org-store-link-to-heading~ user option
:PROPERTIES:
:CUSTOM_ID: h:d99de1fb-b1b7-4a74-8667-575636a4d6a4
:END:

#+vindex: denote-org-store-link-to-heading
The user option ~denote-org-store-link-to-heading~ determines whether
~org-store-link~ links to the current Org heading (such links are
merely "stored" and need to be inserted afterwards with the command
~org-insert-link~). Note that the ~org-capture~ command uses the
~org-link~ internally if it has to store a link.

When its value is non-nil, ~org-store-link~ stores a link to the
current Org heading inside the Denote Org file. If the heading does
not have a =CUSTOM_ID=, it creates it and includes it in the heading's
=PROPERTIES= drawer. If a =CUSTOM_ID= exists, ~org-store-link~ use it
as-is.

This makes the resulting link a combination of the =denote:= link type,
pointing to the identifier of the current file, plus the value of the
heading's =CUSTOM_ID=, such as:

- =[[denote:20240118T060608][Some test]]=
- =[[denote:20240118T060608::#h:eed0fb8e-4cc7-478f-acb6-f0aa1a8bffcd][Some test::Heading text]]=

Both lead to the same Denote file, but the latter jumps to the heading
with the given =CUSTOM_ID=. Notice that the link to the heading also
has a different description, which includes the heading text.

The value of the =CUSTOM_ID= is determined by the Org user option
~org-id-method~. The sample shown above uses the default UUID
infrastructure.

If ~denote-org-store-link-to-heading~ is set to a nil value, the
command ~org-store-link~ only stores links to the Denote file (using
its identifier), but not to the given heading. This is what Denote was
doing in versions prior to =2.3.0=.

Note that the optional extension =denote-org-extras.el= defines the command
~denote-org-extras-link-to-heading~, which always links to a file+heading
regardless of the aforementioned user option ([[#h:fc1ad245-ec08-41be-8d1e-7153d99daf02][Insert link to an Org file with a further pointer to a heading]]).

[ This feature only works in Org mode files, as other file types do
  not have a linking mechanism that handles unique identifiers for
  headings or other patterns to jump to. If ~org-store-link~ is
  invoked in one such file, it captures only the Denote identifier of
  the file, even if this user option is set to a non-nil value. ]

** Insert link to an Org file with a further pointer to a heading
:PROPERTIES:
:CUSTOM_ID: h:fc1ad245-ec08-41be-8d1e-7153d99daf02
:END:

#+findex: denote-org-extras-link-to-heading
As part of the optional =denote-org-extras.el= extension, the command
~denote-org-extras-link-to-heading~ prompts for a link to an Org file
and then asks for a heading therein, using minibuffer completion. Once
the user provides input at the two prompts, the command inserts a link
at point which has the following pattern: =[[denote:IDENTIFIER::#ORG-HEADING-CUSTOM-ID]][Description::Heading text]]=.

Because only Org files can have links to individual headings, the
command ~denote-org-extras-link-to-heading~ prompts only for Org files
(i.e. files which include the =.org= extension). Remember that Denote
works with many file types ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

This feature is similar to the concept of the user option ~denote-org-store-link-to-heading~
([[#h:d99de1fb-b1b7-4a74-8667-575636a4d6a4][The ~denote-org-store-link-to-heading~ user option]]). It is, however,
interactive and differs in the directionality of the action. With that
user option, the command ~org-store-link~ will generate a =CUSTOM_ID=
for the current heading (or capture the value of one as-is), giving
the user the option to then call ~org-insert-link~ wherever they see
fit. By contrast, the command ~denote-org-extras-link-to-heading~
prompts for a file, then a heading, and inserts the link at point.

Just as with files, it is possible to show backlinks for the given
heading ([[#h:604bf92a-908a-485c-98b8-37ccae559afd][Backlinks for Org headings]]).

** Insert links matching a regexp
:PROPERTIES:
:CUSTOM_ID: h:9bec2c83-36ca-4951-aefc-7187c5463f90
:END:

#+findex: denote-add-links
The command ~denote-add-links~ adds links at point matching a
regular expression or plain string.  The links are inserted as a
typographic list, such as:

#+begin_example
- link1
- link2
- link3
#+end_example

Each link is formatted according to the file type of the current note,
as explained further above about the ~denote-link~ command.  The current
note is excluded from the matching entries (adding a link to itself is
pointless).

When called with a prefix argument (=C-u=) ~denote-add-links~ will
format all links as =[[denote:IDENTIFIER]]=, hence a typographic list:

#+begin_example
- [[denote:IDENTIFIER-1]]
- [[denote:IDENTIFIER-2]]
- [[denote:IDENTIFIER-3]]
#+end_example

Same examples of a regular expression that can be used with this
command:

- =journal= match all files which include =journal= anywhere in their
  name.

- =_journal= match all files which include =journal= as a keyword.

- =^2022.*_journal= match all file names starting with =2022= and
  including the keyword =journal=.

- =\.txt= match all files including =.txt=.  In practical terms, this
  only applies to the file extension, as Denote automatically removes
  dots (and other characters) from the base file name.

If files are created with ~denote-sort-keywords~ as non-nil (the
default), then it is easy to write a regexp that includes multiple
keywords in alphabetic order:

- =_denote.*_package= match all files that include both the =denote= and
  =package= keywords, in this order.

- =\(.*denote.*package.*\)\|\(.*package.*denote.*\)= is the same as
  above, but out-of-order.

Remember that regexp constructs only need to be escaped once (like =\|=)
when done interactively but twice when called from Lisp.  What we show
above is for interactive usage.

Links are created only for files which qualify as a "note" for our
purposes ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).

** Insert link to file with signature
:PROPERTIES:
:CUSTOM_ID: h:066e5221-9844-474b-8858-398398646f86
:END:

#+findex: denote-link-with-signature
The command ~denote-link-with-signature~ prompts for a file among
those that contain a ===SIGNATURE= and inserts a link to it.  The
description of the link includes the text of the signature and that of
the file's title, if any.  For example, a link to the following file:

: 20230925T144303==abc--my-first-signature-note__denote_testing.txt

will get this link: =[[denote:20230925T144303][abc My first signature note]]=.

For more advanced uses, refer to the doc string of the ~denote-link~
function ([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]).

** Insert links from marked files in Dired
:PROPERTIES:
:CUSTOM_ID: h:9cbb692e-5d8a-44a6-9193-899a07872a07
:END:

#+findex: denote-link-dired-marked-notes
The command ~denote-link-dired-marked-notes~ is similar to
~denote-add-links~ in that it inserts in the buffer a typographic list
of links to Denote notes ([[#h:9bec2c83-36ca-4951-aefc-7187c5463f90][Insert links matching a regexp]]).  Though
instead of reading a regular expression, it lets the user mark files
in Dired and link to them.  This should be easier for users of all
skill levels, instead of having to write a potentially complex regular
expression.

If there are multiple buffers that visit a Denote note, this command
will ask to select one among them, using minibuffer completion.  If
there is only one buffer, it will operate in it outright.  If there are
no buffers, it will produce an error.

With optional =ID-ONLY= as a prefix argument (=C-u= by default), the
command inserts links with just the identifier, which is the same
principle as with ~denote-link~ and others ([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]).

The command ~denote-link-dired-marked-notes~ is meant to be used from a
Dired buffer.

As always, links are created only for files which qualify as a "note"
for our purposes ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).

** Link to an existing note or create a new one
:PROPERTIES:
:CUSTOM_ID: h:b6056e6b-93df-4e6b-a778-eebd105bac46
:END:

In one's note-taking workflow, there may come a point where they are
expounding on a certain topic but have an idea about another subject
they would like to link to ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).  The user can always rely on
the other linking facilities we have covered herein to target files that
already exist.  Though they may not know whether they already have notes
covering the subject or whether they would need to write new ones.  To
this end, Denote provides two convenience commands:

#+findex: denote-link-after-creating
+ ~denote-link-after-creating~ :: Create new note in the background and
  link to it directly.

  Use ~denote~ interactively to produce the new note.  Its doc string or
  this manual explains which prompts will be used and under what
  conditions ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).

  With optional =ID-ONLY= as a prefix argument (this is the =C-u= key,
  by default) create a link that consists of just the identifier.  Else
  try to also include the file's title.  This has the same meaning as in
  ~denote-link~ ([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]).

  IMPORTANT NOTE: Normally, ~denote~ does not save the buffer it
  produces for the new note ([[#h:bf80f4cd-6f56-4f7c-a991-8573161e4511][The ~denote-save-buffer-after-creation~ option]]).
  This is a safety precaution to not write to disk unless the user
  wants it (e.g. the user may choose to kill the buffer, thus
  cancelling the creation of the note). However, for this command the
  creation of the note happens in the background and the user may miss
  the step of saving their buffer. We thus have to save the buffer in
  order to (i) establish valid links, and (ii) retrieve whatever front
  matter from the target file.

#+findex: denote-link-after-creating-with-command
+ ~denote-link-after-creating-with-command~ :: This command is like
  ~denote-link-after-creating~ except it prompts for a note-creating
  command ([[*Points of entry][Points of entry]]).  Use this to, for example, call
  ~denote-signature~ so that the newly created note has a signature as
  part of its file name.  Optional =ID-ONLY= has the same meaning as
  in the command ~denote-link-after-creating~.

#+findex: denote-link-or-create
+ ~denote-link-or-create~ :: Use ~denote-link~ on =TARGET= file,
  creating it if necessary.

  If =TARGET= file does not exist, call ~denote-link-after-creating~
  which runs the ~denote~ command interactively to create the file.  The
  established link will then be targeting that new file.

  If =TARGET= file does not exist, add the user input that was used to
  search for it to the history of the ~denote-file-prompt~.  The user
  can then retrieve and possibly further edit their last input, using
  it as the newly created note's actual title.  At the ~denote-file-prompt~
  type =M-p= with the default key bindings, which calls ~previous-history-element~.

  With optional =ID-ONLY= as a prefix argument create a link with just
  the file's identifier.  This has the same meaning as in ~denote-link~.

  This command has the alias ~denote-link-to-existing-or-new-note~,
  which helps with discoverability.

#+findex: denote-link-or-create-with-command
+ ~denote-link-or-create-with-command~ :: This is like the above,
  except when it is about to create the new note it first prompts for
  the specific file-creating command to use ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]). For
  example, the user may want to specify a signature for this new file,
  so they can select the ~denote-signature~ command.

In all of the above, an optional prefix argument (=C-u= by default)
creates a link that consists of just the identifier.  This has the
same meaning as in the regular ~denote-link~ command.

Denote provides similar functionality for opening an existing note or
creating a new one ([[#h:ad91ca39-cf10-4e16-b224-fdf78f093883][Open an existing note or create it if missing]]).

** The backlinks' buffer
:PROPERTIES:
:CUSTOM_ID: h:c73f1f68-e214-49d5-b369-e694f6a5d708
:END:

#+findex: denote-backlinks
The command ~denote-backlinks~ produces a bespoke buffer which
displays backlinks to the current note.  A "backlink" is a link back
to the present entry.

By default, the backlinks' buffer is designed to display the file name
of the note linking to the current entry.  Each file name is presented
on its own line, like this:

#+begin_example
Backlinks to "On being honest" (20220614T130812)
------------------------------------------------

20220614T145606--let-this-glance-become-a-stare__journal.txt
20220616T182958--feeling-butterflies-in-your-stomach__journal.txt
#+end_example

#+vindex: denote-backlinks-show-context
When the user option ~denote-backlinks-show-context~ is non-nil, the
backlinks' buffer displays the line on which a link to the current
note occurs.  It also shows multiple occurrences, if present.  It looks
like this (and has the appropriate fontification):

#+begin_example
Backlinks to "On being honest" (20220614T130812)
------------------------------------------------

20220614T145606--let-this-glance-become-a-stare__journal.txt
37: growing into it: [[denote:20220614T130812][On being honest]].
64: As I said in [[denote:20220614T130812][On being honest]] I have never
20220616T182958--feeling-butterflies-in-your-stomach__journal.txt
62: indifference.  In [[denote:20220614T130812][On being honest]] I alluded
#+end_example

Note that the width of the lines in the context depends on the
underlying file.  In the above example, the lines are split at the
~fill-column~.  Long lines will show up just fine.  Also note that the
built-in user option ~xref-truncation-width~ can truncate long lines
to a given maximum number of characters.

[[#h:893eec49-d7be-4603-bcff-fcc247244011][Speed up backlinks' buffer creation?]]

#+findex: denote-backlinks-mode
#+vindex: denote-backlinks-mode-map
The backlinks' buffer runs the major-mode ~denote-backlinks-mode~.  It
binds keys to move between links with =n= (next) and =p= (previous).
These are stored in the ~denote-backlinks-mode-map~ (use =M-x
describe-mode= (=C-h m=) in an unfamiliar buffer to learn more about
it).  When the user option ~denote-backlinks-show-context~ is non-nil,
all relevant Xref key bindings are fully functional: again, check
~describe-mode~.

The backlinking facility uses Emacs' built-in Xref infrastructure.  On
some operating systems, the user may need to add certain executables
to the relevant environment variable.

[[#h:42f6b07e-5956-469a-8294-17f9cf62eb2b][Why do I get "Search failed with status 1" when I search for backlinks?]]

Backlinks to the current file can also be visited by using the
minibuffer completion interface with the ~denote-find-backlink~
command ([[#h:1bc2adad-dca3-4878-b9f0-b105d5dec6f4][Visiting linked files via the minibuffer]]).

#+vindex: denote-link-backlinks-display-buffer-action
The placement of the backlinks' buffer is subject to the user option
~denote-link-backlinks-display-buffer-action~.  Due to the nature of the
underlying ~display-buffer~ mechanism, this inevitably is a relatively
advanced feature.  By default, the backlinks' buffer is displayed below
the current window.  The doc string of our user option includes a sample
configuration that places the buffer in a left side window instead.
Reproducing it here for the sake of convenience:

#+begin_src emacs-lisp
(setq denote-link-backlinks-display-buffer-action
      '((display-buffer-reuse-window
         display-buffer-in-side-window)
        (side . left)
        (slot . 99)
        (window-width . 0.3)
        (dedicated . t)
        (preserve-size . (t . t))))
#+end_src

*** Backlinks for Org headings
:PROPERTIES:
:CUSTOM_ID: h:604bf92a-908a-485c-98b8-37ccae559afd
:END:

The optional =denote-org-extras.el= can produce Denote links to
individual headings ([[#h:fc1ad245-ec08-41be-8d1e-7153d99daf02][Insert link to an Org file with a further pointer to a heading]]).
It is then possible to produce a corresponding backlinks buffer with
the command ~denote-org-extras-backlinks-for-heading~. The resulting
buffer behaves the same way as the standard backlinks buffer we
provide ([[#h:c73f1f68-e214-49d5-b369-e694f6a5d708][The backlinks' buffer]]).

** Writing metanotes
:PROPERTIES:
:CUSTOM_ID: h:6060a7e6-f179-4d42-a9de-a9968aaebecc
:END:

A "metanote" is an entry that describes other entries who have something
in common.  Writing metanotes can be part of a workflow where the user
periodically reviews their work in search of patterns and deeper
insights.  For example, you might want to read your journal entries from
the past year to reflect on your experiences, evolution as a person, and
the like.

The commands ~denote-add-links~, ~denote-link-dired-marked-notes~ are
suited for this task.

[[#h:9bec2c83-36ca-4951-aefc-7187c5463f90][Insert links matching a regexp]].

[[#h:9cbb692e-5d8a-44a6-9193-899a07872a07][Insert links from marked files in Dired]].

You will create your metanote the way you use Denote ordinarily
(metanotes may have the =metanote= keyword, among others), write an
introduction or however you want to go about it, invoke the command
which inserts multiple links at once (see the above-cited nodes), and
continue writing.

Metanotes can serve as entry points to groupings of individual notes.
They are not the same as a filtered list of files, i.e. what you would
do in Dired or the minibuffer where you narrow the list of notes to a
given query.  Metanotes contain the filtered list plus your thoughts
about it.  The act of purposefully grouping notes together and
contemplating on their shared patterns is what adds value.

Your future self will appreciate metanotes for the function they serve
in encapsulating knowledge, while current you will be equipped with the
knowledge derived from the deliberate self-reflection.

** Visiting linked files via the minibuffer
:PROPERTIES:
:CUSTOM_ID: h:1bc2adad-dca3-4878-b9f0-b105d5dec6f4
:END:

#+findex: denote-find-link
Denote has a major-mode-agnostic mechanism to collect all linked file
references in the current buffer and return them as an appropriately
formatted list.  This list can then be used in interactive commands.
The ~denote-find-link~ is such a command.  It uses minibuffer
completion to visit a file that is linked to from the current note.
The candidates have the correct metadata, which is ideal for
integration with other standards-compliant tools ([[#h:8ed2bb6f-b5be-4711-82e9-8bee5bb06ece][Extending Denote]]).
For instance, a package such as =marginalia= will display accurate
annotations, while the =embark= package will be able to work its magic
such as in exporting the list into a filtered Dired buffer (i.e. a
familiar Dired listing with only the files of the current minibuffer
session).

#+findex: denote-find-backlink
To visit backlinks to the current note via the minibuffer, use
~denote-find-backlink~.  This is an alternative to placing backlinks
in a dedicated buffer ([[#h:c73f1f68-e214-49d5-b369-e694f6a5d708][The backlinks' buffer]]).

** Convert =denote:= links to =file:= links
:PROPERTIES:
:CUSTOM_ID: h:ed220cac-7dcb-4bb7-9243-1bb85e452e5f
:END:

Sometimes the user needs to translate all =denote:= link types to
their =file:= equivalent. This may be because some other tool does not
recognise =denote:= links (or other custom links types---which are a
standard feature of Org, by the way). The user thus needs to (i)
either make a copy of their Denote note or edit the existing one, and
(ii) convert all links to the generic =file:= link type that
external/other programs understand.

The optional extension =denote-org-extras.el= contains two commands
that are relevant for this use-case:

#+findex: denote-org-extras-convert-links-to-file-type
+ Convert =denote:= links to =file:= links :: The command ~denote-org-extras-convert-links-to-file-type~
  goes through the buffer to find all =denote:= links. It gets the
  identifier of the link and resolves it to the actual file system
  path. It then replaces the match so that the link is written with
  the =file:= type and then the file system path. The optional search
  terms and/or link description are preserved ([[#h:fc1ad245-ec08-41be-8d1e-7153d99daf02][Insert link to an Org file with a further pointer to a heading]]).

#+findex: denote-org-extras-convert-links-to-denote-type
+ Convert =file:= links to =denote:= links :: The command ~denote-org-extras-convert-links-to-denote-type~
  behaves like the one above. The difference is that it finds the file
  system path and converts it into its identifier.

** Fontify links in non-Org buffers
:PROPERTIES:
:CUSTOM_ID: h:156c5ea3-147b-4f9d-a404-86a00558c60a
:END:

#+findex: denote-fontify-links-mode
Denote links are automatically fontified in Org buffers ([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]).
This means that Org recognises the link and applies the relevant
properties to it to make it clickable/actionable. Other major modes,
such as ~markdown-mode~ (for =.md= files) or ~text-mode~ (for =.txt=
files) do not have this feature built into them. Users can still get
the same behaviour as with Org by activating the ~denote-fontify-links-mode~.

The ~denote-fontify-links-mode~ is a buffer-local minor mode. Users can enable
it automatically in plain text files that correspond to denote notes with
something like this:

#+begin_src emacs-lisp
(add-hook 'text-mode-hook #'denote-fontify-links-mode-maybe)
#+end_src

The ~text-mode-hook~ applies to all modes derived from ~text-mode~, including
~markdown-mode~. Though a more explicit setup does no harm:

#+begin_src emacs-lisp
(add-hook 'markdown-mode-hook #'denote-fontify-links-mode-maybe)
#+end_src

Because Org already recognises =denote:= links, the function
~denote-fontify-links-mode-maybe~ will not enable the mode
~denote-fontify-links-mode~ in Org buffers.

#+findex: denote-link-markdown-follow
In files whose major mode is ~markdown-mode~, the default key binding
=C-c C-o= (which calls the command ~markdown-follow-thing-at-point~)
correctly resolves =denote:= links. Interested users can refer to the
function ~denote-link-markdown-follow~ for the implementation details.

** Miscellaneous information about links
:PROPERTIES:
:CUSTOM_ID: h:dd8f2231-8d77-49b9-acc4-af525c68b271
:END:

*** Aliases for the linking commands
:PROPERTIES:
:CUSTOM_ID: h:078856d9-f608-43a8-be84-f2cad4c27d0e
:END:

#+findex: denote-insert-link
#+findex: denote-show-backlinks-buffer
#+findex: denote-link-insert-links-matching-regexp
For convenience, the ~denote-link~ command has an alias called
~denote-insert-link~.  The ~denote-backlinks~ can also be used as
~denote-show-backlinks-buffer~.  While ~denote-add-links~ is
aliased ~denote-link-insert-links-matching-regexp~.  The purpose of
these aliases is to offer alternative, more descriptive names of
select commands.

*** The ~denote-link-description-function~ to format links
:PROPERTIES:
:CUSTOM_ID: h:f634427c-b451-40e2-993e-e00ac627af68
:END:

#+vindex: denote-link-description-function
The user option ~denote-link-description-function~ takes as its value
the symbol of a function. This is used to format the text of the link.
The default function inserts the title. If the file has a signature,
it includes that as well, prepending it to the title.

The function specified accepts a single =FILE= argument and returns
the description as a string.

* Choose which commands to prompt for
:PROPERTIES:
:CUSTOM_ID: h:98c732ac-da0e-4ebd-a0e3-5c47f9075e51
:END:

#+vindex: denote-commands-for-new-notes
The user option ~denote-commands-for-new-notes~ specifies a list of
commands that are available at the ~denote-command-prompt~.  This
prompt is used by Denote commands that ask the user how to create a
new note, as described elsewhere in this manual:

- [[#h:ad91ca39-cf10-4e16-b224-fdf78f093883][Open an existing note or create it if missing]]
- [[#h:b6056e6b-93df-4e6b-a778-eebd105bac46][Link to a note or create it if missing]]

The default value includes all the basic file-creating commands
([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).  Users may customise this value if (i) they only
want to see fewer options and/or (ii) wish to include their own custom
command in the list ([[#h:11946562-7eb0-4925-a3b5-92d75f1f5895][Write your own convenience commands]]).

* Fontification in Dired
:PROPERTIES:
:CUSTOM_ID: h:337f9cf0-9f66-45af-b73f-f6370472fb51
:END:

#+findex: denote-dired-mode
One of the upsides of Denote's file-naming scheme is the predictable
pattern it establishes, which appears as a near-tabular presentation in
a listing of notes (i.e. in Dired).  The ~denote-dired-mode~ can help
enhance this impression, by fontifying the components of the file name
to make the date (identifier) and keywords stand out.

There are two ways to set the mode.  Either use it for all directories,
which probably is not needed:

#+begin_src emacs-lisp
(add-hook 'dired-mode-hook #'denote-dired-mode)
#+end_src

#+vindex: denote-dired-directories
#+findex: denote-dired-mode-in-directories
Or configure the user option ~denote-dired-directories~ and then set up
the function ~denote-dired-mode-in-directories~:

#+begin_src emacs-lisp
;; We use different ways to specify a path for demo purposes.
(setq denote-dired-directories
      (list denote-directory
            (thread-last denote-directory (expand-file-name "attachments"))
            (expand-file-name "~/Documents/vlog")))

(add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)
#+end_src

#+vindex: denote-dired-directories-include-subdirectories
The user option ~denote-dired-directories-include-subdirectories~
specifies whether the ~denote-dired-directories~ also cover their
subdirectories. By default they do not. Set this option to ~t~ to
include subdirectories as well.

The faces we define for this purpose are:

#+vindex: denote-faces-date
#+vindex: denote-faces-delimiter
#+vindex: denote-faces-extension
#+vindex: denote-faces-keywords
#+vindex: denote-faces-signature
#+vindex: denote-faces-subdirectory
#+vindex: denote-faces-time
#+vindex: denote-faces-title
+ ~denote-faces-date~
+ ~denote-faces-delimiter~
+ ~denote-faces-extension~
+ ~denote-faces-keywords~
- ~denote-faces-signature~
+ ~denote-faces-subdirectory~
+ ~denote-faces-time~
+ ~denote-faces-title~

For more control, we also provide these:

#+vindex denote-faces-year
#+vindex denote-faces-month
#+vindex denote-faces-day
#+vindex denote-faces-hour
#+vindex denote-faces-minute
#+vindex denote-faces-second
+ ~denote-faces-year~
+ ~denote-faces-month~
+ ~denote-faces-day~
+ ~denote-faces-hour~
+ ~denote-faces-minute~
+ ~denote-faces-second~

For the time being, the =diredfl= package is not compatible with this
facility.

The ~denote-dired-mode~ does not only fontify note files that were
created by Denote: it covers every file name that follows our naming
conventions ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).  This is particularly useful for
scenaria where, say, one wants to organise their collection of PDFs and
multimedia in a systematic way (and, perhaps, use them as attachments
for the notes Denote produces if you are writing Org notes and are using
its standand attachments' facility).

* Automatically rename Denote buffers
:PROPERTIES:
:CUSTOM_ID: h:3ca4db16-8f26-4d7d-b748-bac48ae32d69
:END:

#+findex: denote-rename-buffer-mode
The minor mode ~denote-rename-buffer-mode~ provides the means to
automatically rename the buffer of a Denote file upon visiting the
file. This applies both to existing Denote files as well as new ones
([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]). Enable the mode thus:

#+begin_src emacs-lisp
(denote-rename-buffer-mode 1)
#+end_src

#+vindex: denote-rename-buffer-function
#+findex: denote-rename-buffer
#+vindex: denote-rename-buffer-format
Buffers are named by applying the function specified in the user
option ~denote-rename-buffer-function~. The default function is
~denote-rename-buffer~: it renames the buffer based on the template
set in the user option ~denote-rename-buffer-format~. By default, the
formatting template targets only the =TITLE= component of the file
name ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]). Other fields are explained elsewhere in
this manual ([[#h:35507c18-35b1-41b9-9d80-52f54fcef3cb][The denote-rename-buffer-format]]).

Note that renaming a buffer is not the same as renaming a file
([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]). The former is just for convenience inside of Emacs.
Whereas the latter is for writing changes to disk, making them
available to all programs.

** The ~denote-rename-buffer-format~ option
:PROPERTIES:
:CUSTOM_ID: h:35507c18-35b1-41b9-9d80-52f54fcef3cb
:END:

The user option ~denote-rename-buffer-format~ controls how the
function ~denote-rename-buffer~ chooses the name of the
buffer-to-be-renamed.

The value of this user option is a string. The following specifiers
are placeholders for Denote file name components ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]):

#+vindex: denote-buffer-has-backlinks-string
- The =%t= is the Denote =TITLE= of the file.
- The =%i= is the Denote =IDENTIFIER= of the file.
- The =%d= is the same as =%i= (=DATE= mnemonic).
- The =%s= is the Denote =SIGNATURE= of the file.
- The =%k= is the Denote =KEYWORDS= of the file.
- The =%b= is an indicator of whether or not the file has backlinks
  pointing to it. The indicator string is defined in the user option
  ~denote-buffer-has-backlinks-string~ [ Part of {{{development-version}}} ].
- The =%%= is a literal percent sign.

In addition, the following flags are available for each of the specifiers:

- =0= :: Pad to the width, if given, with zeros instead of spaces.
- =-= :: Pad to the width, if given, on the right instead of the left.
- =<= :: Truncate to the width and precision, if given, on the left.
- =>= :: Truncate to the width and precision, if given, on the right.
- =^= :: Convert to upper case.
- =_= :: Convert to lower case.

When combined all together, the above are written thus:

: %<flags><width><precision>SPECIFIER-CHARACTER

Any other string it taken as-is.  Users may want, for example, to
include some text that makes Denote buffers stand out, such as
a =[D]= prefix.  Examples:

#+begin_src emacs-lisp
;; Use the title prefixed with the backlink indicator (default)
(setq denote-rename-buffer-format "%b%t")

;; Customize what the backlink indicator looks like
(setq denote-buffer-has-backlinks-string "!! ")

;; Use the title and keywords with some emoji in between
(setq denote-rename-buffer-format "%t 🤨 %k")

;; Use the title with a literal "[D]" before it
(setq denote-rename-buffer-format "[D] %t")
#+end_src

Users who need yet more flexibility are best served by writing their
own function and assigning it to the ~denote-rename-buffer-function~.

* Use Org dynamic blocks
:PROPERTIES:
:CUSTOM_ID: h:8b542c50-dcc9-4bca-8037-a36599b22779
:END:

[ As part of version 2.3.0, all dynamic blocks are defined in the file
  =denote-org-extras.el=. The file which was once called
  =denote-org-dblock.el= contains aliases for the new function names
  and dipslays a warning about its deprecation. There is no need to
  ~require~ the ~denote-org-extras~ feature because all of Denote's
  Org dynamic blocks are autoloaded (meaning that they work as soon as
  they are used). For backward compatibility, all dynamic blocks
  retain their original names as an alias for the newer one. ]

Denote can optionally integrate with Org mode's "dynamic blocks"
facility. This means that it can use special blocks that are evaluated
with =C-c C-x C-u= (~org-dblock-update~) to generate their contents.
The following subsections describe the types of Org dynamic blocks
provided by Denote.

- [[#h:50160fae-6515-4d7d-9737-995ad925e64b][Org dynamic blocks to insert links or backlinks]]
- [[#h:f15fa143-5036-416f-9bff-1bcabbb03456][Org dynamic block to insert file contents]]

A dynamic block gets its contents by evaluating a function that
corresponds to the type of block. The block type and its parameters
are stated in the opening =#+BEGIN= line. Typing =C-c C-x C-u=
(~org-dblock-update~) with point on that line runs (or re-runs) the
associated function with the given parameters and populates the
block's contents accordingly.

Dynamic blocks are particularly useful for metanote entries that
reflect on the status of earlier notes ([[#h:6060a7e6-f179-4d42-a9de-a9968aaebecc][Writing metanotes]]).

The Org manual describes the technicalities of Dynamic Blocks.
Evaluate:

#+begin_src emacs-lisp
(info "(org) Dynamic Blocks")
#+end_src

** Org dynamic blocks to insert links or backlinks
:PROPERTIES:
:CUSTOM_ID: h:50160fae-6515-4d7d-9737-995ad925e64b
:END:

[ As part of version 2.3.0, all dynamic blocks are defined in the file
  =denote-org-extras.el=. The file which was once called
  =denote-org-dblock.el= contains aliases for the new function names
  and dipslays a warning about its deprecation. There is no need to
  ~require~ the ~denote-org-extras~ feature because all of Denote's
  Org dynamic blocks are autoloaded (meaning that they work as soon as
  they are used). For backward compatibility, all dynamic blocks
  retain their original names as an alias for the newer one. ]

#+findex: denote-org-extras-dblock-insert-links
The =denote-links= block can be inserted at point with the command
~denote-org-extras-dblock-insert-links~ or by manually including the
following in an Org file:

: #+BEGIN: denote-links :regexp "YOUR REGEXP HERE" :sort-by-component nil :reverse-sort nil :id-only nil
:
: #+END:

The =denote-links= block is also registered as an option for the
command ~org-dynamic-block-insert-dblock~.

Type =C-c C-x C-u= (~org-dblock-update~) with point on the =#+BEGIN=
line to update the block.

- The =:regexp= parameter is mandatory. Its value is a string and its
  behaviour is the same as that of the ~denote-add-links~ command
  ([[#h:9bec2c83-36ca-4951-aefc-7187c5463f90][Insert links matching a regexp]]). Concretely, it produces a
  typographic list of links to files matching the giving regular
  expression. The value of the =:regexp= parameter may also be of the
  form read by the ~rx~ macro (Lisp notation instead of a string), as
  explained in the Emacs Lisp Reference Manual (evaluate this code to
  read the documentation: =(info "(elisp) Rx Notation")=). Note that
  you do not need to write an actual regular expression to get
  meaningful results: even something like =_journal= will work to
  include all files that have a =journal= keyword.

- The =:sort-by-component= parameter is optional. It sorts the files
  by the given Denote file name component. The value it accepts is an
  unquoted symbol among =title=, =keywords=, =signature=, =identifier=.
  When using the command ~denote-org-extras-dblock-insert-files~, this
  parameter is automatically inserted together with the (=:regexp=
  parameter) and the user is prompted for a file name component.

- The =:reverse-sort= parameter is optional. It reverses the order in
  which files appear in. This is meaningful even without the presence
  of the parameter =:sort-by-component=, though it also combines with
  it.

- The =:id-only= parameter is optional. It accepts a ~t~ value, in
  which case links are inserted without a description text but only
  with the identifier of the given file. This has the same meaning as
  with the ~denote-link~ command and related facilities ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).

- An optional =:block-name= parameter can be specified with a string
  value to add a =#+name= to the results. This is useful for further
  processing using Org facilities (a feature that is outside Denote's
  purview).

#+findex: denote-org-extras-dblock-insert-backlinks
The same as above except for the =:regexp= parameter are true for the
=denote-backlinks= block. The block can be inserted at point with the
command ~denote-org-extras-dblock-insert-backlinks~ or by manually writing
this in an Org file:

: #+BEGIN: denote-backlinks :sort-by-component nil :reverse-sort nil :id-only nil
:
: #+END:

#+findex: denote-org-extras-dblock-insert-missing-links
Finally, the =denote-missing-links= block is available with the
command ~denote-org-extras-dblock-insert-missing-links~. It is like
the aforementioned =denote-links= block, except it only lists links to
files that are not present in the current buffer. The parameters are
otherwise the same:

: #+BEGIN: denote-missing-links :regexp "YOUR REGEXP HERE" :sort-by-component nil :reverse-sort nil :id-only nil
:
: #+END:

Remember to type =C-c C-x C-u= (~org-dblock-update~) with point on the
=#+BEGIN= line to update the block.

** Org dynamic block to insert file contents
:PROPERTIES:
:CUSTOM_ID: h:f15fa143-5036-416f-9bff-1bcabbb03456
:END:

[ As part of version 2.3.0, all dynamic blocks are defined in the file
  =denote-org-extras.el=. The file which was once called
  =denote-org-dblock.el= contains aliases for the new function names
  and dipslays a warning about its deprecation. There is no need to
  ~require~ the ~denote-org-extras~ feature because all of Denote's
  Org dynamic blocks are autoloaded (meaning that they work as soon as
  they are used). For backward compatibility, all dynamic blocks
  retain their original names as an alias for the newer one. ]

Denote can optionally use Org's dynamic blocks facility to produce a
section that lists entire file contents ([[#h:8b542c50-dcc9-4bca-8037-a36599b22779][Use Org dynamic blocks]]).
This works by instructing Org to match a regular expression of Denote
files, the same way we do with Denote links ([[#h:9bec2c83-36ca-4951-aefc-7187c5463f90][Insert links matching a regexp]]).

This is useful to, for example, compile a dynamically concatenated
list of scattered thoughts on a given topic, like =^2023.*_emacs= for
a long entry that incorporates all the notes written in 2023 with the
keyword =emacs=.

#+findex: denote-org-extras-dblock-insert-files
To produce such a block, call the command ~denote-org-extras-dblock-insert-files~
or manually write the following block in an Org file and then type
 =C-c C-x C-u= (~org-dblock-update~) on the =#+BEGIN= line to run it
(do it again to recalculate the block):

: #+BEGIN: denote-files :regexp "YOUR REGEXP HERE"
:
: #+END:

To fully control the output, include these additional optional
parameters, which are described further below:

: #+BEGIN: denote-files :regexp "YOUR REGEXP HERE" :sort-by-component nil :reverse-sort nil :no-front-matter nil :file-separator nil :add-links nil
:
: #+END:

- The =:regexp= parameter is mandatory. Its value is a string,
  representing a regular expression to match Denote file names. Its
  value may also be an ~rx~ expression instead of a string, as noted
  in the previous section ([[#h:50160fae-6515-4d7d-9737-995ad925e64b][Org dynamic blocks to insert links or backlinks]]).
  Note that you do not need to write an actual regular expression to
  get meaningful results: even something like =_journal= will work to
  include all files that have a =journal= keyword.

- The =:sort-by-component= parameter is optional. It sorts the files
  by the given Denote file name component. The value it accepts is an
  unquoted symbol among =title=, =keywords=, =signature=, =identifier=.
  When using the command ~denote-org-extras-dblock-insert-files~, this
  parameter is automatically inserted together with the (=:regexp=
  parameter) and the user is prompted for a file name component.

- The =:reverse-sort= parameter is optional. It reverses the order in
  which files appear in. This is meaningful even without the presence
  of the parameter =:sort-by-component=, though it also combines with
  it.

#+vindex: denote-org-extras-dblock-file-contents-separator
- The =:file-separator= parameter is optional. If it is omitted, then
  Denote will use no separator between the files it inserts. If the
  value is ~t~ the ~denote-org-extras-dblock-file-contents-separator~ is
  applied at the end of each file: it introduces some empty lines and
  a horizontal rule between them to visually distinguish individual
  files. If the =:file-separator= value is a string, it is used as the
  file separator (e.g. use ="\n"= to insert just one empty new line).

- The =:no-front-matter= parameter is optional. When set to a ~t~
  value, Denote tries to remove front matter from the files it is
  inserting in the dynamic block. The technique used to perform this
  operation is by removing all lines from the top of the file until
  the first empty line. This works with the default front matter that
  Denote adds, but is not 100% reliable with all sorts of user-level
  modifications and edits to the file. When the =:no-front-matter= is
  set to a natural number, Denote will omit that many lines from the
  top of the file.

- The =:add-links= parameter is optional. When it is set to a ~t~
  value, all files are inserted as a typographic list and are indented
  accordingly. The first line in each list item is a link to the file
  whose contents are inserted in the following lines. When the value
  is =id-only=, then links are inserted without a description text but
  only with the identifier of the given file. This has the same
  meaning as with the ~denote-link~ command and related facilities
  ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]). Remember that Org can fold the items in a
  typographic list the same way it does with headings. So even long
  files can be presented in this format without much trouble.

- An optional =:block-name= parameter can be specified with a string
  value to add a =#+name= to the results. This is useful for further
  processing using Org facilities (a feature that is outside Denote's
  purview).

* Sort files by component
:PROPERTIES:
:CUSTOM_ID: h:9fe01e63-f34f-4479-8713-f162a5ca865e
:END:

The =denote-sort.el= file is an optional extension to the core
functionality of Denote, which empowers users to sort files by the
given file name component ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

#+findex: denote-sort-dired
The command ~denote-sort-dired~ produces a Dired file listing with a
flat, filtered, and sorted set of files from the ~denote-directory~.
It does so by means of three minibuffer prompts:

1. It first asks for a regular expression with which to match Denote
   files. Remember that due to Denote's efficient file-naming scheme,
   you do not need to write some complex regular expression. Even
   something like =_journal= will match only files with a =journal=
   keyword.
2. Once the regular expression is provided, the command asks for a
   Denote file name component to sort files by. This is a symbol among
   =title=, =keywords=, =signature=, and =identifier=.
3. Finally, it asks a "yes or no" on whether to reverse the sort
   order.

The resulting Dired listing is a regular Dired buffer, unlike that of
~dired-virtual-mode~ ([[#h:d35d8d41-f51b-4139-af8f-9c8cc508e35b][Use ~dired-virtual-mode~ for arbitrary file listings]]).

The dynamic Org blocks that Denote defines to insert file contents
also use this feature ([[#h:f15fa143-5036-416f-9bff-1bcabbb03456][Org dynamic block to insert file contents]]).

DEVELOPMENT NOTE as of 2023-11-30 07:24 +0200: The sort mechanism will
be incorporated in more functions on a case-by-case basis, subject to
user feedback. For the time being, I am not documenting the functions
that are only accessed from Lisp. Do not hesitate to contact me
(Protesilaos) in person or on one of the development sources (mailing
list or GitHub/GitLab mirror) if you have a use-case where sorting
seems useful. I am happy to help but do not want to roll this feature
everywhere before eliciting relevant feedback: once we add it, we are
not going back.

* Keep a journal or diary
:PROPERTIES:
:CUSTOM_ID: h:4a6d92dd-19eb-4fcc-a7b5-05ce04da3a92
:END:

Denote provides a general-purpose mechanism to create new files that
broadly count as "notes" ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).  Such files can be daily
entries in a journal.  While it is possible to use the generic
~denote~ command to maintain a journal, we provide an optional set of
convenience options and commands as part of =denote-journal-extras.el=.
To use those, add the following the Denote configuration:

#+begin_src emacs-lisp
(require 'denote-journal-extras)
#+end_src

#+findex: denote-journal-extras-new-entry
#+vindex: denote-journal-extras-keyword
#+vindex: denote-journal-extras-directory
The command ~denote-journal-extras-new-entry~ creates a new entry in
the journal.  Such a file has the ~denote-journal-extras-keyword~,
which is =journal= by default ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).  The user can
set this keyword to an arbitrary string (single word is preferred).
New journal entries can be stored in the ~denote-directory~ or
subdirectory thereof.  To make it easier for the user, the new journal
entry will be placed in ~denote-journal-extras-directory~, which
defaults to a subdirectory of ~denote-directory~ called =journal=.

If ~denote-journal-extras-directory~ is nil, the ~denote-directory~ is
used.  Journal entries will thus be in a flat listing together with
all other notes.  They can still be retrieved easily by searching for
the ~denote-journal-extras-keyword~ ([[#h:1a953736-86c2-420b-b566-fb22c97df197][Features of the file-naming scheme for searching or filtering]]).

#+vindex: denote-journal-extras-title-format
Furthermore, the command ~denote-journal-extras-new-entry~ will use
the current date as the title of the new entry.  The exact format is
controlled by the user option ~denote-journal-extras-title-format~.
Acceptable values for ~denote-journal-extras-title-format~ and their
corresponding styles are:

| Symbol                  | Style                             |
|-------------------------+-----------------------------------|
| day                     | Monday                            |
| day-date-month-year     | Monday 19 September 2023          |
| day-date-month-year-24h | Monday 19 September 2023 20:49    |
| day-date-month-year-12h | Monday 19 September 2023 08:49 PM |

For example:

#+begin_src emacs-lisp
(setq denote-journal-extras-title-format 'day-date-month-year)
#+end_src

If the value of this user option is ~nil~, then
~denote-journal-extras-new-entry~ will prompt for a title.

The ~denote-journal-extras-new-entry~ command also accepts an optional
=DATE= argument. When called internactively, this is a universal
prefix (e.g. =C-u= with the default key bindings). With =DATE=, it
prompts for a date to create a new journal entry for. The date prompt
can optionally use the Org date+calendar selection interface
([[#h:e7ef08d6-af1b-4ab3-bb00-494a653e6d63][The ~denote-date-prompt-use-org-read-date~ option]]).

In terms of workflow, using the current date as the title is better
for maintaining a daily journal.  A prompt for an arbitrary title is
more suitable for those who like to keep a record of something like a
thought or event (though this can also be achieved by the regular
~denote~ command or maybe ~denote-subdirectory~).

#+vindex: denote-journal-extras-hook
The ~denote-journal-extras-new-entry~ command calls the normal hook
~denote-journal-extras-hook~ after it is done.  The user can leverage
this to produce consequences therefrom, such as to set a timer with
the ~tmr~ package from GNU ELPA ([[#h:4af1f81e-e93a-43cc-b344-960032a16d42][Journaling with a timer]]).

#+findex: denote-journal-extras-new-or-existing-entry
The command ~denote-journal-extras-new-or-existing-entry~ locates an
existing journal entry or creates a new one.  A journal entry is one
that has ~denote-journal-extras-keyword~ as part of its file name.  If
there are multiple journal entries for the current date, it prompts
for one among them using minibuffer completion.  If there is only one,
it visits it outright.  If there is no journal entry, it creates one
by calling ~denote-journal-extra-new-entry~ (as described above).

#+findex: denote-journal-extras-link-or-create-entry
The command ~denote-journal-extras-link-or-create-entry~ links to the
journal entry for today or creates it in the background, if missing,
and then links to it from the current file. If there are multiple
journal entries for the same day, it prompts to select one among them
and then links to it. When called with an optional prefix argument
(such as =C-u= with default key bindings), the command prompts for a
date and then performs the aforementioned. With a double prefix
argument (=C-u C-u=), it also produces a link whose description
includes just the file's identifier.

** Journaling with a timer
:PROPERTIES:
:CUSTOM_ID: h:4af1f81e-e93a-43cc-b344-960032a16d42
:END:

[ Revised as part of version 2.1.0 to conform with how we
  now tend to the needs of users who use Denote for journaling
  purposes ([[#h:4a6d92dd-19eb-4fcc-a7b5-05ce04da3a92][Keep a journal or diary]]). ]

Sometimes journaling is done with the intent to hone one's writing
skills.  Perhaps you are learning a new language or wish to communicate
your ideas with greater clarity and precision.  As with everything that
requires a degree of sophistication, you have to work for it---write,
write, write!

One way to test your progress is to set a timer.  It helps you gauge
your output and its quality.  To use a timer with Emacs, consider the
~tmr~ package.  A new timer can be set with something like this:

#+begin_src emacs-lisp
;; Set 10 minute timer with the given description
(tmr "10" "Practice writing in my journal")
#+end_src

To make this timer start as soon as a new journal entry is created
with the command ~denote-journal-extras-new-entry~, add a function to
the ~denote-journal-extras-hook~.  For example:

#+begin_src emacs-lisp
;; Add an anonymous function, which is more difficult to modify after
;; the fact:
(add-hook 'denote-journal-extras-hook (lambda ()
                                        (tmr "10" "Practice writing in my journal")))

;; Or write a small function that you can then modify without
;; revaluating the hook:
(defun my-denote-tmr ()
  (tmr "10" "Practice writing in my journal"))

(add-hook 'denote-journal-extras-hook 'my-denote-tmr)

;; Or to make it fully featured, define variables for the duration and
;; the description and set it up so that you only need to modify
;; those:
(defvar my-denote-tmr-duration "10")

(defvar my-denote-tmr-description "Practice writing in my journal")

(defun my-denote-tmr ()
  (tmr my-denote-tmr-duration my-denote-tmr-description))

(add-hook 'denote-journal-extras-hook 'my-denote-tmr)
#+end_src

Once the timer elapses, stop writing and review your performance.
Practice makes perfect!

Sources for ~tmr~:

+ Package name (GNU ELPA): ~tmr~
+ Official manual: <https://protesilaos.com/emacs/tmr>
+ Change log: <https://protesilaos.com/emacs/denote-changelog>
+ Git repo on SourceHut: <https://git.sr.ht/~protesilaos/tmr>
  - Mirrors:
    + GitHub: <https://github.com/protesilaos/tmr>
    + GitLab: <https://gitlab.com/protesilaos/tmr>
+ Mailing list: <https://lists.sr.ht/~protesilaos/tmr>

* Minibuffer histories
:PROPERTIES:
:CUSTOM_ID: h:82dc1203-d689-44b2-9a6c-b37776209651
:END:

Denote has a dedicated minibuffer history for each one of its prompts.
This practically means that using =M-p= (~previous-history-element~) and
=M-n= (~next-history-element~) will only cycle through the relevant
record of inputs, such as your latest titles in the =TITLE= prompt, and
keywords in the =KEYWORDS= prompt.

The built-in =savehist= library saves minibuffer histories.  Sample
configuration:

#+begin_src emacs-lisp
(require 'savehist)
(setq savehist-file (locate-user-emacs-file "savehist"))
(setq history-length 500)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history t)
(add-hook 'after-init-hook #'savehist-mode)
#+end_src

* Extending Denote
:PROPERTIES:
:CUSTOM_ID: h:8ed2bb6f-b5be-4711-82e9-8bee5bb06ece
:END:

Denote is a tool with a narrow scope: create notes and link between
them, based on the aforementioned file-naming scheme.  For other common
operations the user is advised to rely on standard Emacs facilities or
specialised third-party packages.  This section covers the details.

** Create a new note in any directory
:PROPERTIES:
:CUSTOM_ID: h:c9d7c157-85a6-4bb7-bd21-d00bccf5e799
:END:

The commands that create new files are designed to write to the
~denote-directory~. The idea is that the linking mechanism can find
any file by its identifier if it is in the ~denote-directory~
(searching the entire file system would be cumbersome).

However, these are cases where the user needs to create a new note in
an arbitrary directory. The following command can do this. Put the
code in your configuration file and evaluate it. Then call the command
by its name with =M-x=.

#+begin_src emacs-lisp
(defun my-denote-create-note-in-any-directory ()
  "Create new Denote note in any directory.
Prompt for the directory using minibuffer completion."
  (declare (interactive-only t))
  (interactive)
  (let ((denote-directory (read-directory-name "New note in: " nil nil :must-match)))
    (call-interactively 'denote)))
#+end_src

** Narrow the list of files in Dired
:PROPERTIES:
:CUSTOM_ID: h:ea173a01-69ef-4574-89a7-6e60ede02f13
:END:

Emacs' standard file manager (or directory editor) can read a regular
expression to mark the matching files.  This is the command
~dired-mark-files-regexp~, which is bound to =% m= by default.  For
example, =% m _denote= will match all files that have the =denote=
keyword ([[#h:1a953736-86c2-420b-b566-fb22c97df197][Features of the file-naming scheme for searching or filtering]]).

Once the files are matched, the user has two options: (i) narrow the
list to the matching items or (ii) exclude the matching items from the
list.

For the former, we want to toggle the marks by typing =t= (calls the
command ~dired-toggle-marks~ by default) and then hit the letter =k=
(for ~dired-do-kill-lines~).  The remaining files are those that match
the regexp that was provided earlier.

For the latter approach of filtering out the matching items, simply
involves the use of the =k= command (~dired-do-kill-lines~) to omit the
marked files from the list.

These sequences can be combined to incrementally narrow the list.  Note
that ~dired-do-kill-lines~ does not delete files: it simply hides them
from the current view.

Revert to the original listing with =g= (~revert-buffer~).

For a convenient wrapper, consider this example:

#+begin_src emacs-lisp
(defvar prot-dired--limit-hist '()
  "Minibuffer history for `prot-dired-limit-regexp'.")

;;;###autoload
(defun prot-dired-limit-regexp (regexp omit)
  "Limit Dired to keep files matching REGEXP.

With optional OMIT argument as a prefix (\\[universal-argument]),
exclude files matching REGEXP.

Restore the buffer with \\<dired-mode-map>`\\[revert-buffer]'."
  (interactive
   (list
    (read-regexp
     (concat "Files "
             (when current-prefix-arg
               (propertize "NOT " 'face 'warning))
             "matching PATTERN: ")
     nil 'prot-dired--limit-hist)
    current-prefix-arg))
  (dired-mark-files-regexp regexp)
  (unless omit (dired-toggle-marks))
  (dired-do-kill-lines))
#+end_src

** Use ~dired-virtual-mode~ for arbitrary file listings
:PROPERTIES:
:CUSTOM_ID: h:d35d8d41-f51b-4139-af8f-9c8cc508e35b
:END:

Emacs' Dired is a powerful file manager that builds its functionality
on top of the Unix =ls= command.  As noted elsewhere in this manual,
the user can update the =ls= flags that Dired uses to display its
contents ([[#h:a7fd5e0a-78f7-434e-aa2e-e150479c16e2][I want to sort by last modified, why won't Denote let me?]]).

What Dired cannot do is parse the output of a result that is produced
by piped commands, such as =ls -l | sort -t _ -k2=.  This specific
example targets the second underscore-separated field of the file
name, per our conventions ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).  Conceretely, it
matches the "alpha" as the sorting key in something like this:

#+begin_src emacs-lisp
20220929T200432--testing-file-one__alpha.txt
#+end_src

Consider then, how Dired will sort those files by their identifier:

#+begin_src emacs-lisp
20220929T200432--testing-file-one__alpha.txt
20220929T200532--testing-file-two__beta.txt
20220929T200632--testing-file-three__alpha.txt
20220929T200732--testing-file-four__beta.txt
#+end_src

Whereas on the command line, we can get the following:

#+begin_example
$ ls | sort -t _ -k 2
20220929T200432--testing-file-one__alpha.txt
20220929T200632--testing-file-three__alpha.txt
20220929T200532--testing-file-two__beta.txt
20220929T200732--testing-file-four__beta.txt
#+end_example

This is where ~dired-virtual-mode~ shows its utility.  If we tweak our
command-line invocation to include =ls -l=, this mode can behave like
Dired on the listed files.  (We omit the output of the =-l= flag from
this tutorial, as it is too verbose.)

What we now need is to capture the output of =ls -l | sort -t _ -k 2=
in an Emacs buffer and then enable ~dired-virtual-mode~.  To do that,
we can rely on either =M-x shell= or =M-x eshell= and then manually
copy the relevant contents.

For the user's convenience, I share what I have for Eshell to quickly
capture the last command's output in a dedicated buffer:

#+begin_src emacs-lisp
(defcustom prot-eshell-output-buffer "*Exported Eshell output*"
  "Name of buffer with the last output of Eshell command.
Used by `prot-eshell-export'."
  :type 'string
  :group 'prot-eshell)

(defcustom prot-eshell-output-delimiter "* * *"
  "Delimiter for successive `prot-eshell-export' outputs.
This is formatted internally to have newline characters before
and after it."
  :type 'string
  :group 'prot-eshell)

(defun prot-eshell--command-prompt-output ()
  "Capture last command prompt and its output."
  (let ((beg (save-excursion
               (goto-char (eshell-beginning-of-input))
               (goto-char (point-at-bol)))))
    (when (derived-mode-p 'eshell-mode)
      (buffer-substring-no-properties beg (eshell-end-of-output)))))

;;;###autoload
(defun prot-eshell-export ()
  "Produce a buffer with output of the last Eshell command.
If `prot-eshell-output-buffer' does not exist, create it.  Else
append to it, while separating multiple outputs with
`prot-eshell-output-delimiter'."
  (interactive)
  (let ((eshell-output (prot-eshell--command-prompt-output)))
    (with-current-buffer (get-buffer-create prot-eshell-output-buffer)
      (let ((inhibit-read-only t))
        (goto-char (point-max))
        (unless (eq (point-min) (point-max))
          (insert (format "\n%s\n\n" prot-eshell-output-delimiter)))
        (goto-char (point-at-bol))
        (insert eshell-output)
        (switch-to-buffer-other-window (current-buffer))))))
#+end_src

Bind ~prot-eshell-export~ to a key in the ~eshell-mode-map~ and give
it a try (I use =C-c C-e=).  In the produced buffer, activate the
~dired-virtual-mode~.

** Use Embark to collect minibuffer candidates
:PROPERTIES:
:CUSTOM_ID: h:edf9b651-86eb-4d5f-bade-3c9e270082f0
:END:

=embark= is a remarkable package that lets you perform relevant,
context-dependent actions using a prefix key (simplifying in the
interest of brevity).

For our purposes, Embark can be used to produce a Dired listing
directly from the minibuffer.  Suppose the current note has links to
three other notes.  You might use the ~denote-find-link~ command to
pick one via the minibuffer.  But why not turn those three links into
their own Dired listing?  While in the minibuffer, invoke ~embark-act~
which you may have already bound to =C-.= and then follow it up with
=E= (for the ~embark-export~ command).

This pattern can be repeated with any list of candidates, meaning that
you can narrow the list by providing some input before eventually
exporting the results with Embark.

Overall, this is very powerful and you might prefer it over doing the
same thing directly in Dired, since you also benefit from all the power
of the minibuffer ([[#h:ea173a01-69ef-4574-89a7-6e60ede02f13][Narrow the list of files in Dired]]).

** Search file contents
:PROPERTIES:
:CUSTOM_ID: h:76198fab-d6d2-4c67-9ccb-7a08cc883952
:END:

Emacs provides built-in commands which are wrappers of standard Unix
tools: =M-x grep= lets the user input the flags of a ~grep~ call and
pass a regular expression to the =-e= flag.

The author of Denote uses this thin wrapper instead:

#+begin_src emacs-lisp
(defvar prot-search--grep-hist '()
  "Input history of grep searches.")

;;;###autoload
(defun prot-search-grep (regexp &optional recursive)
  "Run grep for REGEXP.

Search in the current directory using `lgrep'.  With optional
prefix argument (\\[universal-argument]) for RECURSIVE, run a
search starting from the current directory with `rgrep'."
  (interactive
   (list
    (read-from-minibuffer (concat (if current-prefix-arg
                                      (propertize "Recursive" 'face 'warning)
                                    "Local")
                                  " grep for PATTERN: ")
                          nil nil nil 'prot-search--grep-hist)
    current-prefix-arg))
  (unless grep-command
    (grep-compute-defaults))
  (if recursive
      (rgrep regexp "*" default-directory)
    (lgrep regexp "*" default-directory)))
#+end_src

Rather than maintain custom code, consider using the excellent =consult=
package: it provides commands such as ~consult-grep~ and ~consult-find~
which provide live results and are generally easier to use than the
built-in commands.

** Bookmark the directory with the notes
:PROPERTIES:
:CUSTOM_ID: h:1bba4c1e-6812-4749-948f-57df4fd49b36
:END:

Part of the reason Denote does not reinvent existing functionality is to
encourage you to learn more about Emacs.  You do not need a bespoke
"jump to my notes" directory because such commands do not scale well.
Will you have a "jump to my downloads" then another for multimedia and
so on?  No.

Emacs has a built-in framework for recording persistent markers to
locations.  Visit the ~denote-directory~ (or any dir/file for that
matter) and invoke the ~bookmark-set~ command (bound to =C-x r m= by
default).  It lets you create a bookmark.

The list of bookmarks can be reviewed with the ~bookmark-bmenu-list~
command (bound to =C-x r l= by default).  A minibuffer interface is
available with ~bookmark-jump~ (=C-x r b=).

If you use the =consult= package, its default ~consult-buffer~ command
has the means to group together buffers, recent files, and bookmarks.
Each of those types can be narrowed to with a prefix key.  The package
=consult-dir= is an extension to =consult= which provides useful extras
for working with directories, including bookmarks.

** Use the ~denote-explore~ package to explore your notes
:PROPERTIES:
:CUSTOM_ID: h:110ae3a4-5fc6-45da-b9bb-0e294bd12981
:END:

Peter Prevos has developed the ~denote-explore~ package which provides
four groups of Emacs commands to explore your Denote files:

- Summary statistics :: Count notes, attachments and keywords.
- Random walks :: Generate new ideas using serendipity.
- Janitor :: Manage your denote collection.
- Visualisations :: Visualise your Denote network.

The package's documentation covers the details:
<https://lucidmanager.org/productivity/denote-explore/>.

** Use the ~citar-denote~ package for bibliography notes
:PROPERTIES:
:CUSTOM_ID: h:226d66e4-b7de-4617-87e2-a7f2d6f007dd
:END:

Peter Prevos has produced the ~citar-denote~ package which makes it
possible to write notes on BibTeX entries with the help of the ~citar~
package.  These notes have the citation's unique key associated with
them in the file's front matter.  They also get a configurable keyword
in their file name, making it easy to find them in Dired and/or
retrieve them with the various Denote methods.

With ~citar-denote~, the user leverages standard minibuffer completion
mechanisms (e.g. with the help of the ~vertico~ and ~embark~ packages)
to manage bibliographic notes and access those notes with ease.  The
package's documentation covers the details: <https://lucidmanager.org/productivity/bibliographic-notes-in-emacs-with-citar-denote/>.

** Use the ~consult-notes~ package for enhanced minibuffer interactions
:PROPERTIES:
:CUSTOM_ID: h:113a13e1-35da-46f1-9414-81e9be2facc1
:END:

The ~consult-denote~ package by me (Protesilaos) integrates Denote
with Daniel Mendler's ~consult~ package: <https://github.com/protesilaos/consult-denote>.

The idea is to preserve the familiar patterns of interaction with the
various Denote commands but add to them an extra layer of
functionality, such as the preview mechanism that Consult provides
(e.g. preview the file you are about to link to).

Additionally, ~consult-denote~ defines new "sources" for the
~consult-buffer~ command. This command provides a single point of
entry for buffers, recently opened files, and bookmarks. With
~consult-denote~, it has a dedicated place for Denote-specific
buffers, silos, and more (all of which are configurable).

Unlike the ~consult-notes~ package by Colin McLear, ~consult-denote~
uses the same presentation of data in the minibuffer to stay in sync
with Denote and make its feature set entirely optional ([[#h:8907f4bc-992a-45bc-a60e-267ed1ce9c2d][Use the ~consult-notes~ package]]).
It also only works with Denote.

** Use the ~consult-notes~ package
:PROPERTIES:
:CUSTOM_ID: h:8907f4bc-992a-45bc-a60e-267ed1ce9c2d
:END:

[ Also check the ~consult-denote~ package by me (Protesilaos):
  [[#h:113a13e1-35da-46f1-9414-81e9be2facc1][Use the ~consult-notes~ package for enhanced minibuffer interactions]]. ]

If you are using Daniel Mendler's ~consult~ (which is a brilliant
package), you will most probably like its ~consult-notes~ extension,
developed by Colin McLear.  It uses the familiar mechanisms of Consult
to preview the currently selected entry and to filter searches via a
prefix key.  For example:

#+begin_src emacs-lisp
(setq consult-notes-file-dir-sources
      `(("Denote Notes"  ?d ,(denote-directory))
        ("Books"  ?b "~/Documents/books/")))
#+end_src

With the above, =M-x consult-notes= will list the files in those two
directories.  If you type =d= and space, it narrows the list to just
the notes, while =b= does the same for books.

The other approach is to enable the ~consult-notes-denote-mode~.  It
takes care to add the ~denote-directory~ to the sources that
~consult-notes~ reads from.  Denote notes are then filtered by the =d=
prefix followed by a space.

The minor mode has the extra feature of reformatting the title of
notes shown in the minibuffer.  It isolates the =TITLE= component of
each note and shows it without hyphens, while presenting keywords in
their own column.  The user option ~consult-notes-denote-display-id~
can be set to ~nil~ to hide the identifier.  Depending on how one
searches through their notes, this refashioned presentation may be the
best option ([[#h:1a953736-86c2-420b-b566-fb22c97df197][Features of the file-naming scheme for searching or filtering]]).

** Use the ~denote-menu~ package
:PROPERTIES:
:CUSTOM_ID: h:472db709-27de-4a1f-a171-c3fe0a7a9be8
:END:

Denote's file-naming scheme is designed to be efficient and to provide
valueable meta information about the file.  The cost, however, is that
it is terse and harder to read, depending on how the user chooses to
filter and process their notes.

To this end, [[https://github.com/namilus/denote-menu][the ~denote-menu~ package by Mohamed Suliman]] provides the
convenience of a nice tabular interface for all notes.  ~denote-menu~
removes the delimiters that are found in Denote file names and
presents the information in a human-readable format.  Furthermore, the
package provides commands to interact with the list of notes, such as
to filter them and to transition from the tabular list to Dired.  Its
documentation expands on the technicalities.

** Treat your notes as a project
:PROPERTIES:
:CUSTOM_ID: h:fad3eb08-ddc7-43e4-ba28-210d89668037
:END:

Emacs has a built-in library for treating a directory tree as a
"project".  This means that the contents of this tree are seen as part
of the same set, so commands like ~project-switch-to-buffer~ (=C-x p b=
by default) will only consider buffers in the current project
(e.g. three notes that are currently being visited).

Normally, a "project" is a directory tree whose root is under version
control.  For our purposes, all you need is to navigate to the
~denote-directory~ (for the shell or via Dired) and use the command-line
to run this (requires the =git= executable):

: git init

From Dired, you can type =M-!= which invokes ~dired-smart-shell-command~
and then run the git call there.

The project can then be registered by invoking any project-related
command inside of it, such as ~project-find-file~ (=C-x p f=).

It is a good idea to keep your notes under version control, as that
gives you a history of changes for each file.  We shall not delve into
the technicalities here, though suffice to note that Emacs' built-in
version control framework or the exceptionally well-crafted =magit=
package will get the job done (VC can work with other backends besides
Git).

** Use the tree-based file prompt for select commands
:PROPERTIES:
:CUSTOM_ID: h:8f9e0971-8b30-4e7b-af79-8fed257dbcfa
:END:

Older versions of Denote had a file prompt that resembled that of the
standard ~find-file~ command (bound to =C-x C-f= by default).  This
means that it used a tree-based method of navigating the filesystem by
selecting the specific directory and then the given file.

Currently, Denote flattens the file prompt so that every file in the
~denote-directory~ and its subdirectories can be matched from anywhere
using the power of Emacs' minibuffer completion (such as with the help
of the ~orderless~ package in addition to built-in options).

Users who need the old behaviour on a per-command basis can define
their own wrapper functions as shown in the following code block.

#+begin_src emacs-lisp
;; This is the old `denote-file-prompt' that we renamed to
;; `denote-file-prompt-original' for clarity.
(defun denote-file-prompt-original (&optional initial-text)
  "Prompt for file with identifier in variable `denote-directory'.
With optional INITIAL-TEXT, use it to prepopulate the minibuffer."
  (read-file-name "Select note: " (denote-directory) nil nil initial-text
                  (lambda (f)
                    (or (denote-file-has-identifier-p f)
                        (file-directory-p f)))))

;; Our wrapper command that changes the current `denote-file-prompt'
;; to the functionality of `denote-file-prompt-original' only when
;; this command is used.
(defun my-denote-link ()
  "Call `denote-link' but use Denote's original file prompt.
See `denote-file-prompt-original'."
  (interactive)
  (cl-letf (((symbol-function 'denote-file-prompt) #'denote-file-prompt-original))
    (call-interactively #'denote-link)))
#+end_src

** Rename files with Denote in the Image Dired thumbnails buffer
:PROPERTIES:
:CUSTOM_ID: h:e666ced6-da75-4bdb-9be3-82c2f4455ee9
:END:

[[#h:2d5ee9bf-e8f2-426c-8bf7-bf78bc88d1ee][Rename files with Denote using ~dired-preview~]]

Just as with the ~denote-dired-rename-marked-files-with-keywords~,
we can use Denote in the Image Dired buffer ([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files at once]]).
Here is the custom code:

#+begin_src emacs-lisp
(autoload 'image-dired--with-marked "image-dired")
(autoload 'image-dired-original-file-name "image-dired-util")

(defun my-denote-image-dired-rename-marked-files (keywords)
  "Like `denote-dired-rename-marked-files-with-keywords' but for Image Dired.
Prompt for KEYWORDS and rename all marked files in the Image
Dired buffer to have a Denote-style file name with the given
KEYWORDS.

IMPORTANT NOTE: if there are marked files in the corresponding
Dired buffers, those will be targeted as well.  This is not the
fault of Denote: it is how Dired and Image Dired work in tandem.
To only rename the marked thumbnails, start by unmarking
everything in Dired.  Then mark the items in Image Dired and
invoke this command."
  (interactive (list (denote-keywords-prompt)) image-dired-thumbnail-mode)
  (image-dired--with-marked
   (when-let* ((file (image-dired-original-file-name))
               (dir (file-name-directory file))
               (id (or (denote-retrieve-filename-identifier file) ""))
               (file-type (denote-filetype-heuristics file))
               (title (denote--retrieve-title-or-filename file file-type))
               (signature (or (denote-retrieve-filename-signature file) "")
               (extension (file-name-extension file t))
               (new-name (denote-format-file-name dir id keywords title extension signature))
               (default-directory dir))
     (denote-rename-file-and-buffer file new-name))))
#+end_src

While the ~my-denote-image-dired-rename-marked-files~ renames files in
the helpful Denote-compliant way, users may still need to not prepend
a unique identifier and not sluggify (hyphenate and downcase) the
image's existing file name.  To this end, the following custom command
can be used instead:

#+begin_src emacs-lisp
(defun my-image-dired-rename-marked-files (keywords)
  "Like `denote-dired-rename-marked-files-with-keywords' but for Image Dired.
Prompt for keywords and rename all marked files in the Image
Dired buffer to have Denote-style keywords, but none of the other
conventions of Denote's file-naming scheme."
  (interactive (list (denote-keywords-prompt)) image-dired-thumbnail-mode)
  (image-dired--with-marked
   (when-let* ((file (image-dired-original-file-name))
               (dir (file-name-directory file))
               (file-type (denote-filetype-heuristics file))
               (title (denote--retrieve-title-or-filename file file-type))
               (extension (file-name-extension file t))
               (kws (denote--keywords-combine keywords))
               (new-name (concat dir title "__" kws extension))
               (default-directory dir))
     (denote-rename-file-and-buffer file new-name))))
#+end_src

** Rename files with Denote using ~dired-preview~
:PROPERTIES:
:CUSTOM_ID: h:2d5ee9bf-e8f2-426c-8bf7-bf78bc88d1ee
:END:

The ~dired-preview~ package (by me/Protesilaos) automatically displays
a preview of the file at point in Dired.  This can be helpful in
tandem with Denote when we want to rename multiple files by taking a
quick look at their contents.

The command ~denote-dired-rename-marked-files-with-keywords~
will generate Denote-style file names based on the keywords it prompts
for. Identifiers are derived from each file's modification date
([[#h:1b6b2c78-42f0-45b8-9ef0-6de21a8b2cde][Rename multiple files at once]]). There is no need for any custom code
in this scenario.

As noted in the section about Image Dired, the user may sometimes not
need a fully fledged Denote-style file name but only append Denote-like
keywords to each file name (e.g. =Original Name__denote_test.jpg=
instead of =20230710T195843--original-name__denote_test.jpg=).

[[#h:e666ced6-da75-4bdb-9be3-82c2f4455ee9][Rename files with Denote in the Image Dired thumbnails buffer]]

In such a workflow, it is unlikely to be dealing with ordinary text
files where front matter can be helpful.  A custom command does not
need to behave like what Denote provides out-of-the-box, but can
instead append keywords to file names without conducting any further
actions.  We thus have:

#+begin_src emacs-lisp
(defun my-denote-dired-rename-marked-files-keywords-only ()
  "Like `denote-dired-rename-marked-files-with-keywords' but only for keywords in file names.

Prompt for keywords and rename all marked files in the Dired
buffer to only have Denote-style keywords, but none of the other
conventions of Denote's file-naming scheme."
  (interactive nil dired-mode)
  (if-let ((marks (dired-get-marked-files)))
      (let ((keywords (denote-keywords-prompt)))
        (dolist (file marks)
          (let* ((dir (file-name-directory file))
                 (file-type (denote-filetype-heuristics file))
                 (title (denote--retrieve-title-or-filename file file-type))
                 (extension (file-name-extension file t))
                 (kws (denote--keywords-combine keywords))
                 (new-name (concat dir title "__" kws extension)))
            (denote-rename-file-and-buffer file new-name)))
        (revert-buffer))
    (user-error "No marked files; aborting")))
#+end_src

** Avoid duplicate identifiers when exporting Denote notes
:PROPERTIES:
:CUSTOM_ID: h:4a8c4546-26b3-4195-8b2c-b08a519986a4
:END:

When exporting Denote notes to, for example, an HTML or PDF file,
there is a high probability that the same file name is used with a new
extension.  This is problematic because it creates files with
duplicate identifiers.  The =20230515T085612--example__keyword.org=
produces a =20230515T085612--example__keyword.pdf=.  Any link to the
=20230515T085612= will thus break: it does not honor Denote's
expectation of finding unique identifiers.  This is not the fault of
Denote: exporting is done by the user without Denote's involvement.

Org Mode and Markdown use different approaches to exporting files.  No
recommended method is available for plain text files as there is no
standardised export functionality for this format (the user can always
create a new note using the file type they want on a case-by-case
basis: [[#h:887bdced-9686-4e80-906f-789e407f2e8f][Convenience commands for note creation]]).

*** Export Denote notes with Org Mode
:PROPERTIES:
:CUSTOM_ID: h:67669d9d-17c3-45bd-8227-da57d8bc3b73
:END:

Org Mode has a built-in configurable export engine.  You can prevent
duplicate identifiers when exporting manually for each exported file
or by advising the Org export function.

Denote also provides commands to convert =denote:= links to their
=file:= equivalent, in case this is a required pre-processing step for
export purposes ([[#h:ed220cac-7dcb-4bb7-9243-1bb85e452e5f][Convert =denote:= links to =file:= links]]).

**** Manually configure Org export
:PROPERTIES:
:CUSTOM_ID: h:bf791e28-73e5-4ed8-88bc-e4e9b3ebaedb
:END:

Insert =#+export_file_name: FILENAME= in the front matter before
exporting to force a filename called whatever the value of =FILENAME=
is.  The =FILENAME= does not specify the file type extension, such as
=.pdf=.  This is up to the export engine.  For example, a Denote note
with a complete file name of =20230515T085612--example__keyword.org=
and a front matter entry of =#+export_file_name: hello= will be
exported as =hello.pdf=.

The advantage of this manual method is that it gives the user full
control over the resulting file name.  The disadvantage is that it
depends on the user's behaviour.  Forgetting to add a new name can
lead to duplicate identifiers, as already noted in the introduction to
this section ([[#h:4a8c4546-26b3-4195-8b2c-b08a519986a4][Export Denote notes]]).

**** Automatically store Org exports in another folder
:PROPERTIES:
:CUSTOM_ID: h:7a61a370-78e5-42a1-9650-98fee140723f
:END:

It is possible to automatically place all exports in another folder by
making Org's function ~org-export-output-file-name~ create the target
directory if needed and move the exported file there.  Remember that
advising Elisp code must be handled with care, as it might break the
original function in subtle ways.

#+begin_src emacs-lisp
(defvar my-org-export-output-directory-prefix "./export_"
  "Prefix of directory used for org-mode export.

The single dot means that the directory is created on the same
level as the one where the Org file that performs the exporting
is.  Use two dots to place the directory on a level above the
current one.

If this directory is part of `denote-directory', make sure it is
not read by Denote.  See `denote-excluded-directories-regexp'.
This way there will be no known duplicate Denote identifiers
produced by the Org export mechanism.")

(defun my-org-export-create-directory (fn extension &rest args)
  "Move Org export file to its appropriate directory.

Append the file type EXTENSION of the exported file to
`my-org-export-output-directory-prefix' and, if absent, create a
directory named accordingly.

Install this as advice around `org-export-output-file-name'.  The
EXTENSION is supplied by that function.  ARGS are its remaining
arguments."
  (let ((export-dir (format "%s%s" my-org-export-output-directory-prefix extension)))
    (unless (file-directory-p export-dir)
      (make-directory export-dir)))
  (apply fn extension args))

(advice-add #'org-export-output-file-name :around #'my-org-export-create-directory)
#+end_src

The target export directory should not be a subdirectory of
~denote-directory~, as that will result in duplicate identifiers.
Exclude it with the ~denote-excluded-directories-regexp~ user option
([[#h:8458f716-f9c2-4888-824b-2bf01cc5850a][Exclude certain directories from all operations]]).

[ NOTE: I (Protesilaos) am not a LaTeX user and cannot test the
  following. ]

Using a different directory will require some additional configuration
when exporting using LaTeX.  The export folder cannot be inside the
path of the ~denote-directory~ to prevent Denote from recognising it
as an attachment:
<https://emacs.stackexchange.com/questions/45751/org-export-to-different-directory>.

**** Org Mode Publishing
:PROPERTIES:
:CUSTOM_ID: h:2f3451ed-2fc4-4f36-bcf2-112939963e20
:END:

Org Mode also has a publishing tool for exporting a collection of
files. Some user might apply this approach to convert their note
collection to a public or private website.

The ~org-publish-project-alist~ variable drives the publishing
process, including the publishing directory.

The publishing directory should not be a subdirectory of
~denote-directory~, as that will result in duplicate identifiers.
Exclude it with the ~denote-excluded-directories-regexp~ user option
([[#h:8458f716-f9c2-4888-824b-2bf01cc5850a][Exclude certain directories from all operations]]).

*** Export Denote notes with Markdown
:PROPERTIES:
:CUSTOM_ID: h:44c6a34a-e9ad-4f43-a24f-12f2c5a8467e
:END:

Exporting from Markdown requires an external processor (e.g.,
Markdown.pl, Pandoc, or MultiMarkdown).  The ~markdown-command~
variable defines the command line used in export, for example:

#+begin_src emacs-lisp
(setq markdown-command "multimarkdown")
#+end_src

The export process thus occurs outside of Emacs.  Users need to read
the documentation of their preferred processor to prevent the creation
of duplicate Denote identifiers.

* Installation
:PROPERTIES:
:CUSTOM_ID: h:f3bdac2c-4704-4a51-948c-a789a2589790
:END:
#+cindex: Installation instructions

** GNU ELPA package
:PROPERTIES:
:CUSTOM_ID: h:42953f87-82bd-43ec-ab99-22b1e22955e7
:END:

The package is available as =denote=.  Simply do:

: M-x package-refresh-contents
: M-x package-install

And search for it.

GNU ELPA provides the latest stable release.  Those who prefer to follow
the development process in order to report bugs or suggest changes, can
use the version of the package from the GNU-devel ELPA archive.  Read:
https://protesilaos.com/codelog/2022-05-13-emacs-elpa-devel/.

** Manual installation
:PROPERTIES:
:CUSTOM_ID: h:d397712c-c8c0-4cfa-ad1a-ef28cf78d1f0
:END:

Assuming your Emacs files are found in =~/.emacs.d/=, execute the
following commands in a shell prompt:

#+begin_src sh
cd ~/.emacs.d

# Create a directory for manually-installed packages
mkdir manual-packages

# Go to the new directory
cd manual-packages

# Clone this repo, naming it "denote"
git clone https://git.sr.ht/~protesilaos/denote denote
#+end_src

Finally, in your =init.el= (or equivalent) evaluate this:

#+begin_src emacs-lisp
;; Make Elisp files in that directory available to the user.
(add-to-list 'load-path "~/.emacs.d/manual-packages/denote")
#+end_src

Everything is in place to set up the package.

* Sample configuration
:PROPERTIES:
:CUSTOM_ID: h:5d16932d-4f7b-493d-8e6a-e5c396b15fd6
:END:
#+cindex: Package configuration

#+begin_src emacs-lisp
(require 'denote)

;; Remember to check the doc strings of those variables.
(setq denote-directory (expand-file-name "~/Documents/notes/"))
(setq denote-save-buffers nil)
(setq denote-known-keywords '("emacs" "philosophy" "politics" "economics"))
(setq denote-infer-keywords t)
(setq denote-sort-keywords t)
(setq denote-file-type nil) ; Org is the default, set others here
(setq denote-prompts '(title keywords))
(setq denote-excluded-directories-regexp nil)
(setq denote-excluded-keywords-regexp nil)
(setq denote-rename-confirmations '(rewrite-front-matter modify-file-name))

;; Pick dates, where relevant, with Org's advanced interface:
(setq denote-date-prompt-use-org-read-date t)


;; Read this manual for how to specify `denote-templates'.  We do not
;; include an example here to avoid potential confusion.


(setq denote-date-format nil) ; read doc string

;; By default, we do not show the context of links.  We just display
;; file names.  This provides a more informative view.
(setq denote-backlinks-show-context t)

;; Also see `denote-link-backlinks-display-buffer-action' which is a bit
;; advanced.

;; If you use Markdown or plain text files (Org renders links as buttons
;; right away)
(add-hook 'text-mode-hook #'denote-fontify-links-mode-maybe)

;; We use different ways to specify a path for demo purposes.
(setq denote-dired-directories
      (list denote-directory
            (thread-last denote-directory (expand-file-name "attachments"))
            (expand-file-name "~/Documents/books")))

;; Generic (great if you rename files Denote-style in lots of places):
;; (add-hook 'dired-mode-hook #'denote-dired-mode)
;;
;; OR if only want it in `denote-dired-directories':
(add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)


;; Automatically rename Denote buffers using the `denote-rename-buffer-format'.
(denote-rename-buffer-mode 1)

;; Denote DOES NOT define any key bindings.  This is for the user to
;; decide.  For example:
(let ((map global-map))
  (define-key map (kbd "C-c n n") #'denote)
  (define-key map (kbd "C-c n c") #'denote-region) ; "contents" mnemonic
  (define-key map (kbd "C-c n N") #'denote-type)
  (define-key map (kbd "C-c n d") #'denote-date)
  (define-key map (kbd "C-c n z") #'denote-signature) ; "zettelkasten" mnemonic
  (define-key map (kbd "C-c n s") #'denote-subdirectory)
  (define-key map (kbd "C-c n t") #'denote-template)
  ;; If you intend to use Denote with a variety of file types, it is
  ;; easier to bind the link-related commands to the `global-map', as
  ;; shown here.  Otherwise follow the same pattern for `org-mode-map',
  ;; `markdown-mode-map', and/or `text-mode-map'.
  (define-key map (kbd "C-c n i") #'denote-link) ; "insert" mnemonic
  (define-key map (kbd "C-c n I") #'denote-add-links)
  (define-key map (kbd "C-c n b") #'denote-backlinks)
  (define-key map (kbd "C-c n f f") #'denote-find-link)
  (define-key map (kbd "C-c n f b") #'denote-find-backlink)
  ;; Note that `denote-rename-file' can work from any context, not just
  ;; Dired bufffers.  That is why we bind it here to the `global-map'.
  (define-key map (kbd "C-c n r") #'denote-rename-file)
  (define-key map (kbd "C-c n R") #'denote-rename-file-using-front-matter))

;; Key bindings specifically for Dired.
(let ((map dired-mode-map))
  (define-key map (kbd "C-c C-d C-i") #'denote-link-dired-marked-notes)
  (define-key map (kbd "C-c C-d C-r") #'denote-dired-rename-files)
  (define-key map (kbd "C-c C-d C-k") #'denote-dired-rename-marked-files-with-keywords)
  (define-key map (kbd "C-c C-d C-R") #'denote-dired-rename-marked-files-using-front-matter))

(with-eval-after-load 'org-capture
  (setq denote-org-capture-specifiers "%l\n%i\n%?")
  (add-to-list 'org-capture-templates
               '("n" "New note (with denote.el)" plain
                 (file denote-last-path)
                 #'denote-org-capture
                 :no-save t
                 :immediate-finish nil
                 :kill-buffer t
                 :jump-to-captured t)))

;; Also check the commands `denote-link-after-creating',
;; `denote-link-or-create'.  You may want to bind them to keys as well.


;; If you want to have Denote commands available via a right click
;; context menu, use the following and then enable
;; `context-menu-mode'.
(add-hook 'context-menu-functions #'denote-context-menu)
#+end_src

* For developers or advanced users
:PROPERTIES:
:CUSTOM_ID: h:c916d8c5-540a-409f-b780-6ccbd90e088e
:END:

Denote is in a stable state and can be relied upon as the basis for
custom extensions.  Further below is a list with the functions or
variables we provide for public usage.  Those are in addition to all
user options and commands that are already documented in the various
sections of this manual.

In this context "public" is any form with single hyphens in its symbol,
such as ~denote-directory-files~.  We expressly support those, meaning
that we consider them reliable and commit to documenting any changes in
their particularities (such as through ~make-obsolete~, a record in the
change log, a blog post on the maintainer's website, and the like).

By contradistinction, a "private" form is declared with two hyphens in
its symbol such as ~denote--file-extension~.  Do not use those as we
might change them without further notice.

#+vindex: denote-id-format
+ Variable ~denote-id-format~ :: Format of ID prefix of a note's
  filename.  The note's ID is derived from the date and time of its
  creation ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

#+vindex: denote-id-regexp
+ Variable ~denote-id-regexp~ :: Regular expression to match
  ~denote-id-format~.

#+vindex: denote-signature-regexp
+ Variable ~denote-signature-regexp~ :: Regular expression to match
  the =SIGNATURE= field in a file name.

#+vindex: denote-title-regexp
+ Variable ~denote-title-regexp~ :: Regular expression to match the
  =TITLE= field in a file name ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

#+vindex: denote-keywords-regexp
+ Variable ~denote-keywords-regexp~ :: Regular expression to match the
  =KEYWORDS= field in a file name ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

#+vindex: denote-excluded-punctuation-regexp
+ Variable ~denote-excluded-punctuation-regexp~ :: Punctionation that
  is removed from file names.  We consider those characters illegal
  for our purposes.

#+vindex: denote-excluded-punctuation-extra-regexp
+ Variable ~denote-excluded-punctuation-extra-regexp~ :: Additional
  punctuation that is removed from file names.  This variable is for
  advanced users who need to extend the ~denote-excluded-punctuation-regexp~.
  Once we have a better understanding of what we should be omitting,
  we will update things accordingly.

#+findex: denote-file-is-note-p
+ Function ~denote-file-is-note-p~ :: Return non-nil if =FILE= is an
  actual Denote note. For our purposes, a note must satisfy
  ~file-regular-p~ and ~denote-filename-is-note-p~.

#+findex: denote-file-has-identifier-p
+ Function ~denote-file-has-identifier-p~ :: Return non-nil if =FILE=
  has a Denote identifier.

#+findex: denote-file-has-signature-p
+ Function ~denote-file-has-signature-p~ :: Return non-nil if =FILE=
  has a signature.

#+findex: denote-file-has-supported-extension-p
+ Function ~denote-file-has-supported-extension-p~ :: Return non-nil
  if =FILE= has supported extension.  Also account for the possibility
  of an added =.gpg= suffix. Supported extensions are those implied by
  ~denote-file-type~.

#+findex: denote-file-is-writable-and-supported-p
+ Function ~denote-file-is-writable-and-supported-p~ :: Return non-nil
  if =FILE= is writable and has supported extension.

#+findex: denote-file-type-extensions
+ Function ~denote-file-type-extensions~ :: Return all file type
  extensions in ~denote-file-types~.

#+vindex: denote-encryption-file-extensions
+ Variable ~denote-encryption-file-extensions~ :: List of strings
  specifying file extensions for encryption.

#+findex: denote-file-type-extensions-with-encryption
+ Function ~denote-file-type-extensions-with-encryption~ :: Derive
  ~denote-file-type-extensions~ plus ~denote-encryption-file-extensions~.

#+findex: denote-get-file-extension
+ Function ~denote-get-file-extension~ :: Return extension of =FILE=
  with dot included.  Account for ~denote-encryption-file-extensions~.
  In other words, return something like =.org.gpg= if it is part of
  the file, else return =.org=.

#+findex: denote-get-file-extension-sans-encryption
+ Function ~denote-get-file-extension-sans-encryption~ :: Return
  extension of =FILE= with dot included and without the encryption
  part.  Build on top of ~denote-get-file-extension~ though always
  return something like =.org= even if the actual file extension is
  =.org.gpg=.

#+findex: denote-keywords
+ Function ~denote-keywords~ :: Return appropriate list of keyword
  candidates.  If ~denote-infer-keywords~ is non-nil, infer keywords
  from existing notes and combine them into a list with
  ~denote-known-keywords~.  Else use only the latter set of keywords
  ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note creation]]).

#+findex: denote-keywords-sort
+ Function ~denote-keywords-sort~ :: Sort =KEYWORDS= if
  ~denote-sort-keywords~ is non-nil.  =KEYWORDS= is a list of strings,
  per ~denote-keywords-prompt~.

#+findex: denote-keywords-combine
+ Function ~denote-keywords-combine~ :: Combine =KEYWORDS= list of
  strings into a single string. Keywords are separated by the
  underscore character, per the Denote file-naming scheme.

#+findex: denote-valid-date-p
+ Function ~denote-valid-date-p~ :: Return =DATE= as a valid date. A
  valid =DATE= is a value that can be parsed by either ~decode-time~
  or ~date-to-time~ .Those functions signal an error if =DATE= is a
  value they do not recognise. If =DATE= is nil, return nil.

#+findex: denote-parse-date
+ Function ~denote-parse-date~ :: Return =DATE= as an appropriate
  value for the ~denote~ command. Pass =DATE= through
  ~denote-valid-date-p~ and use its return value. If either that or
  =DATE= is nil, return ~current-time~.

#+findex: denote-directory
+ Function ~denote-directory~ :: Return path of the variable
  ~denote-directory~ as a proper directory, also because it accepts a
  directory-local value for what we internally refer to as "silos"
  ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directories for notes]]).  Custom Lisp code can
  ~let~ bind the value of the variable ~denote-directory~
  to override what this function returns.

#+findex: denote-directory-files
+ Function ~denote-directory-files~ :: Return list of absolute file
  paths in variable ~denote-directory~. Files that match
  ~denote-excluded-files-regexp~ are excluded from the list. Files
  only need to have an identifier. The return value may thus include
  file types that are not implied by ~denote-file-type~. With optional
  =FILES-MATCHING-REGEXP=, restrict files to those matching the given
  regular expression. With optional =OMIT-CURRENT= as a non-nil value,
  do not include the current Denote file in the returned list. With
  optional =TEXT-ONLY= as a non-nil value, limit the results to text
  files that satisfy ~denote-file-is-note-p~.

#+findex: denote-directory-subdirectories
+ Function ~denote-directory-subdirectories~ :: Return list of
  subdirectories in variable ~denote-directory~. Omit dotfiles (such
  as .git) unconditionally.  Also exclude whatever matches
  ~denote-excluded-directories-regexp~.  Note that the
  ~denote-directory~ accepts a directory-local value for what we call
  "silos" ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directories for notes]]).

#+findex: denote-file-name-relative-to-denote-directory
+ Function ~denote-file-name-relative-to-denote-directory~ :: Return
  name of =FILE= relative to the variable ~denote-directory~.  =FILE=
  must be an absolute path.

#+findex: denote-get-path-by-id
+ Function ~denote-get-path-by-id~ :: Return absolute path of =ID=
  string in ~denote-directory-files~.

#+findex: denote-barf-duplicate-id
+ Function ~denote-barf-duplicate-id~ :: Throw a ~user-error~ if
  =IDENTIFIER= already exists.

#+findex: denote-sluggify
+ Function ~denote-sluggify~ :: Make =STR= an appropriate slug for
  file name =COMPONENT= ([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).
  Apply the function specified in ~denote-file-name-slug-function~ to
  =COMPONENT= which is one of =title=, =signature=, =keyword=. If the
  resulting string still contains consecutive =-=,=_= or ~=~, they are
  replaced by a single occurence of the character, if necessary
  according to =COMPONENT=. If =COMPONENT= is ~keyword~, remove
  underscores from =STR= as they are used as the keywords separator in
  file names.

#+findex: denote-sluggify-keyword
+ Function ~denote-sluggify-keyword~ :: Sluggify =STR= while joining
  separate words.

#+findex: denote-sluggify-signature
+ Function ~denote-sluggify-signature~ :: Make =STR= an appropriate
  slug for signatures ([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).

#+findex: denote-sluggify-keywords
+ Function ~denote-sluggify-keywords~ :: Sluggify =KEYWORDS=, which is
  a list of strings ([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggification of file name components]]).

#+findex: denote-filetype-heuristics
+ Function ~denote-filetype-heuristics~ :: Return likely file type of
  =FILE=. If in the process of ~org-capture~, consider the file type to
  be that of Org. Otherwise, use the file extension to detect the file
  type of =FILE=.

  If more than one file type correspond to this file extension, use
  the first file type for which the :title-key-regexp in
  ~denote-file-types~ matches in the file.

  Return nil if the file type is not recognized.

#+findex: denote-use-date
+ Function ~denote-use-date~ :: The date to be used in a note creation
  command. See the documentation of ~denote~ for acceptable values.
  This variable is ignored if nil. Only ever ~let~ bind this,
  otherwise the title will always be the same and the title prompt
  will be skipped.

#+findex: denote-use-directory
+ Function ~denote-use-directory~ :: The directory to be used in a
  note creation command. See the documentation of ~denote~ for
  acceptable values. This variable is ignored if nil. Only ever ~let~
  bind this, otherwise the title will always be the same and the title
  prompt will be skipped.

#+findex: denote-use-file-type
+ Function ~denote-use-file-type~ :: The file type to be used in a
  note creation command. See the documentation of ~denote~ for
  acceptable values. This variable is ignored if nil. Only ever ~let~
  bind this, otherwise the title will always be the same and the title
  prompt will be skipped.

#+findex: denote-use-keywords
+ Function ~denote-use-keywords~ :: The keywords to be used in a note
  creation command. See the documentation of ~denote~ for acceptable
  values. This variable is ignored if nil. Only ever ~let~ bind this,
  otherwise the title will always be the same and the title prompt
  will be skipped.

#+findex: denote-use-signature
+ Function ~denote-use-signature~ :: The signature to be used in a
  note creation command. See the documentation of ~denote~ for
  acceptable values. This variable is ignored if nil. Only ever ~let~
  bind this, otherwise the title will always be the same and the title
  prompt will be skipped.

#+findex: denote-use-template
+ Function ~denote-use-template~ :: The template to be used in a note
  creation command. See the documentation of ~denote~ for acceptable
  values. This variable is ignored if nil. Only ever ~let~ bind this,
  otherwise the title will always be the same and the title prompt
  will be skipped.

#+findex: denote-use-title
+ Function ~denote-use-title~ :: The title to be used in a note
  creation command. See the documentation of ~denote~ for acceptable
  values. This variable is ignored if nil. Only ever ~let~ bind this,
  otherwise the title will always be the same and the title prompt
  will be skipped.

#+findex: denote-format-file-name
+ Function ~denote-format-file-name~ :: Format file name. =DIR-PATH=,
  =ID=, =KEYWORDS=, =TITLE=, =EXTENSION= and =SIGNATURE= are expected to
  be supplied by ~denote~ or equivalent command.

  =DIR-PATH= is a string pointing to a directory. It ends with a
  forward slash (the function ~denote-directory~ makes sure this is
  the case when returning the value of the variable ~denote-directory~).
  =DIR-PATH= cannot be nil or an empty string.

  =ID= is a string holding the identifier of the note. It cannot be
  nil or an empty string and must match ~denote-id-regexp~.

  =DIR-PATH= and =ID= form the base file name.

  =KEYWORDS= is a list of strings that is reduced to a single string
  by ~denote-keywords-combine~. =KEYWORDS= can be an empty list or a
  nil value, in which case the relevant file name component is not
  added to the base file name.

  =TITLE= and =SIGNATURE= are strings. They can be an empty string, in
  which case their respective file name component is not added to the
  base file name.

  =EXTENSION= is a string that contains a dot followed by the file
  type extension. It can be an empty string or a nil value, in which
  case it is not added to the base file name.

#+findex: denote-extract-keywords-from-path
+ Function ~denote-extract-keywords-from-path~ :: Extract keywords
  from =PATH= and return them as a list of strings.  =PATH= must be a
  Denote-style file name where keywords are prefixed with an
  underscore.  If =PATH= has no such keywords, which is possible,
  return nil ([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-naming scheme]]).

#+findex: denote-extract-id-from-string
+ Function ~denote-extract-id-from-string~ :: Return existing Denote
  identifier in =STRING=, else nil.

#+findex: denote-retrieve-filename-identifier
+ Function ~denote-retrieve-filename-identifier~ :: Extract identifier
  from =FILE= name, if present, else return nil.  To create a new one, refer to the
  ~denote-create-unique-file-identifier~ function.

#+findex: denote-retrieve-filename-title
+ Function ~denote-retrieve-filename-title~ ::  Extract Denote title
  component from =FILE= name, if present, else return nil.

#+findex: denote-retrieve-filename-keywords
+ Function ~denote-retrieve-filename-keywords~ ::  Extract keywords
  from =FILE= name, if present, else return nil. Return
  matched keywords as a single string.

#+findex: denote-retrieve-filename-signature
+ Function ~denote-retrieve-filename-signature~ :: Extract signature
  from =FILE= name, if present, else return nil.

#+findex: denote-retrieve-title-or-filename
+ Function ~denote-retrieve-title-or-filename~ :: Return appropriate
  title for =FILE= given its =TYPE=. This is a wrapper for
  ~denote-retrieve-front-matter-title-value~ and
  =denote-retrieve-filename-title=.

#+findex: denote-get-identifier
+ Function ~denote-get-identifier~ :: Convert =DATE= into a Denote
  identifier using ~denote-id-format~. =DATE= is parsed by
  ~denote-valid-date-p~. If =DATE= is nil, use the current time.

#+findex: denote-create-unique-file-identifier
+ Function ~denote-create-unique-file-identifier~ :: Create a new unique
  =FILE= identifier.  Test that the identifier is unique among
  =USED-IDS=.  The conditions are as follows:

  - If =DATE= is non-nil, invoke ~denote-prompt-for-date-return-id~.

  - If =DATE= is nil, use the file attributes to determine the last
    modified date and format it as an identifier.

  - As a fallback, derive an identifier from the current time.

  With optional =USED-IDS= as nil, test that the identifier is unique
  among all files and buffers in variable ~denote-directory~.

  To only return an existing identifier, refer to the function
  ~denote-retrieve-filename-identifier~.

#+findex: denote-retrieve-front-matter-title-value
+ Function ~denote-retrieve-front-matter-title-value~ :: Return title value from
  =FILE= front matter per =FILE-TYPE=.

#+findex: denote-retrieve-front-matter-title-line
+ Function ~denote-retrieve-front-matter-title-line~ :: Return title line from
  =FILE= front matter per =FILE-TYPE=.

#+findex: denote-retrieve-front-matter-keywords-value
+ Function ~denote-retrieve-front-matter-keywords-value~ :: Return keywords value
  from =FILE= front matter per =FILE-TYPE=. The return value is a list
  of strings.

#+findex: denote-retrieve-front-matter-keywords-line
+ Function ~denote-retrieve-front-matter-keywords-line~ :: Return keywords line
  from =FILE= front matter per =FILE-TYPE=.

#+findex: denote-add-prompts
+ Function ~denote-add-prompts~ :: Add list of =ADDITIONAL-PROMPTS= to
  ~denote-prompts~. This is best done inside of a ~let~ to create a
  wrapper function around ~denote~, ~denote-rename-file~, and
  generally any command that consults the value of ~denote-prompts~.

#+findex: denote-signature-prompt
+ Function ~denote-signature-prompt~ :: Prompt for signature string.
  With optional =INITIAL-SIGNATURE= use it as the initial minibuffer
  text. With optional =PROMPT-TEXT= use it in the minibuffer instead
  of the default prompt. Previous inputs at this prompt are available
  for minibuffer completion if the user option ~denote-history-completion-in-prompts~
  is set to a non-nil value ([[#h:403422a7-7578-494b-8f33-813874c12da3][The ~denote-history-completion-in-prompts~ option]]).

#+findex: denote-file-prompt
+ Function ~denote-file-prompt~ :: Prompt for file in variable
  ~denote-directory~. Files that match ~denote-excluded-files-regexp~
  are excluded from the list. With optional =FILES-MATCHING-REGEXP=,
  filter the candidates per the given regular expression. With
  optional =PROMPT-TEXT=, use it instead of the default call to select
  a file. With optional =NO-REQUIRE-MATCH= accept the given input
  as-is. Return the absolute path to the matching file.

#+findex: denote-keywords-prompt
+ Function ~denote-keywords-prompt~ :: Prompt for one or more keywords.
  Read entries as separate when they are demarcated by the
  ~crm-separator~, which typically is a comma. With optional
  =PROMPT-TEXT=, use it to prompt the user for keywords. Else use a
  generic prompt. With optional =INITIAL-KEYWORDS= use them as the
  initial minibuffer text.

#+findex: denote-title-prompt
+ Function ~denote-title-prompt~ :: Prompt for title string. With
  optional =INITIAL-TITLE= use it as the initial minibuffer text. With
  optional =PROMPT-TEXT= use it in the minibuffer instead of the
  default prompt. Previous inputs at this prompt are available
  for minibuffer completion if the user option ~denote-history-completion-in-prompts~
  is set to a non-nil value ([[#h:403422a7-7578-494b-8f33-813874c12da3][The ~denote-history-completion-in-prompts~ option]]).

#+vindex: denote-title-prompt-current-default
+ Variable ~denote-title-prompt-current-default~ :: Currently bound
  default title for ~denote-title-prompt~.  Set the value of this
  variable within the lexical scope of a command that needs to supply
  a default title before calling ~denote-title-prompt~ and use
  ~unwind-protect~ to set its value back to nil.

#+findex: denote-file-type-prompt
+ Function ~denote-file-type-prompt~ :: Prompt for ~denote-file-type~.
  Note that a non-nil value other than ~text~, ~markdown-yaml~, and
  ~markdown-toml~ falls back to an Org file type.  We use ~org~ here
  for clarity.

#+findex: denote-date-prompt
+ Function ~denote-date-prompt~ :: Prompt for date, expecting
  =YYYY-MM-DD= or that plus =HH:MM= (or even =HH:MM:SS=).  Use Org's
  more advanced date selection utility if the user option
  ~denote-date-prompt-use-org-read-date~ is non-nil.  It requires Org
  ([[#h:e7ef08d6-af1b-4ab3-bb00-494a653e6d63][The denote-date-prompt-use-org-read-date option]]).

#+findex: denote-command-prompt
+ Function ~denote-command-prompt~ ::  Prompt for command among
  ~denote-commands-for-new-notes~ ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).

#+vindex: denote-prompts-with-history-as-completion
+ Variable ~denote-prompts-with-history-as-completion~ :: Prompts that
  conditionally perform completion against their history. These are
  minibuffer prompts that ordinarily accept a free form string input,
  as opposed to matching against a predefined set. These prompts can
  optionally perform completion against their own minibuffer history
  when the user option ~denote-history-completion-in-prompts~ is set
  to a non-nil value ([[#h:403422a7-7578-494b-8f33-813874c12da3][The ~denote-history-completion-in-prompts~ option]]).

#+findex: denote-files-matching-regexp-prompt
+ Function ~denote-files-matching-regexp-prompt~ ::  Prompt for
  =REGEXP= to filter Denote files by. With optional =PROMPT-TEXT= use
  it instead of a generic prompt.

#+findex: denote-prompt-for-date-return-id
+ Function ~denote-prompt-for-date-return-id~ :: Use
  ~denote-date-prompt~ and return it as ~denote-id-format~.

#+findex: denote-template-prompt
+ Function ~denote-template-prompt~ :: Prompt for template key in
  ~denote-templates~ and return its value.

#+findex: denote-subdirectory-prompt
+ Function ~denote-subdirectory-prompt~ :: Prompt for subdirectory of
  the variable ~denote-directory~.  The table uses the ~file~
  completion category (so it works with packages such as ~marginalia~
  and ~embark~).

#+findex: denote-rename-file-prompt
- Function ~denote-rename-file-prompt~ :: Prompt to rename file named
  =OLD-NAME= to =NEW-NAME=. If ~denote-rename-confirmations~ does not
  contain ~modify-file-name~, return t without prompting.

#+findex: denote-rename-file-and-buffer
+ Function ~denote-rename-file-and-buffer~ :: Rename file named
  =OLD-NAME= to =NEW-NAME=, updating buffer name.

#+findex: denote-rewrite-front-matter
+ Function ~denote-rewrite-front-matter~ :: Rewrite front matter of
  note after ~denote-rename-file~ (or related) The =FILE=, =TITLE=,
  =KEYWORDS=, and =FILE-TYPE= arguments are given by the renaming
  command and are used to construct new front matter values if
  appropriate. If ~denote-rename-confirmations~ contains
  ~rewrite-front-matter~, prompt to confirm the rewriting of the front
  matter. Otherwise produce a ~y-or-n-p~ prompt to that effect.

#+findex: denote-add-front-matter-prompt
+ Function ~denote-add-front-matter-prompt~ :: Prompt to add a
  front-matter to =FILE=. Return non-nil if a new front matter should
  be added. If ~denote-rename-confirmations~ does not contain
  ~add-front-matter~, return t without prompting.

#+findex: denote-rewrite-keywords
+ Function ~denote-rewrite-keywords~ :: Rewrite =KEYWORDS= in =FILE=
  outright according to =FILE-TYPE=. Do the same as
  ~denote-rewrite-front-matter~ for keywords, but do not ask for
  confirmation. With optional =SAVE-BUFFER=, save the buffer
  corresponding to =FILE=. This function is for use in the commands
  ~denote-keywords-add~, ~denote-keywords-remove~,
  ~denote-dired-rename-files~, or related.

#+findex: denote-update-dired-buffers
+ Function ~denote-update-dired-buffers~ :: Update Dired buffers of
  variable ~denote-directory~. Also revert the current Dired buffer
  even if it is not inside the ~denote-directory~. Note that the
  ~denote-directory~ accepts a directory-local value for what we
  internally refer to as "silos" ([[#h:15719799-a5ff-4e9a-9f10-4ca03ef8f6c5][Maintain separate directories for notes]]).

#+vindex: denote-file-types
+ Variable ~denote-file-types~ :: Alist of ~denote-file-type~ and
  their format properties.

  Each element is of the form =(SYMBOL PROPERTY-LIST)=.  =SYMBOL= is
  one of those specified in ~denote-file-type~ or an arbitrary symbol
  that defines a new file type.

  =PROPERTY-LIST= is a plist that consists of the following elements:

  1. =:extension= is a string with the file extension including the
     period.

  2. =:date-function= is a function that can format a date.  See the
     functions ~denote--date-iso-8601~, ~denote--date-rfc3339~, and
     ~denote--date-org-timestamp~.

  3. =:front-matter= is either a string passed to ~format~ or a
     variable holding such a string.  The ~format~ function accepts
     four arguments, which come from ~denote~ in this order: =TITLE=,
     =DATE=, =KEYWORDS=, =IDENTIFIER=.  Read the doc string of
     ~format~ on how to reorder arguments.

  4. =:title-key-regexp= is a regular expression that is used to
     retrieve the title line in a file.  The first line matching this
     regexp is considered the title line.

  5. =:title-value-function= is the function used to format the raw
     title string for inclusion in the front matter (e.g. to surround
     it with quotes).  Use the ~identity~ function if no further
     processing is required.

  6. =:title-value-reverse-function= is the function used to retrieve
     the raw title string from the front matter.  It performs the
     reverse of =:title-value-function=.

  7. =:keywords-key-regexp= is a regular expression used to retrieve
     the keywords' line in the file.  The first line matching this
     regexp is considered the keywords' line.

  8. =:keywords-value-function= is the function used to format the
     keywords' list of strings as a single string, with appropriate
     delimiters, for inclusion in the front matter.

  9. =:keywords-value-reverse-function= is the function used to retrieve
     the keywords' value from the front matter.  It performs the reverse
     of the =:keywords-value-function=.

  10. =:link= is a string, or variable holding a string, that
      specifies the format of a link.  See the variables
      ~denote-org-link-format~, ~denote-md-link-format~.

  11. =:link-in-context-regexp= is a regular expression that is used
      to match the aforementioned link format.  See the variables
      ~denote-org-link-in-context-regexp~, ~denote-md-link-in-context-regexp~.

  If ~denote-file-type~ is nil, use the first element of this list for
  new note creation.  The default is ~org~.

#+vindex: denote-org-front-matter
+ Variable ~denote-org-front-matter~ :: Specifies the Org front
  matter.  It is passed to ~format~ with arguments =TITLE=, =DATE=,
  =KEYWORDS=, =ID= ([[#h:7f918854-5ed4-4139-821f-8ee9ba06ad15][Change the front matter format]])

#+vindex: denote-yaml-front-matter
+ Variable ~denote-yaml-front-matter~ :: Specifies the YAML (Markdown)
  front matter.  It is passed to ~format~ with arguments =TITLE=,
  =DATE=, =KEYWORDS=, =ID= ([[#h:7f918854-5ed4-4139-821f-8ee9ba06ad15][Change the front matter format]])

#+vindex: denote-toml-front-matter
+ Variable ~denote-toml-front-matter~ :: Specifies the TOML (Markdown)
  front matter.  It is passed to ~format~ with arguments =TITLE=,
  =DATE=, =KEYWORDS=, =ID= ([[#h:7f918854-5ed4-4139-821f-8ee9ba06ad15][Change the front matter format]])

#+vindex: denote-text-front-matter
+ Variable ~denote-text-front-matter~ :: Specifies the plain text
  front matter.  It is passed to ~format~ with arguments =TITLE=,
  =DATE=, =KEYWORDS=, =ID= ([[#h:7f918854-5ed4-4139-821f-8ee9ba06ad15][Change the front matter format]])

#+vindex: denote-org-link-format
+ Variable ~denote-org-link-format~ :: Format of Org link to note.
  The value is passed to ~format~ with =IDENTIFIER= and =TITLE=
  arguments, in this order.  Also see ~denote-org-link-in-context-regexp~.

#+vindex: denote-md-link-format
+ Variable ~denote-md-link-format~ :: Format of Markdown link to note.
  The =%N$s= notation used in the default value is for ~format~ as the
  supplied arguments are =IDENTIFIER= and =TITLE=, in this order.
  Also see ~denote-md-link-in-context-regexp~.

#+vindex: denote-id-only-link-format
+ Variable ~denote-id-only-link-format~ :: Format of identifier-only
  link to note.  The value is passed to ~format~ with =IDENTIFIER= as
  its sole argument.    Also see ~denote-id-only-link-in-context-regexp~.

#+vindex: denote-org-link-in-context-regexp
+ Variable ~denote-org-link-in-context-regexp~ :: Regexp to match an
  Org link in its context.  The format of such links is ~denote-org-link-format~.

#+vindex: denote-md-link-in-context-regexp
+ Variable ~denote-md-link-in-context-regexp~ :: Regexp to match an
  Markdown link in its context.  The format of such links is ~denote-md-link-format~.

#+vindex: denote-id-only-link-in-context-regexp
+ Variable ~denote-id-only-link-in-context-regexp~ :: Regexp to match
  an identifier-only link in its context.  The format of such links is
  ~denote-id-only-link-format~.

#+findex: denote-date-org-timestamp
+ Function ~denote-date-org-timestamp~ :: Format =DATE= using the Org
  inactive timestamp notation.

#+findex: denote-date-rfc3339
+ Function ~denote-date-rfc3339~ :: Format =DATE= using the RFC3339
  specification.

#+findex: denote-date-iso-8601
+ Function ~denote-date-iso-8601~ :: Format =DATE= according to ISO
  8601 standard.

#+findex: denote-trim-whitespace
+ Function ~denote-trim-whitespace~ :: Trim whitespace around string
  =S=.  This can be used in ~denote-file-types~ to format front
  mattter.

#+findex: denote-trim-whitespace-then-quotes
+ Function ~denote-trim-whitespace-then-quotes~ :: Trim whitespace
  then quotes around string =S=.  This can be used in
  ~denote-file-types~ to format front mattter.

#+findex: denote-format-string-for-org-front-matter
+ Function ~denote-format-string-for-org-front-matter~ :: Return
  string =S= as-is for Org or plain text front matter. If =S= is not a
  string, return an empty string.

#+findex: denote-format-string-for-md-front-matter
+ Function ~denote-format-string-for-md-front-matter~ :: Surround
  string =S= with quotes. If =S= is not a string, return a literal
  emptry string. This can be used in ~denote-file-types~ to format
  front mattter.

#+findex: denote-format-keywords-for-md-front-matter
+ Function ~denote-format-keywords-for-md-front-matter~ :: Format
  front matter =KEYWORDS= for markdown file type.  =KEYWORDS= is a
  list of strings.  Consult the ~denote-file-types~ for how this is
  used.

#+findex: denote-format-keywords-for-text-front-matter
+ Function ~denote-format-keywords-for-text-front-matter~ :: Format
  front matter =KEYWORDS= for text file type.  =KEYWORDS= is a list of
  strings.  Consult the ~denote-file-types~ for how this is used.

#+findex: denote-format-keywords-for-org-front-matter
+ Function ~denote-format-keywords-for-org-front-matter~ :: Format
  front matter =KEYWORDS= for org file type.  =KEYWORDS= is a list of
  strings.  Consult the ~denote-file-types~ for how this is used.

#+findex: denote-extract-keywords-from-front-matter
+ Function ~denote-extract-keywords-from-front-matter~ :: Format front
  matter =KEYWORDS= for org file type.  =KEYWORDS= is a list of
  strings.  Consult the ~denote-file-types~ for how this is used.

#+findex: denote-select-linked-file-prompt
+ Function ~denote-select-linked-file-prompt~ :: Prompt for linked
  file among =FILES=.

#+findex: denote-link-return-links
+ Function ~denote-link-return-links~ :: Return list of links in
  current or optional =FILE=.  Also see ~denote-link-return-backlinks~.

#+findex: denote-link-return-backlinks
+ Function ~denote-link-return-backlinks~ :: Return list of backlinks
  in current or optional =FILE=.  Also see ~denote-link-return-links~.

#+vindex: denote-link-signature-format
+ Variable ~denote-link-signature-format~ :: Format of link
  description for ~denote-link-with-signature~.

#+findex: denote-link-description-with-signature-and-title
+ Function ~denote-link-description-with-signature-and-title~ :: Return
  link description for =FILE=.  Produce a description as follows:

- If the region is active, use it as the description.

- If =FILE= as a signature, then use the
  ~denote-link-signature-format~.  By default, this looks like
  "signature title".

- If =FILE= does not have a signature, then use its title as the
  description.

#+vindex: denote-link-description-function
+ Variable ~denote-link-description-function~ :: Function to use to
  create the description of links. The function specified should take
  a =FILE= argument and should return the description as a string. By
  default, the title of the file is returned as the description.

* Troubleshoot Denote in a pristine environment
:PROPERTIES:
:CUSTOM_ID: h:9c4467d5-6480-4681-80fb-cd9717bf8b3b
:END:

Sometimes we get reports on bugs that may not be actually caused by
some error in the Denote code base.  To help gain insight into what
the problem is, we need to be able to reproduce the issue in a minimum
viable system.  Below is one way to achieve this.

1. Find where your =denote.el= file is stored on your filesystem.

2. Assuming you have already installed the package, one way to do this
   is to invoke =M-x find-library= and search for ~denote~.  It will
   take you to the source file.  There do =M-x eval-expression=, which
   will bring up a minibuffer prompt.  At the prompt evaluate:

#+begin_example emacs-lisp
(kill-new (expand-file-name (buffer-file-name)))
#+end_example

3. The above will save the full file system path to your kill ring.

4. In a terminal emulator or an =M-x shell= buffer execute:

#+begin_example
emacs -Q
#+end_example

5. This will open a new instance of Emacs in a pristine environment.
   Only the default settings are loaded.

6. In the =*scratch*= buffer of =emacs -Q=, add your configurations
   like the following and try to reproduce the issue:

#+begin_example emacs-lisp
(require 'denote "/full/path/to/what/you/got/denote.el")

;; Your configurations here
#+end_example

Then try to see if your problem still occurs.  If it does, then the
fault is with Denote.  Otherwise there is something external to it
that we need to account for.  Whatever the case, this exercise helps
us get a better sense of the specifics.

* Contributing
:PROPERTIES:
:CUSTOM_ID: h:1ebe4865-c001-4747-a6f2-0fe45aad71cd
:END:

Denote is a GNU ELPA package. As such, any significant change to the
code requires copyright assignment to the Free Software Foundation
(more below).

You do not need to be a programmer to contribute to this package.
Sharing an idea or describing a workflow is equally helpful, as it
teaches us something we may not know and might be able to cover either
by extending Denote or expanding this manual. If you prefer to write a
blog post, make sure you share it with us: we can add a section herein
referencing all such articles. Everyone gets acknowledged
([[#h:f8126820-3b59-49fa-bcc2-73bd60132bb9][Acknowledgements]]). There is no such thing as an "insignificant
contribution"---they all matter.

+ Package name (GNU ELPA): ~denote~
+ Official manual: <https://protesilaos.com/emacs/denote>
+ Change log: <https://protesilaos.com/emacs/denote-changelog>
+ Git repositories:
  + GitHub: <https://github.com/protesilaos/denote>
  + GitLab: <https://gitlab.com/protesilaos/denote>

If our public media are not suitable, you are welcome to contact me
(Protesilaos) in private: <https://protesilaos.com/contact>.

Copyright assignment is a prerequisite to sharing code. It is a simple
process. Check the request form below (please adapt it accordingly).
You must write an email to the address mentioned in the form and then
wait for the FSF to send you a legal agreement. Sign the document and
file it back to them. This could all happen via email and take about a
week. You are encouraged to go through this process. You only need to
do it once. It will allow you to make contributions to Emacs in
general.

#+begin_example text
Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.

Please use your full legal name (in ASCII characters) as the subject
line of the message.

REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES

[What is the name of the program or package you're contributing to?]

GNU Emacs

[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]

Copied a few snippets from the same files I edited.  Their author,
Protesilaos Stavrou, has already assigned copyright to the Free Software
Foundation.

[Do you have an employer who might have a basis to claim to own
your changes?  Do you attend a school which might make such a claim?]


[For the copyright registration, what country are you a citizen of?]


[What year were you born?]


[Please write your email address here.]


[Please write your postal address here.]





[Which files have you changed so far, and which new files have you written
so far?]

#+end_example

** Wishlist of what we can do to extend Denote
:PROPERTIES:
:CUSTOM_ID: h:044a6a0f-e382-4013-8279-8bf4e64e73c0
:END:

These are various ideas to extend Denote. Whether they should be in
the core package or a separate extension is something we can discuss.
I, Protesilaos, am happy to help anyone who wants to do any of this.

- denote-consult.el :: This can be a separate package that enhances or
  replaces the various prompts we have for files (and maybe more) by
  using the ~consult~ package. Consult provides the preview mechanism
  and can probably be used for more things, such as to define a source
  for Denote-only buffers in the ~consult-buffer~ command. If we need
  to tweak things in =denote.el=, I am happy to do it. For example, we
  could have a ~denote-file-prompt-function~ variable, which would
  default to ~denote-file-prompt~ (what we currently have) and would
  also such a hypothetical package to easily plug into what we have.

- denote-embark.el :: Provide integration with the ~embark~ package.
  This can be for doing something with the identifier/link at point.
  For example, it could provide an action to produce backlinks for the
  identifier/file we are linking to, not just the current one.

- denote-transient.el :: The ~transient~ package is built into Emacs
  29 (Denote supports Emacs 28 though). We can use it to define an
  alternative to what we have for the menu bar. Perhaps this interface
  can used to toggle various options, such as to call ~denote~ with a
  different set of prompts.

- A ~denote-directories~ user option :: This can be either an
  extension of the ~denote-directory~ (accept a list of file paths
  value) or a new variable. The idea is to let the user define
  separate Denote directories which do know about the presence of each
  other (unlike silos). This way, a user can have an entry in
  =~/Documents/notes/= link to something =~/Git/projects/= and
  everything work as if the ~denote-directory~ is set to the =~/=
  (with the status quo as of 2024-02-18 08:27 +0200).

- Signatures before identifiers :: This is probably going to increase
  the complixity of =denote.el= and may not be worth pursuing. But
  just to explore the idea: we could have an option to rearrange file
  names such that the signature appears before the identifier. If we
  can do this in a smart way, we can probably extend the principle for
  all file name components. Again though, this may be too complex and
  not worth doing.

- Encode the day in the identifier :: The idea is to use some coded
  reference for Monday, Tuesday, etc. instead of having the generic
  =T= in the identifier. For example, Monday is =A= so the identifier
  for it is something like =20240219A101522= instead of what we now
  have as =20240219T101522=. The old method should still be supported.
  Apart from changing a few regular expressions, this does not seem
  too complex to me. We would need a user option to opt in to such a
  feature. Then tweak the relevant parts. The tricky issue is to
  define a mapping of day names to letters/symbols that works for
  everyone. Do all countries have a seven-day week, for example? We
  need something universally applicable here.

Anything else? You are welcome to discuss these and/or add to the
list.

* Publications about Denote
:PROPERTIES:
:CUSTOM_ID: h:ca0c38f9-fa3e-4901-947e-1b589335781d
:END:

The Emacs community is putting Denote to great use.  This section
includes publications that show how people configure their note-taking
setup.  If you have a blog post, video, or configuration file about
Denote, feel welcome to tell us about it ([[#h:1ebe4865-c001-4747-a6f2-0fe45aad71cd][Contributing]]).

+ David Wilson (SystemCrafters): /Generating a Blog Site from Denote
  Entries/, 2022-09-09, <https://www.youtube.com/watch?v=5R7ad5xz5wo>

+ David Wilson (SystemCrafters): /Trying Out Prot's Denote, an Org
  Roam Alternative?/, 2022-07-15, <https://www.youtube.com/watch?v=QcRY_rsX0yY>

+ Jack Baty: /Keeping my Org Agenda updated based on Denote keywords/,
  2022-11-30, <https://baty.net/2022/keeping-my-org-agenda-updated>

+ Jeremy Friesen: /Denote Emacs Configuration/, 2022-10-02,
  <https://takeonrules.com/2022/10/09/denote-emacs-configuration/>

+ Jeremy Friesen: /Exploring the Denote Emacs Package/, 2022-10-01,
  <https://takeonrules.com/2022/10/01/exploring-the-denote-emacs-package/>

+ Jeremy Friesen: /Migration Plan for Org-Roam Notes to Denote/,
  2022-10-02, <https://takeonrules.com/2022/10/02/migration-plan-for-org-roam-notes-to-denote/>

+ Jeremy Friesen: /Project Dispatch Menu with Org Mode Metadata,
  Denote, and Transient/, 2022-11-19,
  <https://takeonrules.com/2022/11/19/project-dispatch-menu-with-org-mode-metadata-denote-and-transient/>

+ Mohamed Suliman: /Managing a bibliography of BiBTeX entries with
  Denote/, 2022-12-20, <https://www.scss.tcd.ie/~sulimanm/posts/denote-bibliography.html>

+ Peter Prevos: /Simulating Text Files with R to Test the Emacs Denote
  Package/, 2022-07-28, <https://lucidmanager.org/productivity/testing-denote-package/>

+ Peter Prevos: /Emacs Writing Studio/, 2023-10-19. A configuration for authors, using Denote for taking notes, literature reviews and manage collections of images:
  - <https://lucidmanager.org/productivity/taking-notes-with-emacs-denote/>
  - <https://lucidmanager.org/productivity/denote-explore/>
  - <https://lucidmanager.org/productivity/bibliographic-notes-in-emacs-with-citar-denote/>
  - <https://lucidmanager.org/productivity/using-emacs-image-dired/>

+ Stefan Thesing: /Denote as a Zettelkasten/, 2023-03-02,
  <https://www.thesing-online.de/blog/denote-as-a-zettelkasten>

+ Summer Emacs: /An explanation of how I use Emacs/, 2023-05-04,
  <https://github.com/summeremacs/howiuseemacs/blob/main/full-explanation-of-how-i-use-emacs.org>

* Alternatives to Denote
:PROPERTIES:
:CUSTOM_ID: h:dbb51a1b-90b8-48e8-953c-e2fb3e36981e
:END:

What follows is a list of Emacs packages for note-taking.  I
(Protesilaos) have not used any of them, as I was manually applying my
file-naming scheme beforehand and by the time those packages were
available I was already hacking on the predecessor of Denote as a means
of learning Emacs Lisp (a package which I called "Unassuming Sidenotes
of Little Significance", aka "USLS" which is pronounced as "U-S-L-S" or
"useless").  As such, I cannot comment at length on the differences
between Denote and each of those packages, beside what I gather from
their documentation.

+ [[https://github.com/org-roam/org-roam][org-roam]] :: The de facto standard in the Emacs milieu---and rightly
  so!  It has a massive community, is featureful, and should be an
  excellent companion to anyone who is invested in the Org ecosystem
  and/or knows what "Roam" is (I don't).  It has been explained to me
  that Org Roam uses a database to store a cache about your notes.  It
  otherwise uses standard Org files.  The cache helps refer to the same
  node through aliases which can provide lots of options.  Personally, I
  follow a single-topic-per-note approach, so anything beyond that is
  overkill.  If the database is only for a cache, then maybe that has no
  downside, though I am careful with any kind of specialised program as
  it creates a dependency.  If you ask me about database software in
  particular, I have no idea how to use one, let alone debug it or
  retrieve data from it if something goes awry (I could learn, but that
  is beside the point).

+ [[https://github.com/localauthor/zk][zk (or zk.el)]] :: Reading its documentation makes me think that this is
  Denote's sibling---the two projects have a lot of things in common,
  including the preference to rely on plain files and standard tools.
  The core difference is that Denote has a strict file-naming scheme.
  Other differences in available features are, in principle, matters of
  style or circumstance: both packages can have them.  As its initials
  imply, ZK enables a zettelkasten-like workflow.  It does not enforce
  it though, letting the user adapt the method to their needs and
  requirements.

+ [[https://github.com/ymherklotz/emacs-zettelkasten][zettelkasten]] :: This is another one of Denote's relatives, at least
  insofar as the goal of simplicity is concerned.  The major difference
  is that according to its documentation "the name of the file that is
  created is just a unique ID".  This is not consistent with our
  file-naming scheme which is all about making sense of your files by
  their name alone and being able to visually parse a listing of them
  without any kind of specialised tool (e.g. =ls -l= or =ls -C= on the
  command-line from inside the ~denote-directory~ give you a
  human-readable set of files names, while =find * -maxdepth 0 -type f=
  is another approach).

+ [[https://github.com/EFLS/zetteldeft][zetteldeft]] :: This is a zettelkasten note-taking system built on top
  of the =deft= package.  Deft provides a search interface to a
  directory, in this case the one holding the user's =zetteldeft= notes.
  Denote has no such dependency and is not opinionated about how the
  user prefers to search/access their notes: use Dired, Grep, the
  =consult= package, or whatever else you already have set up for all
  things Emacs, not just your notes.

Searching through =M-x list-packages= for "zettel" brings up more
matches.  =zetteldesk= is an extension to Org Roam and, as such, I
cannot possibly know what Org Roam truly misses and what the added-value
of this package is.  =neuron-mode= builds on top of an external program
called =neuron=, which I have never used.

Searching for "note" gives us a few more results.  =notes-mode= has
precious little documentation and I cannot tell what it actually does
(as I said in my presentation for LibrePlanet 2022, inadequate docs are
a bug).  =side-notes= differs from what we try to do with Denote, as it
basically gives you the means to record your thoughts about some other
project you are working on and keep them on the side: so it and Denote
should not be mutually exclusive.

If I missed something, please let me know.

** Alternative implementations and further reading
:PROPERTIES:
:CUSTOM_ID: h:188c0986-f2fa-444f-b493-5429356e75cf
:END:

This section covers blog posts and implementations from the Emacs
community about the topic of note-taking and file organization.  They
may refer to some of the packages covered in the previous section or
provide their custom code ([[#h:dbb51a1b-90b8-48e8-953c-e2fb3e36981e][Alternatives to Denote]]).  The list is
unsorted.

+ José Antonio Ortega Ruiz (aka "jao") explains a note-taking method
  that is simple like Denote but differs in other ways.  An interesting
  approach overall: https://jao.io/blog/simple-note-taking.html.

+ Jethro Kuan (the main =org-roam= developer) explains their note-taking
  techniques: https://jethrokuan.github.io/org-roam-guide/.  Good ideas
  all round, regardless of the package/code you choose to use.

+ Karl Voit's tools [[https://github.com/novoid/date2name][date2name]], [[https://github.com/novoid/filetags/][filetags]], [[https://github.com/novoid/appendfilename/][appendfilename]], and
  [[https://github.com/novoid/move2archive][move2archive]] provide a Python-based implementation to organize
  individual files which do not require Emacs.  His approach ([[https://karl-voit.at/managing-digital-photographs/][blog
  post]] and his [[https://www.youtube.com/watch?v=rckSVmYCH90][presentation at GLT18]]) has been complemented by [[https://github.com/novoid/memacs][memacs]]
  to process e.g., the date of creation of photographs, or the log of
  a phone call in a format compatible to org.

[ Development note: help expand this list. ]

* Frequently Asked Questions
:PROPERTIES:
:CUSTOM_ID: h:da2944c6-cde6-4c65-8f2d-579305a159bb
:END:

I (Protesilaos) answer some questions I have received or might get.  It
is assumed that you have read the rest of this manual: I will not go
into the specifics of how Denote works.

** Why develop Denote when PACKAGE already exists?
:PROPERTIES:
:CUSTOM_ID: h:b875450a-ae22-4899-ac23-c10fa9c279bb
:END:

I wrote Denote because I was using a variant of Denote's file-naming
scheme before I was even an Emacs user (I switched to Emacs from
Tmux+Vim+CLI in the summer of 2019).  I was originally inspired by
Jekyll, the static site generator, which I started using for my website
in 2016 (was on WordPress before).  Jekyll's files follow the
=YYYY-MM-DD-TITLE.md= pattern.  I liked its efficiency relative to the
unstructured mess I had before.  Eventually, I started using that scheme
outside the confines of my website's source code.  Over time I refined
it and here we are.

Note-taking is something I take very seriously, as I am a prolific
writer (just check my website, which only reveals the tip of the
iceberg).  As such, I need a program that does exactly what I want and
which I know how to extend.  I originally tried to use Org capture
templates to create new files with a Denote-style file-naming scheme but
never managed to achieve it.  Maybe because ~org-capture~ has some
hard-coded assumptions or I simply am not competent enough to hack on
core Org facilities.  Whatever the case, an alternative was in order.

The existence of PACKAGE is never a good reason for me not to conduct my
own experiments for recreational, educational, or practical purposes.
When the question arises of "why not contribute to PACKAGE instead?" the
answer is that without me experimenting in the first place, I would lack
the skills for such a task.  Furthermore, contributing to another
package does not guarantee I get what I want in terms of workflow.

Whether you should use Denote or not is another matter altogether:
choose whatever you want.

** Why not rely exclusively on Org?
:PROPERTIES:
:CUSTOM_ID: h:b9831849-5c71-484e-b444-bac19cc13151
:END:

I think Org is one of Emacs' killer apps.  I also believe it is not the
right tool for every job.  When I write notes, I want to focus on
writing.  Nothing more.  I thus have no need for stuff like org-babel,
scheduling to-do items, clocking time, and so on.  The more "mental
dependencies" you add to your workflow, the heavier the burden you carry
and the less focused you are on the task at hand: there is always that
temptation to tweak the markup, tinker with some syntactic construct,
obsess about what ought to be irrelevant to writing as such.

In technical terms, I also am not fond of Org's code base (I understand
why it is the way it is---just commenting on the fact).  Ever tried to
read it?  You will routinely find functions that are tens-to-hundreds of
lines long and have all sorts of special casing.  As I am not a
programmer and only learnt to write Elisp through trial and error, I
have no confidence in my ability to make Org do what I want at that
level, hence =denote= instead of =org-denote= or something.

Perhaps the master programmer is one who can deal with complexity and
keep adding to it.  I am of the opposite view, as language---code
included---is at its communicative best when it is clear and accessible.

Make no mistake: I use Org for the agenda and also to write technical
documentation that needs to be exported to various formats, including
this very manual.

** Why care about Unix tools when you use Emacs?
:PROPERTIES:
:CUSTOM_ID: h:da1e2469-8f04-450b-a379-a854efa80a36
:END:

My notes form part of my longer-term storage.  I do not want to have to
rely on a special program to be able to read them or filter them.  Unix
is universal, at least as far as I am concerned.

Denote streamlines some tasks and makes things easier in general, which
is consistent with how Emacs provides a layer of interactivity on top of
Unix.  Still, Denote's utilities can, in principle, be implemented as
POSIX shell scripts (minus the Emacs-specific parts like fontification
in Dired or the buttonization of links).

Portability matters.  For example, in the future I might own a
smartphone, so I prefer not to require Emacs, Org, or some other
executable to access my files on the go.

Furthermore, I might want to share those files with someone.  If I make
Emacs a requirement, I am limiting my circle to a handful of relatively
advanced users.

Please don't misinterpret this: I am using Emacs full-time for my
computing and maintain a growing list of packages for it.  This is just
me thinking long-term.

** Why many small files instead of few large ones?
:PROPERTIES:
:CUSTOM_ID: h:7d2e7b8a-d484-4c1d-8688-17f70f242ad7
:END:

I have read that Org favours the latter method.  If true, I strongly
disagree with it because of the implicit dependency it introduces and
the way it favours machine-friendliness over human-readability in terms
of accessing information.  Notes are long-term storage.  I might want to
access them on (i) some device with limited features, (ii) print on
paper, (iii) share with another person who is not a tech wizard.

There are good arguments for few large files, but all either prioritize
machine-friendliness or presuppose the use of sophisticated tools like
Emacs+Org.

Good luck using =less= on a generic TTY to read a file with a zillion
words, headings, sub-headings, sub-sub-headings, property drawers, and
other constructs!  You will not get the otherwise wonderful folding of
headings the way you do in Emacs---do not take such features for
granted.

My point is that notes should be atomic to help the user---and
potentially the user's family, friends, acquaintances---make sense of
them in a wide range of scenaria.  The more program-agnostic your file
is, the better for you and/or everyone else you might share your
writings with.

Human-readability means that we optimize for what matters to us.  If (a)
you are the only one who will ever read your notes, (b) always have
access to good software like Emacs+Org, (c) do not care about printing
on paper, then Denote's model is not for you.  Maybe you need to tweak
some ~org-capture~ template to append a new entry to one mega file (I do
that for my Org agenda, by the way, as I explained before about using
the right tool for the job).

** Does Denote perform well at scale?
:PROPERTIES:
:CUSTOM_ID: h:863f812a-aac7-42ea-83b3-fbbdb58e08d7
:END:

Denote does not do anything fancy and has no special requirements: it
uses standard tools to accomplish ordinary tasks.  If Emacs can cope
with lots of files, then that is all you need to know: Denote will work.

To put this to the test, Peter Prevos is running simulations with R that
generate large volumes of notes.  You can read the technicalities here:
<https://lucidmanager.org/productivity/testing-denote-package/>.
Excerpt:

#+begin_quote
Using this code I generated ten thousands notes and used this to test
the Denote package to see it if works at a large scale. This tests shows
that Prot's approach is perfectly capable of working with thousands of
notes.
#+end_quote

Of course, we are always prepared to make refinements to the code, where
necessary, without compromising on the project's principles.

** I add TODOs to my notes; will many files slow down the Org agenda?
:PROPERTIES:
:CUSTOM_ID: h:63c2f8d4-79ed-4c55-b3ef-e048a05802c0
:END:

Yes, many files will slow down the agenda due to how that works.  Org
collects all files specified in the ~org-agenda-files~, searches through
their contents for timestamped entries, and then loops through all days
to determine where each entry belongs.  The more days and more files,
the longer it takes to build the agenda.  Doing this with potentially
hundreds of files will have a noticeable impact on performance.

This is not a deficiency of Denote.  It happens with generic Org files.
The way the agenda is built is heavily favoring the use of a single file
that holds all your timestamped entries (or at least a few such files).
Tens or hundreds of files are inefficient for this job.  Plus doing so
has the side-effect of making Emacs open all those files, which you
probably do not need.

If you want my opinion though, be more forceful with the separation of
concerns.  Decouple your knowledge base from your ephemeral to-do list:
Denote (and others) can be used for the former, while you let standard
Org work splendidly for the latter---that is what I do, anyway.

Org has a powerful linking facility, whether you use ~org-store-link~ or
do it via an ~org-capture~ template.  If you want a certain note to be
associated with a task, just store the task in a single =tasks.org= (or
however you name it) and link to the relevant context.

Do not mix your knowledge base with your to-do items.  If you need help
figuring out the specifics of this workflow, you are welcome to ask for
help in our relevant channels ([[#h:1ebe4865-c001-4747-a6f2-0fe45aad71cd][Contributing]]).

** I want to sort by last modified in Dired, why won't Denote let me?
:PROPERTIES:
:CUSTOM_ID: h:a7fd5e0a-78f7-434e-aa2e-e150479c16e2
:END:

Denote does not control how Dired sorts files. I encourage you to read
the manpage of the =ls= executable. It will help you in general, while
it applies to Emacs as well via Dired. The gist is that you can update
the =ls= flags that Dired uses on-the-fly: type =C-u M-x
dired-sort-toggle-or-edit= (=C-u s= by default) and append
=--sort=time= at the prompt. To reverse the order, add the =-r= flag.
The user option ~dired-listing-switches~ sets your default preference.

For an on-demand sorted and filtered Dired listing of Denote files,
use the command ~denote-sort-dired~ ([[#h:9fe01e63-f34f-4479-8713-f162a5ca865e][Sort files by component]]).

** How do you handle the last modified case?
:PROPERTIES:
:CUSTOM_ID: h:764b5e87-cd22-4937-b5fc-af3892d6b3d8
:END:

Denote does not insert any meta data or heading pertaining to edits in
the file.  I am of the view that these either do not scale well or are
not descriptive enough.  Suppose you use a "lastmod" heading with a
timestamp: which lines where edited and what did the change amount to?

This is where an external program can be helpful.  Use a Version Control
System, such as Git, to keep track of all your notes.  Every time you
add a new file, record the addition.  Same for post-creation edits.
Your VCS will let you review the history of those changes.  For
instance, Emacs' built-in version control framework has a command that
produces a log of changes for the current file: =M-x vc-print-log=,
bound to =C-x v l= by default.  From there one can access the
corresponding diff output (use =M-x describe-mode= (=C-h m=) in an
unfamiliar buffer to learn more about it).  With Git in particular,
Emacs users have the option of the all-round excellent =magit= package.

In short: let Denote (or equivalent) create notes and link between them,
the file manager organise and provide access to files, search programs
deal with searching and narrowing, and version control software handle
the tracking of changes.

** Why are some Org links opening outside Emacs?
:PROPERTIES:
:CUSTOM_ID: h:4f354db1-aa78-47fd-ac60-c3d1e0f0b0a4
:END:

Org has its own mechanism to determine how best to open a link. This
affects the =file:= link type, but also the =denote:= one (which is
designed to be as close to =file:= as possible).

When following a link, Org usually displays the data in an Emacs
buffer, though it might launch an external application instead. The
idea is to use a specialised program when that is relevant, such as to
display a video. Though there can be scenaria the user does not like,
such as when Org decides to load =.md= or =.html= files with an
external app. To compound the problem, users can name any file type
using the Denote file-naming scheme, including images, PDFs, videos,
and more ([[#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca][Renaming files]]).

To instruct Org to stay in Emacs for such cases, the user needs to
modify the variable ~org-file-apps~, which is not specific to Denote.
As one use-case, ~org-file-apps~ associates a regular expression to
match file names with a method on how to display them (do =M-x
describe-variable= and then search for ~org-file-apps~ to read its
documentation). Thus, the user can use something like the following
in their Org or Denote configuration:

#+begin_src emacs-lisp
;; Tell Org to use Emacs when opening files that end in .md
(add-to-list 'org-file-apps '("\\.md\\'" . emacs))

;; Do the same for .html
(add-to-list 'org-file-apps '("\\.html\\'" . emacs))
#+end_src

Each of these adds a new entry to the existing value of that user
option. Replace =md= or =html= with the desired file type extension.

** Speed up backlinks' buffer creation?
:PROPERTIES:
:CUSTOM_ID: h:893eec49-d7be-4603-bcff-fcc247244011
:END:

Denote leverages the built-in =xref= library to search for the
identifier of the current file and return any links to it.  For users
of Emacs version 28 or higher, there exists a user option to specify
the program that performs this search: ~xref-search-program~.  The
default is =grep=, which can be slow, though one may opt for =ugrep=,
=ripgrep=, or even specify something else (read the doc string of that
user option for the details).

Try either for these for better results:

#+begin_src emacs-lisp
(setq xref-search-program 'ripgrep)

;; OR

(setq xref-search-program 'ugrep)
#+end_src

To use whatever executable is available on your system, use something
like this:

#+begin_src emacs-lisp
;; Prefer ripgrep, then ugrep, and fall back to regular grep.
(setq xref-search-program
      (cond
       ((or (executable-find "ripgrep")
            (executable-find "rg"))
        'ripgrep)
       ((executable-find "ugrep")
        'ugrep)
       (t
        'grep)))
#+end_src

** Why do I get "Search failed with status 1" when I search for backlinks?
:PROPERTIES:
:CUSTOM_ID: h:42f6b07e-5956-469a-8294-17f9cf62eb2b
:END:

Denote uses [[info:emacs#Xref][Emacs' Xref]] to find backlinks.  Xref requires ~xargs~ and
one of ~grep~ or ~ripgrep~, depending on your configuration.

This is usually not an issue on *nix systems, but the necessary
executables are not available on Windows Emacs distributions.  Please
ensure that you have both ~xargs~ and either ~grep~ or ~ripgrep~
available within your ~PATH~ environment variable.

If you have ~git~ on Windows installed, then you may use the following
code (adjust the git's installation path if necessary):
#+begin_src emacs-lisp
  (setenv "PATH" (concat (getenv "PATH") ";" "C:\\Program Files\\Git\\usr\\bin"))
#+end_src

** Why do I get a double =#+title= in Doom Emacs?
:PROPERTIES:
:CUSTOM_ID: h:0f737b7d-40e6-46a7-b1db-117c0ffcbfef
:END:

Doom Emacs provides a set of bespoke templates for Org. One of those
prefills any new Org file with a =#+title= field. So when Denote
creates a new Org file and inserts front matter to it, it inevitably
adds an extra title to the existing one.

This is not a Denote problem. We can only expect a new file to be
empty by default. Check how to disable the relevant module in your
Doom Emacs configuration file.

* Acknowledgements
:PROPERTIES:
:CUSTOM_ID: h:f8126820-3b59-49fa-bcc2-73bd60132bb9
:END:
#+cindex: Contributors

Denote is meant to be a collective effort.  Every bit of help matters.

+ Author/maintainer :: Protesilaos Stavrou.

+ Contributions to code or the manual :: Abdul-Lateef Haji-Ali, Abin
  Simon, Adam Růžička, Alan Schmitt, Alexandre Rousseau, Ashton
  Wiersdorf, Benjamin Kästner, Bruno Boal, Charanjit Singh, Clemens
  Radermacher, Colin McLear, Damien Cassou, Eduardo Grajeda, Elias
  Storms, Eshel Yaron, Florian, Glenna D., Graham Marlow, Hilde Rhyne,
  Ivan Sokolov, Jack Baty, Jakub Szczerbowski, Jean-Charles Bagneris,
  Jean-Philippe Gagné Guay, Jianwei Hou, Joseph Turner, Jürgen Hötzel,
  Kaushal Modi, Kai von Fintel, Kostas Andreadis, Kristoffer
  Balintona, Kyle Meyer, Marc Fargas, Matthew Lemon, Noboru Ota
  (nobiot), Norwid Behrnd, Peter Prevos, Philip Kaludercic, Quiliro
  Ordóñez, Stephen R. Kifer, Stefan Monnier, Stefan Thesing, Thibaut
  Benjamin, Tomasz Hołubowicz, Vedang Manerikar, Wesley Harvey, Zhenxu
  Xu, arsaber101, ezchi, jarofromel, leinfink (Henrik), l-o-l-h
  (Lincoln), mattyonweb, maxbrieiev, mentalisttraceur, pmenair,
  relict007, skissue.

+ Ideas and/or user feedback :: Abin Simon, Aditya Yadav, Alan
  Schmitt, Aleksandr Vityazev, Alex Hirschfeld, Alexis Purslane,
  Alfredo Borrás, Ashton Wiersdorf, Benjamin Kästner, Claudiu
  Tănăselia, Colin McLear, Damien Cassou, Elias Storms, Federico
  Stilman, Florian, Frédéric Willem Frank Ehmsen, Glenna D., Guo Yong,
  Hanspeter Gisler Harold Ollivier, Jack Baty, Jay Rajput,
  Jean-Charles Bagneris, Jens Östlund, Jeremy Friesen, Jonathan Sahar,
  Johan Bolmsjö, Jousimies, Juanjo Presa, Julian Hoch, Kai von Fintel,
  Kaushal Modi, Kolmas, M. Hadi Timachi, Maikol Solis, Mark Olson,
  Mirko Hernandez, Niall Dooley, Nick Bell, Paul van Gelder, Peter
  Prevos, Peter Smith, Samuel W. Flint, Suhail Singh, Shreyas Ragavan,
  Stefan Thesing, Summer Emacs, Sven Seebeck, Taoufik, TJ Stankus,
  Vick (VicZz), Viktor Haag, Wade Mealing, Yi Liu, Ypot, atanasj,
  azegas, babusri, doolio, duli, drcxd, elge70, fingerknight,
  hpgisler, mentalisttraceur, pRot0ta1p, rbenit68, relict007, sienic,
  skissue, sundar bp, yetanotherfossman, zadca123

Special thanks to Peter Povinec who helped refine the file-naming
scheme, which is the cornerstone of this project.

Special thanks to Jean-Philippe Gagné Guay for the numerous
contributions to the code base.

* GNU Free Documentation License
:PROPERTIES:
:APPENDIX: t
:CUSTOM_ID: h:2d84e73e-c143-43b5-b388-a6765da974ea
:END:

#+texinfo: @include doclicense.texi

#+begin_export html
<pre>

                GNU Free Documentation License
                 Version 1.3, 3 November 2008


 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
     <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other
functional and useful document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.

This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.


1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License.  Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein.  The "Document", below,
refers to any such manual or work.  Any member of the public is a
licensee, and is addressed as "you".  You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.

A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject.  (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

The "Invariant Sections" are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.  If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant.  The Document may contain zero
Invariant Sections.  If the Document does not identify any Invariant
Sections then there are none.

The "Cover Texts" are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.  A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.

A "Transparent" copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text.  A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML, PostScript or PDF designed for human modification.  Examples of
transparent image formats include PNG, XCF and JPG.  Opaque formats
include proprietary formats that can be read and edited only by
proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML, PostScript or PDF produced by some word
processors for output purposes only.

The "Title Page" means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, "Title Page" means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.

The "publisher" means any person or entity that distributes copies of
the Document to the public.

A section "Entitled XYZ" means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language.  (Here XYZ stands for a
specific section name mentioned below, such as "Acknowledgements",
"Dedications", "Endorsements", or "History".)  To "Preserve the Title"
of such a section when you modify the Document means that it remains a
section "Entitled XYZ" according to this definition.

The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document.  These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.

2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no
other conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and
you may publicly display copies.


3. COPYING IN QUANTITY

If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.

It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to
give them a chance to provide you with an updated version of the
Document.


4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

A. Use in the Title Page (and on the covers, if any) a title distinct
   from that of the Document, and from those of previous versions
   (which should, if there were any, be listed in the History section
   of the Document).  You may use the same title as a previous version
   if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities
   responsible for authorship of the modifications in the Modified
   Version, together with at least five of the principal authors of the
   Document (all of its principal authors, if it has fewer than five),
   unless they release you from this requirement.
C. State on the Title page the name of the publisher of the
   Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications
   adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice
   giving the public permission to use the Modified Version under the
   terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections
   and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled "History", Preserve its Title, and add
   to it an item stating at least the title, year, new authors, and
   publisher of the Modified Version as given on the Title Page.  If
   there is no section Entitled "History" in the Document, create one
   stating the title, year, authors, and publisher of the Document as
   given on its Title Page, then add an item describing the Modified
   Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for
   public access to a Transparent copy of the Document, and likewise
   the network locations given in the Document for previous versions
   it was based on.  These may be placed in the "History" section.
   You may omit a network location for a work that was published at
   least four years before the Document itself, or if the original
   publisher of the version it refers to gives permission.
K. For any section Entitled "Acknowledgements" or "Dedications",
   Preserve the Title of the section, and preserve in the section all
   the substance and tone of each of the contributor acknowledgements
   and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document,
   unaltered in their text and in their titles.  Section numbers
   or the equivalent are not considered part of the section titles.
M. Delete any section Entitled "Endorsements".  Such a section
   may not be included in the Modified Version.
N. Do not retitle any existing section to be Entitled "Endorsements"
   or to conflict in title with any Invariant Section.
O. Preserve any Warranty Disclaimers.

If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.

You may add a section Entitled "Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.


5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy.  If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections Entitled "History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled "Acknowledgements",
and any sections Entitled "Dedications".  You must delete all sections
Entitled "Endorsements".


6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other
documents released under this License, and replace the individual
copies of this License in the various documents with a single copy
that is included in the collection, provided that you follow the rules
of this License for verbatim copying of each of the documents in all
other respects.

You may extract a single document from such a collection, and
distribute it individually under this License, provided you insert a
copy of this License into the extracted document, and follow this
License in all other respects regarding verbatim copying of that
document.


7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an "aggregate" if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.

If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.


8. TRANSLATION

Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections.  You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers.  In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements",
"Dedications", or "History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.


9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense, or distribute it is void, and
will automatically terminate your rights under this License.

However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.

Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.


10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the
GNU Free Documentation License from time to time.  Such new versions
will be similar in spirit to the present version, but may differ in
detail to address new problems or concerns.  See
https://www.gnu.org/licenses/.

Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation.  If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.  If the Document
specifies that a proxy can decide which future versions of this
License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the
Document.

11. RELICENSING

"Massive Multiauthor Collaboration Site" (or "MMC Site") means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works.  A
public wiki that anybody can edit is an example of such a server.  A
"Massive Multiauthor Collaboration" (or "MMC") contained in the site
means any set of copyrightable works thus published on the MMC site.

"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.

"Incorporate" means to publish or republish a Document, in whole or in
part, as part of another Document.

An MMC is "eligible for relicensing" if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole or
in part into the MMC, (1) had no cover texts or invariant sections, and
(2) were thus incorporated prior to November 1, 2008.

The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.


ADDENDUM: How to use this License for your documents

To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:

    Copyright (c)  YEAR  YOUR NAME.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU
    Free Documentation License".

If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the "with...Texts." line with this:

    with the Invariant Sections being LIST THEIR TITLES, with the
    Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.

If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.

If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
</pre>
#+end_export

#+html: <!--

* Indices
:PROPERTIES:
:CUSTOM_ID: h:dd530040-de9d-4f2b-8dfd-d8b8f14c058e
:END:

** Function index
:PROPERTIES:
:INDEX: fn
:CUSTOM_ID: h:317b8c20-6dc1-4390-a20a-d01d75a48ccb
:END:

** Variable index
:PROPERTIES:
:INDEX: vr
:CUSTOM_ID: h:2f69d4fe-0804-4f7f-aa57-4e03e7f20d98
:END:

** Concept index
:PROPERTIES:
:INDEX: cp
:CUSTOM_ID: h:10365e44-2fc0-4b66-a613-682fea09ee68
:END:

#+html: -->
