[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote a89755c686 1/6: Add denote-file-has-denoted-file
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote a89755c686 1/6: Add denote-file-has-denoted-filename-p function |
Date: |
Mon, 9 Dec 2024 06:58:47 -0500 (EST) |
branch: externals/denote
commit a89755c686fc744545414059d4439b34c12e188d
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Add denote-file-has-denoted-filename-p function
---
denote.el | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/denote.el b/denote.el
index f5ba8372d3..3fb9532f30 100644
--- a/denote.el
+++ b/denote.el
@@ -1190,6 +1190,31 @@ For our purposes, a note must satisfy `file-regular-p'
and
`denote-filename-is-note-p'."
(and (file-regular-p file) (denote-filename-is-note-p file)))
+(defun denote-file-has-denoted-filename-p (file)
+ "Return non-nil if FILE respects the file-naming scheme of Denote.
+
+This tests the rules of Denote's file-naming scheme. Sluggification is
+ignored. It is done by removing all file name components and validating
+what remains."
+ (let ((filename (file-name-nondirectory file))
+ (title (denote-retrieve-filename-title file))
+ (keywords-string (denote-retrieve-filename-keywords file))
+ (signature (denote-retrieve-filename-signature file))
+ (identifier (denote-retrieve-filename-identifier file)))
+ (when title
+ (setq filename (replace-regexp-in-string (concat "\\(--" (regexp-quote
title) "\\).*\\'") "" filename nil nil 1)))
+ (when keywords-string
+ (setq filename (replace-regexp-in-string (concat "\\(__" (regexp-quote
keywords-string) "\\).*\\'") "" filename nil nil 1)))
+ (when signature
+ (setq filename (replace-regexp-in-string (concat "\\(==" (regexp-quote
signature) "\\).*\\'") "" filename nil nil 1)))
+ (when identifier
+ (if (string-match-p "@@" filename)
+ (setq filename (replace-regexp-in-string (concat "\\(@@"
(regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))
+ (setq filename (replace-regexp-in-string (concat "\\(" (regexp-quote
identifier) "\\).*\\'") "" filename nil nil 1))))
+ ;; What remains should be the empty string or the file extension.
+ (or (string-empty-p filename)
+ (string-prefix-p "." filename))))
+
(defun denote-file-has-signature-p (file)
"Return non-nil if FILE has a Denote identifier."
(denote-retrieve-filename-signature file))
- [elpa] externals/denote updated (7a2034516e -> c68e9bee1e), ELPA Syncer, 2024/12/09
- [elpa] externals/denote a89755c686 1/6: Add denote-file-has-denoted-filename-p function,
ELPA Syncer <=
- [elpa] externals/denote 26629820f7 2/6: Refactor denote-retrieve-title-or-filename, ELPA Syncer, 2024/12/09
- [elpa] externals/denote 63a6603b62 5/6: Merge pull request #491 from jeanphilippegg/denote-retrieve-title-or-filename, ELPA Syncer, 2024/12/09
- [elpa] externals/denote c68e9bee1e 6/6: Mention denote-file-has-denoted-filename-p in the manual, ELPA Syncer, 2024/12/09
- [elpa] externals/denote f89f9ee963 4/6: Make denote-date-prompt accept optional INITIAL-DATE and PROMPT-TEXT, ELPA Syncer, 2024/12/09
- [elpa] externals/denote 5ae74c1158 3/6: Change the way denote--used-ids is used, ELPA Syncer, 2024/12/09