diff options
| author | Stefan Monnier | 2018-01-23 12:14:48 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2018-01-23 12:14:48 -0500 |
| commit | f2918640bf35d6bb0130f854b2ea8ed4b4fd89d4 (patch) | |
| tree | 7e3cccebbefe0c919536b43f0d8d600c0bec1ab0 | |
| parent | 6d836771da7e9a6a67fcd18e52dd16de1cdc154e (diff) | |
| download | emacs-f2918640bf35d6bb0130f854b2ea8ed4b4fd89d4.tar.gz emacs-f2918640bf35d6bb0130f854b2ea8ed4b4fd89d4.zip | |
* lisp/ecomplete.el: Add completion-table; use lexical-binding and cl-lib
Also remove redundant :group args.
(ecomplete-database-file): Use locate-user-emacs-file.
(ecomplete-completion-table): New completion table.
(completion-category-defaults): Set default behavior for that table.
| -rw-r--r-- | etc/NEWS | 10 | ||||
| -rw-r--r-- | lisp/ecomplete.el | 64 |
2 files changed, 49 insertions, 25 deletions
| @@ -94,6 +94,13 @@ non-text modes. | |||
| 94 | 94 | ||
| 95 | * Changes in Specialized Modes and Packages in Emacs 27.1 | 95 | * Changes in Specialized Modes and Packages in Emacs 27.1 |
| 96 | 96 | ||
| 97 | ** Ecomplete | ||
| 98 | *** The ecomplete sorting has changed to a decay-based algorithm. | ||
| 99 | This can be controlled by the new `ecomplete-sort-predicate' variable. | ||
| 100 | |||
| 101 | *** The 'ecompleterc' file is now placed in ~/.emacs.d/ecompleterc by default | ||
| 102 | Of course it will still find it if you have it in ~/.ecompleterc | ||
| 103 | |||
| 97 | ** Smtpmail | 104 | ** Smtpmail |
| 98 | Authentication mechanisms can be added via external packages, by | 105 | Authentication mechanisms can be added via external packages, by |
| 99 | defining new cl-defmethod of smtpmail-try-auth-method. | 106 | defining new cl-defmethod of smtpmail-try-auth-method. |
| @@ -237,9 +244,6 @@ It's a simple convenience function for looking up MIME types based on | |||
| 237 | file name extensions. | 244 | file name extensions. |
| 238 | 245 | ||
| 239 | +++ | 246 | +++ |
| 240 | ** The ecomplete sorting has changed to a decay-based algorithm. This | ||
| 241 | can be controlled by the new `ecomplete-sort-predicate' variable. | ||
| 242 | |||
| 243 | ** The new function 'read-answer' accepts either long or short answers | 247 | ** The new function 'read-answer' accepts either long or short answers |
| 244 | depending on the new customizable variable 'read-answer-short'. | 248 | depending on the new customizable variable 'read-answer-short'. |
| 245 | 249 | ||
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index 3f0d21c2305..3bfab4743cb 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; ecomplete.el --- electric completion of addresses and the like | 1 | ;;; ecomplete.el --- electric completion of addresses and the like -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2006-2018 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2006-2018 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -53,22 +53,20 @@ | |||
| 53 | 53 | ||
| 54 | ;;; Code: | 54 | ;;; Code: |
| 55 | 55 | ||
| 56 | (eval-when-compile | 56 | (eval-when-compile (require 'cl-lib)) |
| 57 | (require 'cl)) | ||
| 58 | 57 | ||
| 59 | (defgroup ecomplete nil | 58 | (defgroup ecomplete nil |
| 60 | "Electric completion of email addresses and the like." | 59 | "Electric completion of email addresses and the like." |
| 61 | :group 'mail) | 60 | :group 'mail) |
| 62 | 61 | ||
| 63 | (defcustom ecomplete-database-file "~/.ecompleterc" | 62 | (defcustom ecomplete-database-file |
| 63 | (locate-user-emacs-file "ecompleterc" "~/.ecompleterc") | ||
| 64 | "The name of the file to store the ecomplete data." | 64 | "The name of the file to store the ecomplete data." |
| 65 | :group 'ecomplete | ||
| 66 | :type 'file) | 65 | :type 'file) |
| 67 | 66 | ||
| 68 | (defcustom ecomplete-database-file-coding-system 'iso-2022-7bit | 67 | (defcustom ecomplete-database-file-coding-system 'iso-2022-7bit |
| 69 | "Coding system used for writing the ecomplete database file." | 68 | "Coding system used for writing the ecomplete database file." |
| 70 | :type '(symbol :tag "Coding system") | 69 | :type '(symbol :tag "Coding system")) |
| 71 | :group 'ecomplete) | ||
| 72 | 70 | ||
| 73 | (defcustom ecomplete-sort-predicate 'ecomplete-decay | 71 | (defcustom ecomplete-sort-predicate 'ecomplete-decay |
| 74 | "Predicate to use when sorting matched. | 72 | "Predicate to use when sorting matched. |
| @@ -80,8 +78,7 @@ string that was matched." | |||
| 80 | :type '(radio (function-item :tag "Sort by usage and newness" ecomplete-decay) | 78 | :type '(radio (function-item :tag "Sort by usage and newness" ecomplete-decay) |
| 81 | (function-item :tag "Sort by times used" ecomplete-usage) | 79 | (function-item :tag "Sort by times used" ecomplete-usage) |
| 82 | (function-item :tag "Sort by newness" ecomplete-newness) | 80 | (function-item :tag "Sort by newness" ecomplete-newness) |
| 83 | (function :tag "Other")) | 81 | (function :tag "Other"))) |
| 84 | :group 'ecomplete) | ||
| 85 | 82 | ||
| 86 | ;;; Internal variables. | 83 | ;;; Internal variables. |
| 87 | 84 | ||
| @@ -116,13 +113,13 @@ string that was matched." | |||
| 116 | (with-temp-buffer | 113 | (with-temp-buffer |
| 117 | (let ((coding-system-for-write ecomplete-database-file-coding-system)) | 114 | (let ((coding-system-for-write ecomplete-database-file-coding-system)) |
| 118 | (insert "(") | 115 | (insert "(") |
| 119 | (loop for (type . elems) in ecomplete-database | 116 | (cl-loop for (type . elems) in ecomplete-database |
| 120 | do | 117 | do |
| 121 | (insert (format "(%s\n" type)) | 118 | (insert (format "(%s\n" type)) |
| 122 | (dolist (entry elems) | 119 | (dolist (entry elems) |
| 123 | (prin1 entry (current-buffer)) | 120 | (prin1 entry (current-buffer)) |
| 124 | (insert "\n")) | 121 | (insert "\n")) |
| 125 | (insert ")\n")) | 122 | (insert ")\n")) |
| 126 | (insert ")") | 123 | (insert ")") |
| 127 | (write-region (point-min) (point-max) | 124 | (write-region (point-min) (point-max) |
| 128 | ecomplete-database-file nil 'silent)))) | 125 | ecomplete-database-file nil 'silent)))) |
| @@ -132,9 +129,9 @@ string that was matched." | |||
| 132 | (match (regexp-quote match)) | 129 | (match (regexp-quote match)) |
| 133 | (candidates | 130 | (candidates |
| 134 | (sort | 131 | (sort |
| 135 | (loop for (key count time text) in elems | 132 | (cl-loop for (_key count time text) in elems |
| 136 | when (string-match match text) | 133 | when (string-match match text) |
| 137 | collect (list count time text)) | 134 | collect (list count time text)) |
| 138 | ecomplete-sort-predicate))) | 135 | ecomplete-sort-predicate))) |
| 139 | (when (> (length candidates) 10) | 136 | (when (> (length candidates) 10) |
| 140 | (setcdr (nthcdr 10 candidates) nil)) | 137 | (setcdr (nthcdr 10 candidates) nil)) |
| @@ -183,9 +180,7 @@ matches." | |||
| 183 | (lookup-key local-map command)) | 180 | (lookup-key local-map command)) |
| 184 | (apply (key-binding command) nil) | 181 | (apply (key-binding command) nil) |
| 185 | (setq highlight (ecomplete-highlight-match-line matches line)))) | 182 | (setq highlight (ecomplete-highlight-match-line matches line)))) |
| 186 | (if selected | 183 | (message (or selected "Abort")) |
| 187 | (message selected) | ||
| 188 | (message "Abort")) | ||
| 189 | selected))))) | 184 | selected))))) |
| 190 | 185 | ||
| 191 | (defun ecomplete-highlight-match-line (matches line) | 186 | (defun ecomplete-highlight-match-line (matches line) |
| @@ -218,6 +213,31 @@ matches." | |||
| 218 | (expt 1.05 (/ (- (float-time) (cadr elem)) | 213 | (expt 1.05 (/ (- (float-time) (cadr elem)) |
| 219 | (* 7 24 60 60))))) | 214 | (* 7 24 60 60))))) |
| 220 | 215 | ||
| 216 | ;; `ecomplete-get-matches' uses substring matching, so also use the `substring' | ||
| 217 | ;; style by default. | ||
| 218 | (add-to-list 'completion-category-defaults | ||
| 219 | '(ecomplete (styles basic substring))) | ||
| 220 | |||
| 221 | (defun ecomplete-completion-table (type) | ||
| 222 | "Return a completion-table suitable for TYPE." | ||
| 223 | (lambda (string pred action) | ||
| 224 | (pcase action | ||
| 225 | (`(boundaries . ,_) nil) | ||
| 226 | ('metadata `(metadata (category . ecomplete) | ||
| 227 | (display-sort-function . ,#'identity) | ||
| 228 | (cycle-sort-function . ,#'identity))) | ||
| 229 | (_ | ||
| 230 | (let* ((elems (cdr (assq type ecomplete-database))) | ||
| 231 | (candidates | ||
| 232 | (mapcar (lambda (x) (nth 2 x)) | ||
| 233 | (sort | ||
| 234 | (cl-loop for x in elems | ||
| 235 | when (string-prefix-p string (nth 3 x) | ||
| 236 | completion-ignore-case) | ||
| 237 | collect (cdr x)) | ||
| 238 | ecomplete-sort-predicate)))) | ||
| 239 | (complete-with-action action candidates string pred)))))) | ||
| 240 | |||
| 221 | (provide 'ecomplete) | 241 | (provide 'ecomplete) |
| 222 | 242 | ||
| 223 | ;;; ecomplete.el ends here | 243 | ;;; ecomplete.el ends here |