From b56db3eea43ba67f319defca1ed65666b7f68bd5 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 17 Feb 2024 08:41:39 +0100 Subject: Turn orderless-annotation/without into a "pattern transformer" orderless-annotation and orderless-without take a PRED and a REGEXP argument and turn it into a new predicate. This looks like a good solution. The complexity is pushed to orderless--compile-component and orderless-without is as simple as possible. --- orderless.el | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/orderless.el b/orderless.el index 3ca7628..ea36428 100644 --- a/orderless.el +++ b/orderless.el @@ -273,15 +273,14 @@ regexp." string-end))))) string-end)) -(defun orderless-without (component) - "Match strings that do *not* match COMPONENT." - (pcase-let ((`(,pred . ,regexp) component)) - (lambda (str) - (not (or (and pred (funcall pred str)) - (and regexp (string-match-p regexp str))))))) - -(defun orderless-annotation (component) - "Match candidates where the annotation matches COMPONENT." +(defun orderless-without (pred regexp) + "Match strings that do *not* match PRED or REGEXP." + (lambda (str) + (not (or (and pred (funcall pred str)) + (and regexp (string-match-p regexp str)))))) + +(defun orderless-annotation (pred regexp) + "Match candidates where the annotation matches PRED and REGEXP." (when-let (((minibufferp)) (table minibuffer-completion-table) (metadata (completion-metadata @@ -292,11 +291,10 @@ regexp." (when-let ((aff (or (completion-metadata-get metadata 'affixation-function) (plist-get completion-extra-properties :affixation-function)))) (lambda (cand) (caddr (funcall aff (list cand)))))))) - (pcase-let ((`(,pred . ,regexp) component)) - (lambda (str) - (when-let ((ann (funcall fun str))) - (and (or (not pred) (funcall pred ann)) - (or (not regexp) (string-match-p regexp ann)))))))) + (lambda (str) + (when-let ((ann (funcall fun str))) + (and (or (not pred) (funcall pred ann)) + (or (not regexp) (string-match-p regexp ann))))))) ;;; Highlighting matches @@ -392,14 +390,11 @@ DEFAULT as the list of styles." (cl-loop with pred = nil for style in newsty - ;; TODO orderless-without and orderless-annotation are hardcoded here. - ;; Changed this such that orderless-affix-dispatch-alist contains a flag or - ;; introduce a new configuration variable. - for newcomp2 = (if (memq style '(orderless-without orderless-annotation)) - (orderless--compile-component newcomp idx total styles dispatchers) - newcomp) - when newcomp2 - for res = (funcall style newcomp2) + for res = (condition-case nil + (funcall style newcomp) + (wrong-number-of-arguments + (when-let ((res (orderless--compile-component newcomp idx total styles dispatchers))) + (funcall style (car res) (cdr res))))) if (functionp res) do (cl-callf orderless--predicate-and pred res) else if res collect (if (stringp res) `(regexp ,res) res) into regexps finally return -- cgit v1.0