diff options
| author | Omar AntolĂn Camarena <omar.antolin@gmail.com> | 2021-03-23 17:26:01 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-23 17:26:01 -0600 |
| commit | d6eb575714f2d86ec7b0d5c42f9acb23ac439a02 (patch) | |
| tree | 5abbe7377f2f85b43fa7e224913b8271bd98bf48 | |
| parent | 150155ce3cdd28a8a94cdf99d769b2350cf07b5c (diff) | |
| parent | e5cb3f7b57d910247d7551866560dfac3ca07cdb (diff) | |
Merge pull request #44 from minad/invalid-regexp
Minor invalid regexp improvements
| -rw-r--r-- | README.org | 10 | ||||
| -rw-r--r-- | orderless.el | 32 |
2 files changed, 19 insertions, 23 deletions
@@ -100,11 +100,8 @@ define new matching styles. The predefined ones are: - orderless-regexp :: the component is treated as a regexp that must match somewhere in the candidate. - If the component is not a valid regexp, it matches literally. - (Having the component be invalid is actually pretty common while you - are typing, so be prepared for the results to be a little funny - before you close a bracket or parentheses, etc.) - + If the component is not a valid regexp, it is ignored. + - orderless-literal :: the component is treated as a literal string that must occur in the candidate. @@ -117,7 +114,7 @@ define new matching styles. The predefined ones are: 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. @@ -406,4 +403,3 @@ you get out of order matching! - Ivy has =ivy-restrict-to-matches=, bound to =S-SPC=, so you can get the effect of out of order matching without using =ivy--regex-ignore-order=. - diff --git a/orderless.el b/orderless.el index 5be0a12..921fa09 100644 --- a/orderless.el +++ b/orderless.el @@ -187,10 +187,10 @@ is determined by the values of `completion-ignore-case', ;;; Matching styles (defun orderless-regexp (component) - "Match a component as a regexp." + "Match COMPONENT as a regexp." (condition-case nil (progn (string-match-p component "") component) - (invalid-regexp (regexp-quote component)))) + (invalid-regexp nil))) (defalias 'orderless-literal #'regexp-quote "Match a component as a literal string. @@ -397,7 +397,9 @@ compilers." (rx-to-string `(or ,@(cl-loop for style in newstyles - collect `(regexp ,(funcall style newcomp)))))))) + for result = (funcall style newcomp) + if result + collect `(regexp ,result))))))) ;;; Completion style implementation @@ -411,19 +413,17 @@ The predicate PRED is used to constrain the entries in TABLE." (defun orderless-filter (string table &optional pred) "Split STRING into components and find entries TABLE matching all. The predicate PRED is used to constrain the entries in TABLE." - (condition-case nil - (save-match-data - (pcase-let* ((`(,prefix . ,pattern) - (orderless--prefix+pattern string table pred)) - (completion-regexp-list - (funcall orderless-pattern-compiler pattern)) - (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))) - (all-completions prefix table pred))) - (invalid-regexp nil))) + (save-match-data + (pcase-let* ((`(,prefix . ,pattern) + (orderless--prefix+pattern string table pred)) + (completion-regexp-list + (funcall orderless-pattern-compiler pattern)) + (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))) + (all-completions prefix table pred)))) ;;;###autoload (defun orderless-all-completions (string table pred _point) |
