From ecf6a94df717791f85be6449f953ddef29244a15 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 21 Nov 2025 17:54:52 +0100 Subject: orderless-compile, orderless-escapable-split-on-space: Preserve empty components Fix #55 Only drop the last empty component. The new behavior has the following effects: 1. The first empty component is preserved and can be treated specifically as requested in #55. The assumption is that a separator at the beginning is intentional. (cdr (orderless-compile " ")) => ("") (cdr (orderless-compile " foo")) => ("" "foo") 2. Completely blank input will compile to an empty regexp list. This is important for completion command startup performance: (cdr (orderless-compile "")) => nil 3. When separating components, the last separator will not lead to an intermediate artificial empty component, as long as the user has not finished typing. For example the user types the words "foo bar": (cdr (orderless-compile "foo")) => ("foo") (cdr (orderless-compile "foo ")) => ("foo") (cdr (orderless-compile "foo bar")) => ("foo" "bar") --- orderless.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/orderless.el b/orderless.el index bd34856..1ff379e 100644 --- a/orderless.el +++ b/orderless.el @@ -370,7 +370,7 @@ converted to a list of regexps according to the value of "\\\\\\\\\\|\\\\ " (lambda (x) (if (equal x "\\ ") (string 0) x)) string 'fixedcase 'literal) - " +" t))) + " +"))) (defun orderless--dispatch (dispatchers default string index total) "Run DISPATCHERS to compute matching styles for STRING. @@ -457,9 +457,10 @@ string as argument." (unless dispatchers (setq dispatchers orderless-style-dispatchers)) (cl-loop with predicate = nil - with components = (if (functionp orderless-component-separator) - (funcall orderless-component-separator pattern) - (split-string pattern orderless-component-separator t)) + with temp = (if (functionp orderless-component-separator) + (funcall orderless-component-separator pattern) + (split-string pattern orderless-component-separator)) + with components = (if (equal (car (last temp)) "") (nbutlast temp) temp) with total = (length components) for comp in components and index from 0 for (pred . regexp) = (orderless--compile-component -- cgit v1.0