annotate lisp/packages/pending-del.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defvar pending-delete-verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 "*nil disables on/off messages for pending-del mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 1 suppresses messages on loading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 t enables all messages")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defun delete-active-region (&optional killp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (if (and (not buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (extentp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (eq (current-buffer) (extent-buffer zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (<= (extent-start-position zmacs-region-extent) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (<= (point) (extent-end-position zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (if killp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (kill-region (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (extent-end-position zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (delete-region (extent-start-position zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (extent-end-position zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (zmacs-deactivate-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun pending-delete-pre-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (let ((type (and (symbolp this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (get this-command 'pending-delete))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (cond ((eq type 'kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (delete-active-region t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ((eq type 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if (delete-active-region ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (setq this-command '(lambda () (interactive)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (delete-active-region ())))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (put 'self-insert-command 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (put 'yank 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (put 'x-yank-clipboard-selection 'pending-delete t)
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 'delete-backward-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (put 'delete-char 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (put 'c-electric-delete 'pending-delete 'supersede)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; Don't delete for these. They're more problematic than helpful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; (put 'newline-and-indent 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; (put 'newline 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; (put 'open-line 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (put 'insert-register 'pending-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun pending-delete-on (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "Turn on pending delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 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
82 When it is OFF, typed text is just inserted at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (and verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (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
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun pending-delete-off (verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Turn off pending delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 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
92 When it is OFF, typed text is just inserted at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (and verbose (message "pending delete is OFF")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun pending-delete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "Toggle automatic deletion of the selected region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 With a positive argument, turns it on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 With a non-positive argument, turns it off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 When active, typed text replaces the selection."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (on-p (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (not was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (> (prefix-numeric-value arg) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (cond ((eq on-p was-on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (on-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (pending-delete-on pending-delete-verbose))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (pending-delete-off pending-delete-verbose)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; 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
116 ;; it on, even if it is already on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (pending-delete-on (eq pending-delete-verbose t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (provide 'pending-del)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; pending-del.el ends here