# Emacs + ledger mode solves problem

**URL:** <https://forum.plaintextaccounting.org/t/emacs-ledger-mode-solves-problem/270>\
**Category:** News\
**Tags:** emacs, editors\
**Created:** [May 17, 2024, 2:41pm UTC](https://forum.plaintextaccounting.org/t/emacs-ledger-mode-solves-problem/270 "2024-05-17T14:41:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hledgerfan](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hledgerfan](https://forum.plaintextaccounting.org/u/hledgerfan)\
**Post date:** [May 17, 2024, 2:41pm UTC](https://forum.plaintextaccounting.org/t/emacs-ledger-mode-solves-problem/270/1 "2024-05-17T14:41:04Z")

</div>

I use ledger mode in Emacs to look up a transaction from a past year:  
[https://hledgerfan.com/getting-narrow-minded-in-emacs/](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.

---

<div class="post-metadata">

**Author:** ![simonmic](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.plaintextaccounting.org/simonmic/32/1_2.png) [@simonmic](https://forum.plaintextaccounting.org/u/simonmic)\
**Post date:** [May 17, 2024, 5:56pm UTC](https://forum.plaintextaccounting.org/t/emacs-ledger-mode-solves-problem/270/2 "2024-05-17T17:56:15Z")

</div>

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 ...

```

---

<div class="post-metadata">

**Author:** ![hledgerfan](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hledgerfan](https://forum.plaintextaccounting.org/u/hledgerfan)\
**Post date:** [May 17, 2024, 8:54pm UTC](https://forum.plaintextaccounting.org/t/emacs-ledger-mode-solves-problem/270/3 "2024-05-17T20:54:39Z")

</div>

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.
