WIP. ledger-sort-region still drops the first transaction in the region.
This commit is contained in:
parent
f853510f03
commit
5c91124955
2 changed files with 25 additions and 14 deletions
|
|
@ -82,7 +82,7 @@ customizable to ease retro-entry.")
|
||||||
(define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
|
(define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
|
||||||
(define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry)
|
(define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry)
|
||||||
(define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
|
(define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
|
||||||
(define-key map [(control ?c) (control ?s)] 'ledger-sort)
|
(define-key map [(control ?c) (control ?s)] 'ledger-sort-buffer)
|
||||||
(define-key map [(control ?c) (control ?t)] 'ledger-test-run)
|
(define-key map [(control ?c) (control ?t)] 'ledger-test-run)
|
||||||
(define-key map [tab] 'pcomplete)
|
(define-key map [tab] 'pcomplete)
|
||||||
(define-key map [(control ?i)] 'pcomplete)
|
(define-key map [(control ?i)] 'pcomplete)
|
||||||
|
|
@ -109,7 +109,7 @@ customizable to ease retro-entry.")
|
||||||
(define-key map [menu-bar ldg-menu sm] '("Set Month" . ledger-set-month))
|
(define-key map [menu-bar ldg-menu sm] '("Set Month" . ledger-set-month))
|
||||||
(define-key map [menu-bar ldg-menu sy] '("Set Year" . ledger-set-year))
|
(define-key map [menu-bar ldg-menu sy] '("Set Year" . ledger-set-year))
|
||||||
(define-key map [menu-bar ldg-menu s1] '("--"))
|
(define-key map [menu-bar ldg-menu s1] '("--"))
|
||||||
(define-key map [menu-bar ldg-menu so] '("Sort Buffer" . ledger-sort))
|
(define-key map [menu-bar ldg-menu so] '("Sort Buffer or Region" . ledger-sort-buffer))
|
||||||
(define-key map [menu-bar ldg-menu s2] '("--"))
|
(define-key map [menu-bar ldg-menu s2] '("--"))
|
||||||
(define-key map [menu-bar ldg-menu te] '("Toggle Current Posting" . ledger-toggle-current))
|
(define-key map [menu-bar ldg-menu te] '("Toggle Current Posting" . ledger-toggle-current))
|
||||||
(define-key map [menu-bar ldg-menu tt] '("Toggle Current Transaction" . ledger-toggle-current-entry))
|
(define-key map [menu-bar ldg-menu tt] '("Toggle Current Transaction" . ledger-toggle-current-entry))
|
||||||
|
|
|
||||||
|
|
@ -22,21 +22,32 @@
|
||||||
;; A sample entry sorting function, which works if entry dates are of
|
;; A sample entry sorting function, which works if entry dates are of
|
||||||
;; the form YYYY/mm/dd.
|
;; the form YYYY/mm/dd.
|
||||||
|
|
||||||
(defun ledger-sort ()
|
(defun ledger-next-record-function ()
|
||||||
(interactive)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(sort-subr
|
|
||||||
nil
|
|
||||||
(function
|
|
||||||
(lambda ()
|
|
||||||
(if (re-search-forward
|
(if (re-search-forward
|
||||||
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
|
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
|
||||||
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
|
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
|
||||||
(goto-char (match-beginning 0))
|
(goto-char (match-beginning 0))
|
||||||
(goto-char (point-max)))))
|
(goto-char (point-max))))
|
||||||
(function
|
|
||||||
(lambda ()
|
(defun ledger-end-record-function ()
|
||||||
(forward-paragraph))))))
|
(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)
|
(provide 'ldg-xact)
|
||||||
Loading…
Add table
Reference in a new issue