branch: externals/denote-sequence
commit 122addcc11e918915aa83bf9d7b876f536983a9f
Merge: 21168971a0 ea4a9d3199
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #11 from ashton314/main
    
    Make denote-sequence-find-(next|previous)-sibling skip missing files
---
 denote-sequence.el | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/denote-sequence.el b/denote-sequence.el
index 830ad8f6a8..85f273b974 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -353,6 +353,12 @@ Also see `denote-sequence-increment-partial'."
    (t
     (error "The string `%s' must contain only numbers or letters" string))))
 
+(defun denote-sequence--sequence-start-p (sequence)
+  "True if deepest part of sequence is 1 or a."
+  (pcase-let* ((components (denote-sequence-split sequence))
+               (last-component (car (nreverse components))))
+    (or (string= last-component "1") (string= last-component "a"))))
+
 (defun denote-sequence-depth (sequence)
   "Get the depth of SEQUENCE.
 For example, 1=2=1 and 1b1 are three levels of depth."
@@ -898,7 +904,11 @@ If the current file does not have a sequence, then behave 
exactly like
             (next-sequence (denote-sequence--infer-sibling sequence 'next))
             (path (denote-sequence-get-path next-sequence relatives)))
       (find-file path)
-    (user-error "No next sibling for sequence `%s'" sequence)))
+    (let* ((youngest-sibling (denote-sequence-get-new 'sibling sequence)))
+      (if (string= next-sequence youngest-sibling)
+          (user-error "No next sibling for sequence `%s'" sequence)
+        ;; Might be more siblings; keep looking
+        (denote-sequence-find-next-sibling next-sequence)))))
 
 ;;;###autoload
 (defun denote-sequence-find-previous-sibling (sequence)
@@ -908,7 +918,10 @@ If the current file does not have a sequence, then behave 
exactly like
             (previous-sequence (denote-sequence--infer-sibling sequence 
'previous))
             (path (denote-sequence-get-path previous-sequence relatives)))
       (find-file path)
-    (user-error "No previous sibling for sequence `%s'" sequence)))
+    (if (denote-sequence--sequence-start-p sequence)
+        (user-error "No previous sibling for sequence `%s'" sequence)
+      ;; Skip this one and keep looking
+      (denote-sequence-find-previous-sibling previous-sequence))))
 
 (defvar denote-sequence-relative-types
   '(all-parents parent siblings children all-children)

Reply via email to