annotate lisp/delsel.el @ 2082:4b05402f3ac5

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