annotate lisp/packages/pending-del.el @ 161:28f395d8dc7a r20-3b7

Import from CVS: tag r20-3b7
author cvs
date Mon, 13 Aug 2007 09:42:26 +0200
parents 3bb7ccffb0c0
children 8eaf7971accc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; pending-del.el --- Making insertions replace any selected text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defvar pending-delete-verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "*nil disables on/off messages for pending-del mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 1 suppresses messages on loading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 t enables all messages")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun delete-active-region (&optional killp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (if (and (not buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (extentp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (eq (current-buffer) (extent-buffer zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (<= (extent-start-position zmacs-region-extent) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (<= (point) (extent-end-position zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (if killp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (kill-region (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (extent-end-position zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (delete-region (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (extent-end-position zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (zmacs-deactivate-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defun pending-delete-pre-hook ()
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
51 ;; don't ever signal an error in pre-command-hook!
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
52 (condition-case e
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
53 (let ((type (and (symbolp this-command)
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
54 (get this-command 'pending-delete))))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
55 (cond ((eq type 'kill)
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
56 (delete-active-region t))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
57 ((eq type 'supersede)
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
58 (if (delete-active-region ())
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
59 (setq this-command '(lambda () (interactive)))))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
60 (type
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
61 (delete-active-region ()))))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
62 (error
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 70
diff changeset
63 (warn "Error caught in `pending-delete-pre-hook': %s" e))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (put 'self-insert-command 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (put 'yank 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (put 'x-yank-clipboard-selection 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (put 'delete-backward-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (put 'delete-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (put 'c-electric-delete 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 126
diff changeset
75 ;; Support the XEmacs 20.3 'delete functions
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 126
diff changeset
76
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 126
diff changeset
77 (put 'backward-or-forward-delete-char 'pending-delete 'supersede)
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
78 (put 'cperl-electric-backspace 'pending-delete 'supersede)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
79 (put 'cperl-electric-delete 'pending-delete 'supersede)
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 126
diff changeset
80
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Don't delete for these. They're more problematic than helpful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; (put 'newline-and-indent 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; (put 'newline 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; (put 'open-line 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (put 'insert-register 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defun pending-delete-on (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "Turn on pending delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 When it is ON, typed text replaces the selection if the selection is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 When it is OFF, typed text is just inserted at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (and verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (message "Pending delete is ON, use M-x pending-delete to turn it OFF")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defun pending-delete-off (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Turn off pending delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 When it is ON, typed text replaces the selection if the selection is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 When it is OFF, typed text is just inserted at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (and verbose (message "pending delete is OFF")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defun pending-delete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "Toggle automatic deletion of the selected region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 With a positive argument, turns it on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 With a non-positive argument, turns it off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 When active, typed text replaces the selection."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (on-p (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (not was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (> (prefix-numeric-value arg) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (cond ((eq on-p was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (on-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (pending-delete-on pending-delete-verbose))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (pending-delete-off pending-delete-verbose)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Add pending-del mode. Assume that if we load it then we obviously wanted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; it on, even if it is already on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (pending-delete-on (eq pending-delete-verbose t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (provide 'pending-del)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; pending-del.el ends here