unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* yank-pop error unnecessary and annoying
@ 2010-06-14 16:00 Geoff Gole
  2010-06-14 16:20 ` Juri Linkov
  2010-06-14 22:16 ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Geoff Gole @ 2010-06-14 16:00 UTC (permalink / raw)
  To: Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 3645 bytes --]

If called without a previous yank, yank-pop will produce an error
message and do nothing useful. Why doesn't it just fall back on yank
instead?

diff -c -L /usr/local/share/emacs/23.1.50/lisp/simple.el.gz -L
/tmp/buffer-content-5442SIK /tmp/jka-com5442fSQ
/tmp/buffer-content-5442SIK
*** /usr/local/share/emacs/23.1.50/lisp/simple.el.gz
--- /tmp/buffer-content-5442SIK
***************
*** 3034,3043 ****

  (defun yank-pop (&optional arg)
    "Replace just-yanked stretch of killed text with a different stretch.
! This command is allowed only immediately after a `yank' or a `yank-pop'.
! At such a time, the region contains a stretch of reinserted
! previously-killed text.  `yank-pop' deletes that text and inserts in its
! place a different stretch of killed text.

  With no argument, the previous kill is inserted.
  With argument N, insert the Nth previous kill.
--- 3034,3040 ----

  (defun yank-pop (&optional arg)
    "Replace just-yanked stretch of killed text with a different stretch.
! If there is no such killed text, simply yank.

  With no argument, the previous kill is inserted.
  With argument N, insert the Nth previous kill.
***************
*** 3050,3077 ****
  `yank-excluded-properties' and `yank-handler' as described in the
  doc string for `insert-for-yank-1', which see."
    (interactive "*p")
-   (if (not (eq last-command 'yank))
-       (error "Previous command was not a yank"))
    (setq this-command 'yank)
!   (unless arg (setq arg 1))
!   (let ((inhibit-read-only t)
! 	(before (< (point) (mark t))))
!     (if before
! 	(funcall (or yank-undo-function 'delete-region) (point) (mark t))
!       (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
!     (setq yank-undo-function nil)
!     (set-marker (mark-marker) (point) (current-buffer))
!     (insert-for-yank (current-kill arg))
!     ;; Set the window start back where it was in the yank command,
!     ;; if possible.
!     (set-window-start (selected-window) yank-window-start t)
!     (if before
! 	;; This is like exchange-point-and-mark, but doesn't activate the mark.
! 	;; It is cleaner to avoid activation, even though the command
! 	;; loop would deactivate the mark because we inserted text.
! 	(goto-char (prog1 (mark t)
! 		     (set-marker (mark-marker) (point) (current-buffer))))))
!   nil)

  (defun yank (&optional arg)
    "Reinsert (\"paste\") the last stretch of killed text.
--- 3047,3074 ----
  `yank-excluded-properties' and `yank-handler' as described in the
  doc string for `insert-for-yank-1', which see."
    (interactive "*p")
    (setq this-command 'yank)
!   (if (not (eq last-command 'yank))
!       (yank arg)
!     (unless arg (setq arg 1))
!     (let ((inhibit-read-only t)
! 	  (before (< (point) (mark t))))
!       (if before
! 	  (funcall (or yank-undo-function 'delete-region) (point) (mark t))
! 	(funcall (or yank-undo-function 'delete-region) (mark t) (point)))
!       (setq yank-undo-function nil)
!       (set-marker (mark-marker) (point) (current-buffer))
!       (insert-for-yank (current-kill arg))
!       ;; Set the window start back where it was in the yank command,
!       ;; if possible.
!       (set-window-start (selected-window) yank-window-start t)
!       (if before
! 	  ;; This is like exchange-point-and-mark, but doesn't activate the mark.
! 	  ;; It is cleaner to avoid activation, even though the command
! 	  ;; loop would deactivate the mark because we inserted text.
! 	  (goto-char (prog1 (mark t)
! 		       (set-marker (mark-marker) (point) (current-buffer))))))
!     nil))

  (defun yank (&optional arg)
    "Reinsert (\"paste\") the last stretch of killed text.

[-- Attachment #2: yank-pop-yank-not-error.patch --]
[-- Type: text/x-diff, Size: 3554 bytes --]

diff -c -L /usr/local/share/emacs/23.1.50/lisp/simple.el.gz -L /tmp/buffer-content-5442SIK /tmp/jka-com5442fSQ /tmp/buffer-content-5442SIK
*** /usr/local/share/emacs/23.1.50/lisp/simple.el.gz
--- /tmp/buffer-content-5442SIK
***************
*** 3034,3043 ****
  
  (defun yank-pop (&optional arg)
    "Replace just-yanked stretch of killed text with a different stretch.
! This command is allowed only immediately after a `yank' or a `yank-pop'.
! At such a time, the region contains a stretch of reinserted
! previously-killed text.  `yank-pop' deletes that text and inserts in its
! place a different stretch of killed text.
  
  With no argument, the previous kill is inserted.
  With argument N, insert the Nth previous kill.
--- 3034,3040 ----
  
  (defun yank-pop (&optional arg)
    "Replace just-yanked stretch of killed text with a different stretch.
! If there is no such killed text, simply yank.
  
  With no argument, the previous kill is inserted.
  With argument N, insert the Nth previous kill.
***************
*** 3050,3077 ****
  `yank-excluded-properties' and `yank-handler' as described in the
  doc string for `insert-for-yank-1', which see."
    (interactive "*p")
-   (if (not (eq last-command 'yank))
-       (error "Previous command was not a yank"))
    (setq this-command 'yank)
!   (unless arg (setq arg 1))
!   (let ((inhibit-read-only t)
! 	(before (< (point) (mark t))))
!     (if before
! 	(funcall (or yank-undo-function 'delete-region) (point) (mark t))
!       (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
!     (setq yank-undo-function nil)
!     (set-marker (mark-marker) (point) (current-buffer))
!     (insert-for-yank (current-kill arg))
!     ;; Set the window start back where it was in the yank command,
!     ;; if possible.
!     (set-window-start (selected-window) yank-window-start t)
!     (if before
! 	;; This is like exchange-point-and-mark, but doesn't activate the mark.
! 	;; It is cleaner to avoid activation, even though the command
! 	;; loop would deactivate the mark because we inserted text.
! 	(goto-char (prog1 (mark t)
! 		     (set-marker (mark-marker) (point) (current-buffer))))))
!   nil)
  
  (defun yank (&optional arg)
    "Reinsert (\"paste\") the last stretch of killed text.
--- 3047,3074 ----
  `yank-excluded-properties' and `yank-handler' as described in the
  doc string for `insert-for-yank-1', which see."
    (interactive "*p")
    (setq this-command 'yank)
!   (if (not (eq last-command 'yank))
!       (yank arg)
!     (unless arg (setq arg 1))
!     (let ((inhibit-read-only t)
! 	  (before (< (point) (mark t))))
!       (if before
! 	  (funcall (or yank-undo-function 'delete-region) (point) (mark t))
! 	(funcall (or yank-undo-function 'delete-region) (mark t) (point)))
!       (setq yank-undo-function nil)
!       (set-marker (mark-marker) (point) (current-buffer))
!       (insert-for-yank (current-kill arg))
!       ;; Set the window start back where it was in the yank command,
!       ;; if possible.
!       (set-window-start (selected-window) yank-window-start t)
!       (if before
! 	  ;; This is like exchange-point-and-mark, but doesn't activate the mark.
! 	  ;; It is cleaner to avoid activation, even though the command
! 	  ;; loop would deactivate the mark because we inserted text.
! 	  (goto-char (prog1 (mark t)
! 		       (set-marker (mark-marker) (point) (current-buffer))))))
!     nil))
  
  (defun yank (&optional arg)
    "Reinsert (\"paste\") the last stretch of killed text.

Diff finished.  Mon Jun 14 23:50:10 2010

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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 16:00 yank-pop error unnecessary and annoying Geoff Gole
@ 2010-06-14 16:20 ` Juri Linkov
  2010-06-14 16:47   ` Geoff Gole
  2010-06-14 22:57   ` Chong Yidong
  2010-06-14 22:16 ` Richard Stallman
  1 sibling, 2 replies; 7+ messages in thread
From: Juri Linkov @ 2010-06-14 16:20 UTC (permalink / raw)
  To: Geoff Gole; +Cc: Emacs development discussions

> If called without a previous yank, yank-pop will produce an error
> message and do nothing useful. Why doesn't it just fall back on yank
> instead?

We have a proposal to do more useful things for yank-pop
without a previous yank:

http://thread.gmane.org/gmane.emacs.devel/122139/focus=122670

-- 
Juri Linkov
http://www.jurta.org/emacs/



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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 16:20 ` Juri Linkov
@ 2010-06-14 16:47   ` Geoff Gole
  2010-06-14 22:57   ` Chong Yidong
  1 sibling, 0 replies; 7+ messages in thread
From: Geoff Gole @ 2010-06-14 16:47 UTC (permalink / raw)
  To: Juri Linkov, emacs-devel

> We have a proposal to do more useful things for yank-pop
> without a previous yank:

OK, thanks. I'm happy as long as M-y does something intelligent rather
than giving this entirely unhelpful error.



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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 16:00 yank-pop error unnecessary and annoying Geoff Gole
  2010-06-14 16:20 ` Juri Linkov
@ 2010-06-14 22:16 ` Richard Stallman
  2010-06-15  0:52   ` Geoff Gole
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2010-06-14 22:16 UTC (permalink / raw)
  To: Geoff Gole; +Cc: emacs-devel

    If called without a previous yank, yank-pop will produce an error
    message and do nothing useful. Why doesn't it just fall back on yank
    instead?

I am not sure this is a good idea -- it might lead to doing things
that the users don't expect.  This is the sort of thing that we
ought to ask a lot of people to try, so they can tell us whether
it is useful or confusing.



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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 16:20 ` Juri Linkov
  2010-06-14 16:47   ` Geoff Gole
@ 2010-06-14 22:57   ` Chong Yidong
  2010-06-15  2:31     ` Stephen J. Turnbull
  1 sibling, 1 reply; 7+ messages in thread
From: Chong Yidong @ 2010-06-14 22:57 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Geoff Gole, Emacs development discussions

Juri Linkov <juri@jurta.org> writes:

> We have a proposal to do more useful things for yank-pop
> without a previous yank:
>
> http://thread.gmane.org/gmane.emacs.devel/122139/focus=122670

That is a proposal to do something different (prompt for an entry on the
kill ring).

But usually, what people have in mind when they do a spurious yank-pop
is "delete the stretch of text that I most recently yanked, and replace
it with the next item in the kill ring".  At least, that's what
frequently happens to me, usually when I inadvertently do some cursor
motion after yanking.

(In fact, the error is frequent enough that the above proposed behavior
might be annoying, since I don't just want to yank; I want to *replace*
the text; so I would end up doing an extra C-g to quit out of the
prompt.)

It Would Be Nice (tm) if the "yank-pop without previous yank by deleting
last yank" behavior could be implemented, but I don't know how easy or
difficult it is.  I assume the main complication is how to handle the
case where the buffer is modified since the last yank.



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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 22:16 ` Richard Stallman
@ 2010-06-15  0:52   ` Geoff Gole
  0 siblings, 0 replies; 7+ messages in thread
From: Geoff Gole @ 2010-06-15  0:52 UTC (permalink / raw)
  To: rms, emacs-devel, cyd

> I am not sure this is a good idea -- it might lead to doing things
> that the users don't expect.  This is the sort of thing that we
> ought to ask a lot of people to try, so they can tell us whether
> it is useful or confusing.

I'll see if I can convince some people to try it.

> But usually, what people have in mind when they do a spurious yank-pop
> is "delete the stretch of text that I most recently yanked, and replace
> it with the next item in the kill ring".  At least, that's what
> frequently happens to me, usually when I inadvertently do some cursor
> motion after yanking.

Hmm, usually when I M-y by mistake I simply want some text from some
distance down in the kill-ring but forgot that I need to C-y first. In
this case replacing the previous, probably unrelated yank would be
quite annoying.



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

* Re: yank-pop error unnecessary and annoying
  2010-06-14 22:57   ` Chong Yidong
@ 2010-06-15  2:31     ` Stephen J. Turnbull
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen J. Turnbull @ 2010-06-15  2:31 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Juri Linkov, Geoff Gole, Emacs development discussions

Chong Yidong writes:

 > It Would Be Nice (tm) if the "yank-pop without previous yank by deleting
 > last yank" behavior could be implemented, but I don't know how easy or
 > difficult it is.  I assume the main complication is how to handle the
 > case where the buffer is modified since the last yank.

Finding what to change might also be somewhat harder than "trivial" if
point has moved.



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

end of thread, other threads:[~2010-06-15  2:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14 16:00 yank-pop error unnecessary and annoying Geoff Gole
2010-06-14 16:20 ` Juri Linkov
2010-06-14 16:47   ` Geoff Gole
2010-06-14 22:57   ` Chong Yidong
2010-06-15  2:31     ` Stephen J. Turnbull
2010-06-14 22:16 ` Richard Stallman
2010-06-15  0:52   ` Geoff Gole

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).