unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* M-y in isearch mode
@ 2011-05-02 13:59 Leo
  2011-05-02 16:27 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Leo @ 2011-05-02 13:59 UTC (permalink / raw)
  To: emacs-devel

Hello all,

I would like to propose binding M-y to a new command isearch-yank-pop as
in the attached patch. Please review it.

Thanks - Leo

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2011-04-19 13:44:55 +0000
+++ lisp/isearch.el	2011-05-02 13:51:48 +0000
@@ -473,7 +473,7 @@
 
     (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-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 @@
   (interactive)
   (isearch-yank-string (current-kill 0)))
 
+(defun isearch-yank-pop ()
+  "Replace just-yanked search string with previously killed string.
+This command is allowed only immediately after a
+`isearch-yank-kill' or `isearch-yank-pop'."
+  (interactive)
+  (if (not (memq last-command '(isearch-yank-kill isearch-yank-pop)))
+      (let ((isearch-message-suffix-add
+	     " [previous isearch command was not a yank]"))
+	(isearch-update))
+    (isearch-pop-state)
+    (isearch-yank-string (current-kill 1))))
+
 (defun isearch-yank-x-selection ()
   "Pull current X selection into search string."
   (interactive)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: M-y in isearch mode
  2011-05-02 13:59 M-y in isearch mode Leo
@ 2011-05-02 16:27 ` Stefan Monnier
  2011-05-02 16:51   ` Leo
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-05-02 16:27 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

> I would like to propose binding M-y to a new command isearch-yank-pop as
> in the attached patch. Please review it.

Now that C-y is bound to isearch-yank-kill, it would indeed make sense
for M-y to match the behavior of M-y outside isearch.

But maybe for compatibility with old "finger memory", we should allow
a M-y that does not follow isearch-yank-kill isearch-yank-pop.
I.e. rather than signal a "previous isearch command was not a yank", we
should simply turn it into an isearch-yank-kill.
WDYT?


        Stefan


> === modified file 'lisp/isearch.el'
> --- lisp/isearch.el	2011-04-19 13:44:55 +0000
> +++ lisp/isearch.el	2011-05-02 13:51:48 +0000
> @@ -473,7 +473,7 @@
 
>      (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-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 @@
>    (interactive)
>    (isearch-yank-string (current-kill 0)))
 
> +(defun isearch-yank-pop ()
> +  "Replace just-yanked search string with previously killed string.
> +This command is allowed only immediately after a
> +`isearch-yank-kill' or `isearch-yank-pop'."
> +  (interactive)
> +  (if (not (memq last-command '(isearch-yank-kill isearch-yank-pop)))
> +      (let ((isearch-message-suffix-add
> +	     " [previous isearch command was not a yank]"))
> +	(isearch-update))
> +    (isearch-pop-state)
> +    (isearch-yank-string (current-kill 1))))
> +
>  (defun isearch-yank-x-selection ()
>    "Pull current X selection into search string."
>    (interactive)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: M-y in isearch mode
  2011-05-02 16:27 ` Stefan Monnier
@ 2011-05-02 16:51   ` Leo
  2011-05-02 18:16     ` Stefan Monnier
  2011-05-02 21:21     ` Chong Yidong
  0 siblings, 2 replies; 6+ messages in thread
From: Leo @ 2011-05-02 16:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 2011-05-03 00:27 +0800, Stefan Monnier wrote:
> Now that C-y is bound to isearch-yank-kill, it would indeed make sense
> for M-y to match the behavior of M-y outside isearch.
>
> But maybe for compatibility with old "finger memory", we should allow
> a M-y that does not follow isearch-yank-kill isearch-yank-pop.
> I.e. rather than signal a "previous isearch command was not a yank", we
> should simply turn it into an isearch-yank-kill.
> WDYT?

Sounds good. Patch modified to this suggestion.

diff --git a/lisp/isearch.el b/lisp/isearch.el
index e59fb29a..04d41af2 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -472,7 +472,7 @@ (defvar isearch-mode-map
 
     (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)
 
@@ -636,6 +636,8 @@ (defun isearch-forward (&optional regexp-p no-recursive-edit)
 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
@@ -1499,6 +1501,14 @@ (defun isearch-yank-kill ()
   (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)))
+      (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)




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: M-y in isearch mode
  2011-05-02 16:51   ` Leo
@ 2011-05-02 18:16     ` Stefan Monnier
  2011-05-03  3:41       ` Leo
  2011-05-02 21:21     ` Chong Yidong
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-05-02 18:16 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

> Sounds good. Patch modified to this suggestion.

Fell free to commit.

> +(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)))
> +      (isearch-yank-kill)

You can add a short comment here explaining why we do this fallback (and
we may want to change this fallback in the future if we ever change
yank-pop to do something like the kill-ring-browser).


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: M-y in isearch mode
  2011-05-02 16:51   ` Leo
  2011-05-02 18:16     ` Stefan Monnier
@ 2011-05-02 21:21     ` Chong Yidong
  1 sibling, 0 replies; 6+ messages in thread
From: Chong Yidong @ 2011-05-02 21:21 UTC (permalink / raw)
  To: Leo; +Cc: Stefan Monnier, emacs-devel

Leo <sdl.web@gmail.com> writes:

> Sounds good. Patch modified to this suggestion.

Looks OK to me.  Don't forget to add a NEWS entry.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: M-y in isearch mode
  2011-05-02 18:16     ` Stefan Monnier
@ 2011-05-03  3:41       ` Leo
  0 siblings, 0 replies; 6+ messages in thread
From: Leo @ 2011-05-03  3:41 UTC (permalink / raw)
  To: emacs-devel

On 2011-05-03 02:16 +0800, Stefan Monnier wrote:
[...]
> You can add a short comment here explaining why we do this fallback (and
> we may want to change this fallback in the future if we ever change
> yank-pop to do something like the kill-ring-browser).

Added.

On 2011-05-03 05:21 +0800, Chong Yidong wrote:
[...]
> Looks OK to me.  Don't forget to add a NEWS entry.

Committed in revno: 104087.

Leo




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-05-03  3:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-02 13:59 M-y in isearch mode Leo
2011-05-02 16:27 ` Stefan Monnier
2011-05-02 16:51   ` Leo
2011-05-02 18:16     ` Stefan Monnier
2011-05-03  3:41       ` Leo
2011-05-02 21:21     ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).