;; Author: Oleh Krehel <ohwoeowho@gmail.com>
;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.3.0
+;; Version: 0.4.0
;; Package-Requires: ((emacs "24.1"))
;; Keywords: matching
;; candidates. The search regex can be split into groups with a
;; space. Each group is highlighted with a different face.
;;
-;; The overview back end is `ivy'.
-;;
;; It can double as a quick `regex-builder', although only single
;; lines will be matched.
+;;
+;; It also provides `ivy-mode': a global minor mode that uses the
+;; matching back end of `swiper' for all matching on your system,
+;; including file matching. You can use it in place of `ido-mode'
+;; (can't have both on at once).
;;; Code:
(require 'ivy)
(defface swiper-match-face-1
'((t (:inherit isearch-lazy-highlight-face)))
- "Face for `swiper' matches.")
+ "The background face for `swiper' matches.")
(defface swiper-match-face-2
'((t (:inherit isearch)))
- "Face for `swiper' matches.")
+ "Face for `swiper' matches modulo 1.")
(defface swiper-match-face-3
'((t (:inherit match)))
- "Face for `swiper' matches.")
+ "Face for `swiper' matches modulo 2.")
(defface swiper-match-face-4
- '((t (:inherit isearch)))
- "Face for `swiper' matches.")
+ '((t (:inherit isearch-fail)))
+ "Face for `swiper' matches modulo 3.")
(defface swiper-line-face
'((t (:inherit highlight)))
(from (ivy--regex ivy-text))
(to (query-replace-read-to from "Query replace" t)))
(delete-minibuffer-contents)
- (setq ivy--action
- (lambda ()
- (with-selected-window swiper--window
- (perform-replace from to
- t t nil))))
+ (ivy-set-action (lambda ()
+ (with-selected-window swiper--window
+ (perform-replace from to
+ t t nil))))
(swiper--cleanup)
(exit-minibuffer))))
emms-playlist-mode erc-mode
org-agenda-mode
dired-mode
- jabber-chat-mode)))
+ jabber-chat-mode
+ elfeed-search-mode)))
(unless (> (buffer-size) 100000)
(if (fboundp 'font-lock-ensure)
(font-lock-ensure)
(setq swiper--opoint (point))
(setq swiper--len 0)
(setq swiper--anchor (line-number-at-pos))
- (setq swiper--window (selected-window)))
+ (setq swiper--window (selected-window))
+ (setq ivy--regex-function
+ (cdr (assoc t ivy-re-builders-alist))))
(defun swiper--ivy (&optional initial-input)
"`isearch' with an overview using `ivy'.
:keymap swiper-map
:preselect preselect
:require-match t
- :update-fn #'swiper--update-input-ivy))
- (swiper--cleanup)
+ :update-fn #'swiper--update-input-ivy
+ :unwind #'swiper--cleanup))
(if (null ivy-exit)
(goto-char swiper--opoint)
(swiper--action res ivy-text)))))
(defun swiper--update-input-ivy ()
"Called when `ivy' input is updated."
(swiper--cleanup)
- (let* ((re (ivy--regex ivy-text))
+ (let* ((re (funcall ivy--regex-function ivy-text))
(str ivy--current)
(num (if (string-match "^[0-9]+" str)
(string-to-number (match-string 0 str))
(match-end i)))
(face
(cond ((zerop ivy--subexps)
- (cl-caddr swiper-faces))
+ (cadr swiper-faces))
((zerop i)
(car swiper-faces))
(t
- (nth (1+ (mod (1- i) (1- (length swiper-faces))))
+ (nth (1+ (mod (+ i 2) (1- (length swiper-faces))))
swiper-faces)))))
(push overlay swiper--overlays)
(overlay-put overlay 'face face)
(goto-char (point-min))
(forward-line (1- (read x)))
(re-search-forward
- (ivy--regex input) (line-end-position) t)
+ (funcall ivy--regex-function input) (line-end-position) t)
(swiper--ensure-visible)
(when (/= (point) swiper--opoint)
(unless (and transient-mark-mode mark-active)