emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/orderless 5c2f44d901 115/204: Allow component separator


From: ELPA Syncer
Subject: [elpa] externals/orderless 5c2f44d901 115/204: Allow component separator to be a function
Date: Tue, 11 Jan 2022 12:58:22 -0500 (EST)

branch: externals/orderless
commit 5c2f44d90130c5e03ecd1bf290b7287745c4f0fd
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    Allow component separator to be a function
---
 orderless.el | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/orderless.el b/orderless.el
index 8ef4b07fe9..0255a1faca 100644
--- a/orderless.el
+++ b/orderless.el
@@ -91,12 +91,16 @@
   :group 'orderless)
 
 (defcustom orderless-component-separator " +"
-  "Regexp to match component separators for orderless completion.
-This is passed to `split-string' to divide the pattern into
-component regexps."
+  "Component separators for orderless completion.
+This can either be a string, which is passed to `split-string',
+or a function of a single string argument."
   :type '(choice (const :tag "Spaces" " +")
                  (const :tag "Spaces, hyphen or slash" " +\\|[-/]")
-                 (regexp :tag "Custom regexp"))
+                 (const :tag "Escapable space"
+                        orderless-escapeable-split-on-space)
+                 (const :tag "Quotable spaces" split-string-and-unquote)
+                 (regexp :tag "Custom regexp")
+                 (function : tag "Custom function"))
   :group 'orderless)
 
 (defvar-local orderless-transient-component-separator nil
@@ -323,6 +327,12 @@ converted to a list of regexps according to the value of
 
 ;;; Compiling patterns to lists of regexps
 
+(defun orderless-escapeable-split-on-space (string)
+  "Split STRING on spaces, which can be escaped with backslash."
+  (mapcar
+   (lambda (piece) (replace-regexp-in-string (string 0) " " piece))
+   (split-string (replace-regexp-in-string "\\\\ " (string 0) string) " ")))
+
 (defun orderless-remove-transient-configuration ()
   "Remove all transient orderless configuration.
 Meant to be added to `exit-minibuffer-hook'."
@@ -400,10 +410,11 @@ compilers."
   (unless dispatchers (setq dispatchers orderless-style-dispatchers))
   (setq dispatchers (or orderless-transient-style-dispatchers dispatchers))
   (cl-loop
-   with components = (split-string
-                      pattern
-                      (or orderless-transient-component-separator
-                          orderless-component-separator))
+   with splitter = (or orderless-transient-component-separator
+                       orderless-component-separator)
+   with components = (if (functionp splitter)
+                         (funcall splitter pattern)
+                       (split-string pattern splitter))
    with total = (length components)
    for component in components and index from 0
    for (newstyles . newcomp) = (orderless-dispatch



reply via email to

[Prev in Thread] Current Thread [Next in Thread]