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>
|
175
|
7 ;; Version 2.2
|
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
|
189
|
39 (defcustom pending-delete-mode nil
|
173
|
40 "Non-nil when Pending Delete mode is enabled.
|
189
|
41 In Pending Delete mode, typed text replaces the selected region."
|
|
42 :type 'boolean
|
|
43 :set (lambda (symbol value)
|
|
44 (pending-delete-mode (or value 0)))
|
|
45 :initialize 'custom-initialize-default
|
|
46 :require 'pending-del
|
|
47 :group 'keyboard)
|
173
|
48
|
175
|
49 (defcustom pending-delete-modeline-string " PenDel"
|
|
50 "*String to display in the modeline when Pending Delete mode is active."
|
189
|
51 :type 'string
|
|
52 :group 'keyboard)
|
175
|
53
|
|
54 (add-minor-mode 'pending-delete-mode 'pending-delete-modeline-string)
|
0
|
55
|
173
|
56
|
|
57 (defun pending-delete-active-region (&optional killp)
|
|
58 (when (and (region-active-p)
|
|
59 (eq (extent-object zmacs-region-extent) (current-buffer))
|
|
60 (not buffer-read-only))
|
|
61 ;; Here we used to check whether the point lies between the
|
|
62 ;; beginning and end of the extent. I don't see how it is
|
|
63 ;; necessary, as the C code makes sure that this is so; it only
|
|
64 ;; slow things down.
|
|
65 (if killp
|
|
66 (kill-region (region-beginning) (region-end))
|
|
67 (delete-region (region-beginning) (region-end)))
|
|
68 (zmacs-deactivate-region)
|
|
69 t))
|
0
|
70
|
|
71 (defun pending-delete-pre-hook ()
|
126
|
72 (condition-case e
|
|
73 (let ((type (and (symbolp this-command)
|
|
74 (get this-command 'pending-delete))))
|
|
75 (cond ((eq type 'kill)
|
173
|
76 (pending-delete-active-region t))
|
126
|
77 ((eq type 'supersede)
|
173
|
78 (if (pending-delete-active-region ())
|
|
79 (setq this-command (lambda () (interactive)))))
|
126
|
80 (type
|
173
|
81 (pending-delete-active-region ()))))
|
126
|
82 (error
|
173
|
83 (warn "Error caught in `pending-delete-pre-hook': %s"
|
|
84 (error-message-string e)))))
|
0
|
85
|
173
|
86
|
0
|
87 (put 'self-insert-command 'pending-delete t)
|
|
88
|
|
89 (put 'yank 'pending-delete t)
|
|
90 (put 'x-yank-clipboard-selection 'pending-delete t)
|
173
|
91 (put 'toolbar-paste 'pending-delete t)
|
0
|
92
|
|
93 (put 'delete-backward-char 'pending-delete 'supersede)
|
|
94 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
|
|
95 (put 'delete-char 'pending-delete 'supersede)
|
|
96 (put 'c-electric-delete 'pending-delete 'supersede)
|
|
97
|
159
|
98 ;; Support the XEmacs 20.3 'delete functions
|
|
99
|
|
100 (put 'backward-or-forward-delete-char 'pending-delete 'supersede)
|
161
|
101 (put 'cperl-electric-backspace 'pending-delete 'supersede)
|
|
102 (put 'cperl-electric-delete 'pending-delete 'supersede)
|
159
|
103
|
0
|
104 ;; Don't delete for these. They're more problematic than helpful.
|
|
105 ;;
|
|
106 ;; (put 'newline-and-indent 'pending-delete t)
|
|
107 ;; (put 'newline 'pending-delete t)
|
|
108 ;; (put 'open-line 'pending-delete t)
|
|
109
|
|
110 (put 'insert-register 'pending-delete t)
|
|
111
|
173
|
112
|
0
|
113 ;;;###autoload
|
173
|
114 (defun turn-on-pending-delete (&optional ignored)
|
|
115 "Turn on pending delete minor mode unconditionally."
|
|
116 (interactive)
|
|
117 (pending-delete-mode 1))
|
0
|
118
|
|
119 ;;;###autoload
|
173
|
120 (defun turn-off-pending-delete (&optional ignored)
|
|
121 "Turn off pending delete minor mode unconditionally."
|
|
122 (interactive)
|
|
123 (pending-delete-mode 0))
|
0
|
124
|
|
125 ;;;###autoload
|
173
|
126 (defun pending-delete-mode (&optional arg)
|
|
127 "Toggle Pending Delete minor mode.
|
|
128 When the pending delete is on, typed text replaces the selection.
|
0
|
129 With a positive argument, turns it on.
|
173
|
130 With a non-positive argument, turns it off."
|
0
|
131 (interactive "P")
|
173
|
132 (setq pending-delete-mode
|
|
133 (if (null arg) (not pending-delete-mode)
|
|
134 (> (prefix-numeric-value arg) 0)))
|
|
135 (if pending-delete-mode
|
|
136 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
|
|
137 (remove-hook 'pre-command-hook 'pending-delete-pre-hook))
|
|
138 (force-mode-line-update))
|
|
139
|
|
140
|
|
141 ;; Backward compatibility:
|
|
142 ;;;###autoload
|
|
143 (define-obsolete-function-alias 'pending-delete-on 'turn-on-pending-delete)
|
|
144 ;;;###autoload
|
|
145 (define-obsolete-function-alias 'pending-delete-off 'turn-off-pending-delete)
|
|
146
|
|
147 ;; FSF compatibility:
|
|
148 ;;;###autoload
|
|
149 (define-compatible-function-alias 'delete-selection-mode 'pending-delete-mode)
|
|
150
|
|
151 ;; Compatibility and convenience:
|
|
152 ;;;###autoload
|
|
153 (defalias 'pending-delete 'pending-delete-mode)
|
|
154
|
|
155
|
|
156 ;; The following code used to turn the mode on unconditionally.
|
|
157 ;; However, this is a very bad idea -- since pending-del is
|
|
158 ;; autoloaded, (turn-on-pending-delete) is as easy to add to `.emacs'
|
|
159 ;; as (require 'pending-del) used to be.
|
|
160
|
|
161 ;(pending-delete-on (eq pending-delete-verbose t))
|
0
|
162
|
|
163 (provide 'pending-del)
|
|
164
|
|
165 ;;; pending-del.el ends here
|