1 ;; pending-del.el --- Making insertions replace any selected text.
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
5 ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
9 ;; This file is part of XEmacs.
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Synched up with: 19.34 (distributed as delsel.el in FSF)
30 ;; Much of this code was revamped by Hrvoje Niksic, July 1997, with
31 ;; version number set to 2.x.
33 ;; Pending-del is now a minor mode, with all the normal toggle
34 ;; functions. It should be somewhat faster, too.
40 (defcustom pending-delete-mode nil
41 "Non-nil when Pending Delete mode is enabled. In Pending Delete mode, typed
42 text replaces the selected region. Normally, you shouldn't modify this
43 variable by hand, but use the function `pending-delete-mode' instead. However,
44 you can customize the default value from the options menu (auto delete
47 :set (lambda (symbol value)
48 (pending-delete-mode (or value 0)))
49 :initialize 'custom-initialize-default
53 (defcustom pending-delete-modeline-string " PenDel"
54 "*String to display in the modeline when Pending Delete mode is active.
55 Set this to nil if you don't want a modeline indicator."
57 (const :tag "none" nil))
60 (add-minor-mode 'pending-delete-mode 'pending-delete-modeline-string)
63 (defun pending-delete-active-region (&optional killp)
64 (when (and (region-active-p)
65 (if zmacs-region-rectangular-p
66 (eq (extent-object (car zmacs-region-extent))
68 (eq (extent-object zmacs-region-extent) (current-buffer)))
69 (not buffer-read-only))
70 ;; Here we used to check whether the point lies between the
71 ;; beginning and end of the extent. I don't see how it is
72 ;; necessary, as the C code makes sure that this is so; it only
74 (if zmacs-region-rectangular-p
76 (kill-rectangle (region-beginning) (region-end))
77 (delete-rectangle (region-beginning) (region-end)))
79 (kill-region (region-beginning) (region-end))
80 (delete-region (region-beginning) (region-end))))
81 (zmacs-deactivate-region)
84 (defun pending-delete-pre-hook ()
86 (let ((type (and (symbolp this-command)
87 (get this-command 'pending-delete))))
88 (cond ((eq type 'kill)
89 (pending-delete-active-region t))
91 (if (pending-delete-active-region ())
92 (setq this-command (lambda () (interactive)))))
94 (pending-delete-active-region ()))))
96 (warn "Error caught in `pending-delete-pre-hook': %s"
97 (error-message-string e)))))
101 ;; now set up the keys that delete the selection and do nothing else.
102 ;; (Typically anything that is or could be bound to `delete' or
104 (mapcar #'(lambda (sym)
105 (put sym 'pending-delete 'supersede))
106 '(delete-backward-char
109 backward-or-forward-delete-char
112 backward-or-forward-kill-word
115 cperl-electric-backspace
116 cperl-electric-delete))
118 ;; now set up the keys that delete the selection and then do their normal
120 (mapcar #'(lambda (sym)
121 (put sym 'pending-delete t))
122 '(self-insert-command
126 yank-clipboard-selection
127 x-yank-clipboard-selection
131 cperl-electric-rparen
132 cperl-electric-terminator
134 cperl-electric-lbrace
137 skeleton-pair-insert-maybe
139 electric-c-sharp-sign
140 electric-c-terminator
144 ;; Don't delete for these. They're more problematic than helpful.
146 ;; (put 'newline-and-indent 'pending-delete t)
147 ;; (put 'newline 'pending-delete t)
148 ;; (put 'open-line 'pending-delete t)
150 (put 'insert-register 'pending-delete t)
154 (defun turn-on-pending-delete (&optional ignored)
155 "Turn on pending delete minor mode unconditionally."
157 (pending-delete-mode 1))
160 (defun turn-off-pending-delete (&optional ignored)
161 "Turn off pending delete minor mode unconditionally."
163 (pending-delete-mode 0))
166 (defun pending-delete-mode (&optional arg)
167 "Toggle Pending Delete minor mode.
168 When the pending delete is on, typed text replaces the selection.
169 With a positive argument, turns it on.
170 With a non-positive argument, turns it off."
172 (setq pending-delete-mode
173 (if (null arg) (not pending-delete-mode)
174 (> (prefix-numeric-value arg) 0)))
175 (if pending-delete-mode
176 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
177 (remove-hook 'pre-command-hook 'pending-delete-pre-hook))
178 (force-mode-line-update))
181 ;; Backward compatibility:
183 (define-obsolete-function-alias 'pending-delete-on 'turn-on-pending-delete)
185 (define-obsolete-function-alias 'pending-delete-off 'turn-off-pending-delete)
187 ;; FSF compatibility:
189 (define-compatible-function-alias 'delete-selection-mode 'pending-delete-mode)
190 (define-compatible-variable-alias 'delete-selection-mode 'pending-delete-mode)
192 ;; Compatibility and convenience:
194 (defalias 'pending-delete 'pending-delete-mode)
197 ;; The following code used to turn the mode on unconditionally.
198 ;; However, this is a very bad idea -- since pending-del is
199 ;; autoloaded, (turn-on-pending-delete) is as easy to add to `.emacs'
200 ;; as (require 'pending-del) used to be.
202 ;(pending-delete-on (eq pending-delete-verbose t))
204 (provide 'pending-del)
206 ;;; pending-del.el ends here