summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Branham <alex.branham@gmail.com>2019-08-03 16:00:02 -0500
committerAlex Branham <alex.branham@gmail.com>2019-09-01 09:38:59 -0500
commit896515d2237751d7070e7ac7fad7327c2809516b (patch)
treeaad34c0acd3c2dc3890705422edd5c3973d80057
parent0114525803860b18a34624339825219bb6b8943e (diff)
New commands ledger-navigate-{next/previous}-uncleared
bug#190
-rw-r--r--ledger-navigate.el20
-rw-r--r--test/navigate-test.el28
2 files changed, 48 insertions, 0 deletions
diff --git a/ledger-navigate.el b/ledger-navigate.el
index a96f4b5..811662c 100644
--- a/ledger-navigate.el
+++ b/ledger-navigate.el
@@ -173,6 +173,26 @@ Requires empty line separating xacts."
(ledger-navigate-find-xact-extents pos)
(ledger-navigate-find-directive-extents pos))))
+(defun ledger-navigate-next-uncleared ()
+ "Move point to the next uncleared transaction."
+ (interactive)
+ (when (looking-at ledger-payee-uncleared-regex)
+ (forward-line))
+ (if (re-search-forward ledger-payee-uncleared-regex nil t)
+ (progn (beginning-of-line)
+ (point))
+ (user-error "No next uncleared transactions")))
+
+(defun ledger-navigate-previous-uncleared ()
+ "Move point to the previous uncleared transaction."
+ (interactive)
+ (when (equal (car (ledger-context-at-point)) 'acct-transaction)
+ (ledger-navigate-beginning-of-xact))
+ (if (re-search-backward ledger-payee-uncleared-regex nil t)
+ (progn (beginning-of-line)
+ (point))
+ (user-error "No previous uncleared transactions")))
+
(provide 'ledger-navigate)
diff --git a/test/navigate-test.el b/test/navigate-test.el
index 84656b1..503dbc8 100644
--- a/test/navigate-test.el
+++ b/test/navigate-test.el
@@ -43,6 +43,34 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=441"
(ledger-navigate-prev-xact-or-directive)
(should (eq 104 (point)))))
+(ert-deftest ledger-navigate-uncleared ()
+ :tags '(navigate)
+ (with-temp-buffer
+ (insert
+ "2011/01/27 Book Store
+ Expenses:Books $20.00
+ Liabilities:MasterCard
+
+2011/04/25 * Tom's Used Cars
+ Expenses:Auto $ 5,500.00
+ Assets:Checking
+
+2011/04/27 Bookstore
+ Expenses:Books $20.00
+ Assets:Checking
+
+2011/12/01 * Sale
+ Assets:Checking $ 30.00
+ Income:Sales")
+ (ledger-mode)
+ (goto-char (point-min))
+ (ledger-navigate-next-uncleared)
+ (should (looking-at-p (regexp-quote "2011/04/27 Bookstore")))
+ (should-error (ledger-navigate-next-uncleared))
+ (ledger-navigate-previous-uncleared)
+ (should (bobp))
+ ))
+
(provide 'navigate-test)