-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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.
- Loading branch information
Showing
3 changed files
with
54 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
;; Author: Oleh Krehel <[email protected]> | ||
;; 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." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
;; Author: Oleh Krehel <[email protected]> | ||
;; 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) | ||
|
fdb0c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swiper replace deletes the current buffer contents:
From the doc string of
delete-minibuffer-contents
:Also the
(exit-minibuffer)
call throws an error as the point isn't yet in the minibufferfdb0c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it needs a fail safe so that a user doesn't try calling directly using
M-x
but only executes it using theswiper-map
bindingM-q
after activating swiperfdb0c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing, fixed.
fdb0c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abo-abo: Weird, I am getting this error when pressing
M-q
:query-replace-read-to: Command attempted to use minibuffer while in minibuffer.
Any idea?
fdb0c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. Can you try to reliably reproduce it, then raise an issue with a recipe?