Mercurial > emacs
comparison lisp/delsel.el @ 2074:0196b8bce529
entered into RCS
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 09 Mar 1993 05:37:50 +0000 |
parents | b4d5c9926d98 |
children | fb0ed5a1d0f3 |
comparison
equal
deleted
inserted
replaced
2073:b4d5c9926d98 | 2074:0196b8bce529 |
---|---|
22 | 22 |
23 ;;; This files makes the active region be pending delete, meaning that | 23 ;;; This files makes the active region be pending delete, meaning that |
24 ;;; text inserted while the region is active will replace the region contents. | 24 ;;; text inserted while the region is active will replace the region contents. |
25 ;;; This is a popular behavior of personal computers text editors. | 25 ;;; This is a popular behavior of personal computers text editors. |
26 | 26 |
27 (defvar pending-delete-mode t | |
28 "*Non-nil means Pending Delete mode is enabled. | |
29 In Pending Delete mode, when a region is highlighted, | |
30 insertion commands first delete the region and then insert.") | |
31 | |
27 (defun delete-active-region (&optional killp) | 32 (defun delete-active-region (&optional killp) |
28 (if (and (not buffer-read-only) | 33 (if killp |
29 (extentp primary-selection-extent) | 34 (kill-region (point) (mark)) |
30 (eq (current-buffer) (extent-buffer primary-selection-extent)) | 35 (delete-region (point) (mark))) |
31 (< 0 (extent-start-position primary-selection-extent)) | 36 (setq mark-active nil) |
32 (< 0 (extent-end-position primary-selection-extent))) | 37 (run-hooks 'deactivate-mark-hook) |
33 (progn | 38 t) |
34 (if killp | |
35 (kill-region (extent-start-position primary-selection-extent) | |
36 (extent-end-position primary-selection-extent)) | |
37 (delete-region (extent-start-position primary-selection-extent) | |
38 (extent-end-position primary-selection-extent))) | |
39 (zmacs-deactivate-region) | |
40 t))) | |
41 | 39 |
42 (defun pending-delete-pre-hook () | 40 (defun pending-delete-pre-hook () |
43 (let ((type (and (symbolp this-command) | 41 (if (and pending-delete-mode |
44 (get this-command 'pending-delete)))) | 42 (not buffer-read-only) |
45 (cond ((eq type 'kill) | 43 transient-mark-mode mark-active) |
46 (delete-active-region t)) | 44 (let ((type (and (symbolp this-command) |
47 ((eq type 'supersede) | 45 (get this-command 'pending-delete)))) |
48 (if (delete-active-region ()) | 46 (cond ((eq type 'kill) |
49 (setq this-command '(lambda () (interactive))))) | 47 (delete-active-region t)) |
50 (type | 48 ((eq type 'supersede) |
51 (delete-active-region ()))))) | 49 (if (delete-active-region ()) |
50 (setq this-command '(lambda () (interactive))))) | |
51 (type | |
52 (delete-active-region ())))))) | |
53 | |
54 (add-hook 'pre-command-hook 'pending-delete-pre-hook) | |
52 | 55 |
53 (put 'self-insert-command 'pending-delete t) | 56 (put 'self-insert-command 'pending-delete t) |
54 | 57 |
55 (put 'yank 'pending-delete t) | 58 (put 'yank 'pending-delete t) |
56 (put 'x-yank-clipboard-selection 'pending-delete t) | 59 (put 'x-yank-clipboard-selection 'pending-delete t) |
61 | 64 |
62 (put 'newline-and-indent 'pending-delete 't) | 65 (put 'newline-and-indent 'pending-delete 't) |
63 (put 'newline 'pending-delete t) | 66 (put 'newline 'pending-delete t) |
64 (put 'open-line 'pending-delete t) | 67 (put 'open-line 'pending-delete t) |
65 | 68 |
66 (defun pending-delete-mode () | 69 (defun pending-delete-mode (arg) |
67 "Toggle the state of pending-delete mode. | 70 "Toggle the state of pending-delete mode. |
68 When ON, typed text replaces the selection if the selection is active. | 71 When ON, typed text replaces the selection if the selection is active. |
69 When OFF, typed text is just inserted at point." | 72 When OFF, typed text is just inserted at point." |
70 (interactive) | 73 (interactive "P") |
71 (if (memq 'pending-delete-pre-hook pre-command-hook) | 74 (setq pending-delete-mode |
72 (progn | 75 (if (null arg) (not pending-delete-mode) |
73 (remove-hook 'pre-command-hook 'pending-delete-pre-hook) | 76 (> (prefix-numeric-value arg) 0))) |
74 (message "pending delete is OFF")) | 77 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line. |
75 (progn | |
76 (add-hook 'pre-command-hook 'pending-delete-pre-hook) | |
77 (message | |
78 "Pending delete is ON, use M-x pending-delete to turn it OFF")))) | |
79 | |
80 (pending-delete-mode) | |
81 | 78 |
82 ;; This new definition of control-G makes the first control-G disown the | 79 ;; This new definition of control-G makes the first control-G disown the |
83 ;; selection and the second one signal a QUIT. | 80 ;; selection and the second one signal a QUIT. |
84 ;; This is very useful for cancelling a selection in the minibuffer without | 81 ;; This is very useful for cancelling a selection in the minibuffer without |
85 ;; aborting the minibuffer. | 82 ;; aborting the minibuffer. |
86 ;; It has actually nothing to do with pending-delete but its more necessary | 83 ;; It has actually nothing to do with pending-delete but its more necessary |
87 ;; with pending delete because pending delete users use the selection more. | 84 ;; with pending delete because pending delete users use the selection more. |
88 (defun keyboard-quit () | 85 (defun keyboard-quit () |
89 "Signal a `quit' condition. | 86 "Signal a `quit' condition. |
90 If this character is typed while lisp code is executing, it will be treated | 87 During execution of Lisp code, this character causes a quit directly. |
91 as an interrupt. | 88 At top-level, as an editor command, this simply beeps. |
92 If this character is typed at top-level, this simply beeps. | |
93 | |
94 In Transient Mark mode, if the mark is active, just deactivate it." | 89 In Transient Mark mode, if the mark is active, just deactivate it." |
95 (interactive) | 90 (interactive) |
96 (if (and transient-mark-mode mark-active) | 91 (if (and transient-mark-mode mark-active) |
97 (progn | 92 (progn |
98 ;; Don't beep if just deactivating the region. | 93 ;; Don't beep if just deactivating the region. |