[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 91c8744033 2/3: Merge pull request #365 from jea
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 91c8744033 2/3: Merge pull request #365 from jeanphilippegg/denote-use-variables |
Date: |
Mon, 20 May 2024 06:57:55 -0400 (EDT) |
branch: externals/denote
commit 91c87440339385e707053b8b5b06e67651ed7653
Merge: ed112050d9 f6b08c79f4
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>
Merge pull request #365 from jeanphilippegg/denote-use-variables
Add denote-use-* variables
---
denote.el | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 78 insertions(+), 16 deletions(-)
diff --git a/denote.el b/denote.el
index 00f8e254fa..117f250aba 100644
--- a/denote.el
+++ b/denote.el
@@ -2148,6 +2148,45 @@ 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'.")
+;; NOTE: The following variables are not defcustom because they are not
+;; meant for customization. They are meant to be used from Lisp to
+;; create custom Denote commands and related.
+
+(defvar denote-use-title nil
+ "The title to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-keywords nil
+ "The keywords to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-signature nil
+ "The signature to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-file-type nil
+ "The title to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-directory nil
+ "The directory to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-date nil
+ "The date to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
+(defvar denote-use-template nil
+ "The template to be used in a note creation command.
+See the documentation of `denote' for acceptable values.
+This variable is ignored if nil.")
+
(defun denote--command-with-features (command
force-use-file-prompt-as-default-title force-ignore-region force-save
in-background)
"Execute file-creating COMMAND with specified features.
@@ -2193,35 +2232,58 @@ The path of the newly created file is returned."
path))
(defun denote--creation-get-note-data-from-prompts ()
- "This functions retrieves the data necessary for note creation.
+ "Retrieve the data necessary for note creation.
The data elements are: title, keywords, file-type, directory,
date, template and signature.
-It is retrieved from prompts according to `denote-prompts'."
+It is retrieved from prompts according to `denote-prompts' and
+from `denote-use-*' variables. For example, if
+`denote-use-title' is set to a title, then no prompts happen for
+the title and the value of `denote-use-title' will be used
+instead."
(let (title keywords file-type directory date template signature)
(dolist (prompt denote-prompts)
(pcase prompt
- ('title (setq title (denote-title-prompt
- (when (and (not
denote-ignore-region-in-denote-command)
- (use-region-p))
- (buffer-substring-no-properties
- (region-beginning)
- (region-end))))))
- ('keywords (setq keywords (denote-keywords-prompt)))
- ('file-type (setq file-type (denote-file-type-prompt)))
- ('subdirectory (setq directory (denote-subdirectory-prompt)))
- ('date (setq date (denote-date-prompt)))
- ('template (setq template (denote-template-prompt)))
- ('signature (setq signature (denote-signature-prompt)))))
+ ('title (unless denote-use-title
+ (setq title (denote-title-prompt
+ (when (and (not
denote-ignore-region-in-denote-command)
+ (use-region-p))
+ (buffer-substring-no-properties
+ (region-beginning)
+ (region-end)))))))
+ ('keywords (unless denote-use-keywords
+ (setq keywords (denote-keywords-prompt))))
+ ('file-type (unless denote-use-file-type
+ (setq file-type (denote-file-type-prompt))))
+ ('subdirectory (unless denote-use-directory
+ (setq directory (denote-subdirectory-prompt))))
+ ('date (unless denote-use-date
+ (setq date (denote-date-prompt))))
+ ('template (unless denote-use-template
+ (setq template (denote-template-prompt))))
+ ('signature (unless denote-use-signature
+ (setq signature (denote-signature-prompt))))))
(list title keywords file-type directory date template signature)))
(defun denote--creation-prepare-note-data (title keywords file-type directory
date template signature)
"Return parameters in a valid form for file creation.
The data is: TITLE, KEYWORDS, FILE-TYPE, DIRECTORY, DATE,
-TEMPLATE and SIGNATURE."
- (let* ((title (or title ""))
+TEMPLATE and SIGNATURE.
+
+If a `denote-use-*' variable is set for a data, its value is used
+instead of that of the parameter."
+ (let* (;; Handle the `denote-use-*' variables
+ (title (or denote-use-title title))
+ (keywords (or denote-use-keywords keywords))
+ (file-type (or denote-use-file-type file-type))
+ (directory (or denote-use-directory directory))
+ (date (or denote-use-date date))
+ (template (or denote-use-template template))
+ (signature (or denote-use-signature signature))
+ ;; Make the data valid
+ (title (or title ""))
(file-type (denote--valid-file-type (or file-type denote-file-type)))
(keywords (denote-keywords-sort keywords))
(date (denote-parse-date date))