swiper icon indicating copy to clipboard operation
swiper copied to clipboard

fuzzy vs space separated narrowing

Open habamax opened this issue 9 years ago • 4 comments

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

habamax avatar Jan 25 '16 07:01 habamax

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.

abo-abo avatar Jan 25 '16 08:01 abo-abo

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?

habamax avatar Jan 25 '16 11:01 habamax

@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.

noctuid avatar Oct 15 '16 15:10 noctuid

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

ssnnoo avatar Dec 31 '21 20:12 ssnnoo