diff options
| author | Stefan Monnier | 2022-12-05 23:50:55 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2022-12-05 23:50:55 -0500 |
| commit | a03bc3e98c649226cffc6aeafc2d41ece297aa62 (patch) | |
| tree | f9545cf7e0702aa44c763111a745b3377e4a6fe2 | |
| parent | 18e790944e231a6aa49b09a56f149dced796e939 (diff) | |
| download | emacs-a03bc3e98c649226cffc6aeafc2d41ece297aa62.tar.gz emacs-a03bc3e98c649226cffc6aeafc2d41ece297aa62.zip | |
external-completion.el: Minor changesscratch/backend-completion
* lisp/external-completion.el (external-completion-table): Tweak docstring.
Explicitly handle `lambda`.
* lisp/progmodes/eglot.el (xref-backend-identifier-completion-table):
Rename category to `eglot-xref`.
| -rw-r--r-- | lisp/external-completion.el | 79 | ||||
| -rw-r--r-- | lisp/progmodes/eglot.el | 2 |
2 files changed, 43 insertions, 38 deletions
diff --git a/lisp/external-completion.el b/lisp/external-completion.el index 4f5595e74bc..d305d3d923c 100644 --- a/lisp/external-completion.el +++ b/lisp/external-completion.el | |||
| @@ -30,9 +30,9 @@ | |||
| 30 | ;; such as a shell utility, an inferior process, an http server. | 30 | ;; such as a shell utility, an inferior process, an http server. |
| 31 | 31 | ||
| 32 | ;; The table and external tool are fully in control of the matching of | 32 | ;; The table and external tool are fully in control of the matching of |
| 33 | ;; the pattern string to the potential candidates of completion. When | 33 | ;; the pattern string to the potential candidates of completion. |
| 34 | ;; `external' is in use, the usual styles configured by the user or | 34 | ;; When `external' is in use, the usual styles configured by the user |
| 35 | ;; other in `completion-styles' are ignored. | 35 | ;; or other in `completion-styles' are ignored. |
| 36 | ;; | 36 | ;; |
| 37 | ;; This compromise is for speed: all other styles need the full data | 37 | ;; This compromise is for speed: all other styles need the full data |
| 38 | ;; set to be available in Emacs' addressing space, which is often slow | 38 | ;; set to be available in Emacs' addressing space, which is often slow |
| @@ -50,13 +50,12 @@ | |||
| 50 | external-completion--all-completions | 50 | external-completion--all-completions |
| 51 | "Ad-hoc completion style provided by the completion table.")) | 51 | "Ad-hoc completion style provided by the completion table.")) |
| 52 | 52 | ||
| 53 | (defun external-completion-table (category lookup | 53 | (defun external-completion-table ( category lookup |
| 54 | &optional metadata | 54 | &optional metadata try-completion-function) |
| 55 | try-completion-function) | ||
| 56 | "Make completion table using the `external' completion style. | 55 | "Make completion table using the `external' completion style. |
| 57 | 56 | ||
| 58 | The completion table produced foregoes any styles normally set in | 57 | The completion table produced foregoes any styles normally set in |
| 59 | `completion-styles' and will sets up an entry for the symbol | 58 | `completion-styles' and will set up an entry for the symbol |
| 60 | CATEGORY in `completion-category-defaults', linking it to the | 59 | CATEGORY in `completion-category-defaults', linking it to the |
| 61 | special completion style `external'. | 60 | special completion style `external'. |
| 62 | 61 | ||
| @@ -65,43 +64,45 @@ tool that provides completions. This may be a shell utility, an | |||
| 65 | inferior process, an http server, etc. The external tool does | 64 | inferior process, an http server, etc. The external tool does |
| 66 | the matching, and the full set of candidates doesn't need to be | 65 | the matching, and the full set of candidates doesn't need to be |
| 67 | transferred to Emacs's address space. This often results in much | 66 | transferred to Emacs's address space. This often results in much |
| 68 | faster overall completion at the expense of the convenience of | 67 | faster overall completion at the expense of the choice of |
| 69 | offered by the rich variety of usual completion styles usually | 68 | completion styles. |
| 70 | available. | ||
| 71 | 69 | ||
| 72 | LOOKUP is a function taking a string PATTERN and a number | 70 | LOOKUP is a function taking a string PATTERN and a position POINT. |
| 73 | POINT. The function should contact the backend and return a list | 71 | The function should contact the backend and return a list |
| 74 | of strings representing the candidates matching PATTERN given | 72 | of strings representing the candidates matching PATTERN given |
| 75 | that POINT is the location of point within it. LOOKUP decides if | 73 | that POINT is the location of point within it. LOOKUP decides if |
| 76 | PATTERN is interpreted as a substring, a regular expression, or | 74 | PATTERN is interpreted as a substring, a regular expression, or |
| 77 | any other type of matching key. Strings returned by LOOKUP may | 75 | any other type of matching key. Strings returned by LOOKUP may |
| 78 | be propertized with `completions-common-part' to illustrate the | 76 | be propertized with `completions-common-part' to illustrate the |
| 79 | specific interpretationq. To maintain responsiveness in the face | 77 | specific interpretation. To maintain responsiveness in the face |
| 80 | of all but the spiffiest external tools, LOOKUP should detect | 78 | of all but the spiffiest external tools, LOOKUP should detect |
| 81 | timeouts and pending user input with `while-no-input' or | 79 | timeouts and pending user input with `while-no-input' or |
| 82 | `sit-for' (which see), cancel the request (if that is possible) | 80 | `sit-for' (which see), cancel the request (if that is possible) |
| 83 | and immediately return any non-list. | 81 | and immediately return any non-list. |
| 84 | 82 | ||
| 85 | CATEGORY is a symbol identifying the external tool. METADATA is | 83 | Calls to LOOKUP are cached. There is no option to flush the cache, |
| 86 | an alist of additional properties such as `cycle-sort-function' | 84 | so if you need to do it, create a new completion table by calling |
| 85 | `external-completion-table' again. | ||
| 86 | |||
| 87 | |||
| 88 | CATEGORY is a symbol that should identify the kind of things | ||
| 89 | being completed, so users can refer to it in `completion-category-override'. | ||
| 90 | METADATA is an alist of additional properties such as `cycle-sort-function' | ||
| 87 | to associate with CATEGORY. This means that the caller may still | 91 | to associate with CATEGORY. This means that the caller may still |
| 88 | retain control the sorting of the candidates while the tool | 92 | retain control the sorting of the candidates while the tool |
| 89 | controls the matching. | 93 | controls the matching. |
| 90 | 94 | ||
| 91 | TRY-COMPLETION-FUNCTION is if you want to get fancy. It's a | 95 | TRY-COMPLETION-FUNCTION is a function taking arguments |
| 92 | function taking a (PATTERN POINT ALL-COMPLETIONS), where PATTERN | 96 | \(PATTERN POINT ALL-COMPLETIONS), where PATTERN |
| 93 | and POINT are as described above and ALL-COMPLETIONS are all | 97 | and POINT are as described above and ALL-COMPLETIONS are all |
| 94 | candidates previously gathered by LOOKUP (don't worry, we do some | 98 | candidates previously gathered by LOOKUP. It should return |
| 95 | caching so it doesn't get called more than needed). If you know | 99 | a cons cell (NEWPATTERN . NEWPOINT) such that NEWPATTERN is |
| 96 | how the external tool is interpreting PATTERN, | 100 | as long as possible within the constraints that LOOKUP still returns |
| 97 | TRY-COMPLETION-FUNCTION may return a cons cell (NEW-PATTERN | 101 | the same set of candidates as it does for PATTERN and POINT. |
| 98 | . NEW-POINT) to partially (or fully) complete the user's | 102 | This can only be provided if you happen to know what kind of |
| 99 | completion input. For example, if the tool is completing by | 103 | completion style is used by the external tool and is only worthwhile |
| 100 | prefix, you could use `try-completion' to find the largest prefix | 104 | to provide if that completion style is fairly simple: |
| 101 | in ALL-COMPLETIONS and then return that as NEW-PATTERN. If the | 105 | if the tool is using something like \"flex\", it's probably useless." |
| 102 | tool is using something else, like \"flex\", it's probably | ||
| 103 | useless. Anyway, the default is to return simply a (PATTERN | ||
| 104 | . POINT) unaltered." | ||
| 105 | (unless (assq category completion-category-defaults) | 106 | (unless (assq category completion-category-defaults) |
| 106 | (push `(,category (styles external)) | 107 | (push `(,category (styles external)) |
| 107 | completion-category-defaults)) | 108 | completion-category-defaults)) |
| @@ -130,17 +131,19 @@ useless. Anyway, the default is to return simply a (PATTERN | |||
| 130 | `(external-completion--allc | 131 | `(external-completion--allc |
| 131 | . ,(if pred (cl-remove-if-not pred all) all)))) | 132 | . ,(if pred (cl-remove-if-not pred all) all)))) |
| 132 | (`(boundaries . ,_) nil) | 133 | (`(boundaries . ,_) nil) |
| 134 | ('lambda t) ;; `test-completion' should assume all results are valid. | ||
| 133 | (_method | 135 | (_method |
| 136 | ;; FIXME: I suspect many external backends can't make much use of | ||
| 137 | ;; POINT, in which case the call below may actually be equivalent | ||
| 138 | ;; to one that's already in cache but we will fail to reuse it | ||
| 139 | ;; just because POINT is different :-( | ||
| 134 | (let ((all (lookup-internal string (length string)))) | 140 | (let ((all (lookup-internal string (length string)))) |
| 135 | ;; This is here for two reasons: | 141 | ;; This is here for two reasons: |
| 136 | ;; | 142 | ;; |
| 137 | ;; * for when users try to work around | 143 | ;; * for when users customize `completion-category-overrides' |
| 138 | ;; `completion-category-defaults' and access this table a | 144 | ;; to access this table with a non-`external' completion style. |
| 139 | ;; non-`external' completion style. It won't work very | 145 | ;; It won't work very well for styles more complex than PCM, |
| 140 | ;; well, as this `all' here very often doesn't equate | 146 | ;; but it should work fine for prefix completion. |
| 141 | ;; "the full set" (many tools cap to sth like 100-1000 | ||
| 142 | ;; results). FIXME: I think it would be better to just | ||
| 143 | ;; error here. | ||
| 144 | ;; | 147 | ;; |
| 145 | ;; * for when `_method' above can also be `nil' or `lambda' | 148 | ;; * for when `_method' above can also be `nil' or `lambda' |
| 146 | ;; which has some semantics and use I don't fully | 149 | ;; which has some semantics and use I don't fully |
| @@ -160,10 +163,12 @@ useless. Anyway, the default is to return simply a (PATTERN | |||
| 160 | (cdr res))))) | 163 | (cdr res))))) |
| 161 | 164 | ||
| 162 | (defun external-completion--try-completion (string table pred point) | 165 | (defun external-completion--try-completion (string table pred point) |
| 163 | (external-completion--call 'external-completion--tryc string table pred point)) | 166 | (external-completion--call 'external-completion--tryc |
| 167 | string table pred point)) | ||
| 164 | 168 | ||
| 165 | (defun external-completion--all-completions (string table pred point) | 169 | (defun external-completion--all-completions (string table pred point) |
| 166 | (external-completion--call 'external-completion--allc string table pred point)) | 170 | (external-completion--call 'external-completion--allc |
| 171 | string table pred point)) | ||
| 167 | 172 | ||
| 168 | (provide 'external-completion) | 173 | (provide 'external-completion) |
| 169 | ;;; external-completion.el ends here | 174 | ;;; external-completion.el ends here |
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 5cc769d4b03..0dc7357a436 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el | |||
| @@ -2575,7 +2575,7 @@ If BUFFER, switch to it before." | |||
| 2575 | 0 'eglot--lsp-workspaceSymbol c) | 2575 | 0 'eglot--lsp-workspaceSymbol c) |
| 2576 | :score 0))) | 2576 | :score 0))) |
| 2577 | (external-completion-table | 2577 | (external-completion-table |
| 2578 | 'eglot-indirection-joy | 2578 | 'eglot-xref |
| 2579 | #'lookup | 2579 | #'lookup |
| 2580 | `((cycle-sort-function | 2580 | `((cycle-sort-function |
| 2581 | . ,(lambda (completions) | 2581 | . ,(lambda (completions) |