diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2021-11-24 20:05:19 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2021-11-24 20:06:20 +0100 |
| commit | 0a05e51d2aad419b8650dcf81623887c85ce380d (patch) | |
| tree | c38718a89e704db564ec571875e4d4059899d3f7 | |
| parent | 2bcdd7bfe55d50826546a10e38ab4267d44ba343 (diff) | |
Add cape-capf-with-predicate (See #9)
| -rw-r--r-- | README.org | 1 | ||||
| -rw-r--r-- | cape.el | 10 |
2 files changed, 11 insertions, 0 deletions
@@ -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. @@ -682,6 +682,16 @@ The CMP argument determines how the new input is compared to the old 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. Completion properties include for example :exclusive, :annotation-function |
