-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible orderless support for grep patterns #381
Comments
This seems to work already: (advice-add #'consult--compile-regexp :before-until #'consult-orderless-regexp)
(defun consult-orderless-regexp (input type)
;; Bail out if only weak basic regular expressions are supported.
(unless (eq type 'basic)
;; Ensure that we have only benign matching styles!
(let ((orderless-matching-styles '(orderless-literal orderless-regexp)))
(mapcar (lambda (x) (consult--convert-regexp x type))
(orderless-pattern-compiler input))))) The difference between emacs and extended regular expression is only the escaping of cc @oantolin |
This seems to work well. Documented in the wiki for now: https://github.com/minad/consult/wiki#use-orderless-as-pattern-compiler-for-consult-grepripgrepfind |
Why do you limit the matching styles to only literal and regexp in For me the attraction would be to be able to use my normal orderless configuration. Do the other styles usually generate regexps that are hard to translate or something? |
The Orderless matching styles are not a problem (flex, initialism, without-literal all work). The translation covers everything we need. I temporarily had If it turns out that the configuration of Orderless is a good default setting (needs more testing), I can recommend it in the README. Maybe a hook would then make sense, but the advice I am currently using is also not too bad. It would be great if Orderless could do a little bit better regarding the regular expressions it generates (see oantolin/orderless#73). |
There is one more limitations I should mention. Currently for each command you can specify a :highlight function which transforms the input to a list of regular expressions. I implemented it this way since for each candidate you may only want to highlight a substring of the candidate (e.g. the part after EDIT: Generalized the highlighting function here - 22eed1b. |
I overhauled the infrastructure once more. The way to integrate orderless is now this: (defun consult--orderless-regexp-compiler (input type &rest _config)
(setq input (orderless-pattern-compiler input))
(cons
(mapcar (lambda (r) (consult--convert-regexp r type)) input)
(lambda (str) (orderless--highlight input str))))
(setq consult--regexp-compiler #'consult--orderless-regexp-compiler) |
I found that |
In order to support this the functions
consult--compile-regexp
andconsult--convert-regexp
must be replaced by Orderless/Pcre2el or an alternative more powerful converter.consult/consult.el
Lines 593 to 611 in d9e7a6b
See also the discussion in #380.
The text was updated successfully, but these errors were encountered: