[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 680dbdf6b2 7/7: Merge pull request #55 from jean
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 680dbdf6b2 7/7: Merge pull request #55 from jeanphilippegg/denote--prepare-notes |
Date: |
Mon, 18 Jul 2022 01:57:40 -0400 (EDT) |
branch: externals/denote
commit 680dbdf6b2a01047d59f15e9c838d138a4f23a42
Merge: c9a01a3718 f4fae528c3
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>
Merge pull request #55 from jeanphilippegg/denote--prepare-notes
Refactor denote--prepare-notes and other modifications
---
denote-org-capture.el | 4 ++-
denote.el | 79 ++++++++++++++++++++++++++++++---------------------
2 files changed, 50 insertions(+), 33 deletions(-)
diff --git a/denote-org-capture.el b/denote-org-capture.el
index bc0a5457cd..d80c5f8003 100644
--- a/denote-org-capture.el
+++ b/denote-org-capture.el
@@ -91,7 +91,9 @@ Consult the manual for template samples."
(keywords (denote--keywords-prompt))
(denote-file-type nil)) ; we enforce the .org extension for
`org-capture'
(denote--path title keywords)
- (denote--prepare-note denote-last-title denote-last-keywords
denote-last-path)
+ (setq denote-last-front-matter (denote--file-meta-header
+ title (denote--date nil) keywords
+ (format-time-string denote--id-format
nil)))
(denote--keywords-add-to-history denote-last-keywords)
(concat denote-last-front-matter denote-org-capture-specifiers)))
diff --git a/denote.el b/denote.el
index b778252827..920a707178 100644
--- a/denote.el
+++ b/denote.el
@@ -445,18 +445,15 @@ names that are relative to the variable
`denote-directory'."
(string-prefix-p id (file-name-nondirectory f)))
(denote--directory-files :absolute)))
-(defun denote--directory-files-matching-regexp (regexp &optional
no-check-current)
- "Return list of files matching REGEXP.
-With optional NO-CHECK-CURRENT do not test if the current file is
-part of the list."
+(defun denote--directory-files-matching-regexp (regexp)
+ "Return list of files matching REGEXP."
(delq
nil
(mapcar
(lambda (f)
(when (and (denote--only-note-p f)
(string-match-p regexp f)
- (or no-check-current
- (not (string= (file-name-nondirectory (buffer-file-name))
f))))
+ (not (string= (file-name-nondirectory (buffer-file-name)) f)))
f))
(denote--directory-files))))
@@ -687,23 +684,20 @@ With optional DATE, use it else use the current one."
(t
(denote--date-org-timestamp date)))))
-(defun denote--prepare-note (title keywords &optional path date id)
- "Use TITLE and KEYWORDS to prepare new note file.
-Use optional PATH, else create it with `denote--path'. When PATH
-is provided, refrain from writing to a buffer (useful for org
-capture).
+(defun denote--prepare-note (title keywords date id directory file-type)
+ "Prepare a new note file.
-Optional DATE is passed to `denote--date', while optional ID is
-used to construct the path's identifier."
- (let* ((default-directory (denote-directory))
- (p (or path (denote--path title keywords default-directory id)))
- (buffer (unless path (find-file p)))
+Arguments TITLE, KEYWORDS, DATE, ID, DIRECTORY, and FILE-TYPE
+should be valid for note creation."
+ (let* ((default-directory directory)
+ (path (denote--path title keywords default-directory id))
+ (buffer (find-file path))
(header (denote--file-meta-header
title (denote--date date) keywords
- (format-time-string denote--id-format date))))
- (unless path
- (with-current-buffer buffer (insert header))
- (setq denote-last-buffer buffer))
+ (format-time-string denote--id-format date)
+ file-type)))
+ (with-current-buffer buffer (insert header))
+ (setq denote-last-buffer buffer)
(setq denote-last-front-matter header)))
(defvar denote--title-history nil
@@ -724,8 +718,8 @@ Optional DEFAULT-TITLE is used as the default value."
(defun denote--dir-in-denote-directory-p (directory)
"Return DIRECTORY if in variable `denote-directory', else nil."
(when-let* ((dir directory)
- ((string-match-p (expand-file-name (denote-directory))
- (expand-file-name dir))))
+ ((string-prefix-p (expand-file-name (denote-directory))
+ (expand-file-name dir))))
dir))
;;;###autoload
@@ -763,15 +757,16 @@ When called from Lisp, all arguments are optional.
('subdirectory (aset args 3 (denote--subdirs-prompt)))
('date (aset args 4 (denote--date-prompt)))))
(append args nil)))
- (let* ((denote-file-type (denote--file-type-symbol (or file-type
denote-file-type)))
+ (let* ((file-type (denote--file-type-symbol (or file-type denote-file-type)))
(date (if (or (null date) (string-empty-p date))
(current-time)
(denote--valid-date date)))
(id (format-time-string denote--id-format date))
- (denote-directory (or (denote--dir-in-denote-directory-p subdirectory)
- (denote-directory))))
+ (directory (if (denote--dir-in-denote-directory-p subdirectory)
+ (file-name-as-directory subdirectory)
+ (denote-directory))))
(denote--barf-duplicate-id id)
- (denote--prepare-note (or title "") keywords nil date id)
+ (denote--prepare-note (or title "") keywords date id directory file-type)
(denote--keywords-add-to-history keywords)))
(defalias 'denote-create-note (symbol-function 'denote))
@@ -827,18 +822,38 @@ is set to \\'(file-type title keywords)."
"Return DATE if parsed by `date-to-time', else signal error."
(date-to-time date))
+(defun denote--buffer-file-names ()
+ "Return file names of active buffers."
+ (mapcar
+ (lambda (name)
+ (file-name-nondirectory name))
+ (seq-filter
+ (lambda (name) (denote--only-note-p name))
+ (delq nil
+ (mapcar
+ (lambda (buf)
+ (buffer-file-name buf))
+ (buffer-list))))))
+
+(declare-function cl-some "cl-extra" (cl-pred cl-seq &rest cl-rest))
+
;; This should only be relevant for `denote-date', otherwise the
;; identifier is always unique (we trust that no-one writes multiple
;; notes within fractions of a second).
-(defun denote--id-exists-p (identifier no-check-current)
- "Return non-nil if IDENTIFIER already exists.
-NO-CHECK-CURRENT passes the appropriate flag to
-`denote--directory-files-matching-regexp'."
- (denote--directory-files-matching-regexp identifier no-check-current))
+(defun denote--id-exists-p (identifier)
+ "Return non-nil if IDENTIFIER already exists."
+ (let ((current-buffer-name (when (buffer-file-name)
+ (file-name-nondirectory (buffer-file-name)))))
+ (or (cl-some (lambda (file)
+ (string-match-p (concat "\\`" identifier) file))
+ (delete current-buffer-name (denote--buffer-file-names)))
+ (delete current-buffer-name
+ (denote--directory-files-matching-regexp
+ (concat "\\`" identifier))))))
(defun denote--barf-duplicate-id (identifier)
"Throw a user-error if IDENTIFIER already exists else return t."
- (if (denote--id-exists-p identifier :no-check-current)
+ (if (denote--id-exists-p identifier)
(user-error "`%s' already exists; aborting new note creation" identifier)
t))
- [elpa] externals/denote updated (c9a01a3718 -> 680dbdf6b2), ELPA Syncer, 2022/07/18
- [elpa] externals/denote 0cddca8735 4/7: Remove no-check-current parameter from denote--directory-files-matching-regexp, ELPA Syncer, 2022/07/18
- [elpa] externals/denote 6438bc7965 3/7: Check buffer file names in denote--id-exists-p, ELPA Syncer, 2022/07/18
- [elpa] externals/denote 1d89fa0d33 2/7: Use string-prefix-p in denote--dir-in-denote-directory-p, ELPA Syncer, 2022/07/18
- [elpa] externals/denote c5bba5fef1 5/7: Fix denote with subdirectories, ELPA Syncer, 2022/07/18
- [elpa] externals/denote a80ffc1425 1/7: Rework denote--prepare-note, ELPA Syncer, 2022/07/18
- [elpa] externals/denote 680dbdf6b2 7/7: Merge pull request #55 from jeanphilippegg/denote--prepare-notes,
ELPA Syncer <=
- [elpa] externals/denote f4fae528c3 6/7: Return only Denote files in denote--buffer-file-names, ELPA Syncer, 2022/07/18