Sort buffer now attempts to keep point at the same xact.

This commit is contained in:
Craig Earls 2013-04-18 18:30:27 -07:00
parent 769a73c33b
commit 1761e6a447

View file

@ -71,7 +71,13 @@
(interactive "r") ;; load beg and end from point and mark
;; automagically
(let ((new-beg beg)
(new-end end))
(new-end end)
point-delta
(bounds (ledger-find-xact-extents (point)))
target-xact)
(setq point-delta (- (point) (car bounds)))
(setq target-xact (buffer-substring (car bounds) (cadr bounds)))
(setq inhibit-modification-hooks t)
(save-excursion
(save-restriction
@ -93,14 +99,21 @@
'ledger-next-record-function
'ledger-end-record-function
'ledger-sort-startkey))))
(goto-char beg)
(re-search-forward (regexp-quote target-xact))
(goto-char (+ (match-beginning 0) point-delta))
(setq inhibit-modification-hooks nil)))
(defun ledger-sort-buffer ()
"Sort the entire buffer."
(interactive)
(let (sort-start
sort-end)
(save-excursion
(goto-char (point-min))
(let ((sort-start (ledger-sort-find-start))
(sort-end (ledger-sort-find-end)))
(setq sort-start (ledger-sort-find-start)
sort-end (ledger-sort-find-end)))
(ledger-sort-region (if sort-start
sort-start
(point-min))