Swiper 0.2.0 is out25 Mar 2015
I forgot to mark the
0.1.0 release, so I'm giving an overview of all the fixes and new features
since the first commit in the release notes.
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:
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
copy-sequence) was propagated to the properties of the original string. This was fixed by using
font-lock-append-text-property instead of
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
erc-mode, since it marks all of the buffer
read-only. So once a string with
read-only property is inserted into the minibuffer,
you can't delete it unless you set
Optional initial input
If you call
(swiper "fix"), you'll start searching with initial input
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:
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
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 (
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
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
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
Custom amount of chars to start highlighting
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.
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.
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-%.
Although there are worse bindings than M-% (hold three keys at once), for instance, there's
C-M-% (hold four keys at once) that calls
Enjoy the new features, and a big thanks to all who contributed!