Mercurial > emacs
annotate lisp/delsel.el @ 18879:8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
(jka-compr-write-region): Bind coding-system-for-write.
Set buffer-file-type if dos or nt.
(jka-compr-call-process): Bind coding-system-for-read
and coding-system-for-write.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 20 Jul 1997 04:50:25 +0000 |
parents | c8c67c398475 |
children | 73871027b629 |
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 |
14169 | 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> |
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 |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
8 ;; Last change 18-Feb-93, devin. |
2073 | 9 |
14169 | 10 ;; This file is part of GNU Emacs. |
2073 | 11 |
14169 | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
2073 | 16 |
14169 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
2073 | 21 |
14169 | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
2073 | 26 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
27 ;;; Commentary: |
2073 | 28 |
14169 | 29 ;; This file makes the active region be pending delete, meaning that |
30 ;; text inserted while the region is active will replace the region contents. | |
31 ;; This is a popular behavior of personal computers text editors. | |
2073 | 32 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
33 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2074
diff
changeset
|
34 |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
35 (eval-when-compile |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
36 (require 'cl)) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
37 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
38 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
39 (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
|
40 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
41 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
42 (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
|
43 "Toggle 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
|
44 With prefix ARG, turn Delete Selection mode on if and only if ARG is positive. |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
45 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
46 When Delete Selection mode is enabled, Transient Mark mode is also enabled and |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
47 typed text replaces the selection if the selection is active. Otherwise, typed |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
48 text is just inserted at point regardless of any selection." |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
49 (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
|
50 (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
|
51 (> (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
|
52 (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
|
53 (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
|
54 (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
|
55 (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
|
56 (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
|
57 |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
58 ;;;###autoload |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
59 (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
|
60 "Toggle 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
|
61 When Delete Selection mode is enabled, Transient Mark mode is also enabled and |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
62 typed text replaces the selection if the selection is active. |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
63 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
|
64 :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
|
65 (delete-selection-mode (or value 0))) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
66 :initialize 'custom-initialize-default |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
67 :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
|
68 :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
|
69 :require 'delsel) |
18840
c8c67c398475
(delete-selection-mode): Add custom-loads property.
Richard M. Stallman <rms@gnu.org>
parents:
18785
diff
changeset
|
70 ;; Force loading of this file in order to customize delete-selection-mode. |
c8c67c398475
(delete-selection-mode): Add custom-loads property.
Richard M. Stallman <rms@gnu.org>
parents:
18785
diff
changeset
|
71 (put 'delete-selection-mode 'custom-loads '(delsel)) |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
72 |
18840
c8c67c398475
(delete-selection-mode): Add custom-loads property.
Richard M. Stallman <rms@gnu.org>
parents:
18785
diff
changeset
|
73 ;; This is the standard way mechanism to put the mode into effect |
c8c67c398475
(delete-selection-mode): Add custom-loads property.
Richard M. Stallman <rms@gnu.org>
parents:
18785
diff
changeset
|
74 ;; if delete-selection-mode has already been set to t |
c8c67c398475
(delete-selection-mode): Add custom-loads property.
Richard M. Stallman <rms@gnu.org>
parents:
18785
diff
changeset
|
75 ;; when this file is loaded. |
18785
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
76 (when 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
|
77 (delete-selection-mode t)) |
2074 | 78 |
2073 | 79 (defun delete-active-region (&optional killp) |
2074 | 80 (if killp |
81 (kill-region (point) (mark)) | |
82 (delete-region (point) (mark))) | |
83 (setq mark-active nil) | |
84 (run-hooks 'deactivate-mark-hook) | |
85 t) | |
2073 | 86 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
87 (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
|
88 (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
|
89 (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
|
90 (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
|
91 (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
|
92 (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
|
93 (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
|
94 ((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
|
95 ;; 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
|
96 ;; 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
|
97 ;; 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
|
98 ;; 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
|
99 (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
|
100 (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
|
101 (current-kill 1)) |
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 nil)) |
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 'supersede) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
104 (when (delete-active-region nil) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
105 (setq this-command '(lambda () (interactive))))) |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
106 (type |
1a455d8dfa7c
Customise. Don't modify pre-command-hook on file load; do in command.
Simon Marshall <simon@gnu.org>
parents:
18641
diff
changeset
|
107 (delete-active-region nil)))))) |
2073 | 108 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
109 (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
|
110 (put 'self-insert-iso 'delete-selection t) |
2073 | 111 |
12790
afe7f3c735a3
(delete-selection-pre-hook): New type value `yank'.
Richard M. Stallman <rms@gnu.org>
parents:
11589
diff
changeset
|
112 (put 'yank 'delete-selection 'yank) |
13077
65092cab3f43
(clipboard-yank): Add delete-selection property.
Richard M. Stallman <rms@gnu.org>
parents:
12790
diff
changeset
|
113 (put 'clipboard-yank 'delete-selection 'yank) |
2925 | 114 (put 'insert-register 'delete-selection t) |
2073 | 115 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
116 (put 'delete-backward-char 'delete-selection 'supersede) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
117 (put 'backward-delete-char-untabify 'delete-selection 'supersede) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
118 (put 'delete-char 'delete-selection 'supersede) |
2073 | 119 |
2903
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
120 (put 'newline-and-indent 'delete-selection 't) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
121 (put 'newline 'delete-selection t) |
fa41174db2fa
Renamed from pending-del.el.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
122 (put 'open-line 'delete-selection t) |
2073 | 123 |
124 ;; This is very useful for cancelling a selection in the minibuffer without | |
125 ;; aborting the minibuffer. | |
126 (defun minibuffer-keyboard-quit () | |
127 "Abort recursive edit. | |
2925 | 128 In Delete Selection mode mode, if the mark is active, just deactivate it; |
129 then it takes a second C-g to abort the minibuffer." | |
2073 | 130 (interactive) |
2925 | 131 (if (and delete-selection-mode transient-mark-mode mark-active) |
132 (setq deactivate-mark t) | |
2073 | 133 (abort-recursive-edit))) |
134 | |
135 (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
|
136 (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
|
137 (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
|
138 (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
|
139 (define-key minibuffer-local-isearch-map "\C-g" 'minibuffer-keyboard-quit) |
2073 | 140 |
2925 | 141 (provide 'delsel) |
2073 | 142 |
2925 | 143 ;;; delsel.el ends here |