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.
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
16
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
0
|
23
|
|
24 ;;; Synched up with: Not in FSF.
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (defvar pending-delete-verbose
|
|
29 1
|
|
30 "*nil disables on/off messages for pending-del mode
|
|
31 1 suppresses messages on loading
|
|
32 t enables all messages")
|
|
33
|
|
34 (defun delete-active-region (&optional killp)
|
|
35 (if (and (not buffer-read-only)
|
|
36 (extentp zmacs-region-extent)
|
|
37 (eq (current-buffer) (extent-buffer zmacs-region-extent))
|
|
38 (extent-start-position zmacs-region-extent)
|
|
39 (<= (extent-start-position zmacs-region-extent) (point))
|
|
40 (<= (point) (extent-end-position zmacs-region-extent)))
|
|
41 (progn
|
|
42 (if killp
|
|
43 (kill-region (extent-start-position zmacs-region-extent)
|
|
44 (extent-end-position zmacs-region-extent))
|
|
45 (delete-region (extent-start-position zmacs-region-extent)
|
|
46 (extent-end-position zmacs-region-extent)))
|
|
47 (zmacs-deactivate-region)
|
|
48 t)))
|
|
49
|
|
50 (defun pending-delete-pre-hook ()
|
|
51 (let ((type (and (symbolp this-command)
|
|
52 (get this-command 'pending-delete))))
|
|
53 (cond ((eq type 'kill)
|
|
54 (delete-active-region t))
|
|
55 ((eq type 'supersede)
|
|
56 (if (delete-active-region ())
|
|
57 (setq this-command '(lambda () (interactive)))))
|
|
58 (type
|
|
59 (delete-active-region ())))))
|
|
60
|
|
61 (put 'self-insert-command 'pending-delete t)
|
|
62
|
|
63 (put 'yank 'pending-delete t)
|
|
64 (put 'x-yank-clipboard-selection 'pending-delete t)
|
|
65
|
|
66 (put 'delete-backward-char 'pending-delete 'supersede)
|
|
67 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
|
|
68 (put 'delete-char 'pending-delete 'supersede)
|
|
69 (put 'c-electric-delete 'pending-delete 'supersede)
|
|
70
|
|
71 ;; Don't delete for these. They're more problematic than helpful.
|
|
72 ;;
|
|
73 ;; (put 'newline-and-indent 'pending-delete t)
|
|
74 ;; (put 'newline 'pending-delete t)
|
|
75 ;; (put 'open-line 'pending-delete t)
|
|
76
|
|
77 (put 'insert-register 'pending-delete t)
|
|
78
|
|
79 ;;;###autoload
|
|
80 (defun pending-delete-on (verbose)
|
|
81 "Turn on pending delete.
|
|
82 When it is ON, typed text replaces the selection if the selection is active.
|
|
83 When it is OFF, typed text is just inserted at point."
|
|
84 (interactive "P")
|
|
85 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
|
|
86 (and verbose
|
|
87 (message "Pending delete is ON, use M-x pending-delete to turn it OFF")))
|
|
88
|
|
89 ;;;###autoload
|
|
90 (defun pending-delete-off (verbose)
|
|
91 "Turn off pending delete.
|
|
92 When it is ON, typed text replaces the selection if the selection is active.
|
|
93 When it is OFF, typed text is just inserted at point."
|
|
94 (interactive "P")
|
|
95 (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
|
|
96 (and verbose (message "pending delete is OFF")))
|
|
97
|
|
98 ;;;###autoload
|
|
99 (defun pending-delete (&optional arg)
|
|
100 "Toggle automatic deletion of the selected region.
|
|
101 With a positive argument, turns it on.
|
|
102 With a non-positive argument, turns it off.
|
|
103 When active, typed text replaces the selection."
|
|
104 (interactive "P")
|
|
105 (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
|
|
106 (on-p (if (null arg)
|
|
107 (not was-on)
|
|
108 (> (prefix-numeric-value arg) 0))))
|
|
109 (cond ((eq on-p was-on)
|
|
110 nil)
|
|
111 (on-p
|
|
112 (pending-delete-on pending-delete-verbose))
|
|
113 (t
|
|
114 (pending-delete-off pending-delete-verbose)))))
|
|
115
|
|
116 ;; Add pending-del mode. Assume that if we load it then we obviously wanted
|
|
117 ;; it on, even if it is already on.
|
|
118 (pending-delete-on (eq pending-delete-verbose t))
|
|
119
|
|
120 (provide 'pending-del)
|
|
121
|
|
122 ;;; pending-del.el ends here
|