annotate lisp/delsel.el @ 2315:9e7ec92a4fdf

Added or corrected Commentary headers
author Eric S. Raymond <esr@snark.thyrsus.com>
date Mon, 22 Mar 1993 16:53:22 +0000
parents fb0ed5a1d0f3
children fa41174db2fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
1 ;;; pending-del.el --- pending delete selection
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
2
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;;; Copyright (C) 1992 Free Software Foundation, Inc.
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
4
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
5 ;; Author: Matthieu Devin <devin@lucid.com>
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
6 ;; Created: 14 Jul 92
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
7 ;; Last change 18-Feb-93, devin.
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;;; This file is part of GNU Emacs.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;;; GNU Emacs is free software; you can redistribute it and/or modify
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;;; it under the terms of the GNU General Public License as published by
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;;; the Free Software Foundation; either version 2, or (at your option)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;;; any later version.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;;; GNU Emacs is distributed in the hope that it will be useful,
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;;; GNU General Public License for more details.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;; You should have received a copy of the GNU General Public License
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; along with GNU Emacs; see the file COPYING. If not, write to
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
25 ;;; Commentary:
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
27 ;;; This file makes the active region be pending delete, meaning that
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; text inserted while the region is active will replace the region contents.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; This is a popular behavior of personal computers text editors.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
31 ;;; Code:
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
32
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
33 (defvar pending-delete-mode t
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
34 "*Non-nil means Pending Delete mode is enabled.
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
35 In Pending Delete mode, when a region is highlighted,
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
36 insertion commands first delete the region and then insert.")
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
37
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defun delete-active-region (&optional killp)
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
39 (if killp
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
40 (kill-region (point) (mark))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
41 (delete-region (point) (mark)))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
42 (setq mark-active nil)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
43 (run-hooks 'deactivate-mark-hook)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
44 t)
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (defun pending-delete-pre-hook ()
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
47 (if (and pending-delete-mode
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
48 (not buffer-read-only)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
49 transient-mark-mode mark-active)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
50 (let ((type (and (symbolp this-command)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
51 (get this-command 'pending-delete))))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
52 (cond ((eq type 'kill)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
53 (delete-active-region t))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
54 ((eq type 'supersede)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
55 (if (delete-active-region ())
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
56 (setq this-command '(lambda () (interactive)))))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
57 (type
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
58 (delete-active-region ()))))))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
59
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
60 (add-hook 'pre-command-hook 'pending-delete-pre-hook)
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (put 'self-insert-command 'pending-delete t)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (put 'yank 'pending-delete t)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (put 'x-yank-clipboard-selection 'pending-delete t)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (put 'delete-backward-char 'pending-delete 'supersede)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (put 'delete-char 'pending-delete 'supersede)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (put 'newline-and-indent 'pending-delete 't)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (put 'newline 'pending-delete t)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (put 'open-line 'pending-delete t)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
75 (defun pending-delete-mode (arg)
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "Toggle the state of pending-delete mode.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 When ON, typed text replaces the selection if the selection is active.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 When OFF, typed text is just inserted at point."
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
79 (interactive "P")
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
80 (setq pending-delete-mode
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
81 (if (null arg) (not pending-delete-mode)
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
82 (> (prefix-numeric-value arg) 0)))
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
83 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; This new definition of control-G makes the first control-G disown the
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; selection and the second one signal a QUIT.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; This is very useful for cancelling a selection in the minibuffer without
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; aborting the minibuffer.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; It has actually nothing to do with pending-delete but its more necessary
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; with pending delete because pending delete users use the selection more.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defun keyboard-quit ()
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 "Signal a `quit' condition.
2074
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
93 During execution of Lisp code, this character causes a quit directly.
0196b8bce529 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2073
diff changeset
94 At top-level, as an editor command, this simply beeps.
2073
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 In Transient Mark mode, if the mark is active, just deactivate it."
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (interactive)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (if (and transient-mark-mode mark-active)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (progn
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; Don't beep if just deactivating the region.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (setq mark-active nil)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (run-hooks 'deactivate-mark-hook))
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (signal 'quit nil)))
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defun minibuffer-keyboard-quit ()
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "Abort recursive edit.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 In Transient Mark mode, if the mark is active, just deactivate it."
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (interactive)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (if (and transient-mark-mode mark-active)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (progn
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; Don't beep if just deactivating the region.
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (setq mark-active nil)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (run-hooks 'deactivate-mark-hook))
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (abort-recursive-edit)))
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (define-key minibuffer-local-map "\C-g" 'minibuffer-keyboard-quit)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (provide 'pending-del)
b4d5c9926d98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2074
diff changeset
119 ;;; pending-del.el ends here