Skip to content

Commit 5a45b3f

Browse files
committed
sort-completion-by-posts-desc
commit ad4064c Author: Aaron L. Zeng <[email protected]> Date: Sun Mar 17 14:46:26 2024 -0400 ledger-accounts-list: Sort by number of postings, descending
1 parent d2c8d00 commit 5a45b3f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ledger-complete.el

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Then one of the elements this function returns will be
131131
data)
132132
(push (cons d nil) data))))
133133
(push (cons account data) account-list)
134-
(puthash account t seen)))
134+
(puthash account 0 seen)))
135135
;; Next, gather all accounts declared in postings
136136
(unless
137137
;; FIXME: People who have set `ledger-flymake-be-pedantic' to non-nil
@@ -146,9 +146,11 @@ Then one of the elements this function returns will be
146146
(while (re-search-forward ledger-account-any-status-regex end t)
147147
(let ((account (match-string-no-properties 1)))
148148
(unless (gethash account seen)
149-
(puthash account t seen)
150-
(push (cons account nil) account-list))))))))
151-
(sort account-list (lambda (a b) (string-lessp (car a) (car b)))))))
149+
(push (cons account nil) account-list))
150+
(cl-incf (gethash account seen 0))))))))
151+
(sort account-list
152+
(lambda (a b) (> (gethash (car a) seen)
153+
(gethash (car b) seen)))))))
152154

153155
(defun ledger-accounts-list-in-buffer ()
154156
"Return a list of all known account names in the current buffer as strings.

0 commit comments

Comments
 (0)