New command isearch-yank-pop and bind it to `M-y' in Isearch
authorLeo Liu <sdl.web@gmail.com>
Tue, 3 May 2011 03:34:26 +0000 (11:34 +0800)
committerLeo Liu <sdl.web@gmail.com>
Tue, 3 May 2011 03:34:26 +0000 (11:34 +0800)
etc/ChangeLog
etc/NEWS
lisp/ChangeLog
lisp/isearch.el

index f7e40aa..0eb2140 100644 (file)
@@ -1,3 +1,7 @@
+2011-05-03  Leo Liu  <sdl.web@gmail.com>
+
+       * NEWS: Mention the new command isearch-yank-pop.
+
 2011-05-03  Teodor Zlatanov  <tzz@lifelogs.com>
 
        * NEWS: Mention new library gnutls.el and explain GnuTLS
index 8aa503c..5094ecf 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -281,6 +281,10 @@ replaced with Lisp commands `doc-file-to-man' and `doc-file-to-info'.
 *** C-y in Isearch is now bound to isearch-yank-kill, instead of
 isearch-yank-line.
 
+---
+*** M-y in Isearch is now bound to isearch-yank-pop, instead of
+isearch-yank-kill.
+
 +++
 *** M-s C-e in Isearch is now bound to isearch-yank-line.
 
index 63fef4f..aa9052a 100644 (file)
@@ -1,3 +1,9 @@
+2011-05-03  Leo Liu  <sdl.web@gmail.com>
+
+       * isearch.el (isearch-yank-pop): New command.
+       (isearch-mode-map): bind it to `M-y'.
+       (isearch-forward): Mention it.
+
 2011-05-03  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * simple.el (minibuffer-complete-shell-command): Remove.
index 1e6ac9c..7db7f30 100644 (file)
@@ -473,7 +473,7 @@ This is like `describe-bindings', but displays only Isearch keys."
 
     (define-key map "\M-n" 'isearch-ring-advance)
     (define-key map "\M-p" 'isearch-ring-retreat)
-    (define-key map "\M-y" 'isearch-yank-kill)
+    (define-key map "\M-y" 'isearch-yank-pop)
 
     (define-key map "\M-\t" 'isearch-complete)
 
@@ -637,6 +637,8 @@ Type \\[isearch-yank-char] to yank char from buffer onto end of search\
 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
  and search for it.
 Type \\[isearch-yank-kill] to yank the last string of killed text.
+Type \\[isearch-yank-pop] to replace string just yanked into search prompt
+ with string killed before it.
 Type \\[isearch-quote-char] to quote control character to search for it.
 \\[isearch-abort] while searching or when search has failed cancels input\
  back to what has
@@ -1497,6 +1499,18 @@ If search string is empty, just beep."
   (interactive)
   (isearch-yank-string (current-kill 0)))
 
+(defun isearch-yank-pop ()
+  "Replace just-yanked search string with previously killed string."
+  (interactive)
+  (if (not (memq last-command '(isearch-yank-kill isearch-yank-pop)))
+      ;; Fall back on `isearch-yank-kill' for the benefits of people
+      ;; who are used to the old behavior of `M-y' in isearch mode. In
+      ;; future, this fallback may be changed if we ever change
+      ;; `yank-pop' to do something like the kill-ring-browser.
+      (isearch-yank-kill)
+    (isearch-pop-state)
+    (isearch-yank-string (current-kill 1))))
+
 (defun isearch-yank-x-selection ()
   "Pull current X selection into search string."
   (interactive)