Skip to content

Commit 98a0a70

Browse files
author
Daniel Dinnyes
committed
Update orderless-escapable-split-on-space to support other characters
Allow customizing the escapable component separator character to be other than just a space.
1 parent 6e3a09d commit 98a0a70

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

orderless.el

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,21 @@
9393
(t :foreground "yellow"))
9494
"Face for matches of components numbered 3 mod 4.")
9595

96-
(defcustom orderless-component-separator #'orderless-escapable-split-on-space
96+
(defcustom orderless-component-separator #'orderless-escapable-split
9797
"Component separators for orderless completion.
9898
This can either be a string, which is passed to `split-string',
9999
or a function of a single string argument."
100100
:type `(choice (const :tag "Spaces" " +")
101101
(const :tag "Spaces, hyphen or slash" " +\\|[-/]")
102-
(const :tag "Escapable space"
103-
,#'orderless-escapable-split-on-space)
102+
(const :tag "Escapable character" ,#'orderless-escapable-split)
104103
(const :tag "Quotable spaces" ,#'split-string-and-unquote)
105104
(regexp :tag "Custom regexp")
106105
(function :tag "Custom function")))
107106

107+
(defcustom orderless-escapable-separator ?\ ; space character
108+
"Character to be used as component separator by `orderless-escapable-split'."
109+
:type 'character)
110+
108111
(defcustom orderless-match-faces
109112
[orderless-match-face-0
110113
orderless-match-face-1
@@ -362,15 +365,20 @@ converted to a list of regexps according to the value of
362365

363366
;;; Compiling patterns to lists of regexps
364367

365-
(defun orderless-escapable-split-on-space (string)
366-
"Split STRING on spaces, which can be escaped with backslash."
367-
(mapcar
368-
(lambda (piece) (replace-regexp-in-string (string 0) " " piece))
369-
(split-string (replace-regexp-in-string
370-
"\\\\\\\\\\|\\\\ "
371-
(lambda (x) (if (equal x "\\ ") (string 0) x))
372-
string 'fixedcase 'literal)
373-
" +")))
368+
(defun orderless-escapable-split (string)
369+
"Split STRING on `orderless-escapable-separator' characters,
370+
which can be escaped with backslash."
371+
(let* ((separator (string orderless-escapable-separator))
372+
(encoded-string
373+
(string-replace
374+
(concat "\\" separator)
375+
(string 0) string))
376+
(encoded-components
377+
(split-string encoded-string separator t)))
378+
(mapcar
379+
(lambda (component)
380+
(string-replace (string 0) separator component))
381+
encoded-components)))
374382

375383
(defun orderless--dispatch (dispatchers default string index total)
376384
"Run DISPATCHERS to compute matching styles for STRING.

0 commit comments

Comments
 (0)