### Orderless Keyword Dispatch Examples Source: https://context7.com/oantolin/orderless/llms.txt Provides various examples of using the Orderless keyword dispatcher for advanced filtering. These examples demonstrate filtering by buffer mode, file path, documentation, minor mode status, buffer modification status, read-only status, category, annotation, content, group, key binding, and variable value. ```emacs-lisp ;; Filter by buffer mode ;; Input: ":mod:org config" matches org-mode buffers containing "config" ;; Filter by file path ;; Input: ":fil:projects meeting" matches buffers visiting files in "projects" dir ;; Filter by documentation ;; Input: ":doc:completion function" finds functions with "completion" in docs ;; Filter enabled minor modes ;; Input: ":on auto" shows only enabled minor modes matching "auto" ;; Filter disabled minor modes ;; Input: ":off line" shows only disabled minor modes matching "line" ;; Filter modified buffers ;; Input: ":dif emacs" shows modified buffers with "emacs" in name ;; Filter read-only buffers ;; Input: ":ro help" shows read-only buffers with "help" in name ;; Match by category ;; Input: ":cat:buffer temp" filters to buffer category entries ;; Match by annotation ;; Input: ":ann:obsolete" matches candidates with "obsolete" in annotation ;; Match buffer content ;; Input: ":con:TODO" matches buffers containing "TODO" in their content ;; Match by group ;; Input: ":grp:files" matches candidates in the "files" group ;; Match by key binding ;; Input: ":key:C-x" finds commands bound to keys containing "C-x" ;; Match by variable value ;; Input: ":val:nil" matches variables with nil value ``` -------------------------------- ### Basic Keyword Dispatch Setup for Orderless Source: https://context7.com/oantolin/orderless/llms.txt Enables and configures the keyword dispatcher for advanced filtering with Orderless. This setup allows for sophisticated filtering based on keywords and separators, providing a powerful way to narrow down completion candidates in Emacs. ```emacs-lisp ;; Enable keyword dispatcher for advanced filtering (require 'orderless-kwd) (add-to-list 'orderless-style-dispatchers #'orderless-kwd-dispatch) ;; Configure keyword syntax (defaults shown) (setq orderless-kwd-prefix ?:, orderless-kwd-separator ":=") ;; Example: Switch to buffer with mode filtering ;; Input in switch-to-buffer: "work :mod:org" ;; Matches all buffers with "work" in name that are in org-mode ``` -------------------------------- ### Helm Integration with Orderless Completion Source: https://context7.com/oantolin/orderless/llms.txt Demonstrates how to configure Orderless completion style for use with the Helm package. This setup ensures that Orderless features are automatically applied when using Helm for command execution or buffer switching, providing a consistent and powerful completion experience. ```emacs-lisp ;; Configure orderless with Helm (setq helm-completion-style 'emacs) ;; Orderless configuration applies automatically (setq completion-styles '(orderless basic)) ;; Example: Using helm-M-x with orderless ;; Input: "mode enable" matches "auto-revert-mode-enable-hook" ``` -------------------------------- ### Basic Orderless Configuration with use-package Source: https://context7.com/oantolin/orderless/llms.txt This snippet shows how to install and configure the Orderless completion style using the `use-package` macro in Emacs. It sets Orderless as the primary completion style with `basic` as a fallback and enables `partial-completion` for file paths. It also includes an alternative manual configuration. ```emacs-lisp ;; Install and configure orderless with use-package (use-package orderless :ensure t :custom ;; Set orderless as primary completion style with basic as fallback (completion-styles '(orderless basic)) ;; Use partial-completion for file paths to support wildcards (completion-category-overrides '((file (styles partial-completion)))) ;; Enable leading wildcards in Emacs 31+ (completion-pcm-leading-wildcard t)) ;; Alternative manual configuration (require 'orderless) (setq completion-styles '(orderless basic) completion-category-overrides '((file (styles partial-completion)))) ``` -------------------------------- ### Custom Keyword Definition for Orderless Source: https://context7.com/oantolin/orderless/llms.txt Demonstrates how to define and register a custom keyword for Orderless filtering. This example shows how to create a keyword to filter buffers based on their size, illustrating the extensibility of the Orderless system. ```emacs-lisp ;; Add custom keyword to filter by buffer size (defun my-orderless-kwd-large-buffer (_) "Match large buffers (>100KB)." (lambda (str) (when-let ((buf (get-buffer str))) (> (buffer-size buf) 100000)))) ;; Register the custom keyword (add-to-list 'orderless-kwd-alist '(large my-orderless-kwd-large-buffer t)) ;; Usage: ":large python" finds large Python buffers ``` -------------------------------- ### Configuring Substring Expansion in Orderless Source: https://context7.com/oantolin/orderless/llms.txt Explains the options for substring expansion in Orderless: `prefix` (default, efficient), `substring` (more flexible), and `nil` (disables expansion). Examples illustrate how each setting affects the completion process when the user triggers completion. ```emacs-lisp ;; Enable prefix expansion (default, efficient) (setq orderless-expand-substring 'prefix) ;; Enable full substring expansion (setq orderless-expand-substring 'substring) ;; Disable expansion (only complete unique matches) (setq orderless-expand-substring nil) ;; Example with prefix expansion: ;; Input: "def" then TAB ;; If unique prefix exists, expands to "default-" ;; Then continue typing for further filtering ;; Example with substring expansion: ;; Input: "mode" then TAB ;; If substring "mode" is unique, expands to full match ;; More flexible but potentially slower ``` -------------------------------- ### Configure Orderless Completion Style with use-package Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code snippet demonstrates how to install and configure the Orderless completion style using the `use-package` macro. It sets Orderless as the primary completion style, configures file completion overrides, and enables leading wildcard matching for partial completions. ```emacs-lisp (use-package orderless :ensure t :custom (completion-styles '(orderless basic)) (completion-category-overrides '((file (styles partial-completion)))) (completion-pcm-leading-wildcard t)) ;; Emacs 31: partial-completion behaves like substring ``` -------------------------------- ### Company Integration for Orderless Completion Source: https://context7.com/oantolin/orderless/llms.txt Configures Orderless completion style for use with the Company package. It allows spaces in company completion and highlights matches using a single face. This setup enhances the completion experience by offering more flexible and visually consistent results. ```emacs-lisp ;; Allow spaces in company completion (setq orderless-component-separator "[ &]") ;; Highlight matches in company using single face (defun just-one-face (fn &rest args) (let ((orderless-match-faces [completions-common-part])) (apply fn args))) (advice-add 'company-capf--candidates :around #'just-one-face) ;; Example: In an Emacs Lisp buffer, typing "buf&mod" ;; completes to "buffer-mode" even with the ampersand separator ;; Alternative: Use different completion styles with company (defun company-completion-styles (capf-fn &rest args) (let ((completion-styles '(basic partial-completion))) (apply capf-fn args))) (advice-add 'company-capf :around #'company-completion-styles) ``` -------------------------------- ### Emacs Lisp: Ivy Integration with Orderless Source: https://context7.com/oantolin/orderless/llms.txt Configures Orderless to work with the Ivy completion UI by setting `ivy-re-builders-alist` and adding `orderless-ivy-highlight` to `ivy-highlight-functions-alist`. An example shows 'file vis' matching 'find-file-visit-truename'. ```emacs-lisp ;; Configure orderless with Ivy (setq ivy-re-builders-alist '((t . orderless-ivy-re-builder))) (add-to-list 'ivy-highlight-functions-alist '(orderless-ivy-re-builder . orderless-ivy-highlight)) ;; Example: Using counsel-M-x with orderless ;; Input: "file vis" matches "find-file-visit-truename" ;; Highlighting shows matched components in different colors ``` -------------------------------- ### Orderless Component Separator Configuration Source: https://context7.com/oantolin/orderless/llms.txt This snippet demonstrates various ways to configure the component separator for Orderless. It shows how to set the separator to split on spaces, spaces/hyphens/slashes, use backslash-escaped spaces, or use shell-style quoted spaces. Each configuration is explained with an example of its usage. ```emacs-lisp ;; Default: split on spaces (setq orderless-component-separator " +") ;; Split on spaces, hyphens, or slashes (useful for file paths and symbols) (setq orderless-component-separator " +\\|[-/]") ;; Use backslash-escaped spaces (setq orderless-component-separator #'orderless-escapable-split-on-space) ;; Use shell-style quoted spaces (setq orderless-component-separator #'split-string-and-unquote) ;; Example usage with escaped spaces: ;; Input: "major\ mode emacs" matches "major mode for emacs" ;; Each escaped space is treated as part of the component, not a separator ``` -------------------------------- ### Emacs Lisp: Literal Prefix Matching Dispatcher Source: https://context7.com/oantolin/orderless/llms.txt Defines a custom dispatcher that enables literal prefix matching for components starting with '^'. It shows an example where '^def value' matches 'default-value' but not 'undefined-value'. ```emacs-lisp ;; Match components as literal prefixes (defun my-prefix-dispatcher (pattern _index _total) (when (string-prefix-p "^" pattern) (cons 'orderless-literal-prefix (substring pattern 1)))) (setq orderless-style-dispatchers '(my-prefix-dispatcher)) ;; Example: Input "^def value" matches: ;; - "default-value" ;; - "define-value-list" ;; But not "undefined-value" (doesn't start with "def") ``` -------------------------------- ### Emacs Lisp: Negation Dispatcher for Orderless Source: https://context7.com/oantolin/orderless/llms.txt Implements a negation dispatcher using the '!' prefix. It allows excluding components from matches, as shown in the example where 'buffer !temp' matches buffers without 'temp'. ```emacs-lisp ;; Use the orderless-not modifier with a dispatcher (defun my-not-dispatcher (pattern _index _total) (cond ((equal "!" pattern) #'ignore) ((string-prefix-p "!" pattern) `(orderless-not . ,(substring pattern 1))))) (setq orderless-style-dispatchers '(my-not-dispatcher)) ;; Example: Input "buffer !temp" matches: ;; - "buffer-list" ;; - "buffer-mode" ;; But not "temporary-buffer" or "buffer-temp-file" ``` -------------------------------- ### Orderless Initialism Matching Style Source: https://context7.com/oantolin/orderless/llms.txt This configuration enables initialism matching within Orderless, allowing users to match candidates by typing the first letter of each word. It's combined with literal and regexp matching for broader compatibility. The example demonstrates how 'eis' can match candidates like 'emacs-init-system'. ```emacs-lisp ;; Enable initialism matching for abbreviations (setq orderless-matching-styles '(orderless-initialism orderless-literal orderless-regexp)) ;; Example: Input "eis" matches: ;; - "emacs-init-system" ;; - "execute-internal-shell" ;; - "eval-in-sequence" ;; Each character must appear at the start of a word in order ``` -------------------------------- ### Define Custom Orderless Style Dispatchers in Emacs Lisp Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code defines custom functions to act as style dispatchers for orderless completion. These functions determine matching styles based on the component pattern, its index, and the total number of components. It overrides default matching styles with regexps, initialisms, flex matching for twiddled patterns, and literal matching for patterns starting with '!'. ```emacs-lisp (defun flex-if-twiddle (pattern _index _total) (when (string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))) (defun first-initialism (pattern index _total) (if (= index 0) 'orderless-initialism)) (defun not-if-bang (pattern _index _total) (cond ((equal "!" pattern) #'ignore) ((string-prefix-p "!" pattern) `(orderless-not . ,(substring pattern 1))))) (setq orderless-matching-styles '(orderless-regexp) orderless-style-dispatchers '(first-initialism flex-if-twiddle not-if-bang)) ``` -------------------------------- ### Orderless Regular Expression Matching Style Source: https://context7.com/oantolin/orderless/llms.txt This snippet configures Orderless to use regular expression matching in addition to literal matching. When enabled, each component of the user's input is interpreted as a regular expression, allowing for more flexible and powerful pattern matching. The example shows how '^def.*or$' can match various candidates. ```emacs-lisp ;; Enable regexp matching (default, combined with literal) (setq orderless-matching-styles '(orderless-regexp orderless-literal)) ;; Example: Input "^def.*or$" matches: ;; - "default-minor-mode-indicator" ;; - "define-error" ;; Components are interpreted as regular expressions ``` -------------------------------- ### Orderless Literal Matching Style Source: https://context7.com/oantolin/orderless/llms.txt This configuration enables only literal matching for Orderless. Literal matching requires each component of the input to appear exactly as typed within the candidate string. The example illustrates how input like 'buf mode' would match candidates containing both 'buf' and 'mode' literally. ```emacs-lisp ;; Enable only literal matching (setq orderless-matching-styles '(orderless-literal)) ;; Example: Input "buf mode" matches: ;; - "buffer-mode" ;; - "mode-in-buffer" ;; - "modify-buffer" ;; Each component must appear exactly as typed ``` -------------------------------- ### Orderless Flex (Fuzzy) Matching Style Source: https://context7.com/oantolin/orderless/llms.txt This snippet shows how to enable flex (fuzzy) matching in Orderless, which allows components to match even if they are not consecutive in the candidate string, as long as the characters appear in the correct order. It's combined with literal and regexp matching. The example illustrates how 'abc' can match candidates like 'a-big-car'. ```emacs-lisp ;; Enable flex matching (setq orderless-matching-styles '(orderless-flex orderless-literal orderless-regexp)) ;; Example: Input "abc" matches: ;; - "a-big-car" ;; - "apply-basic-configuration" ;; - "alphabetic-character" ;; Characters must appear in order but not consecutively ``` -------------------------------- ### Highlighting Matches with Orderless Source: https://context7.com/oantolin/orderless/llms.txt Demonstrates how to use orderless-highlight-matches to visually emphasize strings that match a compiled pattern or a direct list of regexps. It also shows how to create custom highlighting functions. ```emacs-lisp ;; Compile pattern and highlight strings (let* ((pattern "buf mode") (compiled (orderless-compile pattern)) (regexps (cdr compiled)) (strings '("buffer-mode" "mode-buffer-list" "major-mode"))) (orderless-highlight-matches regexps strings)) ;; Returns list with strings highlighted using orderless-match-face-* faces ;; Highlight with direct regexp list (orderless-highlight-matches '("buf" "mode") '("buffer-mode" "global-mode-buffer")) ;; Each component highlighted in different cyclical faces ;; Custom highlighting example (defun my-custom-highlighter (input candidates) "Highlight CANDIDATES matching INPUT with custom colors." (let* ((compiled (orderless-compile input)) (regexps (cdr compiled))) (orderless-highlight-matches regexps candidates))) (my-custom-highlighter "file vis" '("find-file-visit-truename" "file-visitor" "visit-file-hook")) ``` -------------------------------- ### Basic Orderless Pattern Compilation Source: https://context7.com/oantolin/orderless/llms.txt Covers the fundamental use of `orderless-compile` to transform a search string into a list of regular expression strings. It also demonstrates how to use style dispatchers for special matching behaviors like literal or initialism matching. ```emacs-lisp ;; Compile a pattern into predicate and regexps (orderless-compile "buf mode") ;; Returns: (nil . ("buf" "mode")) ;; First element is predicate (nil means no special predicate) ;; Second element is list of regexp strings ;; Compile with style dispatchers (let ((orderless-style-dispatchers '(orderless-affix-dispatch))) (orderless-compile "=buf ,mode")) ;; Returns: (nil . ("\\`buf" "\\ orderless-not ;; & -> orderless-annotation ;; , -> orderless-initialism ;; = -> orderless-literal ;; ^ -> orderless-literal-prefix ;; ~ -> orderless-flex ;; % -> ignore diacritics (char-fold-to-regexp) ``` -------------------------------- ### Emacs Lisp: Add Company Completion Style Around Advice Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code defines a function `company-completion-styles` and adds it as an around advice to the `company-capf` function. This is likely used to customize or extend the behavior of the Company completion framework. ```emacs-lisp (defun company-completion-styles (capf-fn &rest args) (let ((completion-styles '(basic partial-completion))) (apply capf-fn args))) (advice-add 'company-capf :around #'company-completion-styles) ``` -------------------------------- ### Emacs Lisp: Make All Components Match Literally Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code defines a function to set the orderless matching style to literal for all components and disables style dispatchers. It then binds this function to the 'C-l' key in the minibuffer for interactive use. This ensures that during a completion session, all parts of the pattern are treated as literal strings. ```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) ``` -------------------------------- ### Emacs Lisp: Apply Single Face for Orderless Matches in Company Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code defines an advice function 'just-one-face' that wraps the 'company-capf--candidates' function. It forces the 'orderless-match-faces' variable to use only the 'completions-common-part' face. This is a workaround for Company's limitation of only using one face for highlighting matches when orderless is used. ```emacs-lisp (defun just-one-face (fn &rest args) (let ((orderless-match-faces [completions-common-part])) (apply fn args))) (advice-add 'company-capf--candidates :around #'just-one-face) ``` -------------------------------- ### Configuring Smart Case in Orderless Source: https://context7.com/oantolin/orderless/llms.txt Details how to enable or disable the 'smart case' feature in Orderless, which affects case sensitivity during matching. When enabled, input case determines matching behavior; when disabled, it falls back to the standard `completion-ignore-case` setting. ```emacs-lisp ;; Enable smart case (default) (setq orderless-smart-case t) ;; Example with smart case enabled: ;; Input: "buffer mode" (lowercase) - case-insensitive ;; Matches: "Buffer-Mode", "buffer-mode", "BUFFER-MODE" ;; Input: "Buffer Mode" (mixed case) - case-sensitive ;; Matches: "Buffer-Mode" only ;; Does not match: "buffer-mode" or "BUFFER-MODE" ;; Disable smart case (use standard completion-ignore-case) (setq orderless-smart-case nil completion-ignore-case t) ;; Now case sensitivity follows completion-ignore-case setting ``` -------------------------------- ### Perform Batch Filtering with Orderless Source: https://context7.com/oantolin/orderless/llms.txt Provides Emacs Lisp functions for batch filtering operations using orderless. The first function filters a list of candidates against multiple patterns, returning matches for each pattern. The second function counts the number of candidates that match a single pattern. ```emacs-lisp ;; Filter multiple patterns across candidates (defun my-multi-pattern-filter (patterns candidates) "Filter CANDIDATES with multiple PATTERNS using orderless." (cl-loop for pattern in patterns collect (cons pattern (orderless-filter pattern candidates)))) (my-multi-pattern-filter '("buf mode" "file vis" "list all") '("buffer-mode" "file-visitor" "list-buffers-all" "global-mode-buffer" "visit-file" "all-completions-list")) ;; Returns: (("buf mode" . ("buffer-mode" "global-mode-buffer")) ;; ("file vis" . ("file-visitor" "visit-file")) ;; ("list all" . ("list-buffers-all" "all-completions-list"))) ;; Filter and count matches (defun my-count-matches (pattern candidates) "Count candidates matching PATTERN." (length (orderless-filter pattern candidates))) (my-count-matches "mode" (mapcar #'symbol-name obarray)) ;; Returns: number of symbols containing "mode" ``` -------------------------------- ### Emacs Lisp: Set Custom Separator for Orderless Company Integration Source: https://github.com/oantolin/orderless/blob/master/README.org This Emacs Lisp code snippet sets a custom separator for the orderless completion style, specifically for integration with Company. It uses an ampersand ('&') as an allowed separator within identifiers, which is useful for Emacs Lisp code. This modification addresses the limitation where the default space separator can prematurely end a completion component. ```emacs-lisp (setq orderless-component-separator "[ &]") ``` -------------------------------- ### Orderless Style Modifiers - Emacs Lisp Source: https://github.com/oantolin/orderless/blob/master/README.org Provides style modifiers in Emacs Lisp that alter how matching styles are applied. These modifiers can change the matching target (e.g., to annotations) or invert the matching logic (e.g., to exclude matches). They are intended for use with style dispatchers. ```Emacs Lisp ;; orderless-annotation :: this style modifier matches the pattern ;; against the annotation string of the candidate, instead of against ;; the candidate string. ;; orderless-not :: this style modifier inverts the pattern, such that ;; candidates pass which do not match the pattern. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.