summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-07-01 11:01:47 -0700
committerCraig Earls <enderw88@gmail.com>2013-07-01 11:01:47 -0700
commit8da79a8967872c17071e58bf94dcc41c7c453ebf (patch)
tree1d45d1b7caed79d8f2d31240a427e8fc5fa0d780 /lisp
parent52dd81ca9e64f0b3a413156f8cc1d57e2cf162c6 (diff)
downloadfork-ledger-8da79a8967872c17071e58bf94dcc41c7c453ebf.tar.gz
fork-ledger-8da79a8967872c17071e58bf94dcc41c7c453ebf.tar.bz2
fork-ledger-8da79a8967872c17071e58bf94dcc41c7c453ebf.zip
Ensure target balance is actually parseable as a number
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ldg-commodities.el33
1 files changed, 17 insertions, 16 deletions
diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el
index fdc5e802..59b26ff9 100644
--- a/lisp/ldg-commodities.el
+++ b/lisp/ldg-commodities.el
@@ -38,19 +38,19 @@
Returns a list with (value commodity)."
(let ((number-regex (if (assoc "decimal-comma" ledger-environment-alist)
ledger-amount-decimal-comma-regex
- ledger-amount-decimal-period-regex)))
- (if (> (length str) 0)
+ ledger-amount-decimal-period-regex)))
+ (if (> (length str) 0)
(with-temp-buffer
(insert str)
(goto-char (point-min))
- (cond
+ (cond
((re-search-forward "\"\\(.*\\)\"" nil t) ; look for quoted commodities
- (let ((com (delete-and-extract-region
- (match-beginning 1)
+ (let ((com (delete-and-extract-region
+ (match-beginning 1)
(match-end 1))))
- (if (re-search-forward
+ (if (re-search-forward
number-regex nil t)
- (list
+ (list
(ledger-string-to-number
(delete-and-extract-region (match-beginning 0) (match-end 0)))
com))))
@@ -113,7 +113,7 @@ Returns a list with (value commodity)."
(while (string-match "\\." str)
(setq str (replace-match "," nil nil str)))
str)))
-
+
(defun ledger-commodity-to-string (c1)
"Return string representing C1.
Single character commodities are placed ahead of the value,
@@ -126,14 +126,15 @@ longer ones are after the value."
(defun ledger-read-commodity-string (prompt)
(let ((str (read-from-minibuffer
- (concat prompt " (" ledger-reconcile-default-commodity "): ")))
- comm)
- (if (> (length str) 0)
- (progn
- (setq comm (ledger-split-commodity-string str))
- (if (cadr comm)
- comm
- (list (car comm) ledger-reconcile-default-commodity))))))
+ (concat prompt " (" ledger-reconcile-default-commodity "): ")))
+ comm)
+ (if (and (> (length str) 0)
+ (ledger-split-commodity-string str))
+ (progn
+ (setq comm (ledger-split-commodity-string str))
+ (if (cadr comm)
+ comm
+ (list (car comm) ledger-reconcile-default-commodity))))))
(provide 'ldg-commodities)