branch: externals/denote-sequence
commit 8d8c5be20861a741a5f740da02c9c54e13fd98b8
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Add WORK-IN-PROGRESS sequence scheme "alphanumeric-delimited"
---
denote-sequence.el | 35 ++++++++++++++++++++++++++++++++++-
tests/denote-sequence-test.el | 12 ++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/denote-sequence.el b/denote-sequence.el
index 572d496816..14c6c09460 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -106,7 +106,40 @@ zx (z is 26 and x is 25)."
(string-match-p "\\`[0-9]+" sequence)
(not (string-match-p "=" sequence)))
sequence))
-
+(defun denote-sequence-alphanumeric-delimited-p (sequence)
+ "Return SEQUENCE if it is an alphanumeric and delimited.
+Refer to the `denote-sequence-scheme' for the details."
+ (cond
+ ((string-match-p "\\`[0-9]+\\'" sequence)
+ sequence)
+ (t
+ (when (and (string-match-p "=" sequence)
+ (not (denote-sequence-numeric-p sequence)))
+ (let ((start 0)
+ (strings nil))
+ (while (string-match
"\\(?1:[0-9]+\\)[[:alpha:]]\\|\\(?2:[[:alpha:]]+\\)[0-9]*" sequence start)
+ (if-let* ((match (match-string 1 sequence)))
+ (progn
+ (setq start (match-end 1))
+ (push match strings))
+ (push (match-string 2 sequence) strings)
+ (setq start (match-end 2))))
+ (catch 'error
+ (let ((last-type nil)
+ (current-type nil))
+ ;; FIXME 2026-03-23: We need to test for length of each
+ ;; segment. Specifically, the first should be 1, then
+ ;; every other should be maximum 3 (where the numbers
+ ;; refer to levels of depth).
+ (dolist (string (nreverse strings))
+ (if (string-match-p "\\`[0-9]+\\'" string)
+ (setq current-type 'numeric)
+ (setq current-type 'alpha))
+ (when (eq current-type last-type)
+ (throw 'error nil))
+ (setq last-type current-type)))
+ sequence))))))
+
(defun denote-sequence-user-selected-scheme-p (sequence)
"Return SEQUENCE if it is consistent with `denote-sequence-scheme'.
Also see `denote-sequence-alphanumeric-p' and `denote-sequence-numeric-p'."
diff --git a/tests/denote-sequence-test.el b/tests/denote-sequence-test.el
index c9a66f872c..f962022063 100644
--- a/tests/denote-sequence-test.el
+++ b/tests/denote-sequence-test.el
@@ -60,6 +60,18 @@
(should (string= (denote-sequence-alphanumeric-p "1") "1"))
(should (string= (denote-sequence-alphanumeric-p "1a") "1a")))
+(ert-deftest dst-denote-sequence-alphanumeric-delimited-p ()
+ "Test that `denote-sequence-alphanumeric-delimited-p' does what it is
supposed to."
+ (should-not (denote-sequence-alphanumeric-delimited-p "1a"))
+ (should-not (denote-sequence-alphanumeric-delimited-p "1=1"))
+ (should-not (denote-sequence-alphanumeric-delimited-p "1=a=a"))
+ (should-not (denote-sequence-alphanumeric-delimited-p "1=a=1")) ; check
FIXME in the source
+ (should-not (denote-sequence-alphanumeric-delimited-p "hello"))
+ (should (string= (denote-sequence-alphanumeric-delimited-p "1") "1"))
+ (should (string= (denote-sequence-alphanumeric-delimited-p "1=a") "1=a"))
+ (should (string= (denote-sequence-alphanumeric-delimited-p "1=a1b") "1=a1b"))
+ (should (string= (denote-sequence-alphanumeric-delimited-p "1=a1b=2a1")
"1=a1b=2a1")))
+
(ert-deftest dst-denote-sequence--get-new-exhaustive ()
"Test if we get the correct parent, child, sibling, or relatives of a
sequence.
Use the function `denote-sequence-get-new' for child and sibling with