emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/cape 0a05e51d2a 053/146: Add cape-capf-with-predicate (


From: ELPA Syncer
Subject: [elpa] externals/cape 0a05e51d2a 053/146: Add cape-capf-with-predicate (See #9)
Date: Sun, 9 Jan 2022 20:57:42 -0500 (EST)

branch: externals/cape
commit 0a05e51d2aad419b8650dcf81623887c85ce380d
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add cape-capf-with-predicate (See #9)
---
 README.org |  1 +
 cape.el    | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/README.org b/README.org
index eef1a87b08..8ec09aba7c 100644
--- a/README.org
+++ b/README.org
@@ -120,3 +120,4 @@ achieve a similarly refreshing strategy.
 
 - ~cape-silent-capf~: Wrap a chatty Capf and silence it.
 - ~cape-capf-with-properties~: Add completion properties to a Capf.
+- ~cape-capf-with-predicate~: Add predicate to control if the Capf should 
activate.
diff --git a/cape.el b/cape.el
index db93c6d9c5..e0412544a6 100644
--- a/cape.el
+++ b/cape.el
@@ -681,6 +681,16 @@ The CMP argument determines how the new input is compared 
to the old input.
              ('equal (equal old-input new-input))
              ('substring (string-match-p (regexp-quote old-input) 
new-input))))))
 
+;;;###autoload
+(defun cape-capf-with-predicate (capf predicate)
+  "Return a new CAPF which activates only when the PREDICATE is non-nil.
+The PREDICATE takes the completion beginning and end positions as arguments."
+  (lambda ()
+    (pcase (funcall capf)
+      ((and result `(,beg ,end ,_table . ,_plist))
+       (when (funcall predicate beg end)
+         result)))))
+
 ;;;###autoload
 (defun cape-capf-with-properties (capf &rest properties)
   "Return a new CAPF with additional completion PROPERTIES.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]