Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger-mode setup for hledger needs documenting #367

Open
simonmichael opened this Issue Jul 13, 2016 · 19 comments

Comments

Projects
None yet
4 participants
@simonmichael
Copy link
Owner

simonmichael commented Jul 13, 2016


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@taksuyu

This comment has been minimized.

Copy link

taksuyu commented Jul 13, 2016

Since I'm working on getting this working, I don't mind writing something up once I got it working reasonably well.

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jul 13, 2016

FYI:

; Simon's ledger-mode tweaks

(custom-set-variables

 ; neutralise some ledgerisms
 '(ledger-binary-path (expand-file-name "~/.local/bin/hledger"))
 '(ledger-mode-should-check-version nil)
 '(ledger-init-file-name " ")

 ; move default amount position right allowing longer account names
 '(ledger-post-amount-alignment-column 64)

 ; disable distracting highlight
 '(ledger-highlight-xact-under-point nil)

 )

; automatically show new transactions from hledger add or hledger-web
(add-hook 'ledger-mode-hook 'auto-revert-tail-mode)

; M-1 to collapse all transactions to one line, M-0 to reset. Useful for quickly scanning
(global-set-key "\M-0" (lambda () (interactive) (set-selective-display (* tab-width 0))))
(global-set-key "\M-1" (lambda () (interactive) (set-selective-display (* tab-width 1))))
(add-hook 'ledger-mode-hook (lambda () (setq tab-width 4)))

; enable some highlighting for CSV rules files
(add-to-list 'auto-mode-alist '("\\.rules$" . conf-mode))

; useful when running reports in a shell buffer
(defun highlight-negative-amounts nil (interactive)
  (highlight-regexp "\\(\\$-\\|-\\$\\)[.,0-9]+" (quote hi-red-b))
)
@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jul 13, 2016

; recognise more file suffixes
(add-to-list 'auto-mode-alist '("\\.\\(h?ledger\\|journal\\|j\\)$" . ledger-mode))

; enable orgstruct minor mode, TAB while on a * comment expands/collapses org node
; (can get slow though)
(add-hook 'ledger-mode-hook 'orgstruct-mode)

@simonmichael simonmichael modified the milestone: 0.28 Jul 17, 2016

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jul 19, 2016

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jul 19, 2016

Other editor modes like https://github.com/ledger/vim-ledger would also be nice to know about.

@taksuyu

This comment has been minimized.

Copy link

taksuyu commented Aug 11, 2016

I seem to be comfortable using this configuration. I imagine there is more to look into and fixing little things.

(setq ledger-binary-path "hledger")
(setq ledger-mode-should-check-version nil)
(add-to-list 'auto-mode-alist '("\\.\\(h?ledger\\|journal\\|j\\)$" . ledger-mode))

(defvar ledger-report-balance
  (list "bal" (concat ledger-binary-path " -f %(ledger-file) bal")))

(defvar ledger-report-reg
  (list "reg" (concat ledger-binary-path " -f %(ledger-file) reg")))

(defvar ledger-report-payee
  (list "payee" (concat ledger-binary-path " -f %(ledger-file) reg @%(payee)")))

(defvar ledger-report-account
  (list "account" (concat ledger-binary-path " -f %(ledger-file) reg %(account)")))

(setq ledger-reports
      (list ledger-report-balance
            ledger-report-reg
            ledger-report-payee
            ledger-report-account))

Having hledger specific reports may also benefit.

@simonmichael simonmichael modified the milestones: 1.0, post 1.0 Oct 31, 2016

@simonmichael simonmichael modified the milestone: 1.1 Dec 29, 2016

@arademaker

This comment has been minimized.

Copy link

arademaker commented Nov 21, 2017

The C-c C-a with hledger gives me hledger: command xact is not recognized, run with no command to see a list what did I miss?

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Nov 21, 2017

ledger-mode's C-c C-a runs ledger-add-transaction. On my setup this is somehow working, I get a Transaction: prompt in minibuffer with today's date filled in, and enter inserts the date in the journal. Not terribly useful.

On yours, I guess it assumes the ledger-binary-path program has a xact command, and expects that to produce a journal entry on stdout. xact is an alias for Ledger's entry command.

hledger doesn't have the entry/xact command, though related functionality exists in several other commands (print --match, register-match, find, add). You could possibly make a good enough version with something like this in an executable hledger-xact.sh script in $PATH:

#!/bin/sh
hledger print --match $@
@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Nov 21, 2017

PS ledger-mode 2017-09-02 24b43e34 here.

@arademaker

This comment has been minimized.

Copy link

arademaker commented Nov 21, 2017

Thanks , but I guess I will also need to redefine the command ledger-add-transaction or create a new one bound to C-c C-a right ?

@arademaker

This comment has been minimized.

Copy link

arademaker commented Aug 7, 2018

Hi @simonmichael , it took me a while to try your suggestion but it didn't work as I expected. Can you please help me? Using Ledger (prompt) I can have a new transaction with a new value given other fields automatically filled. For instance, using the xact I give a date, description (payee in my case), a new amount and the partial name of account 2. Like a magic, Ledger deduce the account 1 for me and complete the name of the account 2 also.

$ ledger -f lixo.dat xact 2018/08/10 Recanto R$\ 100 real:cc
2018/08/10 Recanto
    Expenses:Educacao:Escola:Sofia         R$ 100,00
    Assets:AR:Real:CC

If I give more info, it will also work. In the following case, housing is used to find the account Expense:Housing and real:cc to find Assets:AR:Real:CC

$ ledger -f lixo.dat xact 2018/08/10 Recanto housing R$\ 100 real:cc
2018/08/10 Recanto
    Expenses:Housing                       R$ 100,00
    Assets:AR:Real:CC

I haven't figured out how to have similar behaviour with hledger!

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Aug 16, 2018

Hi @arademaker, let's handle that question on the mail list and/or IRC channel. Perhaps you can repost there, and add all data needed for others to reproduce it and understand.

@levitanong

This comment has been minimized.

Copy link

levitanong commented Oct 28, 2018

When using ledger-report, I'm running into hledger's complaints about unsupported options --columns and --color.
Ledger mode is passing those options here:
https://github.com/ledger/ledger-mode/blob/d6a67d177bada0a5913019893dfc6015590bcb76/ledger-report.el#L438

So in order for me to use hledger's reports, I've had to:

(setq ledger-report-auto-width nil
      ledger-report-use-native-highlighting nil)
@levitanong

This comment has been minimized.

Copy link

levitanong commented Jan 27, 2019

Running into trouble with reconciliation. ledger still uses the old "uncleared" instead of "unmarked". Unsure how to modify reconcile-mode to use the new "unmarked". Any ideas?

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jan 27, 2019

-U ?

@levitanong

This comment has been minimized.

Copy link

levitanong commented Jan 28, 2019

I'm aware of -U, but I don't know where to set it in emacs. 😅 is there something like ledger-reconcile-cli-command?

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jan 28, 2019

It doesn't look like it. I think you'd have to submit a patch to ledger-mode changing --uncleared to -U (in ledger-do-reconcile).

I was thinking -U was a spelling that both tools would recognise. But, now I remember hledger's -U/--unmarked is different from ledger's -U/--uncleared. The exact match for ledger --uncleared is hledger --unmarked --pending (hledger -UP).

@simonmichael

This comment has been minimized.

Copy link
Owner Author

simonmichael commented Jan 28, 2019

PS I would be open to a PR making --uncleared a compatibility synonym for --unmarked --pending.

@levitanong

This comment has been minimized.

Copy link

levitanong commented Feb 3, 2019

Alas, I have no experience in haskell, so I won't be much help here. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.