summaryrefslogtreecommitdiff
path: root/lisp/ldg-xact.el
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-01-31 15:13:00 -0700
committerCraig Earls <enderw88@gmail.com>2013-01-31 15:13:00 -0700
commit5c91124955b2c570b071dc81ac971f9c75b406cf (patch)
treec9105e5ead79abfbbf109ceeefe8db9a689544ca /lisp/ldg-xact.el
parentf853510f0370641015eef6cf6da6cd13569e4ef7 (diff)
downloadledger-5c91124955b2c570b071dc81ac971f9c75b406cf.tar.gz
ledger-5c91124955b2c570b071dc81ac971f9c75b406cf.tar.bz2
ledger-5c91124955b2c570b071dc81ac971f9c75b406cf.zip
WIP. ledger-sort-region still drops the first transaction in the region.
Diffstat (limited to 'lisp/ldg-xact.el')
-rw-r--r--lisp/ldg-xact.el35
1 files changed, 23 insertions, 12 deletions
diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el
index 11e6fbaf..8907f58e 100644
--- a/lisp/ldg-xact.el
+++ b/lisp/ldg-xact.el
@@ -22,21 +22,32 @@
;; A sample entry sorting function, which works if entry dates are of
;; the form YYYY/mm/dd.
-(defun ledger-sort ()
- (interactive)
- (save-excursion
- (goto-char (point-min))
- (sort-subr
- nil
- (function
- (lambda ()
+(defun ledger-next-record-function ()
(if (re-search-forward
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
(goto-char (match-beginning 0))
- (goto-char (point-max)))))
- (function
- (lambda ()
- (forward-paragraph))))))
+ (goto-char (point-max))))
+
+(defun ledger-end-record-function ()
+ (forward-paragraph))
+
+(defun ledger-sort-region (beg end)
+ (interactive "r") ;load beg and end from point and mark automagically
+ (save-excursion
+ (save-restriction
+ (narrow-to-region beg end)
+ (goto-char (point-min))
+ (message "%s %s %s" beg end (point-min))
+ (let ((inhibit-field-text-motion t))
+ (sort-subr
+ nil
+ 'ledger-next-record-function
+ 'ledger-end-record-function)))))
+
+(defun ledger-sort-buffer ()
+ (interactive)
+ (ledger-sort-region (point-min) (point-max)))
+
(provide 'ldg-xact) \ No newline at end of file