diff options
| author | Lars Ingebrigtsen | 2018-01-16 15:22:11 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2018-01-17 00:17:23 +0100 |
| commit | f121b5d7f3aef080d0019eb39a57de51015ceb39 (patch) | |
| tree | a349d180f4226864d2af211cc0d0766c59abfd55 | |
| parent | b02a06317b04b56d54f73a7d97568a0bc150a18b (diff) | |
| download | emacs-f121b5d7f3aef080d0019eb39a57de51015ceb39.tar.gz emacs-f121b5d7f3aef080d0019eb39a57de51015ceb39.zip | |
Introduce a variable to control ecomplete sorting
* lisp/ecomplete.el (ecomplete-sort-predicate): New variable.
(ecomplete-get-matches): Use it.
| -rw-r--r-- | doc/misc/message.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/ecomplete.el | 31 |
3 files changed, 36 insertions, 2 deletions
diff --git a/doc/misc/message.texi b/doc/misc/message.texi index ca06de38d17..0d5f85f3dc4 100644 --- a/doc/misc/message.texi +++ b/doc/misc/message.texi | |||
| @@ -1485,6 +1485,9 @@ choose one of these completions, use the @kbd{M-n} command to move | |||
| 1485 | down to the list. Use @kbd{M-n} and @kbd{M-p} to move down and up the | 1485 | down to the list. Use @kbd{M-n} and @kbd{M-p} to move down and up the |
| 1486 | list, and @kbd{RET} to choose a completion. | 1486 | list, and @kbd{RET} to choose a completion. |
| 1487 | 1487 | ||
| 1488 | The @code{ecomplete-sort-predicate} variable controls how | ||
| 1489 | @code{ecomplete} matches are sorted. | ||
| 1490 | |||
| 1488 | @node Spelling | 1491 | @node Spelling |
| 1489 | @section Spelling | 1492 | @section Spelling |
| 1490 | @cindex spelling | 1493 | @cindex spelling |
| @@ -230,6 +230,10 @@ are implemented in C using the Jansson library. | |||
| 230 | It's a simple convenience function for looking up MIME types based on | 230 | It's a simple convenience function for looking up MIME types based on |
| 231 | file name extensions. | 231 | file name extensions. |
| 232 | 232 | ||
| 233 | +++ | ||
| 234 | ** The ecomplete sorting has changed to a decay-based algorithm. This | ||
| 235 | can be controlled by the new `ecomplete-sort-predicate' variable. | ||
| 236 | |||
| 233 | 237 | ||
| 234 | * Changes in Emacs 27.1 on Non-Free Operating Systems | 238 | * Changes in Emacs 27.1 on Non-Free Operating Systems |
| 235 | 239 | ||
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 @@ | |||
| 70 | :type '(symbol :tag "Coding system") | 70 | :type '(symbol :tag "Coding system") |
| 71 | :group 'ecomplete) | 71 | :group 'ecomplete) |
| 72 | 72 | ||
| 73 | (defcustom ecomplete-sort-predicate 'ecomplete-decay | ||
| 74 | "Predicate to use when sorting matched. | ||
| 75 | The predicate is called with two parameters that represent the | ||
| 76 | completion. Each parameter is a list where the first element is | ||
| 77 | the times the completion has been used, the second is the | ||
| 78 | timestamp of the most recent usage, and the third item is the | ||
| 79 | string that was matched." | ||
| 80 | :type '(radio (function-item :tag "Sort by usage and newness" ecomplete-decay) | ||
| 81 | (function-item :tag "Sort by times used" ecomplete-usage) | ||
| 82 | (function-item :tag "Sort by newness" ecomplete-newness) | ||
| 83 | (function :tag "Other")) | ||
| 84 | :group 'ecomplete) | ||
| 85 | |||
| 73 | ;;; Internal variables. | 86 | ;;; Internal variables. |
| 74 | 87 | ||
| 75 | (defvar ecomplete-database nil) | 88 | (defvar ecomplete-database nil) |
| @@ -122,8 +135,7 @@ | |||
| 122 | (loop for (key count time text) in elems | 135 | (loop for (key count time text) in elems |
| 123 | when (string-match match text) | 136 | when (string-match match text) |
| 124 | collect (list count time text)) | 137 | collect (list count time text)) |
| 125 | (lambda (l1 l2) | 138 | ecomplete-sort-predicate))) |
| 126 | (> (car l1) (car l2)))))) | ||
| 127 | (when (> (length candidates) 10) | 139 | (when (> (length candidates) 10) |
| 128 | (setcdr (nthcdr 10 candidates) nil)) | 140 | (setcdr (nthcdr 10 candidates) nil)) |
| 129 | (unless (zerop (length candidates)) | 141 | (unless (zerop (length candidates)) |
| @@ -189,6 +201,21 @@ matches." | |||
| 189 | (forward-char 1))) | 201 | (forward-char 1))) |
| 190 | (buffer-string))) | 202 | (buffer-string))) |
| 191 | 203 | ||
| 204 | (defun ecomplete-usage (l1 l2) | ||
| 205 | (> (car l1) (car l2))) | ||
| 206 | |||
| 207 | (defun ecomplete-newness (l1 l2) | ||
| 208 | (> (cadr l1) (cadr l2))) | ||
| 209 | |||
| 210 | (defun ecomplete-decay (l1 l2) | ||
| 211 | (> (ecomplete-decay-1 l1) (ecomplete-decay-1 l2))) | ||
| 212 | |||
| 213 | (defun ecomplete-decay-1 (elem) | ||
| 214 | ;; We subtract 5% from the item for each week it hasn't been used. | ||
| 215 | (/ (car elem) | ||
| 216 | (expt 1.05 (/ (- (float-time) (cadr elem)) | ||
| 217 | (* 7 24 60 60))))) | ||
| 218 | |||
| 192 | (provide 'ecomplete) | 219 | (provide 'ecomplete) |
| 193 | 220 | ||
| 194 | ;;; ecomplete.el ends here | 221 | ;;; ecomplete.el ends here |