branch: externals/denote
commit 6000313eeccc31e03daebac8c0056d8909da4a7b
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Enforce sluggification of keywords; document it
---
README.org | 18 ++++++++++++++++++
denote.el | 32 ++++++++++++++++++++------------
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/README.org b/README.org
index 35450ae3b5..41a7d5ffe1 100644
--- a/README.org
+++ b/README.org
@@ -153,6 +153,24 @@ does not actually depend on org.el and/or its
accoutrements.
Notes are stored as a flat list in the ~denote-directory~ (i.e. no
subdirectories). The default path is =~/Documents/notes=.
+** Sluggified title and keywords
+:PROPERTIES:
+:CUSTOM_ID: h:ae8b19a1-7f67-4258-96b3-370a72c43f4e
+:END:
+
+Denote has to be highly opinionated about which characters can be used
+in file names and the file's front matter in order to enforce its
+file-naming scheme. The private variable ~denote--punctuation-regexp~
+holds the relevant value. In simple terms:
+
++ What we count as "illegal characters" are converted into hyphens.
+
++ Input for a file title is hyphenated and downcased. The original
+ value is preserved only in the note's contents
([[#h:13218826-56a5-482a-9b91-5b6de4f14261][Front matter]]).
+
++ Keywords should not have spaces or other delimiters. If they do, they
+ are converted into hyphens. Keywords are always downcased.
+
* Points of entry
:PROPERTIES:
:CUSTOM_ID: h:17896c8c-d97a-4faa-abf6-31df99746ca6
diff --git a/denote.el b/denote.el
index d24759233d..19e578811a 100644
--- a/denote.el
+++ b/denote.el
@@ -174,7 +174,8 @@ is suspended: we use whatever the user wants."
"Regular expression to match `denote-keywords'.")
(defconst denote--punctuation-regexp "[][{}!@#$%^&*()_=+'\"?,.\|;:~`‘’“”]*"
- "Regular expression of punctionation that should be removed.")
+ "Regular expression of punctionation that should be removed.
+We consider those characters illigal for our purposes.")
(defvar denote-last-path nil "Store last path.")
(defvar denote-last-title nil "Store last title.")
@@ -216,9 +217,15 @@ trailing hyphen."
(replace-regexp-in-string "--+\\|\s+" "-" str))))
(defun denote--sluggify (str)
- "Make STR an appropriate file name slug."
+ "Make STR an appropriate slug for file names and related."
(downcase (denote--slug-hyphenate (denote--slug-no-punct str))))
+(defun denote--sluggify-keywords (keywords)
+ "Sluggify KEYWORDS."
+ (if (listp keywords)
+ (mapcar #'denote--sluggify keywords)
+ (denote--sluggify keywords)))
+
(defun denote--file-empty-p (file)
"Return non-nil if FILE is empty."
(zerop (or (file-attribute-size (file-attributes file)) 0)))
@@ -358,15 +365,16 @@ keyword is just downcased.
With optional TYPE, format the keywords accordingly (this might
be `toml' or, in the future, some other spec that needss special
treatment)."
- (cond
- ((and (> (length keywords) 1) (not (stringp keywords)))
- (pcase type
- ('toml (format "[%s]" (denote--map-quote-downcase keywords)))
- (_ (mapconcat #'downcase keywords " "))))
- (t
- (pcase type
- ('toml (format "[%S]" (downcase keywords)))
- (_ (downcase keywords))))))
+ (let ((kw (denote--sluggify-keywords keywords)))
+ (cond
+ ((and (> (length kw) 1) (not (stringp kw)))
+ (pcase type
+ ('toml (format "[%s]" (denote--map-quote-downcase kw)))
+ (_ (mapconcat #'downcase kw " "))))
+ (t
+ (pcase type
+ ('toml (format "[%S]" (downcase kw)))
+ (_ (downcase kw)))))))
(defvar denote-tml-front-matter
"+++
@@ -435,7 +443,7 @@ Format current time, else use optional ID."
(denote--format-file
(file-name-as-directory denote-directory)
(format-time-string denote--id)
- keywords
+ (denote--sluggify-keywords keywords)
(denote--sluggify title)
(denote--file-extension))))