diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2026-01-22 08:33:19 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2026-01-22 08:33:37 +0100 |
| commit | b811bacfb343b07b17c78d3269ca18e663b85e45 (patch) | |
| tree | d389e03a797897f9304bfe5f97f44122173d069f | |
| parent | dfb3bca62238aab8f64ec319a77a125df86a0eee (diff) | |
cape-wrap-properties: Override completion table properties
| -rw-r--r-- | cape.el | 37 |
1 files changed, 31 insertions, 6 deletions
@@ -1126,16 +1126,41 @@ This function can be used as an advice around an existing Capf." (`(,beg ,end ,table . ,plist) `(,beg ,end ,(cape--passthrough-table table) ,@plist)))) +(defun cape--properties-table (table properties) + "Create completion TABLE with PROPERTIES. +The properties of the table must be overridden too, since they take +precedence over the properties specified as part of the Capf result." + (let* ((dsort (plist-get properties :display-sort-function)) + (csort (plist-get properties :cycle-sort-function)) + (cat (plist-get properties :category)) + (ann (plist-get properties :annotation-function)) + (aff (plist-get properties :affixation-function)) + (alist (append (and dsort `((display-sort-function . ,dsort))) + (and csort `((cycle-sort-function . ,csort))) + (and cat `((category . ,cat))) + (and ann `((annotation-function . ,ann))) + (and aff `((annotation-function . ,aff)))))) + (if alist + (lambda (str pred action) + (if (eq action 'metadata) + `(metadata + ,@alist + ,@(and (functionp table) + (cdr (funcall table str pred action)))) + (complete-with-action action table str pred))) + table))) + ;;;###autoload (defun cape-wrap-properties (capf &rest properties) - "Call CAPF and strip or add completion PROPERTIES. -Completion properties include for example :exclusive, :category, -:annotation-function, :display-sort-function and various :company-* -extensions. Strip all properties if PROPERTIES is :strip." + "Call CAPF and add completion PROPERTIES. +Completion properties include :exclusive, :category, +:annotation-function, :affixation-function, :display-sort-function, +:company-kind, :company-doc-buffer, :company-docsig, :company-location, +:company-deprecated and :company-prefix-length." (pcase (funcall capf) (`(,beg ,end ,table . ,plist) - `( ,beg ,end ,table - ,@(and (not (eq :strip (car properties))) (append properties plist)))))) + `( ,beg ,end ,(cape--properties-table table properties) + ,@properties ,@plist)))) ;;;###autoload (defun cape-wrap-nonexclusive (capf) |
