;;; swiper.el --- Isearch with an overview. Oh, man! -*- lexical-binding: t -*-
-;; Copyright (C) 2015 Oleh Krehel
+;; Copyright (C) 2015 Free Software Foundation, Inc.
;; Author: Oleh Krehel <ohwoeowho@gmail.com>
;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.1.0
+;; Version: 0.2.0
;; Package-Requires: ((emacs "24.1") (ivy "0.1.0"))
;; Keywords: matching
-;; This file is not part of GNU Emacs
+;; This file is part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
"Only highlight matches for regexps at least this long."
:type 'integer)
+(defvar swiper-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "M-q") 'swiper-query-replace)
+ (define-key map (kbd "C-l") 'swiper-recenter-top-bottom)
+ map)
+ "Keymap for swiper.")
+
+(defun swiper-query-replace ()
+ "Start `query-replace' with string to replace from last search string."
+ (interactive)
+ (if (null (window-minibuffer-p))
+ (user-error "Should only be called in the minibuffer through `swiper-map'")
+ (let* ((enable-recursive-minibuffers t)
+ (from (ivy--regex ivy-text))
+ (to (query-replace-read-to from "Query replace" t)))
+ (delete-minibuffer-contents)
+ (setq ivy--action
+ (lambda ()
+ (perform-replace from to
+ t t t)))
+ (swiper--cleanup)
+ (exit-minibuffer))))
+
+(defun swiper-recenter-top-bottom (&optional arg)
+ "Call (`recenter-top-bottom' ARG) in `swiper--window'."
+ (interactive "P")
+ (with-selected-window swiper--window
+ (recenter-top-bottom arg)))
+
(defvar swiper--window nil
"Store the current window.")
(defun swiper-font-lock-ensure ()
"Ensure the entired buffer is highlighted."
(unless (or (derived-mode-p 'magit-mode)
- (memq major-mode '(package-menu-mode emms-playlist-mode)))
+ (memq major-mode '(package-menu-mode
+ gnus-summary-mode
+ gnus-article-mode
+ gnus-group-mode
+ emms-playlist-mode erc-mode)))
(if (fboundp 'font-lock-ensure)
(font-lock-ensure)
(font-lock-fontify-buffer))))
(line-beginning-position)
(line-end-position)))
candidates)
- (zerop (forward-line 1)))
+ (forward-line 1))
(nreverse candidates))))))
(defvar swiper--opoint 1
"%s" "pattern: " swiper--format-spec)
candidates
initial-input
- #'swiper--update-input-ivy
- preselect))
+ swiper-map
+ preselect
+ #'swiper--update-input-ivy))
(ido-mode 1)
(swiper--cleanup)
(if (null ivy-exit)
(forward-line (1- num))
(isearch-range-invisible (line-beginning-position)
(line-end-position))
- (unless (and (> (point) (window-start))
- (< (point) (window-end swiper--window t)))
+ (unless (and (>= (point) (window-start))
+ (<= (point) (window-end swiper--window t)))
(recenter)))
(let ((ov (make-overlay
(line-beginning-position)