[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 9b981a2958 01/39: Add denote-prompts option and
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 9b981a2958 01/39: Add denote-prompts option and refactor the denote command |
Date: |
Mon, 11 Jul 2022 00:57:40 -0400 (EDT) |
branch: externals/denote
commit 9b981a2958de9d4fa00b05df6a9f5b0685d8a623
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add denote-prompts option and refactor the denote command
The user option denote-prompts allows the user to specify the prompts
of the denote command and their order.
Refactor 'denote-type', 'denote-date', and 'denote-subdirectory' to
use the 'denote' command.
---
denote.el | 137 +++++++++++++++++++++++++++++++-------------------------------
1 file changed, 69 insertions(+), 68 deletions(-)
diff --git a/denote.el b/denote.el
index 9729286b91..34516da8cc 100644
--- a/denote.el
+++ b/denote.el
@@ -162,6 +162,21 @@ the appropriate list of strings."
:group 'denote
:type 'boolean)
+(defcustom denote-prompts '(title keywords)
+ "Specify the prompts of the `denote' command.
+
+Valid values are:
+ date: The date of the note.
+ file-type: The filetype of the note (md, txt, org).
+ subdirectory: The subdirectory in which to create the note.
+ title: The title of the note. If unspecified, the title is
+ \"unspecified\".
+ keywords: The keywords of the note.
+
+The prompts will happen in the given order."
+ :group 'denote
+ :type '(repeat symbol))
+
(defcustom denote-sort-keywords t
"Whether to sort keywords in new files.
@@ -651,26 +666,37 @@ Optional DEFAULT-TITLE is used as the default value."
;;;;; The `denote' command
;;;###autoload
-(defun denote (title keywords)
- "Create new note with the appropriate metadata and file name.
-
-This command first prompts for a file TITLE and then for one or
-more KEYWORDS (separated by the `crm-separator', typically a
-comma). The latter supports completion though any arbitrary
-string can be inserted.
-
-Completion candidates are those of `denote-known-keywords'. If
-`denote-infer-keywords' is non-nil, then keywords in existing
-file names are also provided as candidates.
-
-When `denote-sort-keywords' is non-nil, keywords are sorted
-alphabetically in both the file name and file contents."
- (interactive
- (list
- (denote--title-prompt)
- (denote--keywords-prompt)))
- (denote--prepare-note title keywords)
- (denote--keywords-add-to-history keywords))
+(defun denote (&optional title keywords type date subdir)
+ "Create a new note with the appropriate metadata and file name.
+
+When called interactively, the metadata and file name are prompted
+according to the value of `denote-prompts'.
+
+Optional TITLE should be a string or nil.
+Optional KEYWORDS should be a list of strings.
+Optional TYPE should be a symbol among 'org, 'markdown-toml,
+'markdown-yaml or 'text.
+Optional DATE should be a string representing a date, or nil.
+Optional SUBDIR should be the path string of the subdir in
+which to create the note, or nil."
+ (interactive)
+ (when (called-interactively-p 'any)
+ (dolist (prompt denote-prompts)
+ (pcase prompt
+ ('title (setq title (denote--title-prompt)))
+ ('date (setq date (denote--date-prompt)))
+ ('file-type (setq type (denote--file-type-prompt)))
+ ('subdirectory (setq subdir (denote--subdirs-prompt)))
+ ('keywords (setq keywords (denote--keywords-prompt))))))
+ (let* ((denote-file-type (denote--file-type-symbol (or type
denote-file-type)))
+ (date (if (or (null date) (string-empty-p date))
+ (current-time)
+ (denote--valid-date date)))
+ (id (format-time-string denote--id-format date))
+ (denote-directory (or subdir (denote-directory))))
+ (denote--barf-duplicate-id id)
+ (denote--prepare-note (or title "") keywords nil date id)
+ (denote--keywords-add-to-history keywords)))
(defalias 'denote-create-note (symbol-function 'denote))
@@ -698,14 +724,13 @@ here for clarity."
(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)))
+(defun denote-type ()
+ "Convenience function to have `denote' prompt for a date.
+
+This is equivalent to calling `denote' when `denote-prompts' is set to
+'(file-type title keywords)."
+ (interactive)
+ (let ((denote-prompts '(file-type title keywords)))
(call-interactively #'denote)))
(defalias 'denote-create-note-using-type (symbol-function 'denote-type))
@@ -741,30 +766,14 @@ NO-CHECK-CURRENT passes the appropriate flag to
t))
;;;###autoload
-(defun denote-date (date title keywords)
- "Like `denote', but create new note for given DATE.
-
-DATE can either be something like 2022-06-16 or that plus time:
-2022-06-16 14:30.
-
-The hour can be omitted, in which case it is interpreted as
-00:00. Beware that you might create files with non-unique
-identifiers if they both have the same date and time. In such a
-case, Denote will refrain from creating the new note. Try with
-another DATE value where, for instance, a different time is
-specified.
-
-The TITLE and KEYWORDS arguments are the same as with `denote'."
- (interactive
- (list
- (denote--date-prompt)
- (denote--title-prompt)
- (denote--keywords-prompt)))
- (when-let ((d (denote--valid-date date))
- (id (format-time-string denote--id-format d))
- ((denote--barf-duplicate-id id)))
- (denote--prepare-note title keywords nil d id)
- (denote--keywords-add-to-history keywords)))
+(defun denote-date ()
+ "Convenience function to have `denote' prompt for a date.
+
+This is equivalent to calling `denote' when `denote-prompts' is set to
+'(date title keywords)."
+ (interactive)
+ (let ((denote-prompts '(date title keywords)))
+ (call-interactively #'denote)))
(defalias 'denote-create-note-using-date (symbol-function 'denote-date))
@@ -803,22 +812,14 @@ The TITLE and KEYWORDS arguments are the same as with
`denote'."
(denote--subdirs-completion-table dirs)))
;;;###autoload
-(defun denote-subdirectory (directory title keywords)
- "Like `denote' but ask for DIRECTORY to put the note in.
-
-The DIRECTORY is either the variable `denote-directory' or a
-subdirectory of it. The TITLE and KEYWORDS are the same as for
-the `denote' command.
-
-Denote does not create subdirectories."
- (interactive
- (list
- (denote--subdirs-prompt)
- (denote--title-prompt)
- (denote--keywords-prompt)))
- (let ((denote-directory directory))
- (denote--prepare-note title keywords)
- (denote--keywords-add-to-history keywords)))
+(defun denote-subdirectory ()
+ "Convenience function to have `denote' prompt for subdirectory.
+
+This is equivalent to calling `denote' when `denote-prompts' is set to
+'(subdirectory title keywords)."
+ (interactive)
+ (let ((denote-prompts '(subdirectory title keywords)))
+ (call-interactively #'denote)))
(defalias 'denote-create-note-in-subdirectory (symbol-function
'denote-subdirectory))
- [elpa] externals/denote updated (934c8c362f -> 089b0bea0e), ELPA Syncer, 2022/07/11
- [elpa] externals/denote 81e756b118 08/39: Clarify in denote-prompts that subdir must exist, ELPA Syncer, 2022/07/11
- [elpa] externals/denote 9b981a2958 01/39: Add denote-prompts option and refactor the denote command,
ELPA Syncer <=
- [elpa] externals/denote 335307382f 03/39: Add internal constant for denote-prompts symbols, ELPA Syncer, 2022/07/11
- [elpa] externals/denote 95feac8448 12/39: Clarify a TODO, ELPA Syncer, 2022/07/11
- [elpa] externals/denote b94537cd94 14/39: Remove else part in denote--file-name-relative-to-denote-directory, ELPA Syncer, 2022/07/11
- [elpa] externals/denote a285d4df6a 23/39: Merge pull request #42 from jeanphilippegg/refactor-denote-prompts, ELPA Syncer, 2022/07/11
- [elpa] externals/denote bfda1b829f 06/39: Make 'denote' use 'denote--prompts', ELPA Syncer, 2022/07/11
- [elpa] externals/denote f4c3f1c2d5 18/39: Expand denote-prompts doc string, ELPA Syncer, 2022/07/11
- [elpa] externals/denote 71b56a6b0f 22/39: Refine interactive spec of 'denote' command, ELPA Syncer, 2022/07/11
- [elpa] externals/denote cb863db07d 25/39: Change order of arguments in 'denote', ELPA Syncer, 2022/07/11
- [elpa] externals/denote 61f48726b0 07/39: Clarify denote-prompts empty title case, ELPA Syncer, 2022/07/11
- [elpa] externals/denote 7c36c51665 09/39: Update doc string of 'denote' command, ELPA Syncer, 2022/07/11