summaryrefslogtreecommitdiff
path: root/orderless.el
diff options
context:
space:
mode:
authorOmar AntolĂ­n Camarena <omar.antolin@gmail.com>2024-03-04 07:19:50 -0600
committerGitHub <noreply@github.com>2024-03-04 07:19:50 -0600
commit41d0287b6f1bb6ec3f5c3fc5b4986f278de63f55 (patch)
tree51d1524fda573137255dbc4d30969d7a19082d69 /orderless.el
parent7545dc7c07d1465e9661209ca5930ae3f1a870a3 (diff)
parent890999e1c89c4fdffed82c3f036598795e49f56d (diff)
Merge pull request #167 from minad/minor-additions
Two minor additions & bugfixes
Diffstat (limited to 'orderless.el')
-rw-r--r--orderless.el37
1 files changed, 24 insertions, 13 deletions
diff --git a/orderless.el b/orderless.el
index 0186241..38a2624 100644
--- a/orderless.el
+++ b/orderless.el
@@ -133,6 +133,7 @@ customizing this variable to see a list of them."
(?@ . ,#'orderless-annotation)
(?, . ,#'orderless-initialism)
(?= . ,#'orderless-literal)
+ (?^ . ,#'orderless-literal-prefix)
(?~ . ,#'orderless-flex))
"Alist associating characters to matching styles.
The function `orderless-affix-dispatch' uses this list to
@@ -145,8 +146,9 @@ matched according the style associated to it."
:value-type (choice
(const :tag "Annotation" ,#'orderless-annotation)
(const :tag "Literal" ,#'orderless-literal)
- (const :tag "Regexp" ,#'orderless-regexp)
(const :tag "Without literal" ,#'orderless-without-literal)
+ (const :tag "Literal prefix" ,#'orderless-literal-prefix)
+ (const :tag "Regexp" ,#'orderless-regexp)
(const :tag "Not" ,#'orderless-not)
(const :tag "Flex" ,#'orderless-flex)
(const :tag "Initialism" ,#'orderless-initialism)
@@ -221,6 +223,10 @@ is determined by the values of `completion-ignore-case',
"Match COMPONENT as a literal string."
`(literal ,component))
+(defun orderless-literal-prefix (component)
+ "Match COMPONENT as a literal prefix string."
+ `(seq bos (literal ,component)))
+
(defun orderless--separated-by (sep rxs &optional before after)
"Return a regexp to match the rx-regexps RXS with SEP in between.
If BEFORE is specified, add it to the beginning of the rx
@@ -282,14 +288,19 @@ which can invert any predicate or regexp."
(lambda (str)
(not (orderless--match-p pred regexp str))))
+(defun orderless--metadata ()
+ "Return completion metadata iff inside minibuffer."
+ (when-let (((minibufferp))
+ (table minibuffer-completion-table))
+ ;; Return non-nil metadata iff inside minibuffer
+ (or (completion-metadata (buffer-substring-no-properties
+ (minibuffer-prompt-end) (point))
+ table minibuffer-completion-predicate)
+ '((nil . nil)))))
+
(defun orderless-annotation (pred regexp)
"Match candidates where the annotation matches PRED and REGEXP."
- (when-let (((minibufferp))
- (table minibuffer-completion-table)
- (metadata (completion-metadata
- (buffer-substring-no-properties
- (minibuffer-prompt-end) (point))
- table minibuffer-completion-predicate))
+ (when-let ((metadata (orderless--metadata))
(fun (or (completion-metadata-get
metadata 'annotation-function)
(plist-get completion-extra-properties
@@ -482,12 +493,12 @@ The predicate PRED is used to constrain the entries in TABLE."
;; Thanks to @jakanakaevangeli for writing a version of this function:
;; https://github.com/oantolin/orderless/issues/79#issuecomment-916073526
-(defun orderless--anchored-quoted-regexp (regexp)
+(defun orderless--literal-prefix-p (regexp)
"Determine if REGEXP is a quoted regexp anchored at the beginning.
-If REGEXP is of the form \"\\(?:^q\\)\" for q = (regexp-quote u),
+If REGEXP is of the form \"\\(?:\\`q\\)\" for q = (regexp-quote u),
then return (cons REGEXP u); else return nil."
- (when (and (string-prefix-p "\\(?:^" regexp) (string-suffix-p "\\)" regexp))
- (let ((trimmed (substring regexp 5 -2)))
+ (when (and (string-prefix-p "\\(?:\\`" regexp) (string-suffix-p "\\)" regexp))
+ (let ((trimmed (substring regexp 6 -2)))
(unless (string-match-p "[$*+.?[\\^]"
(replace-regexp-in-string
"\\\\[$*+.?[\\^]" "" trimmed
@@ -506,10 +517,10 @@ then return (cons REGEXP u); else return nil."
(defun orderless--filter (prefix regexps ignore-case table pred)
"Filter TABLE by PREFIX, REGEXPS and PRED.
The matching should be case-insensitive if IGNORE-CASE is non-nil."
- ;; If there is a regexp of the form \(?:^quoted-regexp\) then
+ ;; If there is a regexp of the form \(?:\`quoted-regexp\) then
;; remove the first such and add the unquoted form to the prefix.
(pcase (cl-loop for r in regexps
- thereis (orderless--anchored-quoted-regexp r))
+ thereis (orderless--literal-prefix-p r))
(`(,regexp . ,literal)
(setq prefix (concat prefix literal)
regexps (remove regexp regexps))))