Insert links to all files matching a query in their file name
The command denote-add-links adds links at point to all file names in the denote-directory that match a regular expression or plain string. This is similar to the denote-link command, which establishes a direct link to a specified file (Adding a single direct link). Links to files whose names match the given search terms are inserted as a typographic list, such as:
- link1
- link2
- link3Each 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:
- [[denote:IDENTIFIER-1]]
- [[denote:IDENTIFIER-2]]
- [[denote:IDENTIFIER-3]]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 (Linking notes).