Skip to content

Interactively changing the configuration

You might want to change the separator or the matching style configuration on the fly while matching. There many possible user interfaces for this: you could toggle between two chosen configurations, cycle among several, have a keymap where each key sets a different configurations, have a set of named configurations and be prompted (with completion) for one of them, popup a hydra to choose a configuration, etc. Since there are so many possible UIs and which to use is mostly a matter of taste, ‘orderless’ does not provide any such commands. But it’s easy to write your own!

For example, say you want to use the keybinding ‘C-l’ to make all components match literally. You could use the following code:

emacs-lisp
(defun my/match-components-literally ()
  "Components match literally for the rest of the session."
  (interactive)
  (setq-local orderless-matching-styles '(orderless-literal)
              orderless-style-dispatchers nil))

(define-key minibuffer-local-completion-map (kbd "C-l")
  #'my/match-components-literally)

Using ‘setq-local’ to assign to the configuration variables ensures the values are only used for that minibuffer completion session.