;;; delsel.el --- delete selection if you insert
-;;; Copyright (C) 1992 Free Software Foundation, Inc.
+;; Copyright (C) 1992 Free Software Foundation, Inc.
;; Author: Matthieu Devin <devin@lucid.com>
;; Created: 14 Jul 92
;; Last change 18-Feb-93, devin.
-;;; This file is part of GNU Emacs.
+;; This file is part of GNU Emacs.
-;;; 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)
-;;; any later version.
+;; 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)
+;; any later version.
-;;; GNU Emacs is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;;; GNU General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
-;;; You should have received a copy of the GNU General Public License
-;;; along with GNU Emacs; see the file COPYING. If not, write to
-;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
;;; Commentary:
-;;; This file makes the active region be pending delete, meaning that
-;;; text inserted while the region is active will replace the region contents.
-;;; This is a popular behavior of personal computers text editors.
+;; This file makes the active region be pending delete, meaning that
+;; text inserted while the region is active will replace the region contents.
+;; This is a popular behavior of personal computers text editors.
;;; Code:
(get this-command 'delete-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.
+ (if (string= (buffer-substring (point) (mark))
+ (car kill-ring))
+ (current-kill 1))
+ (delete-active-region nil))
((eq type 'supersede)
(if (delete-active-region nil)
(setq this-command '(lambda () (interactive)))))
(put 'self-insert-command 'delete-selection t)
(put 'self-insert-iso 'delete-selection t)
-(put 'yank 'delete-selection t)
+(put 'yank 'delete-selection 'yank)
+(put 'clipboard-yank 'delete-selection 'yank)
(put 'insert-register 'delete-selection t)
(put 'delete-backward-char 'delete-selection 'supersede)