Implement sluggify scheme for signatures

Following the Denote file-naming scheme, we use the equals sign to
separate individual words in the SIGNATURE field.  Signatures are
anchored by the "==" field separator.  For context:

- Titles which are anchroned by the "--" field separator use hyphens.
- Keywords which are anchroned by the "__" field separator use underscores.

Thanks to Alfredo Borrás and Jeremy Friesen for discussiing this issue
on the mailing list:
<https://lists.sr.ht/~protesilaos/denote/%3C2A597B4E-5F18-4D97-9457-B3C859DAA020%40zoho.eu%3E>.

Thanks to Kai von Fintel for doing the same on the GitHub mirror in
issue 147: <https://github.com/protesilaos/denote/issues/147>.
This commit is contained in:
Protesilaos Stavrou 2023-04-10 06:53:52 +03:00
parent 7fd0238470
commit d1275c32f8
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 31 additions and 8 deletions

View file

@ -1268,11 +1268,13 @@ scheme we apply guarantees that a listing is readable in a variety of
contexts. The Denote file-naming scheme is, in essence, an effective,
low-tech invention.
** Sluggified title and keywords
** Sluggified title, keywords, and signature
:PROPERTIES:
:CUSTOM_ID: h:ae8b19a1-7f67-4258-96b3-370a72c43f4e
:END:
[ Signatures are part of {{{development-version}}}. ]
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 variable ~denote-excluded-punctuation-regexp~
@ -1286,6 +1288,9 @@ holds the relevant value. In simple terms:
+ Keywords should not have spaces or other delimiters. If they do, they
are converted into hyphens. Keywords are always downcased.
+ Signatures are like the above, but use the equals sign instead of
hyphens.
** Features of the file-naming scheme for searching or filtering
:PROPERTIES:
:CUSTOM_ID: h:1a953736-86c2-420b-b566-fb22c97df197
@ -3086,6 +3091,10 @@ might change them without further notice.
dehyphenate =STR=, inverting ~denote-sluggify~. Basically, convert
=this-is-a-test= to =This is a test=.
#+findex: denote-sluggify-signature
+ Function ~denote-sluggify-signature~ :: Make STR an appropriate slug
for signatures. [Part of {{{development-version}}}]
#+findex: denote-sluggify-keywords
+ Function ~denote-sluggify-keywords~ :: Sluggify =KEYWORDS=, which is
a list of strings ([[#h:ae8b19a1-7f67-4258-96b3-370a72c43f4e][Sluggified title and keywords]]).
@ -4030,11 +4039,11 @@ Denote is meant to be a collective effort. Every bit of help matters.
Schmitt, Alfredo Borrás, Benjamin Kästner, Colin McLear, Damien
Cassou, Elias Storms, Federico Stilman, Florian, Frank Ehmsen, Guo
Yong, Hanspeter Gisler, Jack Baty, Jeremy Friesen, Jonathan Sahar,
Juanjo Presa, Johan Bolmsjö, Kaushal Modi, M. Hadi Timachi, Mirko
Hernandez, Paul van Gelder, Peter Prevos, Shreyas Ragavan, Stefan
Thesing, Summer Emacs, Sven Seebeck, Taoufik, Viktor Haag, Yi Liu,
Ypot, atanasj, doolio, drcxd, hpgisler, pRot0ta1p, rbenit68,
relict007, sienic, sundar bp.
Juanjo Presa, Johan Bolmsjö, Kai von Fintel, Kaushal Modi, M. Hadi
Timachi, Mirko Hernandez, Paul van Gelder, Peter Prevos, Shreyas
Ragavan, Stefan Thesing, Summer Emacs, Sven Seebeck, Taoufik, Viktor
Haag, Yi Liu, Ypot, atanasj, doolio, drcxd, hpgisler, pRot0ta1p,
rbenit68, relict007, sienic, sundar bp.
Special thanks to Peter Povinec who helped refine the file-naming
scheme, which is the cornerstone of this project.

View file

@ -460,7 +460,7 @@ The note's ID is derived from the date and time of its creation.")
(defconst denote-id-regexp "\\([0-9]\\{8\\}\\)\\(T[0-9]\\{6\\}\\)"
"Regular expression to match `denote-id-format'.")
(defconst denote-signature-regexp "==\\([[:alnum:][:nonascii:]]*\\)"
(defconst denote-signature-regexp "==\\([[:alnum:][:nonascii:]=]*\\)"
"Regular expression to match the SIGNATURE field in a file name.")
(define-obsolete-variable-alias
@ -555,6 +555,20 @@ leading and trailing hyphen."
'denote-sluggify
"1.0.0")
(defun denote--slug-put-equals (str)
"Replace spaces and underscores with equals signs in STR.
Also replace multiple equals signs with a single one and remove
any leading and trailing signs."
(replace-regexp-in-string
"^=\\|=$" ""
(replace-regexp-in-string
"=\\{2,\\}" "="
(replace-regexp-in-string "_\\|\s+" "=" str))))
(defun denote-sluggify-signature (str)
"Make STR an appropriate slug for signatures."
(downcase (denote--slug-put-equals (denote--slug-no-punct str))))
(defun denote-sluggify-and-join (str)
"Sluggify STR while joining separate words."
(downcase
@ -1423,7 +1437,7 @@ construct path to DIR."
(denote-sluggify title)
(denote--file-extension file-type)
(when signature
(denote--slug-no-punct signature))))
(denote-sluggify-signature signature))))
;; Adapted from `org-hugo--org-date-time-to-rfc3339' in the `ox-hugo'
;; package: <https://github.com/kaushalmodi/ox-hugo>.