Merge pull request #435 from Fuco1/balance-at-point-target-commodity
Balance at point and target commodity I like it. Thanks.
This commit is contained in:
commit
b25eb27866
2 changed files with 19 additions and 4 deletions
|
|
@ -33,6 +33,16 @@
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'ledger-reconcile)
|
:group 'ledger-reconcile)
|
||||||
|
|
||||||
|
(defun ledger-read-commodity-with-prompt (prompt)
|
||||||
|
"Read commodity name after PROMPT.
|
||||||
|
|
||||||
|
Default value is `ledger-reconcile-default-commodity'."
|
||||||
|
(let* ((buffer (current-buffer))
|
||||||
|
(commodities (with-temp-buffer
|
||||||
|
(ledger-exec-ledger buffer (current-buffer) "commodities")
|
||||||
|
(split-string (buffer-string) "\n" t))))
|
||||||
|
(completing-read prompt commodities nil t nil nil ledger-reconcile-default-commodity)))
|
||||||
|
|
||||||
(defun ledger-split-commodity-string (str)
|
(defun ledger-split-commodity-string (str)
|
||||||
"Split a commoditized string, STR, into two parts.
|
"Split a commoditized string, STR, into two parts.
|
||||||
Returns a list with (value commodity)."
|
Returns a list with (value commodity)."
|
||||||
|
|
|
||||||
|
|
@ -125,14 +125,19 @@
|
||||||
": "))
|
": "))
|
||||||
nil 'ledger-minibuffer-history default))
|
nil 'ledger-minibuffer-history default))
|
||||||
|
|
||||||
(defun ledger-display-balance-at-point ()
|
(defun ledger-display-balance-at-point (&optional arg)
|
||||||
"Display the cleared-or-pending balance.
|
"Display the cleared-or-pending balance.
|
||||||
And calculate the target-delta of the account being reconciled."
|
And calculate the target-delta of the account being reconciled.
|
||||||
(interactive)
|
|
||||||
|
With prefix argument \\[universal-argument] ask for the target commodity and convert
|
||||||
|
the balance into that."
|
||||||
|
(interactive "P")
|
||||||
(let* ((account (ledger-read-account-with-prompt "Account balance to show"))
|
(let* ((account (ledger-read-account-with-prompt "Account balance to show"))
|
||||||
|
(target-commodity (when arg (ledger-read-commodity-with-prompt "Target commodity: ")))
|
||||||
(buffer (current-buffer))
|
(buffer (current-buffer))
|
||||||
(balance (with-temp-buffer
|
(balance (with-temp-buffer
|
||||||
(ledger-exec-ledger buffer (current-buffer) "cleared" account)
|
(apply 'ledger-exec-ledger buffer (current-buffer) "cleared" account
|
||||||
|
(when target-commodity (list "-X" target-commodity)))
|
||||||
(if (> (buffer-size) 0)
|
(if (> (buffer-size) 0)
|
||||||
(buffer-substring-no-properties (point-min) (1- (point-max)))
|
(buffer-substring-no-properties (point-min) (1- (point-max)))
|
||||||
(concat account " is empty.")))))
|
(concat account " is empty.")))))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue