diff options
author | Craig Earls <enderw88@gmail.com> | 2013-03-24 17:20:36 -0400 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-03-24 17:20:36 -0400 |
commit | 0d0e996e072072c2b203ff9eef2690d5f8c11c4f (patch) | |
tree | a3b9b0cd04a9d4782f1ee165966834c93de7a3af | |
parent | 9079ae8a69b7fad33b4c227e95e5474e514d1453 (diff) | |
download | fork-ledger-0d0e996e072072c2b203ff9eef2690d5f8c11c4f.tar.gz fork-ledger-0d0e996e072072c2b203ff9eef2690d5f8c11c4f.tar.bz2 fork-ledger-0d0e996e072072c2b203ff9eef2690d5f8c11c4f.zip |
Improve ledger-split-commodities to handle multi character commodities.
-rw-r--r-- | lisp/ldg-commodities.el | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 0ed52fc3..7dc0a900 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -32,7 +32,7 @@ :group 'ledger-reconcile) (defun ledger-split-commodity-string (str) - "Split a commoditized amount into two parts" + "Split a commoditized amount into two parts" (if (> (length str) 0) (let (val comm number-regex) (with-temp-buffer @@ -48,18 +48,16 @@ (ledger-commodity-string-number-decimalize (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))) (goto-char (point-min)) - (re-search-forward "[^[:space:]]" nil t) - (setq comm - (delete-and-extract-region (match-beginning 0) (match-end 0))) + (setq comm (nth 0 (split-string (buffer-substring (point-min) (point-max))))) (list val comm)) ((re-search-forward "0" nil t) - ;; couldn't find a decimal number, look for a single 0, - ;; indicating account with zero balance - (list 0 ledger-reconcile-default-commodity)) - (t - (error "split-commodity-string: cannot parse commodity string: %S" str))))) + ;; couldn't find a decimal number, look for a single 0, + ;; indicating account with zero balance + (list 0 ledger-reconcile-default-commodity)) + ))) + + ;; nothing found, return 0 (list 0 ledger-reconcile-default-commodity))) - (defun ledger-string-balance-to-commoditized-amount (str) "Return a commoditized amount (val, 'comm') from STR." |