Add denote-type command

This commit is contained in:
Protesilaos Stavrou 2022-06-13 15:04:08 +03:00
parent e841a51ca7
commit b42f68c8e8
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 42 additions and 4 deletions

View file

@ -217,12 +217,13 @@ holds the relevant value. In simple terms:
:END:
#+findex: denote
#+findex: denote-type
#+findex: denote-org-capture
There are two ways to write a note with Denote: invoke the ~denote~
command or leverage the ~org-capture-templates~ by setting up a template
which calls the function ~denote-org-capture~.
There are three ways to write a note with Denote: invoke the ~denote~,
or ~denote-type~ commands, or leverage the ~org-capture-templates~ by
setting up a template which calls the function ~denote-org-capture~.
In the first case, all that is needed is to run ~denote~. It will first
In the first case, all that is needed is to run ~denote~. It will
prompt for a title. Once it is supplied, the command will ask for
keywords. The resulting note will have a file name as already explained
([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file naming scheme]]).
@ -245,6 +246,11 @@ The ~denote~ command can also be called from Lisp, in which case it
expects the =TITLE= and =KEYWORDS= arguments. The former is a string,
the latter a list of strings.
The ~denote-type~ command is like ~denote~ except it also prompts for a
file type to use as a local value for ~denote-file-type~. In practical
terms, this lets you produce, say, a note in Markdown even though you
normally write in Org ([[#h:f34b172b-3440-446c-aec1-bf818d0aabfe][Notes in multiple file types]]).
For integration with ~org-capture~, the user must first add the relevant
template. Such as:

View file

@ -562,5 +562,37 @@ alphabetically in both the file name and file contents."
(denote--prepare-note title keywords)
(denote--keywords-add-to-history keywords))
(defvar denote--file-type-history nil
"Minibuffer history of `denote--file-type-prompt'.")
(defun 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."
(completing-read
"Select file type: " '(org markdown-yaml markdown-toml text) nil t
nil 'denote--file-type-history))
(defun denote--file-type-symbol (filetype)
"Return FILETYPE as a symbol."
(cond
((stringp filetype)
(intern filetype))
((symbolp filetype)
filetype)
(t (user-error "`%s' is not a symbol or string" filetype))))
;;;###autoload
(defun denote-type (filetype)
"Like `denote' but with FILETYPE for `denote-file-type'.
In practice, this command lets you create, say, a Markdown file
even when your default is Org.
When called from Lisp the FILETYPE must be a symbol."
(interactive (list (denote--file-type-prompt)))
(let ((denote-file-type (denote--file-type-symbol filetype)))
(call-interactively #'denote)))
(provide 'denote)
;;; denote.el ends here