diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index fc1cf7d0d..ac9aa39cf 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -295,19 +295,19 @@ journalAddFile f j@Journal{files=fs} = j{files=fs++[f]} accountdirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate accountdirectivep = do - string "account" + (try $ string "apply" >> many1 spacenonewline >> string "account") + <|> string "account" many1 spacenonewline parent <- accountnamep newline pushParentAccount parent - -- return $ return id return $ ExceptT $ return $ Right id enddirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate enddirectivep = do string "end" + optional $ many1 spacenonewline >> string "apply" >> many1 spacenonewline >> string "account" popParentAccount - -- return (return id) return $ ExceptT $ return $ Right id aliasdirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate diff --git a/hledger-lib/hledger_journal.5.md b/hledger-lib/hledger_journal.5.md index 2f00c5270..6e0a36755 100644 --- a/hledger-lib/hledger_journal.5.md +++ b/hledger-lib/hledger_journal.5.md @@ -596,10 +596,10 @@ $ hledger print ## Default parent account You can specify a parent account which will be prepended to all accounts -within a section of the journal. Use the `account` directive like so: +within a section of the journal. Use the `apply account` directive like so: ``` {.journal} -account home +apply account home 2010/1/1 food $10 @@ -608,6 +608,8 @@ account home end ``` +(`!account`, `account`, and `end apply account` are also supported). + If `end` is omitted, the effect lasts to the end of the file. The above is equivalent to: diff --git a/site/manual.md b/site/manual.md index 89495ed6d..7ea7d20bb 100644 --- a/site/manual.md +++ b/site/manual.md @@ -711,10 +711,10 @@ $ hledger print ##### Default parent account You can specify a parent account which will be prepended to all accounts -within a section of the journal. Use the `account` directive like so: +within a section of the journal. Use the `apply account` directive like so: ``` {.journal} -account home +apply account home 2010/1/1 food $10 @@ -723,6 +723,8 @@ account home end ``` +(`!account`, `account`, and `end apply account` are also supported). + If `end` is omitted, the effect lasts to the end of the file. The above is equivalent to: diff --git a/tests/journal/directives.test b/tests/journal/directives.test new file mode 100644 index 000000000..f793b2e18 --- /dev/null +++ b/tests/journal/directives.test @@ -0,0 +1,48 @@ +# Accept three forms of the account directive +# . !account, !end (ledger 2, hledger) +hledger -f - accounts +<<< +!account a +2016/1/1 + (b) 1 +!end +2016/1/2 + (c) 1 +>>> +a:b +c +>>>=0 + +# . account, end (ledger 3 pre ?, hledger) +hledger -f - accounts +<<< +account a +2016/1/1 + (b) 1 +end +2016/1/2 + (c) 1 +>>> +a:b +c +>>>=0 + +# . apply account, end [apply account] (ledger 3, hledger) +# . now: apply account +hledger -f - accounts +<<< +apply account a +2016/1/1 + (b) 1 +end +apply account aa +2016/1/1 + (b) 1 +end apply account +2016/1/2 + (c) 1 +>>> +a:b +aa:b +c +>>>=0