summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-06-06 11:02:47 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2023-06-06 11:04:45 +0200
commit6c9abaf15adfbd9c6bf593609ac3bea8c8de0611 (patch)
tree58202cf5c0b54c8b9cee5b0a87c757fa1d93b0f4
parentc51acf427c75e58093ba100b5a82354779548f1b (diff)
cape-interactive: Preserve context when Capf is invoked interactively
-rw-r--r--cape.el13
1 files changed, 8 insertions, 5 deletions
diff --git a/cape.el b/cape.el
index aefb68a..9b61aec 100644
--- a/cape.el
+++ b/cape.el
@@ -308,8 +308,7 @@ See the user option `cape-file-directory-must-exist'.
If INTERACTIVE is nil the function acts like a Capf."
(interactive (list t))
(if interactive
- (let (cape-file-directory-must-exist)
- (cape-interactive #'cape-file))
+ (cape-interactive '(cape-file-directory-must-exist) #'cape-file)
(pcase-let* ((default-directory (pcase cape-file-directory
('nil default-directory)
((pred stringp) cape-file-directory)
@@ -487,8 +486,7 @@ See the user options `cape-dabbrev-min-length' and
`cape-dabbrev-check-other-buffers'."
(interactive (list t))
(if interactive
- (let ((cape-dabbrev-min-length 0))
- (cape-interactive #'cape-dabbrev))
+ (cape-interactive '((cape-dabbrev-min-length 0)) #'cape-dabbrev)
(when-let ((bounds (cape--dabbrev-bounds)))
`(,(car bounds) ,(cdr bounds)
,(cape--table-with-properties
@@ -824,7 +822,12 @@ changed. The function `cape-company-to-capf' is experimental."
;;;###autoload
(defun cape-interactive (&rest capfs)
"Complete interactively with the given CAPFS."
- (let ((completion-at-point-functions capfs))
+ (let* ((ctx (and (consp (car capfs)) (car capfs)))
+ (capfs (if ctx (cdr capfs) capfs))
+ (completion-at-point-functions
+ (if ctx
+ (mapcar (lambda (fun) `(lambda () (let ,ctx (,fun)))) capfs)
+ capfs)))
(unless (completion-at-point)
(user-error "%s: No completions"
(mapconcat (lambda (fun)