From b588ba0dcc7d3cd1390414ee7234b30c6b94e686 Mon Sep 17 00:00:00 2001 From: samahri Date: Tue, 28 Oct 2025 23:21:42 -0700 Subject: [PATCH] imp: Show parent accounts in tree mode for context --- hledger/Hledger/Cli/Commands/Accounts.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Accounts.hs b/hledger/Hledger/Cli/Commands/Accounts.hs index 7e94024ea..5f952c318 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.hs +++ b/hledger/Hledger/Cli/Commands/Accounts.hs @@ -92,14 +92,22 @@ accounts opts@CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=query,_r -- within each group of siblings sortedaccts = sortAccountNamesByDeclaration j tree accts + -- 2a. in tree mode, add parent accounts for tree structure context + acctswithparents = + if tree + then dbg4 "acctswithparents" $ + sortAccountNamesByDeclaration j tree $ -- re-sort after adding parents + expandAccountNames sortedaccts -- add all parent accounts + else sortedaccts + -- 3. if there's a depth limit, depth-clip and remove any no longer useful items clippedaccts = dbg4 "clippedaccts" $ - filter (matchesAccount acctq) $ -- clipping can leave accounts that no longer match the query, remove such + (if tree then id else filter (matchesAccount acctq)) $ -- in tree mode, keep parent accounts even if they don't match nub $ -- clipping can leave duplicates (adjacent, hopefully) filter (not . T.null) $ -- depth:0 can leave nulls map (clipAccountName dep) $ -- clip at depth if specified - sortedaccts + acctswithparents -- use expanded list instead of sortedaccts -- 4. print what remains as a list or tree, maybe applying --drop in the former case. -- Add various bits of info if enabled.