summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.org13
-rw-r--r--cape.el11
2 files changed, 24 insertions, 0 deletions
diff --git a/README.org b/README.org
index 5167dd8..111f5cd 100644
--- a/README.org
+++ b/README.org
@@ -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.
diff --git a/cape.el b/cape.el
index 73fde31..08b752b 100644
--- a/cape.el
+++ b/cape.el
@@ -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)