branch: externals/orderless
commit 793eb0ec01ece8ba2a8073411331b03d13db6d47
Author: Omar Antolín <[email protected]>
Commit: Omar Antolín <[email protected]>

    Implement ^literal optimization discussed in #79
    
    If orderless finds that some component of the pattern compiles to a
    regexp of the form ^literal it will now take the first such regexp and
    add the literal to the prefix which which it calls all-completions.
    
    That's a slight lie: it actually looks for regexps of the form
    \(?:^literal\) since that is what the pattern compiler actually
    produces.
    
    With this change people can now add a style dispatcher that adds a ^
    to the first component to use with certain completion-at-point
    functions that can really take advantage of knowing a prefix to return
    fewer completions. Some even (incorrectly) refuse to return all
    possible completions for an empty string!
    
    See the discussion in #79 and the issues linked therein.
---
 orderless.el | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/orderless.el b/orderless.el
index 5a898b7df0..4ffd042f54 100644
--- a/orderless.el
+++ b/orderless.el
@@ -399,11 +399,19 @@ The predicate PRED is used to constrain the entries in 
TABLE."
                   (orderless--prefix+pattern string table pred))
                  (completion-regexp-list
                   (orderless-pattern-compiler pattern))
+                 (initial
+                  ;; try to find a regexp of the form \(?:^literal\)
+                  (cl-find "\\`\\\\(\\?:\\^[^$*+.?[\\^]*\\\\)\\'"
+                           completion-regexp-list
+                           :test #'string-match-p))
                  (completion-ignore-case
                   (if orderless-smart-case
                       (cl-loop for regexp in completion-regexp-list
                                always (isearch-no-upper-case-p regexp t))
                     completion-ignore-case)))
+      (when initial
+        (setq prefix (concat prefix (substring initial 5 -2))
+              completion-regexp-list (delete initial completion-regexp-list)))
       (all-completions prefix table pred))))
 
 ;;;###autoload

Reply via email to