Emacs + ledger mode solves problem

I use ledger mode in Emacs to look up a transaction from a past year:
https://hledgerfan.com/getting-narrow-minded-in-emacs/

However, I remember hearing about a command line solution to the same problem. The idea was that there is a way to tell "hledger add" to use the transaction history from one file, even though you are entering a transaction in a different file. If there is such an animal, could somebody post it here for future reference?

Thank you.

Hail, fellow C-c C-f user! I too use this emacs ledger-mode shortcut fairly often for quickly showing journal entries containing some text or regexp.

The nearest command line equivalent is hledger print SOMEQUERY, and sometimes I do this instead. (I also use hledger acc SOMETEXT to recall account names.)

An advantage of C-c C-f is that the query is simpler, just a text/regexp that searches the whole journal entry. With a hledger query you have to think about description vs account name vs commodity symbol vs tag names vs tag values..

A big sharp edge of C-c C-f is you have to be careful not to edit at the boundary (end ?) of any focussed entry, or it will quietly eat whole swathes of the hidden text, which you may or may not notice when you unfocus again. In that case you'd better be using version control, or use emacs undo relatively soon, to recover.

Re hledger add, you can also mention the previous year's file to get more completions; just make sure the current file is first in the command line, so that add will write to that one:

hledger add -f 2024.journal -f 2023.journal ...

And that explains how, a couple of years ago, it probably happened that some hledger data files ended up with large portions missing. Thankfully, I had backups.