emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/orderless 2750e15c74 065/204: Add ivy integration


From: ELPA Syncer
Subject: [elpa] externals/orderless 2750e15c74 065/204: Add ivy integration
Date: Tue, 11 Jan 2022 12:58:18 -0500 (EST)

branch: externals/orderless
commit 2750e15c742d8460748044522a1286c27e4bfc32
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    Add ivy integration
---
 README.org   | 11 +++++++++++
 orderless.el | 45 +++++++++++++++++++++++++++++++--------------
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/README.org b/README.org
index cb7fd86acf..171d811a73 100644
--- a/README.org
+++ b/README.org
@@ -213,6 +213,17 @@ please file an issue or make a pull request so others can 
benefit from
 your effort. The functions =orderless-filter= and
 =orderless-highlight-matches= are likely to help with the integration.
 
+** Ivy
+
+To use =orderless= from Ivy add this to your Ivy configuration:
+
+#+begin_src emacs-lisp
+  (require 'orderless)
+  (cl-pushnew '(orderless--ivy-re-builder . orderless--ivy-highlight)
+              ivy-highlight-functions-alist)
+  (setq ivy-re-builders-alist '((t . orderless--ivy-re-builder)))
+#+end_src
+
 ** Selectrum
 
 To use =orderless= from Selectrum add this to your Selectrum
diff --git a/orderless.el b/orderless.el
index 7bfb1035bf..2d250d1f44 100644
--- a/orderless.el
+++ b/orderless.el
@@ -164,6 +164,21 @@ at a word boundary in the candidate.  This is similar to 
the
    (cl-loop for prefix in (split-string component "\\>" t)
             collect `(seq word-boundary ,prefix))))
 
+(defun orderless--highlight (regexps string)
+  "Propertize STRING to highlight a match of each of the REGEXPS.
+Warning: only use this if you know all REGEXPs match!"
+  (cl-loop with n = (length orderless-match-faces)
+           for regexp in regexps and i from 0 do
+           (string-match regexp string)
+           (cl-loop
+            for (x y) on (or (cddr (match-data)) (match-data)) by #'cddr
+            when x do
+            (font-lock-prepend-text-property
+             x y
+             'face (aref orderless-match-faces (mod i n))
+             string)))
+  string)
+
 ;;;###autoload
 (defun orderless-highlight-matches (regexps strings)
     "Highlight a match of each of the REGEXPS in each of the STRINGS.
@@ -174,26 +189,15 @@ converted to a list of regexps according to the value of
     (when (stringp regexps)
       (setq regexps (orderless--component-regexps regexps)))
     (cl-loop for original in strings
-             for string = (copy-sequence original) do
-             (cl-loop with n = (length orderless-match-faces)
-                      for regexp in regexps and i from 0 do
-                      (string-match regexp string)
-                      (cl-loop
-                       for (x y) on (or (cddr (match-data)) (match-data))
-                       by #'cddr
-                       when x do
-                       (font-lock-prepend-text-property
-                        x y
-                        'face (aref orderless-match-faces (mod i n))
-                        string)))
-             collect string))
+             for string = (copy-sequence original)
+             collect (orderless--highlight regexps string)))
 
 (defun orderless--component-regexps (pattern)
   "Build regexps to match PATTERN.
 Consults `orderless-component-matching-styles' to decide what to
 match."
   (cl-loop for component in
-           (split-string pattern orderless-component-separator t) 
+           (split-string pattern orderless-component-separator t)
            collect
            (rx-to-string
             `(or ,@(cl-loop for style in orderless-component-matching-styles
@@ -278,5 +282,18 @@ This function is part of the `orderless' completion style."
   (setq orderless-component-separator separator)
   (add-to-list 'minibuffer-exit-hook #'orderless--restore-component-separator))
 
+(defun orderless--ivy-re-builder (str)
+  "Convert STR into regexps for use with ivy.
+This function is for integration of orderless with ivy, use it as
+a value in `ivy-re-builders-alist'."
+  (or (mapcar (lambda (x) (cons x t)) (orderless--component-regexps str)) ""))
+
+(defun orderless--ivy-highlight (str)
+  "Highlight a match in STR of each regexp in `ivy-regex'.
+This function is for integration of orderless with ivy. Add a
+pair with key `orderless--ivy-re-builder' and value
+`orderless--ivy-highlight' to `ivy-highlight-functions-alist'."
+  (orderless--highlight (mapcar #'car ivy-regex) str) str)
+
 (provide 'orderless)
 ;;; orderless.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]