abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

preprocessing user input #2224

Open drorbemet opened 5 years ago

drorbemet commented 5 years ago

In order to search for generated patterns I am looking for the place to preprocess the user-input in ivy / swiper / counsel. Starting with the preprocessing of initial-input and continuing with all further user-input. My first try was to wrap re-builder but that didn't turn out to work until now.

The desired behaviour After every key-stroke as soon and as long as the user-input matches some predicate it is replaced with the result of an input-preprocessing-function called on the user-input before it is converted into a regex-pattern.

example

(defun re-builder-with-input-preprocessing  (s)
;; example for a simple input-preprocessing operation to search for a date-stamp
  (let ((preprocessed (s-replace "tdy" (date-now) s)))
    (re-builder preprocessed)))

(ivy ... :re-builder 're-builder-with-input-preprocessing ...)

Thanks a lot for any hint on where to put an input-preprocessing like this within ivy. I didn't find it in the docs. Maybe I didn't dig deep enough though.

abo-abo commented 5 years ago

You need to define your own custom re-builder which would do the preprocessing for you. The re-builder can then call e.g. ivy--regex-plus afterwards.