branch: externals/denote commit b951a62245806741c43db243ee0f7d47c5107100 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Put capture code in denote-org-capture.el --- denote-org-capture.el | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ denote.el | 58 ----------------------------- 2 files changed, 101 insertions(+), 58 deletions(-) diff --git a/denote-org-capture.el b/denote-org-capture.el new file mode 100644 index 0000000000..0e25fed973 --- /dev/null +++ b/denote-org-capture.el @@ -0,0 +1,101 @@ +;;; denote-org-capture.el --- Denote integration with org-capture -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Protesilaos Stavrou + +;; Author: Protesilaos Stavrou <i...@protesilaos.com> +;; URL: https://git.sr.ht/~protesilaos/denote +;; Version: 0.1.0 +;; Package-Requires: ((emacs "27.1")) + +;; 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: +;; +;; Denote integration with org-capture. + +;;; Code: + +(require 'denote) + +(defgroup denote-org-capture () + "Simple tool for plain text notes." + :group 'files) + +;;; User options + +(defcustom denote-org-capture-specifiers "%l\n%i\n%?" + "String with format specifieirs for `org-capture-templates'. +Check that variable's documentation for the details. + +This string is append to new notes in the `denote-org-capture' +function. Every new note has the standard front matter we +define." + :type 'string + :group 'denote) + + +;;;###autoload +(defun denote-org-capture () + "Create new note through `org-capture-templates'. +Use this as a function that returns the path to the new file. +The file is populated with Denote's front matter. It can then be +expanded with the usual specifiers or strings that +`org-capture-templates' supports. + +Search the source code of this function for a comment with a +sample template. We will eventually have a manual." + (let ((title (denote--title-prompt)) + (keywords (denote--keywords-prompt))) + (denote--path title keywords) + (denote--prepare-note denote-last-title denote-last-keywords denote-last-path) + (denote--keywords-add-to-history denote-last-keywords) + ;; TODO 2022-06-05: Is there a better way to set up this hook? + ;; Alternatively, can we prevent the creation of a file when the + ;; capture is aborted? + (add-hook 'org-capture-after-finalize-hook #'denote-org-capture-delete-empty-file) + (concat denote-last-front-matter denote-org-capture-specifiers))) + +(defun denote-org-capture-delete-empty-file () + "Delete file if capture with `denote-org-capture' is aborted." + (when-let* ((file denote-last-path) + ((zerop (or (file-attribute-size (file-attributes file)) 0)))) + (delete-file denote-last-path))) + +;; Samples of an `org-capture-templates' entry: +;; +;; (setq org-capture-templates +;; '(("n" "New note (with denote.el)" plain +;; (file denote-last-path) +;; #'denote-org-capture +;; :no-save t +;; :immediate-finish nil +;; :kill-buffer t +;; :jump-to-captured t))) +;; +;; (with-eval-after-load 'org-capture +;; (add-to-list 'org-capture-templates +;; '("n" "New note (with denote.el)" plain +;; (file denote-last-path) +;; #'denote-org-capture +;; :no-save t +;; :immediate-finish nil +;; :kill-buffer t +;; :jump-to-captured t))) + +;; TODO 2022-06-04: `denote-rename-file' + +(provide 'denote-org-capture) +;;; denote-org-capture.el ends here diff --git a/denote.el b/denote.el index 0795c14efa..b36ac13d9b 100644 --- a/denote.el +++ b/denote.el @@ -82,16 +82,6 @@ If nil, show the keywords in their given order." :group 'denote :type 'boolean) -(defcustom denote-org-capture-specifiers "%l\n%i\n%?" - "String with format specifieirs for `org-capture-templates'. -Check that variable's documentation for the details. - -This string is append to new notes in the `denote-org-capture' -function. Every new note has the standard front matter we -define." - :type 'string - :group 'denote) - ;;; Main variables ;; TODO 2022-06-04: Can we make the entire file name format a defcustom? @@ -314,54 +304,6 @@ alphabetically." (denote--prepare-note title keywords) (denote--keywords-add-to-history keywords)) -;;;###autoload -(defun denote-org-capture () - "Create new note through `org-capture-templates'. -Use this as a function that returns the path to the new file. -The file is populated with Denote's front matter. It can then be -expanded with the usual specifiers or strings that -`org-capture-templates' supports. - -Search the source code of this function for a comment with a -sample template. We will eventually have a manual." - (let ((title (denote--title-prompt)) - (keywords (denote--keywords-prompt))) - (denote--path title keywords) - (denote--prepare-note denote-last-title denote-last-keywords denote-last-path) - (denote--keywords-add-to-history denote-last-keywords) - ;; TODO 2022-06-05: Is there a better way to set up this hook? - ;; Alternatively, can we prevent the creation of a file when the - ;; capture is aborted? - (add-hook 'org-capture-after-finalize-hook #'denote-org-capture-delete-empty-file) - (concat denote-last-front-matter denote-org-capture-specifiers))) - -(defun denote-org-capture-delete-empty-file () - "Delete file if capture with `denote-org-capture' is aborted." - (when-let* ((file denote-last-path) - ((zerop (or (file-attribute-size (file-attributes file)) 0)))) - (delete-file denote-last-path))) - -;; Samples of an `org-capture-templates' entry: -;; -;; (setq org-capture-templates -;; '(("n" "New note (with denote.el)" plain -;; (file denote-last-path) -;; #'denote-org-capture -;; :no-save t -;; :immediate-finish nil -;; :kill-buffer t -;; :jump-to-captured t))) -;; -;; (with-eval-after-load 'org-capture -;; (add-to-list 'org-capture-templates -;; '("n" "New note (with denote.el)" plain -;; (file denote-last-path) -;; #'denote-org-capture -;; :no-save t -;; :immediate-finish nil -;; :kill-buffer t -;; :jump-to-captured t))) - ;; TODO 2022-06-04: `denote-rename-file' (provide 'denote)