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

    Make final (?) tweaks to support the alphanumeric-delimited scheme
---
 denote-sequence.el            | 22 +++++++-------
 tests/denote-sequence-test.el | 69 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/denote-sequence.el b/denote-sequence.el
index 2510191713..16e8cf3ad7 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -676,7 +676,7 @@ With optional SEQUENCES operate on those, else use the 
return value of
       (lambda (strings)
         (denote-sequence-join
          (seq-take strings depth)
-         (denote-sequence--scheme-of-strings strings)))
+         denote-sequence-scheme))
       lists))))
 
 (defun denote-sequence--pad (sequence type)
@@ -739,7 +739,7 @@ Also see `denote-sequence-sort-sequences'."
 
 (defun denote-sequence--string-length-sans-delimiter (string)
   "Return length of STRING without the equals sign."
-  (if (eq denote-sequence-scheme 'numeric)
+  (if (memq denote-sequence-scheme '(numeric alphanumeric-delimited))
       (length (replace-regexp-in-string "=" "" string))
     (length string)))
 
@@ -769,15 +769,13 @@ TYPE is a symbol among `denote-sequence-types'."
           largest))
     (denote-sequence--get-largest-by-order sequences type)))
 
-(defun denote-sequence--get-start (&optional sequence prepend-delimiter)
+(defun denote-sequence--get-start (&optional sequence)
   "Return the start of a new sequence.
 With optional SEQUENCE, do so based on the final level of depth therein.
-This is usefule only for the alphanumeric `denote-sequence-scheme'.  If
-optional PREPEND-DELIMITER is non-nil, prepend the equals sign to the
-number if `denote-sequence-scheme' is numeric."
+This is usefule only for the alphanumeric `denote-sequence-scheme'."
   ;; TODO 2026-04-03: Rewrite this for clarity.
   (pcase denote-sequence-scheme
-    ('numeric (if prepend-delimiter "=1" "1"))
+    ('numeric "1")
     ((or 'alphanumeric 'alphanumeric-delimited)
      (cond
       ((null sequence) "1")
@@ -809,9 +807,9 @@ Optional SEQUENCES has the same meaning as that specified 
in the
 function `denote-sequence-get-all-sequences-with-prefix'."
   (if-let* ((depth (+ (denote-sequence-depth sequence) 1))
             (all-unfiltered (denote-sequence-get-all-sequences-with-prefix 
sequence sequences))
-            (start-child (denote-sequence--get-start sequence 
:prepend-delimiter)))
+            (start-child (denote-sequence--get-start sequence)))
       (if (= (length all-unfiltered) 1)
-          (format "%s%s" (car all-unfiltered) start-child)
+          (denote-sequence-join (append (denote-sequence-split sequence) (list 
start-child)) denote-sequence-scheme)
         (if-let* ((all-schemeless (cond
                                    
((denote-sequence-get-all-sequences-with-max-depth depth all-unfiltered))
                                    (t all-unfiltered)))
@@ -828,8 +826,8 @@ function `denote-sequence-get-all-sequences-with-prefix'."
                        (append butlast (list new-number))
                      (list largest new-number))
                    scheme))
-              (format "%s%s" largest start-child))
-          (format "%s%s" sequence start-child)))
+              (denote-sequence-join (append (denote-sequence-split largest) 
(list start-child)) denote-sequence-scheme))
+          (denote-sequence-join (append (denote-sequence-split sequence) (list 
start-child)) denote-sequence-scheme)))
     (error "Cannot find sequences given sequence `%s' using scheme `%s'" 
sequence denote-sequence-scheme)))
 
 (defun denote-sequence--get-prefix-for-siblings (sequence)
@@ -862,7 +860,7 @@ function `denote-sequence-get-all-sequences-with-prefix'."
                          (last-component (car (nreverse components)))
                          (new-number (denote-sequence-increment-partial 
last-component)))
               (denote-sequence-join (append butlast (list new-number)) scheme))
-          (number-to-string (+ (string-to-number largest) 1)))
+          (denote-sequence-join (list (number-to-string (+ (string-to-number 
largest) 1))) denote-sequence-scheme))
       (error "Cannot find sequences given sequence `%s' using scheme `%s'" 
sequence denote-sequence-scheme))))
 
 (defun denote-sequence-get-new (type &optional sequence sequences)
diff --git a/tests/denote-sequence-test.el b/tests/denote-sequence-test.el
index a649366c60..54df93a2fd 100644
--- a/tests/denote-sequence-test.el
+++ b/tests/denote-sequence-test.el
@@ -280,7 +280,74 @@ function `denote-sequence-get-relative'."
                             "20241230T075023==10b--test__testing.txt"))
     (should (dst-relative-p "1a" 'all-children
                             "20241230T075023==1a1--test__testing.txt"
-                            "20241230T075023==1a2--test__testing.txt"))))
+                            "20241230T075023==1a2--test__testing.txt")))
+
+  (let* ((denote-sequence-scheme 'alphanumeric-delimited)
+         (denote-directory (expand-file-name "denote-sequence-test" 
temporary-file-directory))
+         (files
+          (mapcar
+           (lambda (file)
+             (let ((path (expand-file-name file (denote-directory))))
+               (if (file-exists-p path)
+                   path
+                 (with-current-buffer (find-file-noselect path)
+                   (save-buffer)
+                   (kill-buffer (current-buffer)))
+                 path)))
+           '("20241230T075023==1--test__testing.txt"
+             "20241230T075023==1=a--test__testing.txt"
+             "20241230T075023==1=a1--test__testing.txt"
+             "20241230T075023==1=a2--test__testing.txt"
+             "20241230T075023==1=b--test__testing.txt"
+             "20241230T075023==1=b1--test__testing.txt"
+             "20241230T075023==1=b1a--test__testing.txt"
+             "20241230T075023==2--test__testing.txt"
+             "20241230T075023==10--test__testing.txt"
+             "20241230T075023==10=a--test__testing.txt"
+             "20241230T075023==10=b--test__testing.txt")))
+         (sequences (denote-sequence-get-all-sequences files)))
+    (should (string= (denote-sequence-get-new 'parent) "11"))
+
+    (should (string= (denote-sequence-get-new 'child "1" sequences) "1=c"))
+    (should (string= (denote-sequence-get-new 'child "1=a" sequences) "1=a3"))
+    (should (string= (denote-sequence-get-new 'child "1=a2" sequences) 
"1=a2a"))
+    (should (string= (denote-sequence-get-new 'child "1=b" sequences) "1=b2"))
+    (should (string= (denote-sequence-get-new 'child "1=b1" sequences) 
"1=b1b"))
+    (should (string= (denote-sequence-get-new 'child "2" sequences) "2=a"))
+    (should-error (denote-sequence-get-new 'child "11" sequences))
+
+    (should (string= (denote-sequence-get-new 'sibling "1" sequences) "11"))
+    (should (string= (denote-sequence-get-new 'sibling "1=a" sequences) "1=c"))
+    (should (string= (denote-sequence-get-new 'sibling "1=a1" sequences) 
"1=a3"))
+    (should (string= (denote-sequence-get-new 'sibling "1=a2" sequences) 
"1=a3"))
+    (should (string= (denote-sequence-get-new 'sibling "1=b" sequences) "1=c"))
+    (should (string= (denote-sequence-get-new 'sibling "1=b1" sequences) 
"1=b2"))
+    (should (string= (denote-sequence-get-new 'sibling "2" sequences) "11"))
+    (should-error (denote-sequence-get-new 'sibling "12" sequences))
+
+    (should (string= (denote-sequence-get-relative "1=b1a" 'parent files)
+                     (expand-file-name 
"20241230T075023==1=b1--test__testing.txt" denote-directory)))
+    (should (string= (denote-sequence-get-relative "10=a" 'parent files)
+                     (expand-file-name 
"20241230T075023==10--test__testing.txt" denote-directory)))
+    (should (dst-relative-p "1=b1a" 'all-parents
+                            "20241230T075023==1--test__testing.txt"
+                            "20241230T075023==1=b--test__testing.txt"
+                            "20241230T075023==1=b1--test__testing.txt"))
+    (should (dst-relative-p "1=a" 'siblings
+                            "20241230T075023==1=a--test__testing.txt"
+                            "20241230T075023==1=b--test__testing.txt"))
+    (should (dst-relative-p "10=a" 'siblings
+                            "20241230T075023==10=a--test__testing.txt"
+                            "20241230T075023==10=b--test__testing.txt"))
+    (should (dst-relative-p "1" 'children
+                            "20241230T075023==1=a--test__testing.txt"
+                            "20241230T075023==1=b--test__testing.txt"))
+    (should (dst-relative-p "10" 'children
+                            "20241230T075023==10=a--test__testing.txt"
+                            "20241230T075023==10=b--test__testing.txt"))
+    (should (dst-relative-p "1=a" 'all-children
+                            "20241230T075023==1=a1--test__testing.txt"
+                            "20241230T075023==1=a2--test__testing.txt"))))
 
 (ert-deftest dst-denote-sequence-split ()
   "Test that `denote-sequence-split' splits a sequence correctly."

Reply via email to