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
|
(interactive "r") ;; load beg and end from point and mark
|
||||||
;; automagically
|
;; automagically
|
||||||
(let ((new-beg beg)
|
(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)
|
(setq inhibit-modification-hooks t)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(save-restriction
|
(save-restriction
|
||||||
|
|
@ -93,14 +99,21 @@
|
||||||
'ledger-next-record-function
|
'ledger-next-record-function
|
||||||
'ledger-end-record-function
|
'ledger-end-record-function
|
||||||
'ledger-sort-startkey))))
|
'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)))
|
(setq inhibit-modification-hooks nil)))
|
||||||
|
|
||||||
(defun ledger-sort-buffer ()
|
(defun ledger-sort-buffer ()
|
||||||
"Sort the entire buffer."
|
"Sort the entire buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(let (sort-start
|
||||||
|
sort-end)
|
||||||
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((sort-start (ledger-sort-find-start))
|
(setq sort-start (ledger-sort-find-start)
|
||||||
(sort-end (ledger-sort-find-end)))
|
sort-end (ledger-sort-find-end)))
|
||||||
(ledger-sort-region (if sort-start
|
(ledger-sort-region (if sort-start
|
||||||
sort-start
|
sort-start
|
||||||
(point-min))
|
(point-min))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue