branch: externals/denote
commit 71630b951082379485372ea0337fff01f8046c78
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Add denote-sequence-get-relative function
    
    This foreshadows commands I will introduce shortly.
---
 denote-sequence.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/denote-sequence.el b/denote-sequence.el
index 8538b31b3b..f383b75f65 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -569,6 +569,23 @@ return value of `denote-sequence-get-all-sequences'."
     ('sibling (denote-sequence--get-new-sibling sequence sequences))
     (_ (error "The type `%s' is not among `denote-sequence-types'" type))))
 
+(defun denote-sequence-get-relative (sequence type &optional files)
+  "Get files of TYPE given the SEQUENCE.
+With optional FILES consider only those, otherwise operate on all files
+returned by `denote-sequence-get-all-files'."
+  (let* ((depth (denote-sequence-depth sequence))
+         (components (denote-sequence-split sequence))
+         (filter (lambda (comparison prefix)
+                   (seq-filter
+                    (lambda (file)
+                      (funcall comparison (denote-sequence-depth 
(denote-retrieve-filename-signature file)) depth))
+                    (denote-sequence-get-all-files-with-prefix prefix 
files)))))
+    (pcase type
+      ('parent (funcall filter '< (car components)))
+      ('sibling (funcall filter '= (denote-sequence-join (butlast components) 
(cdr (denote-sequence-and-scheme-p sequence)))))
+      ('child (funcall filter '> sequence))
+      (_ (error "The type `%s' is not among the `denote-sequence-types'" 
type)))))
+
 (defvar denote-sequence-type-history nil
   "Minibuffer history of `denote-sequence-type-prompt'.")
 

Reply via email to