branch: externals/denote
commit 8d130358a2a7b7063cf9bf3d5a9ef6a29d15738f
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Fix some more issues with denote-sequence--get-new-child
STILL NEEDS TESTING.
---
denote-sequence.el | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/denote-sequence.el b/denote-sequence.el
index f23b30148e..6d4fbbb465 100644
--- a/denote-sequence.el
+++ b/denote-sequence.el
@@ -163,21 +163,24 @@ return value of `denote-sequence-get-all-sequences'."
"Return a new child of SEQUENCE.
Optional SEQUENCES has the same meaning as that specified in the
function `denote-sequence-get-all-sequences-with-prefix'."
- (let* ((descendants-p (string-match-p "=" sequence)))
- (if-let* ((depth (+ (denote-sequence-depth sequence) 1))
- (all-unfiltered (if descendants-p
-
(denote-sequence-get-all-sequences-with-prefix sequence sequences)
- (denote-sequence-get-all-sequences)))
- (all (denote-sequence-get-sequences-with-max-depth depth
all-unfiltered))
+ (let ((no-descendants (= (length sequence) 1)))
+ (if-let* ((depth (if no-descendants
+ 2
+ (denote-sequence-depth sequence)))
+ (all-unfiltered (denote-sequence-get-all-sequences-with-prefix
sequence sequences))
+ (all (or (denote-sequence-get-sequences-with-max-depth depth
all-unfiltered)
+ all-unfiltered))
(largest (denote-sequence--get-largest all 'child)))
- (if descendants-p
- (let* ((components (split-string largest "="))
- (butlast (butlast components))
+ (if (string-match-p "=" largest)
+ (let* ((components (denote-sequence-split largest))
+ (butlast (when no-descendants (butlast components)))
(last-component (car (nreverse components)))
(current-number (string-to-number last-component))
(new-number (number-to-string (+ current-number 1))))
- (mapconcat #'identity (append butlast (list new-number)) "="))
- (number-to-string (+ (string-to-number largest) 1)))
+ (if butlast
+ (mapconcat #'identity (append butlast (list new-number)) "=")
+ (mapconcat #'identity (list largest new-number) "=")))
+ (format "%s=1" largest))
(error "Cannot find sequences given sequence `%s'" sequence))))
(defun denote-sequence--get-new-sibling (sequence &optional sequences)