Abo Abo Swiper Versions Save

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!

0.3.0

9 years ago

One important change related to MELPA is that the ivy package was merged into swiper package. So if you still have a stand-alone ivy package, you should delete it, or you'll get incompatibility problems.

Fixes

Add work-around for window-start being not current

From now on, you won't encounter some un-highlighted matches when your window is scrolled.

Make thing-at-point work

C-h v and C-h f should select thing-at-point properly.

Don't try to fontify huge buffers

It's a nice feature of swiper that everything in the minibuffer is fontified. However, this can cause a slowdown for buffers with x10000 lines. So this feature is automatically turned off for these large buffers.

Exclude a few modes from font locking

Some modes just misbehave when font-lock-ensure is called. Excluded:

  • org-agenda-mode
  • dired-mode

New Features

ivy-mode: complete everything with Ivy

ivy-mode uses swiper's approach to completion for almost all completion in Emacs, like:

  • execute-extended-command
  • package-install
  • find-file

See the wiki page for the details on the key bindings related to ivy-mode, which are especially important to know for find-file. Also see the intro video.

New Counsel functions

  • counsel-describe-variable - replacement for C-h v.
  • counsel-describe-function - replacement for C-h f.
  • counsel-info-lookup-symbol - just a wrapper around info-lookup-symbol, you get the same behavior by just calling info-lookup-symbol with ivy-mode on.
  • counsel-unicode-char - replacement for ucs-insert.

counsel-git-grep

This is a really cool command for grepping at once all the files in your current git repository. For smaller repositories (<20000) lines, ivy handles the completion by itself. For larger repositories, it defers the work to git grep. It works really well for the Emacs repo with its 3,000,000 lines, especially if you're using Emacs 25 (from emacs-snapshot or self-built).

This function makes use of C-M-n and C-M-p bindings, which switch between candidates without exiting the minibuffer. Also, they highlight the current candidate with the swiper faces. You can think of this command as multi-swiper.

Even for very large repos, it will always display the amount of matches correctly. Also note that swiper-style regex is used here (spaces are wild), and the case is ignored.

The arrows can take numeric arguments

C-n / C-p, C-s / C-r, and C-M-n / C-M-p can all take numeric args, e.g. M-5 or C-u.

Add a recenter binding

C-l will recenter the window in which swiper was called.

Look up Ivy key bindings with C-h m

While in the minibuffer, press C-h m to see the active modes. Ivy also has a paragraph with its bindings.

Use C-v and M-v to scroll

You can use these bindings to speed up your minibuffer scrolling.

Allow C-. to jump-to-definition

For counsel-describe-variable and counsel-describe-function:

  • pressing C-m will actually describe the current candidate.
  • pressing C-. will instead jump to definition of the the current candidate.

This is very useful for me, I jump to definitions more often that describe.

Bind arrows

The actual arrow keys are also bound to the corresponding Emacs arrows.

Add a way to exit ignoring the candidates

If your current input matches a candidate, C-m and C-j will exit with that candidate. If you want to exit with your exact input instead, press C-u C-j. This is very useful for creating new files and directories.

Use M-q to toggle regexp-quote

This can be useful while completing file names (with a lot of dots). Pressing M-q toggles between regex and non-regex matching.

Customize ivy-re-builders-alist

This is pretty intricate, look up the variable to see the details. In short, you can use this to apply `regexp-quote' for some types of completion if you want.

Customize what to do on DEL error

The standard behavior on a DEL error (usually empty minibuffer) is to exit the minibuffer. I like this behavior, since it's similar to the behavior to fixing wrongly typed chars: only in this case DEL "fixes" a wrongly typed command.

But if you want to customize it, just set ivy-on-del-error-function to something other than minibuffer-keyboard-quit.

Customize ivy-extra-directories

Customize this if you don't want to see ../ and ./ while completing file names.

Customize ivy-sort-functions-alist

Use this variable to customize sorting, depending on what you're completing. For example:

(setq ivy-sort-functions-alist
  '((read-file-name-internal . ivy-sort-file-function-default)
    (internal-complete-buffer . nil)
    (counsel-git-grep-function . nil)
    (t . string-lessp)))

Customize ivy-subdir-face

While completing file names, the directories will use ivy-subdir-face.

0.2.0

9 years ago

Fixes

Fix font locking in certain modes

Some major modes try to optimize the font locking (highlighting text with various faces) by only doing it for the visible portion of the text. But since swiper needs to access all lines at once, it's necessary to font lock the whole buffer. This is done in swiper-font-lock-ensure. For some modes, the buffer becomes discolored after calling swiper-font-lock-ensure. In theory, this should not happen. As a work-around, I exclude these modes from ensuring font lock:

  • package-menu-mode
  • gnus-summary-mode
  • gnus-article-mode
  • gnus-group-mode
  • emms-playlist-mode
  • erc-mode

If you see a discoloration in one of your favorite major modes while using swiper, just let me know and I'll add it to the list.

Fix face changes in the minibuffer propagating to the main buffer

This was a quite interesting bug. At that moment, I was using add-face-text-property to add faces to the copies of strings in the minibuffer. However, this function destructively modifies the properties, so the change to the properties of a string copy (obtained with concat or copy-sequence) was propagated to the properties of the original string. This was fixed by using font-lock-append-text-property instead of add-face-text-property.

ivy-read returns immediately for 0-1 candidates

An obvious improvement.

Clean up overlays better for C-g

The hidden overlays revealed during the search will be re-hidden if you cancel the search with C-g.

Ensure that candidates don't have read-only property

This issue was causing a bug while using swiper in erc-mode, since it marks all of the buffer content to read-only. So once a string with read-only property is inserted into the minibuffer, you can't delete it unless you set inhibit-read-only.

New Features

Optional initial input

If you call (swiper "fix"), you'll start searching with initial input "fix".

Restore the initial point on canceling

If you cancel the search with e.g. C-g (or DEL when there's no input), the initial point will be restored.

Inherit standard faces

To give a more standard default appearance, swiper faces inherit the default faces:

  • isearch-lazy-highlight-face
  • isearch
  • match
  • isearch again
  • highlight

Most themes customize these faces, so by re-using them swiper blends in better. If you want the cool (my opinion) original faces, have a look at eclipse-theme.

Reveal invisible overlays

This is quite important for searches in org-mode buffers. I tried to make it as close as possible to what isearch is doing.

Mark is saved for successful searches

This is the behavior of isearch. After you complete a search, you can go back to the search start with C-x C-SPC (pop-global-mark).

The current candidate is anchored to the current position

This means that if many candidates are matching the current input, the one which is closest to the current line (going forwards) is selected. This is important for not losing the context of what you're searching.

Don't recenter unless necessary

This is similar to the behavior of isearch: a scroll is performed only if the candidate is out of the window bounds. An alternate strategy of keeping the current candidate always centered in the window is more distracting.

Decouple helm back end

swiper command uses only ivy now. If you want to use helm, have a look at swiper-helm.

Add history handling

M-n will select the next history element, and M-p will select the previous history element.

When there is no input, both C-s and C-r will select the last history element. This is to make it similar to isearch.

When there is no input, and only once during the search, M-n will select symbol-at-point as the current input.

Truncate candidates to window width in the minibuffer

If a candidate is longer than the window width, it will be appropriately truncated with .... You can still match the invisible parts.

Warn for empty buffer

Obviously there's nothing to search for in an empty buffer.

Bring the last history candidate to front

In case of a successful search, the current input will be removed from history, and then re-added to the front.

Make C-n and C-p differ from C-s and C-r

The arrows will not recall the last history element in case the input is empty. Otherwise, C-n matches to C-s and C-p matches to C-r.

ivy-read now displays the number of candidates in the prompt

The prompt argument can hold a format-style expression, e.g. " [% 3d] pattern:", and the integer parameter will be updated with the current amount of matches. You can also customize ivy-count-format, that defaults to "%-4d ".

Custom amount of chars to start highlighting

Customize swiper-min-highlight for this. It defaults to 2, which means that the current buffer will be highlighted when the input has 2 chars or more. You can set it to 1 if you want, I found it slightly distracting, since there will be a lot of highlights for just one char input. Or you can set it to a larger value if you want the highlights to appear later.

Customize wrapping for C-n and C-p

This feature being on by default in helm-swoop was very distracting for me, and one of the reasons that I wrote swiper. So it's off by default, but you can set it if you want. Calling C-p on line number 0 will cycle to the last candidate etc.

Since swiper was added to GNU ELPA, I had to assign the Copyright to the FSF. This also means that you also need an FSF Copyright assignment for Emacs in order to contribute more than total of 15 lines to the swiper code. It's really easy to get and is already necessary to contribute to any package that is part of Emacs.

Add swiper-query-replace

You can start a query replace operation starting with the current candidate with M-q. If you want to query replace in whole buffer, just do M-< M-q. And remember that ! will auto-replace all matches for the current query.

The default binding of M-q is fill-paragraph. This function is useless in the minibuffer, so I chose that binding for query-replace, which is normally bound to sub-optimal M-%.