annotate lisp/packages/pending-del.el @ 110:fe104dbd9147 r20-1b7

Import from CVS: tag r20-1b7
author cvs
date Mon, 13 Aug 2007 09:19:45 +0200
parents 131b0175ea99
children 1370575f1259
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 ()
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
51 (let ((type (and (symbolp this-command)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
52 (get this-command 'pending-delete))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
53 (cond ((eq type 'kill)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
54 (delete-active-region t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
55 ((eq type 'supersede)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
56 (if (delete-active-region ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
57 (setq this-command '(lambda () (interactive)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
58 (type
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
59 (delete-active-region ())))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (put 'self-insert-command 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (put 'yank 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (put 'x-yank-clipboard-selection 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (put 'delete-backward-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (put 'delete-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (put 'c-electric-delete 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; Don't delete for these. They're more problematic than helpful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; (put 'newline-and-indent 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; (put 'newline 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; (put 'open-line 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (put 'insert-register 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun pending-delete-on (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Turn on pending delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 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
83 When it is OFF, typed text is just inserted at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (and verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (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
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-off (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "Turn off 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 (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (and verbose (message "pending delete is OFF")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun pending-delete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "Toggle automatic deletion of the selected region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 With a positive argument, turns it on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 With a non-positive argument, turns it off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 When active, typed text replaces the selection."
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 (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (on-p (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (not was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (> (prefix-numeric-value arg) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (cond ((eq on-p was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (on-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (pending-delete-on pending-delete-verbose))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (pending-delete-off pending-delete-verbose)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; 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
117 ;; it on, even if it is already on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (pending-delete-on (eq pending-delete-verbose t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (provide 'pending-del)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; pending-del.el ends here