Merge from emacs--rel--22
[bpt/emacs.git] / lisp / delsel.el
index 74ef011..8d6e6ea 100644 (file)
@@ -1,7 +1,7 @@
 ;;; delsel.el --- delete selection if you insert
 
 ;; Copyright (C) 1992, 1997, 1998, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Matthieu Devin <devin@lucid.com>
 ;; Maintainer: FSF
@@ -12,7 +12,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -87,12 +87,16 @@ any selection."
          (cond ((eq type 'kill)
                 (delete-active-region t))
                ((eq type 'yank)
-                ;; Before a yank command,
-                ;; make sure we don't yank the same region
-                ;; that we are going to delete.
-                ;; That would make yank a no-op.
-                (when (string= (buffer-substring-no-properties (point) (mark))
-                               (car kill-ring))
+                ;; Before a yank command, make sure we don't yank the
+                ;; head of the kill-ring that really comes from the
+                ;; currently active region we are going to delete
+                ;; (when last-command is one that uses copy-region-as-kill
+                ;; or kill-new).  That would make yank a no-op.
+                (when (and (string= (buffer-substring-no-properties (point) (mark))
+                                    (car kill-ring))
+                           (memq last-command
+                                 '(mouse-set-region mouse-drag-region
+                                   mouse-save-then-kill mouse-secondary-save-then-kill)))
                   (current-kill 1))
                 (delete-active-region))
                ((eq type 'supersede)
@@ -101,7 +105,11 @@ any selection."
                   (unless empty-region
                     (setq this-command 'ignore))))
                (type
-                (delete-active-region)))
+                (delete-active-region)
+                (if (and overwrite-mode (eq this-command 'self-insert-command))
+                  (let ((overwrite-mode nil))
+                    (self-insert-command (prefix-numeric-value current-prefix-arg))
+                    (setq this-command 'ignore)))))
        (file-supersession
         ;; If ask-user-about-supersession-threat signals an error,
         ;; stop safe_run_hooks from clearing out pre-command-hook.