diff options
| author | Eshel Yaron | 2024-04-11 19:16:26 +0200 |
|---|---|---|
| committer | Eshel Yaron | 2024-04-12 10:20:25 +0200 |
| commit | 4ff852a5582be8d0ba16e598371ce359ba3d3cc6 (patch) | |
| tree | e0d4d1b0dd91315665f79ed9a80a61b87004d2e5 | |
| parent | a69890eea946beb0858273a20d260a170485b79a (diff) | |
| download | emacs-4ff852a5582be8d0ba16e598371ce359ba3d3cc6.tar.gz emacs-4ff852a5582be8d0ba16e598371ce359ba3d3cc6.zip | |
; Optimize 'completion-preview--try-table'
* lisp/completion-preview.el (completion-preview-completion-styles):
New variable. Default to only include the 'basic' completion style.
(completion-preview--try-table): Let-bind 'completion-styles' when
calling 'completion-all-completions'. With the default value of
'completion-preview-completion-styles', this yields a significant
performance improvement (up to 4 times faster compared to the
'substring' style when tested with 'elisp-completion-at-point').
Suggested by Ergus <spacibba@aol.com>
| -rw-r--r-- | lisp/completion-preview.el | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index 0bdc13bb8a5..4e52aa9b151 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el | |||
| @@ -206,6 +206,15 @@ Completion Preview mode adds this function to | |||
| 206 | #'completion-preview--window-selection-change t) | 206 | #'completion-preview--window-selection-change t) |
| 207 | (completion-preview-hide))) | 207 | (completion-preview-hide))) |
| 208 | 208 | ||
| 209 | (defvar completion-preview-completion-styles '(basic) | ||
| 210 | "List of completion styles that Completion Preview mode uses. | ||
| 211 | |||
| 212 | Since Completion Preview mode shows prefix completion candidates, this | ||
| 213 | list should normally only include completion styles that perform prefix | ||
| 214 | completion, but other candidates are filtered out and cause no harm. | ||
| 215 | |||
| 216 | See also `completion-styles'.") | ||
| 217 | |||
| 209 | (defun completion-preview--try-table (table beg end props) | 218 | (defun completion-preview--try-table (table beg end props) |
| 210 | "Check TABLE for a completion matching the text between BEG and END. | 219 | "Check TABLE for a completion matching the text between BEG and END. |
| 211 | 220 | ||
| @@ -228,7 +237,11 @@ non-nil, return nil instead." | |||
| 228 | (sort-fn (or (completion-metadata-get md 'cycle-sort-function) | 237 | (sort-fn (or (completion-metadata-get md 'cycle-sort-function) |
| 229 | (completion-metadata-get md 'display-sort-function) | 238 | (completion-metadata-get md 'display-sort-function) |
| 230 | completion-preview-sort-function)) | 239 | completion-preview-sort-function)) |
| 231 | (all (let ((completion-lazy-hilit t)) | 240 | (all (let ((completion-lazy-hilit t) |
| 241 | ;; FIXME: This does not override styles prescribed | ||
| 242 | ;; by the completion category via | ||
| 243 | ;; e.g. `completion-category-defaults'. | ||
| 244 | (completion-styles completion-preview-completion-styles)) | ||
| 232 | (completion-all-completions string table pred | 245 | (completion-all-completions string table pred |
| 233 | (- (point) beg) md))) | 246 | (- (point) beg) md))) |
| 234 | (last (last all)) | 247 | (last (last all)) |