[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 0e2cc10fe6 009/355: Improve integration with org
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 0e2cc10fe6 009/355: Improve integration with org-capture-templates |
Date: |
Sun, 26 Jun 2022 23:57:55 -0400 (EDT) |
branch: externals/denote
commit 0e2cc10fe6fe5e3eca0124762127453c94752594
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Improve integration with org-capture-templates
---
denote.el | 88 +++++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 57 insertions(+), 31 deletions(-)
diff --git a/denote.el b/denote.el
index 46ccfd2dbe..58d9cf82ca 100644
--- a/denote.el
+++ b/denote.el
@@ -177,14 +177,15 @@ In the case of multiple entries, those are separated by
the
`crm-sepator', which typically is a comma. In such a case, the
output is sorted with `string-lessp'."
(let ((choice (denote--keywords-crm (denote-keywords))))
- (cond
- ((null choice)
- "")
- ((= (length choice) 1)
- (car choice))
- ((if denote-sort-keywords
- (sort choice #'string-lessp)
- choice)))))
+ (setq denote--last-keywords
+ (cond
+ ((null choice)
+ "")
+ ((= (length choice) 1)
+ (car choice))
+ ((if denote-sort-keywords
+ (sort choice #'string-lessp)
+ choice))))))
(defun denote--keywords-combine (keywords)
"Format KEYWORDS output of `denote--keywords-prompt'."
@@ -216,10 +217,9 @@ output is sorted with `string-lessp'."
;;;; New note
(defun denote--format-file (path id keywords slug)
- "Helper for `denote-new-note' to format file names.
-PATH, ID, KEYWORDS, SLUG are expected to be supplied by
-`denote-new-note': they will all be converted into a single
-string."
+ "Format file name.
+PATH, ID, KEYWORDS, SLUG are expected to be supplied by `denote'
+or equivalent: they will all be converted into a single string."
(let ((kws (if denote-infer-keywords
(denote--keywords-combine keywords)
keywords)))
@@ -237,17 +237,24 @@ TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which
are
"#+filename: " filename "\n"
"#+identifier: " id "\n\n")))
+(defvar denote--last-path nil "Store last path.")
+(defvar denote--last-title nil "Store last title.")
+(defvar denote--last-keywords nil "Store last keywords.")
+
(defun denote--path (title keywords)
- "Return path to new file with TITLE and KEYWORDS."
- (denote--format-file
- (file-name-as-directory denote-directory)
- (format-time-string denote-id)
- keywords
- (denote--sluggify title)))
-
-(defun denote--prepare-note (title keywords)
- "Use TITLE and KEYWORDS to prepare new note file."
- (let ((filename (denote--path title keywords)))
+ "Return path to new file with TITLE and KEYWORDS.
+Format current time, else use optional ID."
+ (setq denote--last-path
+ (denote--format-file
+ (file-name-as-directory denote-directory)
+ (format-time-string denote-id)
+ keywords
+ (denote--sluggify title))))
+
+(defun denote--prepare-note (title keywords &optional path)
+ "Use TITLE and KEYWORDS to prepare new note file.
+Use optional PATH, else create it with `denote--path'."
+ (let* ((filename (or path (denote--path title keywords))))
(with-current-buffer (find-file filename)
(insert
(denote--file-meta-header
@@ -259,7 +266,8 @@ TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which
are
(defun denote--title-prompt ()
"Read file title for `denote-new-note'."
- (read-string "File title: " nil 'denote--title-history))
+ (setq denote--last-title
+ (read-string "File title: " nil 'denote--title-history)))
;;;###autoload
(defun denote (title keywords)
@@ -286,20 +294,38 @@ alphabetically."
;;;###autoload
(defun denote-org-capture ()
- "Like `denote', but for integration with `org-capture'.
-WORK-IN-PROGRESS."
+ "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--prepare-note title keywords)
- (denote--keywords-add-to-history keywords)))
+ (denote--path title keywords)
+ (denote--keywords-add-to-history denote--last-keywords)
+ (denote--prepare-note denote--last-title denote--last-keywords
denote--last-path)
+ denote--last-path))
;; Sample of an `org-capture-templates' entry:
;;
-;; ("n" "Note" plain
-;; (file ,(denote--directory))
-;; (function denote-org-capture)
+;; ("n" "Note (with denote.el)" plain
+;; (function denote-org-capture-path)
+;; ,(concat "%i"
+;; "\n"
+;; "%a")
+;; :unnarrowed t
;; :no-save t
-;; :immediate-finish t)
+;; :immediate-finish nil
+;; :kill-buffer t
+;; :jump-to-captured t
+;; :empty-lines-before 1)
+;;
+;; FIXME 2022-06-04: The :kill-buffer does not actually kill the buffer
+;; of the file if we use C-c C-k in the capture buffer...
+
;; TODO 2022-06-04: `denote-rename-file'
- [elpa] externals/denote 5744240289 036/355: Remove needless to-do, (continued)
- [elpa] externals/denote 5744240289 036/355: Remove needless to-do, ELPA Syncer, 2022/06/26
- [elpa] externals/denote aaa691aa15 020/355: Refine front-matter, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 153827f6c8 021/355: Add denote-link, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 21104787f7 024/355: Put link functionality in denote-link.el, ELPA Syncer, 2022/06/26
- [elpa] externals/denote b951a62245 025/355: Put capture code in denote-org-capture.el, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 9f4a99243c 035/355: Change how org-capture hook is added, ELPA Syncer, 2022/06/26
- [elpa] externals/denote fa6a3315dc 047/355: Add correct group for org capture specifiers, ELPA Syncer, 2022/06/26
- [elpa] externals/denote f33f8a7040 053/355: Rewrite README as a manual, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 251b35d8f5 003/355: Add GPL, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 2aed386b84 006/355: Add denote-org-capture (WORK-IN-PROGRESS), ELPA Syncer, 2022/06/26
- [elpa] externals/denote 0e2cc10fe6 009/355: Improve integration with org-capture-templates,
ELPA Syncer <=
- [elpa] externals/denote 1079beb858 017/355: Add todo about file deletion post org-capture, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 27642bee14 026/355: Clarify 'denote' doc string, ELPA Syncer, 2022/06/26
- [elpa] externals/denote ec3847607b 028/355: Remove to-do about file name format, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 7fe66f43d4 030/355: Remove needless outline and empty line, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 550428cabf 037/355: Add sample org-capture-templates to Commentary, ELPA Syncer, 2022/06/26
- [elpa] externals/denote efd5135835 039/355: Improve linking functionality, ELPA Syncer, 2022/06/26
- [elpa] externals/denote a34ca52fbf 040/355: Fix regression in M-x denote, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 3b62f8e167 043/355: Implement denote-link-clear-stale-backlinks, ELPA Syncer, 2022/06/26
- [elpa] externals/denote d57ff29c3b 045/355: Add denote--file-regexp, ELPA Syncer, 2022/06/26
- [elpa] externals/denote de00f939d3 048/355: Fix typo, ELPA Syncer, 2022/06/26