From fb09516dfd73809297e77bafc8a5595d4129e6ac Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Tue, 17 May 2022 11:04:53 +0200 Subject: [PATCH] Sort dates without leading 0 naturally E.g. sort 2022/5/7 as expected. Previously one had to write 2022/05/07 to do the sorting reliably. Note the zeros! --- ledger-sort.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ledger-sort.el b/ledger-sort.el index 721b72c8..e27eb7c4 100644 --- a/ledger-sort.el +++ b/ledger-sort.el @@ -27,6 +27,7 @@ ;;; Code: (require 'ledger-regex) (require 'ledger-navigate) +(require 'ledger-xact) (defun ledger-sort-find-start () "Find the beginning of a sort region." @@ -59,8 +60,12 @@ (insert "\n; Ledger-mode: End sort\n\n")) (defun ledger-sort-startkey () - "Return the date portion of the current line, for use in sorting." - (buffer-substring-no-properties (point) (+ 10 (point)))) + "Return a numeric sort key based on the date of the xact beginning at point." + ;; Can use `time-convert' to return an integer instead of a floating-point + ;; number, starting in Emacs 27. + (float-time + (ledger-parse-iso-date + (buffer-substring-no-properties (point) (+ 10 (point)))))) (defun ledger-sort-region (beg end) "Sort the region from BEG to END in chronological order."