Skip to content

Commit

Permalink
hierarchy-extract-tree now returns nil when item is not in hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Apr 14, 2017
1 parent bc455d5 commit 1de3a48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 9 additions & 7 deletions hierarchy.el
Expand Up @@ -168,13 +168,15 @@ default, SORTFN is `string-lessp'."

(defun hierarchy-extract-tree (hierarchy item)
"Return a copy of HIERARCHY with ITEM's descendants and parents."
(let ((tree (hierarchy-new)))
(hierarchy-add-tree tree item
(lambda (each) (hierarchy-parent hierarchy each))
(lambda (each) (when (or (equal each item)
(hierarchy-descendant-p hierarchy each item))
(hierarchy-children hierarchy each))))
tree))
(if (not (hierarchy-has-item hierarchy item))
nil
(let ((tree (hierarchy-new)))
(hierarchy-add-tree tree item
(lambda (each) (hierarchy-parent hierarchy each))
(lambda (each) (when (or (equal each item)
(hierarchy-descendant-p hierarchy each item))
(hierarchy-children hierarchy each))))
tree)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
4 changes: 4 additions & 0 deletions test/hierarchy-test.el
Expand Up @@ -308,6 +308,10 @@
(should (equal (hierarchy-children birds 'animal) '(bird)))
(should (equal (hierarchy-children birds 'bird) '(dove pigeon)))))

(ert-deftest hierarchy-extract-tree-nil-if-not-in-hierarchy ()
(let* ((animals (test-helper-animals)))
(should-not (hierarchy-extract-tree animals 'foobar))))

(ert-deftest hierarchy-labelfn-indent-no-indent-if-0 ()
(let* ((labelfn-base (lambda (_item _indent) (insert "foo")))
(labelfn (hierarchy-labelfn-indent labelfn-base)))
Expand Down

0 comments on commit 1de3a48

Please sign in to comment.