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

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

[elpa] externals/cape 2008d809b6 088/146: Add cape-capf-with-predicate


From: ELPA Syncer
Subject: [elpa] externals/cape 2008d809b6 088/146: Add cape-capf-with-predicate
Date: Sun, 9 Jan 2022 20:57:45 -0500 (EST)

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

    Add cape-capf-with-predicate
---
 README.org |  1 +
 cape.el    | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/README.org b/README.org
index f5fa4bf10a..bc4cc5063b 100644
--- a/README.org
+++ b/README.org
@@ -129,3 +129,4 @@ achieve a similarly refreshing strategy.
 - ~cape-noninterruptible-capf~: Protect a Capf which does not like to be 
interrupted.
 - ~cape-interactive-capf~: Create a Capf which can be called interactively.
 - ~cape-capf-with-properties~: Add completion properties to a Capf.
+- ~cape-capf-with-predicate~: Add candidate predicate to a Capf.
diff --git a/cape.el b/cape.el
index 12735c1883..0c455ac020 100644
--- a/cape.el
+++ b/cape.el
@@ -796,6 +796,24 @@ completion :category symbol can be specified."
               ,(apply #'cape--table-with-properties table properties)
               ,@properties ,@plist)))))
 
+;;;###autoload
+(defun cape-capf-with-predicate (capf predicate)
+  "Return a new CAPF with an additional candidate PREDICATE.
+The PREDICATE is passed the candidate symbol or string."
+  (lambda ()
+    (pcase (funcall capf)
+      (`(,beg ,end ,table . ,plist)
+       `(,beg ,end ,table
+              :predicate
+              ,(if-let (pred (plist-get plist :predicate))
+                   (lambda (&rest args)
+                     (when (apply pred args)
+                       (setq args (car args))
+                       (funcall predicate (if (consp args) (car args) args))))
+                 (lambda (key &optional _val)
+                   (funcall predicate (if (consp key) (car key) key))))
+              ,@plist)))))
+
 ;;;###autoload
 (defun cape-silent-capf (capf)
   "Return a new CAPF which is silent (no messages, no errors)."



reply via email to

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