branch: externals/denote-journal
commit 729beaea78ca6d7a3cf947b2ee003bac5227c3a2
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Add user option denote-journal-signature
    
    Thanks to Halogen3576 for suggesting the idea in issue 13:
    <https://github.com/protesilaos/denote-journal/issues/13>.
---
 README.org        | 45 +++++++++++++++++++++++++++++++++++++--------
 denote-journal.el | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/README.org b/README.org
index 2ab74a23db..9c55a40cfa 100644
--- a/README.org
+++ b/README.org
@@ -193,13 +193,14 @@ The command ~denote-journal-new-or-existing-entry~ 
locates an existing
 journal entry and opens it for editing or creates a new one.
 
 A journal entry is an editable file that has ~denote-journal-keyword~
-as part of its file name. If there are multiple journal entries for
-the current date, ~denote-journal-new-or-existing-entry~ prompts to
-select one among them using minibuffer completion. If there is only
-one matching file, it visits it outright. If there is no journal
-entry, it creates a new one by calling ~denote-journal-new-entry~
-([[#h:create-new-journal-entry][Create new journal entry]]). Depending on 
one's workflow, this can also
-be done via ~org-capture~  
([[#h:create-a-journal-entry-using-org-capture][Create a journal entry using 
Org capture]]).
+as part of its file name ([[#h:e1fe2ec8-9acf-41ec-b2d8-a94b21735d30][The 
~denote-journal-signature~ option]]). If
+there are multiple journal entries for the current date,
+~denote-journal-new-or-existing-entry~ prompts to select one among
+them using minibuffer completion. If there is only one matching file,
+it visits it outright. If there is no journal entry, it creates a new
+one by calling ~denote-journal-new-entry~ 
([[#h:create-new-journal-entry][Create new journal entry]]).
+Depending on one's workflow, this can also be done via ~org-capture~
+([[#h:create-a-journal-entry-using-org-capture][Create a journal entry using 
Org capture]]).
 
 When called with a prefix argument (=C-u= with default key bindings),
 the command ~denote-journal-new-or-existing-entry~ prompts for a date
@@ -285,6 +286,34 @@ notes. They can still be retrieved easily by searching for 
the
 ~denote-journal-keyword~ (read the Denote manual about "Features of
 the file-naming scheme for searching or filtering").
 
+** The ~denote-journal-signature~ option
+:PROPERTIES:
+:CUSTOM_ID: h:e1fe2ec8-9acf-41ec-b2d8-a94b21735d30
+:END:
+
+[ The ~denote-journal-signature~ is part of {{{development-version}}}. ]
+
+#+vindex: denote-journal-signature
+The user option ~denote-journal-signature~ specifies a predefined
+signature to use in new journal entries. This is used by
+~denote-journal-new-entry~ and all related commands 
([[#h:create-new-journal-entry][Create new journal entry]]).
+
+The value of this user option can be one of the following:
+
+- ~nil~, which means to not use a predefined signature;
+- a string, which is used as-is;
+- a function that returns a string, which is then used as-is.
+
+In the case of a function, users may wish to integrate the
+~denote-journal~ package with ~denote-sequence~. For example, each new
+journal entry should be defined as a new parent sequence. Thus:
+
+#+begin_src emacs-lisp
+(setq denote-journal-signature
+      (lambda ()
+        (denote-sequence-get-new 'parent)))
+#+end_src
+
 ** Title format of new journal entries
 :PROPERTIES:
 :CUSTOM_ID: h:title-format-of-new-journal-entries
@@ -431,7 +460,7 @@ Denote Journal is meant to be a collective effort.  Every 
bit of help matters.
 + Contributions to code or the manual :: Alan Schmitt, Ettore Berardi,
   Honza Pokorny, Stefan Monnier, Vineet C. Kulkarni, gk2803, jbwfu.
 
-+ Ideas and/or user feedback :: Alan Schmitt, Kevin McCarthy.
++ Ideas and/or user feedback :: Alan Schmitt, Kevin McCarthy, Halogen3576.
 
 * GNU Free Documentation License
 :PROPERTIES:
diff --git a/denote-journal.el b/denote-journal.el
index 6830721e03..e7d096b2bf 100644
--- a/denote-journal.el
+++ b/denote-journal.el
@@ -66,6 +66,30 @@ It is used by `denote-journal-new-entry' (or related)."
   :type '(choice (string :tag "Keyword")
                  (repeat :tag "List of keywords" string)))
 
+(defcustom denote-journal-signature nil
+  "The signature to use in new journal entries.
+This is used by `denote-journal-new-entry' and related commands.
+
+The value can be one of the following:
+
+- nil, which means to not use a predefined signature;
+- a string, which is used as-is;
+- a function that returns a string, which is then used as-is.
+
+In the case of a function, users may wish to integrate the
+`denote-journal' package with `denote-sequence'.  For example, each new
+journal entry should be defined as a new parent sequence.  Thus:
+
+    (setq denote-journal-signature
+          (lambda ()
+            (denote-sequence-get-new 'parent)))"
+  :type '(choice
+          (const :tag "No predefined signature" nil)
+          (string :tag "The predefined signature to use for new entries")
+          (function :tag "Function that returns a string"))
+  :group 'denote-journal
+  :package-version '(denote . "0.2.0"))
+
 (defcustom denote-journal-title-format 'day-date-month-year-24h
   "Date format to construct the title with `denote-journal-new-entry'.
 The value it can take is either nil, a
@@ -147,6 +171,17 @@ If the path does not exist, then make it first."
       (list denote-journal-keyword)
     denote-journal-keyword))
 
+(defun denote-journal-signature ()
+  "Return the value of the variable `denote-journal-signature'."
+  (cond
+   ((stringp denote-journal-signature) denote-journal-signature)
+   ((functionp denote-journal-signature)
+    (if-let* ((value (funcall denote-journal-signature))
+              (_ (stringp value)))
+        value
+      (error "The `denote-journal-signature' is bound to a function that does 
not return a string")))
+   (t nil)))
+
 (defun denote-journal--keyword-regex ()
   "Return a regular expression string that matches the journal keyword(s)."
   (let ((keywords-sorted (mapcar #'regexp-quote (denote-keywords-sort 
(denote-journal-keyword)))))
@@ -216,7 +251,8 @@ is internally processed by `denote-valid-date-p'."
      (denote-journal-daily--title-format internal-date)
      (denote-journal-keyword)
      nil nil date
-     (denote-journal--get-template))
+     (denote-journal--get-template)
+     (denote-journal-signature))
     (run-hooks 'denote-journal-hook)))
 
 ;;;; New or existing entry based on `denote-journal-interval'

Reply via email to