Function: orderless--dispatch

orderless--dispatch is a byte-compiled function defined in orderless.el.

Signature

(orderless--dispatch DISPATCHERS DEFAULT STRING INDEX TOTAL)

Documentation

Run DISPATCHERS to compute matching styles for STRING.

A style dispatcher is a function that takes a STRING, component INDEX and the TOTAL number of components. It should either return (a) nil to indicate the dispatcher will not handle the string, (b) a new string to replace the current string and continue dispatch, or (c) the matching styles to use and, if needed, a new string to use in place of the current one (for example, a dispatcher can decide which style to use based on a suffix of the string and then it must also return the component stripped of the suffix).

More precisely, the return value of a style dispatcher can be of one of the following forms:

- nil (to continue dispatching)

- a string (to replace the component and continue dispatching),

- a matching style or non-empty list of matching styles to
  return,

- a cons whose car is either as in the previous case or
  nil (to request returning the DEFAULT matching styles), and
  whose cdr is a string (to replace the current one).

This function tries all DISPATCHERS in sequence until one returns a list of styles. When that happens it returns a cons of the list of styles and the possibly updated STRING. If none of the DISPATCHERS returns a list of styles, the return value will use DEFAULT as the list of styles.

Source Code

;; Defined in ~/.emacs.d/elpa/orderless-20260519.1029/orderless.el
(defun orderless--dispatch (dispatchers default string index total)
  "Run DISPATCHERS to compute matching styles for STRING.

A style dispatcher is a function that takes a STRING, component
INDEX and the TOTAL number of components.  It should either
return (a) nil to indicate the dispatcher will not handle the
string, (b) a new string to replace the current string and
continue dispatch, or (c) the matching styles to use and, if
needed, a new string to use in place of the current one (for
example, a dispatcher can decide which style to use based on a
suffix of the string and then it must also return the component
stripped of the suffix).

More precisely, the return value of a style dispatcher can be of
one of the following forms:

- nil (to continue dispatching)

- a string (to replace the component and continue dispatching),

- a matching style or non-empty list of matching styles to
  return,

- a `cons' whose `car' is either as in the previous case or
  nil (to request returning the DEFAULT matching styles), and
  whose `cdr' is a string (to replace the current one).

This function tries all DISPATCHERS in sequence until one returns
a list of styles.  When that happens it returns a `cons' of the
list of styles and the possibly updated STRING.  If none of the
DISPATCHERS returns a list of styles, the return value will use
DEFAULT as the list of styles."
  (cl-loop for dispatcher in dispatchers
           for result = (funcall dispatcher string index total)
           if (stringp result)
           do (setq string result result nil)
           else if (and (consp result) (null (car result)))
           do (setf (car result) default)
           else if (and (consp result) (stringp (cdr result)))
           do (setq string (cdr result) result (car result))
           when result return (cons result string)
           finally (return (cons default string))))