Swiper now has an ivy back end
13 Mar 2015Intro
Just three days ago, I wrote swiper
and introduced it in
a post.
And while swiper
solved the problem of helm-swoop
being awkward for me to use, swiper
's code itself is pretty awkward, since even after using helm
a dozen times in my packages, I'm still not well-versed in its internals.
And, apparently, there are people who don't like helm
because it updates a lot. I don't know if
it counts as a viable complaint, but I do agree that the helm
update time is quite long. So I
wrote down an alternative completion back end for swiper
. It looks quite similar to
ido-vertical-mode
, although it is completely unrelated to ido
. In fact, the matching algorithm
currently is similar to helm-match-plugin
: "for example"
is transformed into
"\\(for\\).*\\(example\\)"
.
The Details
Currently, in the ivy
version of swiper
only the anchoring algorithm is missing. Anchoring is
what I call the process of selecting a close candidate when the number of candidates changes. It
seems that helm
doesn't implement an anchoring algorithm, so both helm-swoop
and swiper
implement their own. I don't know how easy it would be to write down the proper generic thing, my
current implementation for the helm
version of swiper
is quite hacky.
Just to explain to you what needs to be done. Suppose there's an input "ab" that matches 50
candidates, and the candidate number 42 is the current one. Now, if the user types one char to make
the input into "abc", the number of candidates has changed to 10, and the candidate that was current
previously doesn't match any more. It is up to the matcher code to decide which of the 10 candidates
has to be current now. Usually it doesn't matter much, but in the case of swiper
it matters since
the point will be moved to the current candidate in the original window.
In any case, there's still a lot of things that have to be done for ivy
, but I think that
it's quite usable now. Actually, I've already added it to my bindings:
(global-set-key "\C-s" 'swiper)
Here's how it looks like:
And here's an example of completion in dired
:
You need to have Emacs 24.4 in order to get a nicer highlight in the minibuffer that uses
add-face-text-property
instead of the old propertize
.
There's a custom variable that decides the height of the minibuffer window, you can set it as you like:
(defcustom ivy-height 10
"Number of lines for the minibuffer window."
:type 'integer)
Outro
Give the new back end a go, see if you like it. It looks quite pretty and minimalist to me, but I'm biased since I made it.