More on swiper and ivy
14 Mar 2015I'll describe two new things in swiper and ivy
that happened
within the day. Although you can install them separately from MELPA, they still live in a single git
repository.
swiper
/ ivy
faces now inherit the standard ones
It's a good idea by @purcell, and I tend to agree. So now, there are
six faces that inherit highlight
, isearch-lazy-highlight-face
, isearch
and match
faces
between them. The advantage is that most themes re-define the above four faces as they see fit, so
the swiper faces will fit in better without customization.
Still, I really enjoy the previous faces that were derived from the Swiper sprite. You can have them as part of eclipse-theme. The theme creators can just copy them verbatim to a light theme if they so choose.
By the way, it seems that not all Emacs users are aware that you can customize faces. You can do so
interactively for most popular packages. For example, after M-x customize-group
swiper
, you get a GUI for selecting most configurable things for swiper
, including the faces.
The GUI will generate the code that looks something like this:
(custom-set-faces
'(ivy-current-match ((t (:background "#e5b7c0")))))
Elisp completion with ivy
The code to complete Elisp code at point is very simple:
(defun counsel ()
"Elisp completion at point."
(interactive)
(let* ((bnd (bounds-of-thing-at-point 'symbol))
(str (buffer-substring-no-properties (car bnd) (cdr bnd)))
(candidates (all-completions str obarray))
(ivy-height 7)
(res (ivy-read (format "pattern (%s): " str)
candidates)))
(when (stringp res)
(delete-region (car bnd) (cdr bnd))
(insert res))))
The only function above that isn't one of the familiar primitives is ivy-read
. But even that one
has a similar interface to that of completing-read
or ido-completing-read
. I was using
helm-lisp-completion-at-point
before, but counsel
is much less obtrusive, while offering
comparable speed and convenience:
The default minibuffer height for ivy
is set to 10 via ivy-height
. It's quite reasonable all-around, but
for counsel
I've set it to 7 via a let binding.