Skip to content

Commit

Permalink
sort-completion-by-posts-desc
Browse files Browse the repository at this point in the history
commit ad4064c
Author: Aaron L. Zeng <me@bcc32.com>
Date:   Sun Mar 17 14:46:26 2024 -0400

    ledger-accounts-list: Sort by number of postings, descending
  • Loading branch information
bcc32 committed Jul 9, 2024
1 parent 17983be commit 6fd980a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ledger-complete.el
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Then one of the elements this function returns will be
data)
(push (cons d nil) data))))
(push (cons account data) account-list)
(puthash account t seen)))
(puthash account 0 seen)))
;; Next, gather all accounts declared in postings
(unless
;; FIXME: People who have set `ledger-flymake-be-pedantic' to non-nil
Expand All @@ -146,9 +146,11 @@ Then one of the elements this function returns will be
(while (re-search-forward ledger-account-any-status-regex end t)
(let ((account (match-string-no-properties 1)))
(unless (gethash account seen)
(puthash account t seen)
(push (cons account nil) account-list))))))))
(sort account-list (lambda (a b) (string-lessp (car a) (car b)))))))
(push (cons account nil) account-list))
(cl-incf (gethash account seen 0))))))))
(sort account-list
(lambda (a b) (> (gethash (car a) seen)
(gethash (car b) seen)))))))

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

0 comments on commit 6fd980a

Please sign in to comment.