[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fdb0c45 4/7: Add swiper-query-replace
From: |
Oleh Krehel |
Subject: |
[elpa] master fdb0c45 4/7: Add swiper-query-replace |
Date: |
Thu, 26 Mar 2015 11:30:31 +0000 |
branch: master
commit fdb0c4506ebedc0028decee8ec411863bb93c2ac
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add swiper-query-replace
* ivy.el (ivy-read): Update signature - a keymap is also accepted and
the argument order has changed.
The keymap is composed with `ivy-minibuffer-map'.
Update for `ivy--action'.
(ivy--action): New defvar. If a function sets it, `ivy-read' will call it.
* swiper.el (swiper-map): New defvar.
(swiper-query-replace): New defun.
(swiper--ivy): Use swiper-map in the call to `ivy-read'.
* counsel.el (couns-git): Fix one empty candidate.
---
counsel.el | 3 ++-
ivy.el | 46 ++++++++++++++++++++++++++++------------------
swiper.el | 27 ++++++++++++++++++++++++---
3 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/counsel.el b/counsel.el
index 07d9a66..28d10bd 100644
--- a/counsel.el
+++ b/counsel.el
@@ -51,7 +51,8 @@
(cands (split-string
(shell-command-to-string
"git ls-files --full-name --")
- "\n"))
+ "\n"
+ t))
(file (ivy-read "Find file: " cands)))
(when file
(find-file file))))
diff --git a/ivy.el b/ivy.el
index a06b50c..180f081 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4,7 +4,7 @@
;; Author: Oleh Krehel <address@hidden>
;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.1.0
+;; Version: 0.2.0
;; Package-Requires: ((emacs "24.1"))
;; Keywords: matching
@@ -165,7 +165,8 @@ On error (read-only), quit without selecting."
(minibuffer-keyboard-quit))))
;;** Entry Point
-(defun ivy-read (prompt collection &optional initial-input update-fn preselect)
+(defun ivy-read (prompt collection
+ &optional initial-input keymap preselect update-fn)
"Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon
@@ -179,7 +180,9 @@ If INITIAL-INPUT is non-nil, insert it in the minibuffer
initially.
UPDATE-FN is called each time the current candidate(s) is changed.
If PRESELECT is non-nil select the corresponding candidate out of
-the ones that match INITIAL-INPUT."
+the ones that match INITIAL-INPUT.
+
+KEYMAP is composed together with `ivy-minibuffer-map'."
(cl-case (length collection)
(0 nil)
(1 (car collection))
@@ -203,21 +206,28 @@ the ones that match INITIAL-INPUT."
(concat ivy-count-format prompt))
(t
nil)))
- (unwind-protect
- (minibuffer-with-setup-hook
- #'ivy--minibuffer-setup
- (let ((res (read-from-minibuffer
- prompt
- initial-input
- ivy-minibuffer-map
- nil
- 'ivy-history)))
- (when (eq ivy-exit 'done)
- (pop ivy-history)
- (setq ivy-history
- (cons ivy-text (delete ivy-text ivy-history)))
- res)))
- (remove-hook 'post-command-hook #'ivy--exhibit)))))
+ (setq ivy--action nil)
+ (prog1
+ (unwind-protect
+ (minibuffer-with-setup-hook
+ #'ivy--minibuffer-setup
+ (let ((res (read-from-minibuffer
+ prompt
+ initial-input
+ (make-composed-keymap keymap ivy-minibuffer-map)
+ nil
+ 'ivy-history)))
+ (when (eq ivy-exit 'done)
+ (pop ivy-history)
+ (setq ivy-history
+ (cons ivy-text (delete ivy-text ivy-history)))
+ res)))
+ (remove-hook 'post-command-hook #'ivy--exhibit))
+ (when ivy--action
+ (funcall ivy--action))))))
+
+(defvar ivy--action nil
+ "Store a function to call at the end of `ivy--read'.")
(defun ivy--preselect-index (candidates initial-input preselect)
"Return the index in CANDIDATES filtered by INITIAL-INPUT for PRESELECT."
diff --git a/swiper.el b/swiper.el
index 2492d95..6fa2f55 100644
--- a/swiper.el
+++ b/swiper.el
@@ -4,7 +4,7 @@
;; Author: Oleh Krehel <address@hidden>
;; 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
@@ -72,6 +72,26 @@
"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)
+ map)
+ "Keymap for swiper.")
+
+(defun swiper-query-replace ()
+ "Start `query-replace' with string to replace from last search string."
+ (interactive)
+ (delete-minibuffer-contents)
+ (setq ivy--action
+ (lambda ()
+ (let ((from (ivy--regex ivy-text)))
+ (perform-replace
+ from
+ (query-replace-read-to from "Query replace" t)
+ t t t))))
+ (swiper--cleanup)
+ (exit-minibuffer))
+
(defvar swiper--window nil
"Store the current window.")
@@ -150,8 +170,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
"%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)
- [elpa] master updated (90473ac -> 0c2da66), Oleh Krehel, 2015/03/26
- [elpa] master 2ae5b9c 3/7: swiper.el (swiper-font-lock-ensure): Ignore gnus modes, Oleh Krehel, 2015/03/26
- [elpa] master abb6e0b 5/7: swiper.el (swiper-query-replace): Call only in minibuffer, Oleh Krehel, 2015/03/26
- [elpa] master 764e003 1/7: swiper.el (swiper-font-lock-ensure): Omit erc-mode, Oleh Krehel, 2015/03/26
- [elpa] master fdb0c45 4/7: Add swiper-query-replace,
Oleh Krehel <=
- [elpa] master d63ce8f 2/7: Ensure that inserted candidates don't have read-only property, Oleh Krehel, 2015/03/26
- [elpa] master 0c2da66 7/7: Merge commit 'ce516073e5e4359b88f98610bae9b157945eb8e8' from swiper, Oleh Krehel, 2015/03/26
- [elpa] master ce51607 6/7: Allow to cancel "M-q" with "C-g", Oleh Krehel, 2015/03/26