diff options
| -rw-r--r-- | README.org | 13 | ||||
| -rw-r--r-- | cape.el | 11 |
2 files changed, 24 insertions, 0 deletions
@@ -212,6 +212,19 @@ achieve a similarly refreshing strategy. (list (cape-capf-buster #'some-caching-capf))) #+end_src +** completing-read adapter + +/Wrap your completion command in a Cape and turn it into a Capf!/ + +Sometimes it is useful to reuse existing completion commands, which call +~completing-read~ to generate candidates for completion at point. One such example +is the command ~consult-history~. + +#+begin_src emacs-lisp + (defalias 'eshell-buffer-name-capf (cape-interactive-capf (cape-completing-read-to-capf #'consult-history))) +#+end_src + + ** Other Capf transformers - ~cape-interactive-capf~: Create a Capf which can be called interactively. @@ -950,6 +950,17 @@ This feature is experimental." (or (car (member x candidates)) x))))))))) ;;;###autoload +(defun cape-completing-read-to-capf (command) + "Convert a completion COMMAND to a Capf." + (lambda () + (catch 'cape--result + (cl-letf (((symbol-function #'completing-read) + (lambda (_prompt table &rest _) + (throw 'cape--result (list (point) (point) table :exclusive 'no))))) + (call-interactively command)) + nil))) + +;;;###autoload (defun cape-interactive-capf (capf) "Create interactive completion function from CAPF." (lambda (&optional interactive) |
