Thank you to Denote contributors for making such a useful, simple, and
well-documented notes package.
There is some custom behavior I'd like but can't figure out how to
achieve it.
I have a subdirectory of my Denote folder called `library/`, and I want
a convenience command for adding notes to that directory.
I also want to automatically apply the keyword "unread", so that I don't
have to manually type "unread" every time.
Here is my current code. It creates the note in the correct directory,
but I can't figure out how to automatically apply the "unread" keyword
__while still being prompted for the file name__.
(defun jgf/denote-add-to-library ()
"Create an entry with keyword 'unread' in the subdirectory
'library/'."
(interactive)
(let ((denote-directory (concat denote-directory "/library")))
(call-interactively #'denote)))
I've tried a few things along the lines of:
(call-interactively (lambda () (interactive) (denote nil '("unread"))))
(I'm no ELisp professional, this may be an ugly way of doing it, but the
core idea is I tried calling `denote` and passing `nil` for parameters I
still want to be prompted for.)
This creats a note in the "library/" directory with an empty title and
the tag "unread". This isn't surprising, but is not the behavior I want.
I'd like to still be prompted for everything in `denote-prompts`,
__including keywords__. If I could at least be prompted for the title
that would be nice, but ideally I'd be able to add additional keywords
while automatically setting the "unread" keyword.
On 6/25/23 6:40 PM, Jeffrey Fisher wrote:
> Thank you to Denote contributors for making such a useful, simple, and > well-documented notes package.> > There is some custom behavior I'd like but can't figure out how to > achieve it.> > I have a subdirectory of my Denote folder called `library/`, and I want > a convenience command for adding notes to that directory.> > I also want to automatically apply the keyword "unread", so that I don't > have to manually type "unread" every time.> > Here is my current code. It creates the note in the correct directory, > but I can't figure out how to automatically apply the "unread" keyword > __while still being prompted for the file name__.> > (defun jgf/denote-add-to-library ()> "Create an entry with keyword 'unread' in the subdirectory > 'library/'."> (interactive)> (let ((denote-directory (concat denote-directory "/library")))> (call-interactively #'denote)))> > I've tried a few things along the lines of:> > (call-interactively (lambda () (interactive) (denote nil > '("unread"))))> > (I'm no ELisp professional, this may be an ugly way of doing it, but the > core idea is I tried calling `denote` and passing `nil` for parameters I > still want to be prompted for.)> > This creats a note in the "library/" directory with an empty title and > the tag "unread". This isn't surprising, but is not the behavior I want.> > I'd like to still be prompted for everything in `denote-prompts`, > __including keywords__. If I could at least be prompted for the title > that would be nice, but ideally I'd be able to add additional keywords > while automatically setting the "unread" keyword.>
Assuming you also want org-mode, here's how I would set it up:
(defun jgf/denote-add-to-library ()
"Create an entry with keyword 'unread' in the subdirectory 'library/'."
(interactive)
(denote (denote-title-prompt)
(append '("unread") (denote-keywords-prompt))
'org
(expand-file-name "library/" (denote-directory))))
The functions `denote-title-prompt' and `denote-keywords-prompt' are
used to trigger the same completions as the interactive `denote'
function. I also used `expand-file-name' instead of `concat', but I
think that mostly comes down to preference.
Hope this helps!
> From: Jeffrey Fisher <jeffrey@jeffreyfisher.net>> Date: Sun, 25 Jun 2023 21:40:15 -0400>> I'd like to still be prompted for everything in `denote-prompts`, > __including keywords__. If I could at least be prompted for the title > that would be nice, but ideally I'd be able to add additional keywords > while automatically setting the "unread" keyword.
Hello Jeffrey,
Check what Graham suggested. It does what you asked for:
> From: Graham Marlow <graham@mgmarlow.com>> Date: Sun, 25 Jun 2023 19:34:00 -0700> [... 43 lines elided]> Assuming you also want org-mode, here's how I would set it up:>> (defun jgf/denote-add-to-library ()> "Create an entry with keyword 'unread' in the subdirectory 'library/'."> (interactive)> (denote (denote-title-prompt)> (append '("unread") (denote-keywords-prompt))> 'org> (expand-file-name "library/" (denote-directory))))>> The functions `denote-title-prompt' and `denote-keywords-prompt' are > used to trigger the same completions as the interactive `denote' > function. I also used `expand-file-name' instead of `concat', but I > think that mostly comes down to preference.>> Hope this helps!
All the best,
Protesilaos (or simply "Prot")
--
Protesilaos Stavrou
https://protesilaos.com
Thank you, this does exactly what I want!
P.S. Apologies to Graham for the double message, I'm unfamiliar with
mailing lists. I want to make sure the followup was recorded in case
someone else has the same question.