Sort buffer now attempts to keep point at the same xact.
This commit is contained in:
parent
769a73c33b
commit
1761e6a447
1 changed files with 43 additions and 30 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue