[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/orderless e00fbed140: Add a simple affix dispatcher, ma
From: |
ELPA Syncer |
Subject: |
[elpa] externals/orderless e00fbed140: Add a simple affix dispatcher, make it the default (fix #131) |
Date: |
Sun, 29 Jan 2023 12:57:59 -0500 (EST) |
branch: externals/orderless
commit e00fbed14086b6b4bc6a604f407b2efb5721ccbf
Author: Omar Antolín Camarena <omar.antolin@gmail.com>
Commit: Omar Antolín Camarena <omar.antolin@gmail.com>
Add a simple affix dispatcher, make it the default (fix #131)
---
README.org | 29 ++++++++++++++++++++++++++---
orderless.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
orderless.texi | 36 +++++++++++++++++++++++++++++++++---
3 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/README.org b/README.org
index eed72022a3..f1ead4c7c1 100644
--- a/README.org
+++ b/README.org
@@ -169,7 +169,28 @@ regexp styles.
For more fine-grained control on which matching styles to use for
each component of the input string, you can customize the variable
- =orderless-style-dispatchers=.
+ =orderless-style-dispatchers=. You can use this feature to define your
+ own "query syntax". For example, the default value of
+ =orderless-style-dispatchers= lists a single dispatcher called
+ =orderless-affix-dispatch= which enables a simple syntax based on
+ special characters used as either a prefix or suffix:
+
+ - =!= makes the rest of the component match match using the
+ =orderless-without-literal=, that is, both =!bad= and =bad!= will match
+ string that do /not/ contain the substring =bad=.
+ - =,= uses =orderless-initialism=.
+ - === uses =orderless-literal=.
+ - =~= uses =orderless-flex=.
+ - =%= makes the string match ignoring diacritics and similar
+ inflections on characters (it uses the function =char-fold-to-regexp=
+ to do this).
+
+ You can add, remove or change this mapping between affix characters
+ and matching styles by customizing the user option
+ =orderless-affix-dispatch-alist=. Most users will probably find this
+ type of customization sufficient for their query syntax needs, but
+ for those desiring further control the rest of this section explains
+ how to implement your own style dispatchers.
Style dispatchers are functions which take a component, its index in
the list of components (starting from 0), and the total number of
@@ -182,7 +203,8 @@ regexp styles.
the given one. Consult the documentation of =orderless-dispatch= for
full details.
- As an example, say you wanted the following setup:
+ As an example of writing your own dispatchers, say you wanted the
+ following setup:
- you normally want components to match as regexps,
- except for the first component, which should always match as an
@@ -191,7 +213,8 @@ regexp styles.
- 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.
+ component is a literal string not contained in the candidate (this
+ is part of the functionality of the default configuration).
You can achieve this with the following configuration:
diff --git a/orderless.el b/orderless.el
index f424f1ef46..bec5514b6e 100644
--- a/orderless.el
+++ b/orderless.el
@@ -134,7 +134,53 @@ a list of them."
orderless-prefixes
orderless-flex))
-(defcustom orderless-style-dispatchers nil
+(defcustom orderless-affix-dispatch-alist
+ `((?% . ,#'char-fold-to-regexp)
+ (?! . ,#'orderless-without-literal)
+ (?, . ,#'orderless-initialism)
+ (?= . ,#'orderless-literal)
+ (?~ . ,#'orderless-flex))
+ "Alist associating characters to matching styles.
+The function `orderless-affix-dispatch' uses this list to
+determine how to match a pattern component: if the component
+either starts or ends with a character used as a key in this
+alist, the character is removed from the component and the rest is
+matched according the style associated to it."
+ :type '(alist
+ :key-type character
+ :value-type (choice
+ (const :tag "Literal" orderless-literal)
+ (const :tag "Regexp" orderless-regexp)
+ (const :tag "Without" orderless-without-literal)
+ (const :tag "Flex" orderless-flex)
+ (const :tag "Initialism" orderless-initialism)
+ (const :tag "Prefixes" orderless-prefixes)
+ (const :tag "Ignore diacritics" char-fold-to-regexp)
+ (function :tag "Custom matching style"))))
+
+(defun orderless-affix-dispatch (component _index _total)
+ "Match COMPONENT according to the styles in `orderless-affix-dispatch-alist'.
+If the COMPONENT starts or ends with one of the characters used
+as a key in `orderless-affix-dispatch-alist', then that character
+is removed and the remainder of the COMPONENT is matched in the
+style associated to the character."
+ (cond
+ ;; Ignore single without-literal dispatcher
+ ((and (length= component 1)
+ (equal (aref component 0)
+ (car (rassq #'orderless-without-literal
+ orderless-affix-dispatch-alist))))
+ '(orderless-literal . ""))
+ ;; Prefix
+ ((when-let ((style (alist-get (aref component 0)
+ orderless-affix-dispatch-alist)))
+ (cons style (substring component 1))))
+ ;; Suffix
+ ((when-let ((style (alist-get (aref component (1- (length component)))
+ orderless-affix-dispatch-alist)))
+ (cons style (substring component 0 -1))))))
+
+(defcustom orderless-style-dispatchers '(orderless-affix-dispatch)
"List of style dispatchers.
Style dispatchers are used to override the matching styles
based on the actual component and its place in the list of
diff --git a/orderless.texi b/orderless.texi
index 84c8cb0199..9297281083 100644
--- a/orderless.texi
+++ b/orderless.texi
@@ -214,7 +214,35 @@ regexp styles.
For more fine-grained control on which matching styles to use for
each component of the input string, you can customize the variable
-@samp{orderless-style-dispatchers}.
+@samp{orderless-style-dispatchers}. You can use this feature to define your
+own ``query syntax''. For example, the default value of
+@samp{orderless-style-dispatchers} lists a single dispatcher called
+@samp{orderless-affix-dispatch} which enables a simple syntax based on
+special characters used as either a prefix or suffix:
+
+@itemize
+@item
+@samp{!} makes the rest of the component match match using the
+@samp{orderless-without-literal}, that is, both @samp{!bad} and @samp{bad!}
will match
+string that do @emph{not} contain the substring @samp{bad}.
+@item
+@samp{,} uses @samp{orderless-initialism}.
+@item
+@samp{=} uses @samp{orderless-literal}.
+@item
+@samp{~} uses @samp{orderless-flex}.
+@item
+@samp{%} makes the string match ignoring diacritics and similar
+inflections on characters (it uses the function @samp{char-fold-to-regexp}
+to do this).
+@end itemize
+
+You can add, remove or change this mapping between affix characters
+and matching styles by customizing the user option
+@samp{orderless-affix-dispatch-alist}. Most users will probably find this
+type of customization sufficient for their query syntax needs, but
+for those desiring further control the rest of this section explains
+how to implement your own style dispatchers.
Style dispatchers are functions which take a component, its index in
the list of components (starting from 0), and the total number of
@@ -227,7 +255,8 @@ also, if desired, additionally return a new string to use
in place of
the given one. Consult the documentation of @samp{orderless-dispatch} for
full details.
-As an example, say you wanted the following setup:
+As an example of writing your own dispatchers, say you wanted the
+following setup:
@itemize
@item
@@ -241,7 +270,8 @@ later components ending in @samp{~} should match (the
characters
other than the final @samp{~}) in the flex style, and
@item
later components starting with @samp{!} should indicate the rest of the
-component is a literal string not contained in the candidate.
+component is a literal string not contained in the candidate (this
+is part of the functionality of the default configuration).
@end itemize
You can achieve this with the following configuration:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/orderless e00fbed140: Add a simple affix dispatcher, make it the default (fix #131),
ELPA Syncer <=