emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]