branch: externals/denote-sequence
commit 0cd7e000e9790edf7d66f53b4f1af99c046d1fbf
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Expand denote-sequence-join to cover alphanumeric-delimited and write test 
for it
---
 denote-sequence.el            | 14 +++++++++++++-
 tests/denote-sequence-test.el | 11 +++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/denote-sequence.el b/denote-sequence.el
index 0c43db312d..e4fc1caa38 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -297,7 +297,19 @@ SCHEME is a symbol among those mentioned in 
`denote-sequence-scheme'.
 Return resulting sequence if it conforms with `denote-sequence-p'."
   (pcase scheme
     ('numeric (mapconcat #'identity strings "="))
-    ('alphanumeric (apply #'concat strings))))
+    ('alphanumeric (apply #'concat strings))
+    ('alphanumeric-delimited
+     (let* ((result nil)
+            (count 0))
+       (while strings
+         (push (car strings) result)
+         (when (and (or (length= result 1)
+                        (= (% count 3) 0))
+                    (cdr strings))
+           (push "=" result))
+         (setq count (+ count 1))
+         (setq strings (cdr strings)))
+       (string-join (nreverse result))))))
 
 ;; FIXME 2026-03-23: I think this does not actually work with all sort of 
partial sequences.
 (defun denote-sequence-split (sequence &optional partial)
diff --git a/tests/denote-sequence-test.el b/tests/denote-sequence-test.el
index f0cecd6ce2..28f80d42a7 100644
--- a/tests/denote-sequence-test.el
+++ b/tests/denote-sequence-test.el
@@ -123,6 +123,17 @@ levels of depth between delimiters."
      (equal (denote-sequence-and-scheme-p "1")
             (cons "1" 'alphanumeric-delimited)))))
 
+(ert-deftest dst-denote-sequence-join ()
+  "Test that `denote-sequence-join' works as intended.
+The `denote-sequence-join' is not responsible for checking if the
+STRINGS passed to it conform with the given SCHEME."
+  (should (string= (denote-sequence-join '("1" "1" "1" "1") 'numeric) 
"1=1=1=1"))
+  (should (string= (denote-sequence-join '("1" "a" "1" "a") 'alphanumeric) 
"1a1a"))
+  (should (string= (denote-sequence-join '("1" "a") 'alphanumeric-delimited) 
"1=a"))
+  (should (string= (denote-sequence-join '("1" "a" "1") 
'alphanumeric-delimited) "1=a1"))
+  (should (string= (denote-sequence-join '("1" "a" "1" "a") 
'alphanumeric-delimited) "1=a1a"))
+  (should (string= (denote-sequence-join '("1" "a" "1" "a" "1" "a" "1" "a" "1" 
"a") 'alphanumeric-delimited) "1=a1a=1a1=a1a")))
+
 (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

Reply via email to