It turned out not to be too difficult to do what I believe is the right
thing, in limabean at least.

The right thing in my view is to allow the duplicate include if and only if
the include context of tags and metadata is identical.

This is now implemented on main branch of limabean, although not yet in an
official release.  (I have some work to finish on plugins before making a
new release.)

Multiple include examples are here
<https://github.com/tesujimath/limabean/tree/main/examples/beancount>.

And for example:

kiri> limabean --beanfile examples/beancount/multiple-includes.beancount
[Rebel readline] Type :repl/help for online help info
[limabean] 5 directives loaded from
examples/beancount/multiple-includes.beancount

user=> (show (journal))
2014-01-27  Income:Donations    Donations  -100.00  NZD  -100.00 NZD
2014-01-27  Assets:Common       Donations   100.00  NZD
2014-02-05  Income:Work         Work       -750.00  NZD  -750.00 NZD
2014-02-05  Assets:Common       Work        750.00  NZD
:ok


kiri> limabean --beanfile
examples/beancount/multiple-includes-different-context.beancount
[Rebel readline] Type :repl/help for online help info
Error: duplicate include
   ╭─[ examples/beancount/multiple-includes/included-2.beancount:1:9 ]
   │
 1 │ include "common.beancount"
   │         ─────────┬────────
   │                  ╰────────── context #include-2
   │
   ├─[ examples/beancount/multiple-includes/included-1.beancount:1:9 ]
   │
 1 │ include "common.beancount"
   │         ─────────┬────────
   │                  ╰────────── context #include-1
───╯

This was pretty easy to implement in limabean's Rust parser as the codebase
is still quite fresh, and, well, Rust.

Hoping that someone will be able to enjoy this.  And that someone else
might be able to add a similar implementation for OG Beancount. 🤞

On Tue, 3 Mar 2026 at 14:15, Simon Guest <[email protected]> wrote:

> I had a quick look at this in limabean, and it's easily done for sure.
>
> But there seems to be one hard problem:  the tag and metadata context
> prior to inclusion in each place may differ.  In my quick implementation,
> only the first is honoured.  Which is a bit of a dirty hack, eh?
>
>
> pushtag #included
> include "include-duplicate/included.beancount"
> poptag #included
>
> pushtag #duplicate-include
> include "include-duplicate/included.beancount"
> poptag #duplicate-include
>
> results in:
>
> 2023-05-31 * "Include some beer" #included
>   Assets:Bank:Current -15.30 NZD
>   Expenses:Entertainment:Drinks-and-snacks
>
> 2023-06-01 * "Inclusion is everything" #included
>   Assets:Bank:Current -5.65 NZD
>   Expenses:Groceries
>
> Oops, missing that #duplicate-include tag.  🤷
>
> On Tue, 3 Mar 2026 at 13:55, Timothy Jesionowski <
> [email protected]> wrote:
>
>> I would love for that restriction to be removed. Never thought about
>> patching it myself, I hope there's no deep architectural reason for that
>> constraint?
>>
>>
>>
>> Sincerely,
>> Timothy Jesionowski
>>
>> On Mon, Mar 2, 2026, 6:32 PM Aaron Stacy <[email protected]> wrote:
>>
>>> The beancount loader has an error if a file is imported multiple times (
>>> code
>>> <https://github.com/beancount/beancount/blob/eb8be17c750257dc693e3173c30d2cabc9ab2faa/beancount/loader.py#L440>
>>> ).
>>>
>>> I noticed because I was trying to organize my ledger something like this:
>>>
>>> [image: ledger_deps.png]
>>>
>>> And got the error. I want each of banking.beancount and income.beancount
>>> to include accounts.beancount because my editor plugin will give me errors
>>> if I don't (since the accounts aren't defined).
>>>
>>> Looks like this functionality has been around just about as long as the
>>> include directive (commit
>>> <https://github.com/beancount/beancount/commit/1ad7017ca8bba9af7e13ed6613c28f14126b0ea7>),
>>> and I couldn't find any docs on why this would be an error.
>>>
>>> When I remove the error, the loading logic seems to work fine. Any
>>> chance I could mail a PR to remove this error?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Beancount" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/beancount/CACjABknxqNpEK0EgQK7PVh76sUkO41hF%2B6QxSTR91D6U9Z4kag%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/beancount/CACjABknxqNpEK0EgQK7PVh76sUkO41hF%2B6QxSTR91D6U9Z4kag%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Beancount" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/beancount/CAOVsoWTJbV6JW62Toq-mttgL1qRzi8oaKNDS%3D9dTxt6Pt0ZXfA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/beancount/CAOVsoWTJbV6JW62Toq-mttgL1qRzi8oaKNDS%3D9dTxt6Pt0ZXfA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/beancount/CAFhGSbtXSH_q7ti2VzzUc3k%3DzEgpcKT4qs3M%3DDOpnjfdeq5ewA%40mail.gmail.com.

Reply via email to