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

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