branch: externals/orderless
commit e316991cfe1274efe5881fee0230532c67f9b035
Author: Omar AntolÃn Camarena <[email protected]>
Commit: Omar AntolÃn Camarena <[email protected]>
Add negative literals (fix #26)
---
README.org | 24 ++++++++++++++++++++----
orderless.el | 12 ++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/README.org b/README.org
index bedf7ed6d4..e0f5ab7b17 100644
--- a/README.org
+++ b/README.org
@@ -102,6 +102,14 @@ define new matching styles. The predefined ones are:
This is just =regexp-quote=.
+- *orderless-without-literal* :: the component is a treated as a literal
+ string that must *not* occur in the candidate.
+
+ Note that nothing is highlighted for this matching style. You
+ probably don't want to use this style directly in
+ =orderless-matching-styles= but with a style dispatcher instead. There
+ is an example in the section on style dispatchers.
+
- orderless-prefixes :: the component is split at word endings and
each piece must match at a word boundary in the candidate, occurring
in that order.
@@ -143,7 +151,7 @@ define new matching styles. The predefined ones are:
This is similar to the built-in =partial-completion= completion-style.
For example, =re-re= matches =query-replace-regexp=, =recode-region= and
=magit-remote-list-refs=; =f-d.t= matches =final-draft.txt=.
-
+
The variable =orderless-matching-styles= can be set to a list of the
desired matching styles to use. By default it enables the regexp and
initialism styles.
@@ -171,8 +179,10 @@ initialism styles.
- except for the first component, which should always match as an
initialism ---this is pretty useful for, say,
=execute-extended-command= (=M-x=) or =describe-function= (=C-h f=),
- - and any later component ending in =~= should match (the characters
- other than the final =~=) in the flex style.
+ - later components ending in =~= should match (the characters
+ other than the final =~=) in the flex style, and
+ - later components starting with =!= should indicate the rest of the
+ component is a literal string not contained in the candidate.
You can achieve this with the following configuration:
@@ -184,8 +194,14 @@ initialism styles.
(defun first-initialism (pattern index _total)
(if (= index 0) 'orderless-initialism))
+ (defun without-if-bang (pattern _index _total)
+ (when (string-prefix-p "!" pattern)
+ `(orderless-without-literal . ,(substring pattern 1))))
+
(setq orderless-matching-styles '(orderless-regexp)
- orderless-style-dispatchers '(first-initialism flex-if-twiddle))
+ orderless-style-dispatchers '(first-initialism
+ flex-if-twiddle
+ without-if-bang))
#+end_src
** Component separator regexp
diff --git a/orderless.el b/orderless.el
index 3ba62ed1c2..ecd89c7bbf 100644
--- a/orderless.el
+++ b/orderless.el
@@ -307,6 +307,18 @@ at a word boundary in the candidate. This is similar to
the
(cl-loop for prefix in (split-string component "\\>")
collect `(seq word-boundary ,prefix))))
+(defun orderless-without-literal (component)
+ "Match strings that do *not* contain COMPONENT as a literal match."
+ (rx-to-string
+ `(seq
+ (group string-start) ; highlight nothing!
+ (zero-or-more
+ (or ,@(cl-loop for i from 1 below (length component)
+ collect `(seq ,(substring component 1 i)
+ (or (not (any ,(aref component i)))
+ string-end)))))
+ string-end)))
+
;;; Highlighting matches
(defun orderless--highlight (regexps string)