summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2015-10-01 18:14:55 -0700
committerCraig Earls <enderw88@gmail.com>2015-10-01 18:14:55 -0700
commitb25eb27866bfed56e252607e1a24289431f993ad (patch)
treec0d57d5808061fae0110e6737b3c96e18d102e8b /lisp
parent64426842a34f0517e43a47a404cd15c764f1c7f2 (diff)
parenta8fa013417232715151f20bbe15d0b3a96a753f2 (diff)
downloadfork-ledger-b25eb27866bfed56e252607e1a24289431f993ad.tar.gz
fork-ledger-b25eb27866bfed56e252607e1a24289431f993ad.tar.bz2
fork-ledger-b25eb27866bfed56e252607e1a24289431f993ad.zip
Merge pull request #435 from Fuco1/balance-at-point-target-commodity
Balance at point and target commodity I like it. Thanks.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-commodities.el10
-rw-r--r--lisp/ledger-mode.el13
2 files changed, 19 insertions, 4 deletions
diff --git a/lisp/ledger-commodities.el b/lisp/ledger-commodities.el
index ea6319ba..48fb78f7 100644
--- a/lisp/ledger-commodities.el
+++ b/lisp/ledger-commodities.el
@@ -33,6 +33,16 @@
:type 'string
: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)
"Split a commoditized string, STR, into two parts.
Returns a list with (value commodity)."
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index 30f25dfc..26de84fc 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -125,14 +125,19 @@
": "))
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.
-And calculate the target-delta of the account being reconciled."
- (interactive)
+And calculate the target-delta of the account being reconciled.
+
+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"))
+ (target-commodity (when arg (ledger-read-commodity-with-prompt "Target commodity: ")))
(buffer (current-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)
(buffer-substring-no-properties (point-min) (1- (point-max)))
(concat account " is empty.")))))