Mercurial > emacs
annotate lisp/delsel.el @ 23295:722f0b9703c7
(mouse-avoidance-banish-hook): Don't move unless in an
Emacs frame.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 21 Sep 1998 19:42:29 +0000 |
parents | b1ee274d921b |
children | 3f24de6b7748 |
rev | line source |
---|---|
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
1 ;;; delsel.el --- delete selection if you insert |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
2 |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
3 ;; Copyright (C) 1992, 1997, 1998 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> |
17976 | 6 ;; Maintainer: FSF |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
7 ;; Created: 14 Jul 92 |
2073 | 8 |
14169 | 9 ;; This file is part of GNU Emacs. |
2073 | 10 |
14169 | 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. | |
2073 | 15 |
14169 | 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. | |
2073 | 20 |
14169 | 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 the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
2073 | 25 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
26 ;;; Commentary: |
2073 | 27 |
14169 | 28 ;; This file makes the active region be pending delete, meaning that |
29 ;; text inserted while the region is active will replace the region contents. | |
30 ;; This is a popular behavior of personal computers text editors. | |
2073 | 31 |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
32 ;; Interface: |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
33 |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
34 ;; Commands which will delete the selection need a 'delete-selection |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
35 ;; property on their symbols; commands which insert text but don't |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
36 ;; have this property won't delete the selction. It can be one of |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
37 ;; the values: |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
38 ;; 'yank |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
39 ;; For commands which do a yank; ensures the region about to be |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
40 ;; deleted isn't yanked. |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
41 ;; 'supersede |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
42 ;; Delete the active region and ignore the current command, |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
43 ;; i.e. the command will just delete the region. |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
44 ;; 'kill |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
45 ;; `kill-region' is used on the selection, rather than |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
46 ;; `delete-region'. (Text selected with the mouse will typically |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
47 ;; be yankable anyhow.) |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
48 ;; non-nil |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
49 ;; The normal case: delete the active region prior to executing |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
50 ;; the command which will insert replacement text. |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
51 |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
52 ;;; Code: |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
53 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
54 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
55 (defalias 'pending-delete-mode 'delete-selection-mode) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
56 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
57 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
58 (defun delete-selection-mode (&optional arg) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
59 "Toggle Delete Selection mode. |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
60 With prefix ARG, turn Delete Selection mode on if and only if ARG is |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
61 positive. |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
62 |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
63 When Delete Selection mode is enabled, Transient Mark mode is also |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
64 enabled and typed text replaces the selection if the selection is |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
65 active. Otherwise, typed text is just inserted at point regardless of |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
66 any selection." |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
67 (interactive "P") |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
68 (setq delete-selection-mode (if arg |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
69 (> (prefix-numeric-value arg) 0) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
70 (not delete-selection-mode))) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
71 (if (not delete-selection-mode) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
72 (remove-hook 'pre-command-hook 'delete-selection-pre-hook) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
73 (add-hook 'pre-command-hook 'delete-selection-pre-hook) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
74 (transient-mark-mode t))) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
75 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
76 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
77 (defcustom delete-selection-mode nil |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
78 "Toggle Delete Selection mode. |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
79 See command `delete-selection-mode'. |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
80 You must modify via \\[customize] for this variable to have an effect." |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
81 :set (lambda (symbol value) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
82 (delete-selection-mode (or value 0))) |
19488
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
83 :initialize 'custom-initialize-default |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
84 :type 'boolean |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
85 :group 'editing-basics |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
86 :require 'delsel) |
2074 | 87 |
2073 | 88 (defun delete-active-region (&optional killp) |
2074 | 89 (if killp |
90 (kill-region (point) (mark)) | |
91 (delete-region (point) (mark))) | |
92 (setq mark-active nil) | |
93 (run-hooks 'deactivate-mark-hook) | |
94 t) | |
2073 | 95 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
96 (defun delete-selection-pre-hook () |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
97 (when (and delete-selection-mode transient-mark-mode mark-active |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
98 (not buffer-read-only)) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
99 (let ((type (and (symbolp this-command) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
100 (get this-command 'delete-selection)))) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
101 (cond ((eq type 'kill) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
102 (delete-active-region t)) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
103 ((eq type 'yank) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
104 ;; Before a yank command, |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
105 ;; make sure we don't yank the same region |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
106 ;; that we are going to delete. |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
107 ;; That would make yank a no-op. |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
108 (when (string= (buffer-substring-no-properties (point) (mark)) |
12790
afe7f3c735a3
(delete-selection-pre-hook): New type value `yank'.
Richard M. Stallman <rms@gnu.org>
parents:
11589
diff
changeset
|
109 (car kill-ring)) |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
110 (current-kill 1)) |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
111 (delete-active-region)) |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
112 ((eq type 'supersede) |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
113 (delete-active-region) |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
114 (setq this-command 'ignore)) |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
115 (type |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
116 (delete-active-region)))))) |
2073 | 117 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
118 (put 'self-insert-command 'delete-selection t) |
9533
b589ba0d8960
(self-insert-iso): Add delete-selection property.
Richard M. Stallman <rms@gnu.org>
parents:
2925
diff
changeset
|
119 (put 'self-insert-iso 'delete-selection t) |
2073 | 120 |
12790
afe7f3c735a3
(delete-selection-pre-hook): New type value `yank'.
Richard M. Stallman <rms@gnu.org>
parents:
11589
diff
changeset
|
121 (put 'yank 'delete-selection 'yank) |
13077
65092cab3f43
(clipboard-yank): Add delete-selection property.
Richard M. Stallman <rms@gnu.org>
parents:
12790
diff
changeset
|
122 (put 'clipboard-yank 'delete-selection 'yank) |
2925 | 123 (put 'insert-register 'delete-selection t) |
2073 | 124 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
125 (put 'delete-backward-char 'delete-selection 'supersede) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
126 (put 'backward-delete-char-untabify 'delete-selection 'supersede) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
127 (put 'delete-char 'delete-selection 'supersede) |
2073 | 128 |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
129 (put 'newline-and-indent 'delete-selection t) |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
130 (put 'newline 'delete-selection t) |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
131 (put 'open-line 'delete-selection 'kill) |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
132 |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
133 (put 'insert-parentheses 'delete-selection t) |
2073 | 134 |
135 ;; This is very useful for cancelling a selection in the minibuffer without | |
136 ;; aborting the minibuffer. | |
137 (defun minibuffer-keyboard-quit () | |
138 "Abort recursive edit. | |
21720
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
139 In Delete Selection mode, if the mark is active, just deactivate it; |
b1ee274d921b
Don't require cl. Minor doc fixes.
Dave Love <fx@gnu.org>
parents:
19488
diff
changeset
|
140 then it takes a second \\[keyboard-quit] to abort the minibuffer." |
2073 | 141 (interactive) |
2925 | 142 (if (and delete-selection-mode transient-mark-mode mark-active) |
143 (setq deactivate-mark t) | |
2073 | 144 (abort-recursive-edit))) |
145 | |
146 (define-key minibuffer-local-map "\C-g" 'minibuffer-keyboard-quit) | |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
147 (define-key minibuffer-local-ns-map "\C-g" 'minibuffer-keyboard-quit) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
148 (define-key minibuffer-local-completion-map "\C-g" 'minibuffer-keyboard-quit) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
149 (define-key minibuffer-local-must-match-map "\C-g" 'minibuffer-keyboard-quit) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
150 (define-key minibuffer-local-isearch-map "\C-g" 'minibuffer-keyboard-quit) |
2073 | 151 |
2925 | 152 (provide 'delsel) |
2073 | 153 |
19488
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
154 ;; This is the standard way mechanism to put the mode into effect |
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
155 ;; if delete-selection-mode has already been set to t |
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
156 ;; when this file is loaded. |
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
157 (when delete-selection-mode |
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
158 (delete-selection-mode t)) |
25a37a54148f
(delete-selection-mode): Put back :initialize keyword.
Richard M. Stallman <rms@gnu.org>
parents:
19132
diff
changeset
|
159 |
2925 | 160 ;;; delsel.el ends here |