diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2018-01-16 15:22:11 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2018-01-17 00:17:23 +0100 |
commit | f121b5d7f3aef080d0019eb39a57de51015ceb39 (patch) | |
tree | a349d180f4226864d2af211cc0d0766c59abfd55 /lisp/ecomplete.el | |
parent | b02a06317b04b56d54f73a7d97568a0bc150a18b (diff) | |
download | emacs-f121b5d7f3aef080d0019eb39a57de51015ceb39.tar.gz |
Introduce a variable to control ecomplete sorting
* lisp/ecomplete.el (ecomplete-sort-predicate): New variable.
(ecomplete-get-matches): Use it.
Diffstat (limited to 'lisp/ecomplete.el')
-rw-r--r-- | lisp/ecomplete.el | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index 43ab8e691e6..2197d9512de 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el @@ -70,6 +70,19 @@ :type '(symbol :tag "Coding system") :group 'ecomplete) +(defcustom ecomplete-sort-predicate 'ecomplete-decay + "Predicate to use when sorting matched. +The predicate is called with two parameters that represent the +completion. Each parameter is a list where the first element is +the times the completion has been used, the second is the +timestamp of the most recent usage, and the third item is the +string that was matched." + :type '(radio (function-item :tag "Sort by usage and newness" ecomplete-decay) + (function-item :tag "Sort by times used" ecomplete-usage) + (function-item :tag "Sort by newness" ecomplete-newness) + (function :tag "Other")) + :group 'ecomplete) + ;;; Internal variables. (defvar ecomplete-database nil) @@ -122,8 +135,7 @@ (loop for (key count time text) in elems when (string-match match text) collect (list count time text)) - (lambda (l1 l2) - (> (car l1) (car l2)))))) + ecomplete-sort-predicate))) (when (> (length candidates) 10) (setcdr (nthcdr 10 candidates) nil)) (unless (zerop (length candidates)) @@ -189,6 +201,21 @@ matches." (forward-char 1))) (buffer-string))) +(defun ecomplete-usage (l1 l2) + (> (car l1) (car l2))) + +(defun ecomplete-newness (l1 l2) + (> (cadr l1) (cadr l2))) + +(defun ecomplete-decay (l1 l2) + (> (ecomplete-decay-1 l1) (ecomplete-decay-1 l2))) + +(defun ecomplete-decay-1 (elem) + ;; We subtract 5% from the item for each week it hasn't been used. + (/ (car elem) + (expt 1.05 (/ (- (float-time) (cadr elem)) + (* 7 24 60 60))))) + (provide 'ecomplete) ;;; ecomplete.el ends here |