0
|
1 ;; pending-del.el --- Making insertions replace any selected text.
|
|
2
|
|
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
|
173
|
6 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
|
|
7 ;; Version 2.1
|
0
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
16
|
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.
|
0
|
25
|
173
|
26 ;;; Synched up with: 19.34 (distributed as delsel.el in FSF)
|
|
27
|
|
28 ;;; Commentary:
|
0
|
29
|
173
|
30 ;; Much of this code was revamped by Hrvoje Niksic, July 1997, with
|
|
31 ;; version number set to 2.x.
|
|
32
|
|
33 ;; Pending-del is now a minor mode, with all the normal toggle
|
|
34 ;; functions. It should be somewhat faster, too.
|
|
35
|
|
36
|
0
|
37 ;;; Code:
|
|
38
|
173
|
39 (defvar pending-delete-mode nil
|
|
40 "Non-nil when Pending Delete mode is enabled.
|
|
41 In Pending Delete mode, typed text replaces the selected region.")
|
|
42
|
|
43 (add-minor-mode 'pending-delete-mode " PenDel")
|
0
|
44
|
173
|
45
|
|
46 (defun pending-delete-active-region (&optional killp)
|
|
47 (when (and (region-active-p)
|
|
48 (eq (extent-object zmacs-region-extent) (current-buffer))
|
|
49 (not buffer-read-only))
|
|
50 ;; Here we used to check whether the point lies between the
|
|
51 ;; beginning and end of the extent. I don't see how it is
|
|
52 ;; necessary, as the C code makes sure that this is so; it only
|
|
53 ;; slow things down.
|
|
54 (if killp
|
|
55 (kill-region (region-beginning) (region-end))
|
|
56 (delete-region (region-beginning) (region-end)))
|
|
57 (zmacs-deactivate-region)
|
|
58 t))
|
0
|
59
|
|
60 (defun pending-delete-pre-hook ()
|
126
|
61 (condition-case e
|
|
62 (let ((type (and (symbolp this-command)
|
|
63 (get this-command 'pending-delete))))
|
|
64 (cond ((eq type 'kill)
|
173
|
65 (pending-delete-active-region t))
|
126
|
66 ((eq type 'supersede)
|
173
|
67 (if (pending-delete-active-region ())
|
|
68 (setq this-command (lambda () (interactive)))))
|
126
|
69 (type
|
173
|
70 (pending-delete-active-region ()))))
|
126
|
71 (error
|
173
|
72 (warn "Error caught in `pending-delete-pre-hook': %s"
|
|
73 (error-message-string e)))))
|
0
|
74
|
173
|
75
|
0
|
76 (put 'self-insert-command 'pending-delete t)
|
|
77
|
|
78 (put 'yank 'pending-delete t)
|
|
79 (put 'x-yank-clipboard-selection 'pending-delete t)
|
173
|
80 (put 'toolbar-paste 'pending-delete t)
|
0
|
81
|
|
82 (put 'delete-backward-char 'pending-delete 'supersede)
|
|
83 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
|
|
84 (put 'delete-char 'pending-delete 'supersede)
|
|
85 (put 'c-electric-delete 'pending-delete 'supersede)
|
|
86
|
159
|
87 ;; Support the XEmacs 20.3 'delete functions
|
|
88
|
|
89 (put 'backward-or-forward-delete-char 'pending-delete 'supersede)
|
161
|
90 (put 'cperl-electric-backspace 'pending-delete 'supersede)
|
|
91 (put 'cperl-electric-delete 'pending-delete 'supersede)
|
159
|
92
|
0
|
93 ;; Don't delete for these. They're more problematic than helpful.
|
|
94 ;;
|
|
95 ;; (put 'newline-and-indent 'pending-delete t)
|
|
96 ;; (put 'newline 'pending-delete t)
|
|
97 ;; (put 'open-line 'pending-delete t)
|
|
98
|
|
99 (put 'insert-register 'pending-delete t)
|
|
100
|
173
|
101
|
0
|
102 ;;;###autoload
|
173
|
103 (defun turn-on-pending-delete (&optional ignored)
|
|
104 "Turn on pending delete minor mode unconditionally."
|
|
105 (interactive)
|
|
106 (pending-delete-mode 1))
|
0
|
107
|
|
108 ;;;###autoload
|
173
|
109 (defun turn-off-pending-delete (&optional ignored)
|
|
110 "Turn off pending delete minor mode unconditionally."
|
|
111 (interactive)
|
|
112 (pending-delete-mode 0))
|
0
|
113
|
|
114 ;;;###autoload
|
173
|
115 (defun pending-delete-mode (&optional arg)
|
|
116 "Toggle Pending Delete minor mode.
|
|
117 When the pending delete is on, typed text replaces the selection.
|
0
|
118 With a positive argument, turns it on.
|
173
|
119 With a non-positive argument, turns it off."
|
0
|
120 (interactive "P")
|
173
|
121 (setq pending-delete-mode
|
|
122 (if (null arg) (not pending-delete-mode)
|
|
123 (> (prefix-numeric-value arg) 0)))
|
|
124 (if pending-delete-mode
|
|
125 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
|
|
126 (remove-hook 'pre-command-hook 'pending-delete-pre-hook))
|
|
127 (force-mode-line-update))
|
|
128
|
|
129
|
|
130 ;; Backward compatibility:
|
|
131 ;;;###autoload
|
|
132 (define-obsolete-function-alias 'pending-delete-on 'turn-on-pending-delete)
|
|
133 ;;;###autoload
|
|
134 (define-obsolete-function-alias 'pending-delete-off 'turn-off-pending-delete)
|
|
135
|
|
136 ;; FSF compatibility:
|
|
137 ;;;###autoload
|
|
138 (define-compatible-function-alias 'delete-selection-mode 'pending-delete-mode)
|
|
139
|
|
140 ;; Compatibility and convenience:
|
|
141 ;;;###autoload
|
|
142 (defalias 'pending-delete 'pending-delete-mode)
|
|
143
|
|
144
|
|
145 ;; The following code used to turn the mode on unconditionally.
|
|
146 ;; However, this is a very bad idea -- since pending-del is
|
|
147 ;; autoloaded, (turn-on-pending-delete) is as easy to add to `.emacs'
|
|
148 ;; as (require 'pending-del) used to be.
|
|
149
|
|
150 ;(pending-delete-on (eq pending-delete-verbose t))
|
0
|
151
|
|
152 (provide 'pending-del)
|
|
153
|
|
154 ;;; pending-del.el ends here
|