Merge pull request #498 from CurrySoftware/next

Allow printing the depth of the first displayed parent
This commit is contained in:
John Wiegley 2017-11-02 08:12:02 -07:00 committed by GitHub
commit bc8136fa6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -309,6 +309,20 @@ namespace {
return long(&account);
}
value_t get_depth_parent(account_t& account)
{
std::size_t depth = 0;
for (const account_t * acct = account.parent;
acct && acct->parent;
acct = acct->parent) {
std::size_t count = acct->children_with_flags(ACCOUNT_EXT_TO_DISPLAY);
assert(count > 0);
if (count > 1 || acct->has_xflags(ACCOUNT_EXT_TO_DISPLAY))
depth++;
}
return long(depth);
}
value_t get_depth_spacer(account_t& account)
{
std::size_t depth = 0;
@ -425,6 +439,8 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
case 'd':
if (fn_name == "depth")
return WRAP_FUNCTOR(get_wrapper<&get_depth>);
else if (fn_name == "depth_parent")
return WRAP_FUNCTOR(get_wrapper<&get_depth_parent>);
else if (fn_name == "depth_spacer")
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
break;