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