From 9c3535823a8e9ba60a886f7f75532245da993c70 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Wed, 23 Apr 2014 17:07:23 +0100 Subject: improve C-c C-a (ledger-xact-insert-transaction) behaviour When the right place to add a transaction is after all existing transactions, add it just after the last transaction rather than at the end of the buffer. (Otherwise the transactions get added after Local Variables blocks and any other endmatter.) --- lisp/ledger-xact.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lisp') diff --git a/lisp/ledger-xact.el b/lisp/ledger-xact.el index 35b0d62c..4eb88749 100644 --- a/lisp/ledger-xact.el +++ b/lisp/ledger-xact.el @@ -89,12 +89,20 @@ within the transaction." (defun ledger-xact-find-slot (moment) "Find the right place in the buffer for a transaction at MOMENT. MOMENT is an encoded date" - (catch 'found - (ledger-xact-iterate-transactions - (function - (lambda (start date mark desc) - (if (ledger-time-less-p moment date) - (throw 'found t))))))) + (let (last-xact-start) + (catch 'found + (ledger-xact-iterate-transactions + (function + (lambda (start date mark desc) + (setq last-xact-start start) + (if (ledger-time-less-p moment date) + (throw 'found t)))))) + (when (and (eobp) last-xact-start) + (let ((end (cadr (ledger-find-xact-extents last-xact-start)))) + (goto-char end) + (if (eobp) + (insert "\n") + (forward-line)))))) (defun ledger-xact-iterate-transactions (callback) "Iterate through each transaction call CALLBACK for each." -- cgit v1.2.3 From ad4eac43a99af8f6d88efefd8921fb71d7626de0 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Wed, 23 Apr 2014 17:04:19 +0100 Subject: add "year" handling to ledger-iterate-regex --- lisp/ledger-regex.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index 8d838892..3b43172d 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -325,7 +325,7 @@ (note end-note)) (defconst ledger-iterate-regex - (concat "\\(Y\\s-+\\([0-9]+\\)\\|" ;; Catches a Y directive + (concat "\\(\\(?:Y\\|year\\)\\s-+\\([0-9]+\\)\\|" ;; Catches a Y/year directive ledger-iso-date-regexp "\\([ *!]+\\)" ;; mark "\\((.*)\\)?" ;; code -- cgit v1.2.3 From e2d3e02b0d998a74b76f02f0f8e1fa3d5cd2df5e Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Wed, 23 Apr 2014 17:43:43 +0100 Subject: fix ledger-iso-date-regex, abusing its name slightly the year field in dates is sort-of optional, given "year" or "Y" directives. Make the date regex understand this. (This has been lightly tested with C-c C-a, but the rest of the uses of ledger-iso-date-regex have only been eyeballed, not properly audited or tested) --- lisp/ledger-regex.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index 3b43172d..91344523 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -178,8 +178,8 @@ (ledger-define-regexp iso-date ( let ((sep '(or ?- ?/))) (rx (group - (and (group (? (= 4 num))) - (eval sep) + (and (? (and (group (= 4 num))) + (eval sep)) (group (and num (? num))) (eval sep) (group (and num (? num))))))) -- cgit v1.2.3