Vedang Manerikar: 3 Create denote-silo-extra for convenience functions in multiple silos Create denote-journal-extra for daily journaling convenience functions Create denote-create-extra for new note convenience functions 3 files changed, 281 insertions(+), 0 deletions(-)
Hello again Vedang,
I installed your patch. Thank you! I made a few changes on top and documented everything, adapting the manual where necessary. The only item I was not sure about is the prompt for templates. I think we can rely on the existing user option without introducing a new one. Check the TODO I have in the file. Other than that, I think everything works, though I have not yet tested everything thoroughly. All the best, Prot
I am reviewing this now. I think we do not need the new file. I placed 'denote-region' in denote.el and documented it at length. See commit bf59f68. For the rest, they can probably be placed in the file denote-silo-extra.el, though I still need to test them.
Thank you Prot. I have updated to the latest version of Denote today and will test the changes to ensure everything is working properly.
Very well! Please let me know how it goes.
For the rest of the changes in this patch, should I copy them over to denote-silo-extras and create a new patch? Or will you be adding it slowly post testing on your end?
Yes, this is the idea. I still need to test them and, maybe, make some tweaks to them.
Let me know! On Wed, Sep 20, 2023 at 3:47 PM Protesilaos Stavrou <info@protesilaos.com> wrote:
You are welcome!
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~protesilaos/denote/patches/43255/mbox | git am -3Learn more about email & git
Move the functions of the Denote manual related to creating, opening or running commands _after specifying a silo_ to this new file. This commit introduces the following: Variables: * `denote-silo-extra-directories`: List of directories which are silos * `denote-silo-extra-commands-for-silos`: List of common commands we may want to run in a silo Functions: * `denote-silo-extra-pick-silo-then-command` * `denote-silo-extra-create` * `denote-silo-extra-open-or-create` --- denote-silo-extra.el | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 denote-silo-extra.el diff --git a/denote-silo-extra.el b/denote-silo-extra.el new file mode 100644 index 0000000..7063fa3 --- /dev/null +++ b/denote-silo-extra.el @@ -0,0 +1,89 @@ +;;; denote-silo-extra.el --- Convenience functions for using Denote in multiple silos -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; Author: Protesilaos Stavrou <info@protesilaos.com> +;; Maintainer: Denote Development <~protesilaos/denote@lists.sr.ht> +;; URL: https://git.sr.ht/~protesilaos/denote +;; Mailing-List: https://lists.sr.ht/~protesilaos/denote + +;; This file is NOT part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'denote) + +(defgroup denote-silo-extra nil + "Make it easier to use Denote across Silos." + :group 'denote + :link '(info-link "(denote) Top") + :link '(url-link :tag "Homepage" "https://protesilaos.com/emacs/denote")) + +(defcustom denote-silo-extra-directories + `(,denote-directory) + "List of file paths pointing to my Denote silos." + :group 'denote-silo-extra + :link '(info-link "(denote) Maintain separate directories for notes") + :type '(repeat directory)) + +(defvar denote-silo-extra-commands-for-silos + '(denote + denote-date + denote-subdirectory + denote-template + denote-type + denote-signature) + "List of commands to call after selecting a silo.") + +(defun denote-silo-extra-pick-silo-then-command (silo command) + "Select SILO and run Denote COMMAND in it. +SILO is a file path from `denote-silo-extra-directories', while +COMMAND is one among `denote-silo-extra-commands-for-silos'." + (interactive + (list (completing-read "Select a silo: " + denote-silo-extra-directories nil t) + (intern + (completing-read "Run command in silo: " + denote-silo-extra-commands-for-silos nil t)))) + (let ((denote-user-enforced-denote-directory silo)) + (call-interactively command))) + +(defun denote-silo-extra-create (&optional silo) + "Select SILO and run `denote' in it. +SILO is a file path from `denote-silo-extra-directories'." + (interactive + (list (when current-prefix-arg + (completing-read "Select a silo: " + denote-silo-extra-directories nil t)))) + (let ((denote-user-enforced-denote-directory silo)) + (call-interactively #'denote))) + +(defun denote-silo-extra-open-or-create (&optional silo) + "Select SILO and run `denote-open-or-create' in it. +SILO is a file path from `denote-silo-extra-directories'." + (interactive + (list (when current-prefix-arg + (completing-read "Select a silo: " + denote-silo-extra-directories nil t)))) + (let ((denote-user-enforced-denote-directory silo)) + (call-interactively #'denote-open-or-create))) + +(provide 'denote-silo-extra) +;;; denote-silo-extra.el ends here -- 2.41.0
Hello Vedang, I still don't have time to review your patches. I will most probably do it next week, once I have electricity at home. Sorry for the delay. More to follow! Prot
Thank you Vedang! It took me longer than expected to have electricity at home. Now I am back online. I merged this patch and made some changes on top. I will slowly do the same for the rest of your patches.
Move journaling functions from the Denote manual into the `denote-journal-extra.el` file. We introduce the following: Variables: * `denote-journal-extra-directory`: The directory where all your journal entries will be written. * `denote-journal-extra-templates`: Some templates to help you get started with journaling. Functions: * `denote-journal-extra--make-journal-directory`: Create the denote-journal-extra-directory if it does not exist. * `denote-extras-new-stand-alone-journal-entry`: Create a new journal entry (as a stand-alone file) --- denote-journal-extra.el | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 denote-journal-extra.el diff --git a/denote-journal-extra.el b/denote-journal-extra.el new file mode 100644 index 0000000..e6ee945 --- /dev/null +++ b/denote-journal-extra.el @@ -0,0 +1,86 @@ +;;; denote-journal-extra.el --- Convenience functions for daily journaling -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; Author: Protesilaos Stavrou <info@protesilaos.com> +;; Maintainer: Denote Development <~protesilaos/denote@lists.sr.ht> +;; URL: https://git.sr.ht/~protesilaos/denote +;; Mailing-List: https://lists.sr.ht/~protesilaos/denote + +;; This file is NOT part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'denote) + +(defgroup denote-journal-extra nil + "Denote for daily journaling." + :group 'denote + :link '(info-link "(denote) Top") + :link '(url-link :tag "Homepage" "https://protesilaos.com/emacs/denote")) + +(defcustom denote-journal-extra-directory + (expand-file-name "journal" denote-directory) + "Directory for storing daily journal entries." + :group 'denote-journal-extra + :type 'directory) + +(defun denote-journal-extra--make-journal-directory () + "Make the variable `denote-journal-extra-directory' and its parents." + (when (and (stringp denote-journal-extra-directory) + (not (file-directory-p denote-journal-extra-directory))) + (make-directory denote-journal-extra-directory :parents))) + +(defcustom denote-journal-extra-templates + '((journal-morningpage . "* The Morning Journaling Routine + +Stream of consciousness writing to empty your mind.") + (journal-emotion . "* I am feeling <emotion> + +- Capture your emotion here.") + (journal-insight . "* I had an insight! :insight: + +- Capture your insight here") + (journal-checkin . "* The Daily Ongoing Check-in + +- Capture your generic check-in here")) + "Templates for your daily journal entries." + :type '(alist :key-type symbol :value-type string) + :link '(info-link "(denote) The denote-templates option") + :group 'denote-journal-extra) + +(dolist (tem denote-journal-extra-templates) + (add-to-list 'denote-templates tem)) + +(defun denote-journal-extra-new-stand-alone-journal-entry () + "Create a new stand-alone journal entry in `denote-journal-extra-directory`." + (interactive) + (denote-journal-extra--make-journal-directory) + (let ((denote-user-enforced-denote-directory denote-journal-extra-directory)) + (denote + ;; format like Tuesday 14 June 2022 05:49:37 PM + (format-time-string "%A %e %B %Y %I:%M:%S %p") + ;; No need to specify `keywords`, `file-type`, `subdirectory` or `date` + nil nil nil nil + ;; Pick the right template for your journal. + (denote-template-prompt)))) + +(provide 'denote-journal-extra) +;;; denote-journal-extra.el ends here -- 2.41.0
Hello again Vedang,
I installed your patch. Thank you! I made a few changes on top and documented everything, adapting the manual where necessary. The only item I was not sure about is the prompt for templates. I think we can rely on the existing user option without introducing a new one. Check the TODO I have in the file. Other than that, I think everything works, though I have not yet tested everything thoroughly. All the best, Prot
Move "create a new note from existing content" functions from the Denote manual into the `denote-create-extra.el` file. We introduce the following: Functions: * `denote-create-extra-new-note-from-region`: Create a new note whose contents include the text in the selected region. * `denote-create-extra-org-extract-subtree`: Create a new note from the current Org Subtree. * `denote-create-extra-link-after-creating-command`: Create a new note and insert the link to the new note at point. The difference from `denote-link-after-creating` is that this function lets you choose which `denote` command you want to run (as defined in `denote-silo-extra-commands-for-silos`). This is useful for creating the new note with a signature (for example) --- denote-create-extra.el | 106 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 denote-create-extra.el diff --git a/denote-create-extra.el b/denote-create-extra.el new file mode 100644 index 0000000..0ef0bf9 --- /dev/null +++ b/denote-create-extra.el @@ -0,0 +1,106 @@ +;;; denote-create-extra.el --- Convenience functions for creating new notes -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; Author: Protesilaos Stavrou <info@protesilaos.com> +;; Maintainer: Denote Development <~protesilaos/denote@lists.sr.ht> +;; URL: https://git.sr.ht/~protesilaos/denote +;; Mailing-List: https://lists.sr.ht/~protesilaos/denote + +;; This file is NOT part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'denote) +(require 'denote-silo-extra) +(require 'org) +(require 'org-element) + +(defun denote-create-extra-new-note-from-region (beg end) + "Create note whose contents include the text between BEG and END. +Prompt for title and keywords of the new note." + (interactive "r") + (if-let (((region-active-p)) + (text (buffer-substring-no-properties beg end))) + (progn + (denote (denote-title-prompt) (denote-keywords-prompt)) + (insert text)) + (user-error "No region is available"))) + +(defun denote-create-extra-org-extract-subtree (&optional silo) + "Create new Denote note using current Org subtree. + +Select SILO, a file path from `denote-silo-extra-directories', +with a universal prefix argument (\\[universal-argument]). + +Make the new note use the Org file type, regardless of the value +of `denote-file-type'. + +Use the subtree title as the note's title. If available, use the +tags of the heading are used as note keywords. + +Delete the original subtree." + (interactive + (list (when current-prefix-arg + (completing-read "Select a silo: " denote-silo-extra-directories nil t)))) + (if-let ((text (org-get-entry)) + (heading (org-get-heading :no-tags :no-todo :no-priority :no-comment))) + (let ((element (org-element-at-point)) + (tags (org-get-tags)) + (denote-user-enforced-denote-directory silo)) + (delete-region (org-entry-beginning-position) + (save-excursion (org-end-of-subtree t) (point))) + (denote heading + tags + 'org + nil + (or + ;; Check PROPERTIES drawer for :created: or :date: + (org-element-property :DATE element) + (org-element-property :CREATED element) + ;; Check the subtree for CLOSED + (org-element-property :raw-value + (org-element-property :closed element)))) + (insert text)) + (user-error "No subtree to extract; aborting"))) + +(defun denote-create-extra-link-after-creating-command (command &optional id-only) + "Create new note in the background and link to it directly. + +See `denote-link-after-creating' for details of how optional +ID-ONLY works. + +Ask the user for which denote COMMAND to use when creating the +new note. This is useful, for example, to add a signature when +creating the new linked note." + (interactive + (list (intern + (completing-read "Command to create new note: " + denote-silo-extra-commands-for-silos nil t)) + (consp current-prefix-arg))) + (let (path) + (save-window-excursion + (call-interactively command) + (save-buffer) + (setq path (buffer-file-name))) + (denote-link path id-only))) + +(provide 'denote-create-extra) +;;; denote-create-extra.el ends here -- 2.41.0
I am reviewing this now. I think we do not need the new file. I placed 'denote-region' in denote.el and documented it at length. See commit bf59f68. For the rest, they can probably be placed in the file denote-silo-extra.el, though I still need to test them.