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

fuzzy vs space separated narrowing #360

Open habamax opened 8 years ago

habamax commented 8 years ago

Hi,

is it possible to make ivy use fuzzy or space separated search in the same session? I mean, if there is no spaces -- use fuzzy and if there is -- fallback to standard search?

ex: pali --> package-list-packages pa li pa --> package-list-packages

abo-abo commented 8 years ago

It's an interesting idea, but might take time to implement correctly since many things depend on the current value of ivy--regex-function.

You can also switch matchers already with C-o mi.

habamax commented 8 years ago

Yes I understand it might be not that trivial to implement. But it would be really convenient.

My current setup is 'fuzzy' but quite often I remember parts of the symbol and try to narrow to it with 'spaces' with no luck. And then fuzziness as implemented makes me unhappy.

Can we detect 'space entered' and switch matcher to default as with C-o mi?

noctuid commented 8 years ago

@habamax As a quick hack, you could maybe bind space to also change the matcher and then advise backspace to check if the spaces have been deleted:

(defvar noct--original-ivy-regex-function nil)

(defun noct-ivy-space-switch-to-regex ()
  (interactive)
  (unless (eq ivy--regex-function 'ivy--regex-plus)
    (setq ivy--old-re nil)
    (setq noct--original-ivy-regex-function ivy--regex-function)
    (setq ivy--regex-function 'ivy--regex-plus))
  (self-insert-command 1))

(define-key ivy-minibuffer-map (kbd "SPC") #'noct-ivy-space-switch-to-regex)

(defun noct-ivy-maybe-reset-regex-function ()
  (interactive)
  (let ((input (replace-regexp-in-string "\n.*" "" (minibuffer-contents))))
    (when (and noct--original-ivy-regex-function
               (not (string-match " " input)))
      (setq ivy--old-re nil)
      (setq ivy--regex-function noct--original-ivy-regex-function)
      (setq noct--original-ivy-regex-function nil))))

(advice-add 'ivy-backward-delete-char :after #'noct-ivy-maybe-reset-regex-function)
(advice-add 'ivy-delete-char :after #'noct-ivy-maybe-reset-regex-function)

It seems to work okay. Not sure if it's the best idea though.

ssnnoo commented 2 years ago

I guess you can do this with orderless which has ivy support?