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