summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ledger3.texi2
-rw-r--r--lisp/ledger-commodities.el10
-rw-r--r--lisp/ledger-context.el4
-rw-r--r--lisp/ledger-mode.el13
-rw-r--r--lisp/ledger-post.el16
-rwxr-xr-xtest/RegressTests.py7
6 files changed, 41 insertions, 11 deletions
diff --git a/doc/ledger3.texi b/doc/ledger3.texi
index 5d8ab55c..6a74fa30 100644
--- a/doc/ledger3.texi
+++ b/doc/ledger3.texi
@@ -4226,7 +4226,7 @@ $ ledger balance --limit 'account=~/Fuel/' and 'payee=~/Chev/'
@noindent
will show you the amount expended on gasoline at Chevron. The second
-example is the first example of the very power expression language
+example is the first example of the very powerful expression language
available to shape reports. The first example may be easier to
remember, but learning to use the second will open up far more
possibilities.
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-context.el b/lisp/ledger-context.el
index 643ebdd3..629d51a5 100644
--- a/lisp/ledger-context.el
+++ b/lisp/ledger-context.el
@@ -34,8 +34,8 @@
(defconst ledger-indent-string "\\(^[ \t]+\\)")
(defconst ledger-status-string "\\(* \\|! \\)?")
(defconst ledger-account-string "[\\[(]?\\(.*?\\)[])]?")
-(defconst ledger-separator-string "\\s-\\s-+")
-(defconst ledger-amount-string "\\(-?[0-9]+[\\.,][0-9]*\\)")
+(defconst ledger-separator-string "\\(\\s-\\s-+\\)")
+(defconst ledger-amount-string "\\(-?[0-9]+\\(?:[\\.,][0-9]*\\)?\\)")
(defconst ledger-comment-string "[ \t]*;[ \t]*\\(.*?\\)")
(defconst ledger-nil-string "\\([ \t]\\)")
(defconst ledger-commodity-string "\\(.+?\\)")
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.")))))
diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el
index d741442a..f4727342 100644
--- a/lisp/ledger-post.el
+++ b/lisp/ledger-post.el
@@ -41,6 +41,16 @@
:type 'integer
:group 'ledger-post)
+(defcustom ledger-post-amount-alignment-at :end
+ "Position at which the amount is ailgned.
+
+Can be :end to align on the last number of the amount (can be
+followed by unaligned commodity) or :decimal to align at the
+decimal separator."
+ :type '(radio (const :tag "align at the end of amount" :end)
+ (const :tag "align at the decimal separator" :decimal))
+ :group 'ledger-post)
+
(defcustom ledger-post-use-completion-engine :built-in
"Which completion engine to use, :iswitchb or :ido chose those engines.
:built-in uses built-in Ledger-mode completion"
@@ -79,7 +89,11 @@ point at beginning of the commodity."
(when (re-search-forward ledger-amount-regex end t)
(goto-char (match-beginning 0))
(skip-syntax-forward " ")
- (- (match-end 3) (point)))))
+ (cond
+ ((eq ledger-post-amount-alignment-at :end)
+ (- (or (match-end 4) (match-end 3)) (point)))
+ ((eq ledger-post-amount-alignment-at :decimal)
+ (- (match-end 3) (point)))))))
(defun ledger-next-account (&optional end)
"Move to the beginning of the posting, or status marker, limit to END.
diff --git a/test/RegressTests.py b/test/RegressTests.py
index 0fef2127..a5bab42d 100755
--- a/test/RegressTests.py
+++ b/test/RegressTests.py
@@ -57,9 +57,6 @@ class RegressFile(object):
in_error = False
line = self.fd.readline()
- if not line:
- print >>sys.stderr, "WARNING: Empty testfile detected: %s" % (self.filename)
- return False
#print "line =", line
while line:
if line.startswith("test "):
@@ -167,6 +164,10 @@ class RegressFile(object):
harness.failure(os.path.basename(self.filename))
def run_tests(self):
+ if os.path.getsize(self.filename) == 0:
+ print >>sys.stderr, "WARNING: Empty testfile detected: %s" % (self.filename)
+ harness.failure(os.path.basename(self.filename))
+ return False
test = self.read_test()
while test:
self.run_test(test)