Last summer I landed a few patches in Emacs’s ledger-mode that make it easier to use with alternative implementations of Ledger, such as hledger. Since the competing hledger-mode garnered some attention last week on Hacker News, I thought these new features might be worth highlighting to those interested in plain-text accounting in Emacs.

Why choose ledger-mode over hledger-mode?

ledger-mode is the original major mode for the Ledger file format, first penned by current Emacs maintainer and Ledger author John Wiegley himself. It’s generally less opinionated than the newer hledger-mode and is less tied to the specifics of hledger’s command line output, but each has some nice features the other lacks.

Unfortunately, up until last summer certain commands (such as register reports) expected command line flags that hledger lacks, and so several things were broken if you tried to use hledger to run your reports instead.

To summarise the changes, you can now use hledger pretty seamlessly by adding the following somewhere in your init.el file:

;; Required to use hledger instead of ledger itself. ( setq ledger-mode-should-check-version nil ledger-report-links-in-register nil ledger-binary-path "hledger" )

If you write your own reports, you might also be interested in the new %(binary) format specifier (demo below), which will substitute in whatever you have set as the binary path. This makes it a little easier to switch back and forth, too.

Why use hledger at all?

Again, this is mostly a matter of taste, but hledger and Ledger do offer slightly different features. I’m particularly fond of hledger’s column format for periodic reports. I find it useful to compare expenses from one month to the next, and this makes it easy to do so.

For example, you could add the following to your ledger-reports :

( "monthly expenses" ( concat "%(binary) -f %(ledger-file) balance expenses" "--tree --no-total --row-total --average --monthly" ))

It should produce output like the following:

Balance changes in 2016/12/01-2017/02/28: || 2016/12 2017/01 2017/02 Total Average ===============++============================================== Expenses || $1977.97 $1713.99 $1402.97 $5094.93 $1698.31 Bills || $90.00 $90.00 $90.00 $270.00 $90.00 Internet || $35.00 $35.00 $35.00 $105.00 $35.00 Phone || $55.00 $55.00 $55.00 $165.00 $55.00 Cash || $41.00 $27.50 $60.00 $128.50 $42.83 Food || $549.21 $679.52 $443.09 $1671.82 $557.27 Dining || $247.67 $302.31 $186.77 $736.75 $245.58 Groceries || $301.54 $377.21 $256.32 $935.07 $311.69 FunTimes || $177.76 $210.21 $145.56 $533.53 $177.84 Misc || $500.00 $86.76 $44.32 $631.08 $210.36 Books || 0 $34.99 0 $34.99 $11.66 Car || 0 $51.77 $44.32 $96.09 $32.03 Gifts || $340.00 0 0 $340.00 $113.33 Travel || $160.00 0 0 $160.00 $53.33 Rent || $500.00 $500.00 $500.00 $1500.00 $500.00 Transit || $120.00 $120.00 $120.00 $360.00 $120.00

(No, this is not my real data.)