2073
|
1 ;;; Pending delete selection
|
|
2 ;;; Copyright (C) 1992 Free Software Foundation, Inc.
|
|
3 ;;; Created: 14 Jul 92, Matthieu Devin <devin@lucid.com>
|
|
4 ;;; Last change 18-Feb-93, devin.
|
|
5
|
|
6 ;;; This file is part of GNU Emacs.
|
|
7
|
|
8 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
9 ;;; it under the terms of the GNU General Public License as published by
|
|
10 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;;; any later version.
|
|
12
|
|
13 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 ;;; GNU General Public License for more details.
|
|
17
|
|
18 ;;; You should have received a copy of the GNU General Public License
|
|
19 ;;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
20 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
21
|
|
22
|
|
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.
|
|
25 ;;; This is a popular behavior of personal computers text editors.
|
|
26
|
2074
|
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
|
2073
|
32 (defun delete-active-region (&optional killp)
|
2074
|
33 (if killp
|
|
34 (kill-region (point) (mark))
|
|
35 (delete-region (point) (mark)))
|
|
36 (setq mark-active nil)
|
|
37 (run-hooks 'deactivate-mark-hook)
|
|
38 t)
|
2073
|
39
|
|
40 (defun pending-delete-pre-hook ()
|
2074
|
41 (if (and pending-delete-mode
|
|
42 (not buffer-read-only)
|
|
43 transient-mark-mode mark-active)
|
|
44 (let ((type (and (symbolp this-command)
|
|
45 (get this-command 'pending-delete))))
|
|
46 (cond ((eq type 'kill)
|
|
47 (delete-active-region t))
|
|
48 ((eq type 'supersede)
|
|
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)
|
2073
|
55
|
|
56 (put 'self-insert-command 'pending-delete t)
|
|
57
|
|
58 (put 'yank 'pending-delete t)
|
|
59 (put 'x-yank-clipboard-selection 'pending-delete t)
|
|
60
|
|
61 (put 'delete-backward-char 'pending-delete 'supersede)
|
|
62 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
|
|
63 (put 'delete-char 'pending-delete 'supersede)
|
|
64
|
|
65 (put 'newline-and-indent 'pending-delete 't)
|
|
66 (put 'newline 'pending-delete t)
|
|
67 (put 'open-line 'pending-delete t)
|
|
68
|
2074
|
69 (defun pending-delete-mode (arg)
|
2073
|
70 "Toggle the state of pending-delete mode.
|
|
71 When ON, typed text replaces the selection if the selection is active.
|
|
72 When OFF, typed text is just inserted at point."
|
2074
|
73 (interactive "P")
|
|
74 (setq pending-delete-mode
|
|
75 (if (null arg) (not pending-delete-mode)
|
|
76 (> (prefix-numeric-value arg) 0)))
|
|
77 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
|
2073
|
78
|
|
79 ;; This new definition of control-G makes the first control-G disown the
|
|
80 ;; selection and the second one signal a QUIT.
|
|
81 ;; This is very useful for cancelling a selection in the minibuffer without
|
|
82 ;; aborting the minibuffer.
|
|
83 ;; It has actually nothing to do with pending-delete but its more necessary
|
|
84 ;; with pending delete because pending delete users use the selection more.
|
|
85 (defun keyboard-quit ()
|
|
86 "Signal a `quit' condition.
|
2074
|
87 During execution of Lisp code, this character causes a quit directly.
|
|
88 At top-level, as an editor command, this simply beeps.
|
2073
|
89 In Transient Mark mode, if the mark is active, just deactivate it."
|
|
90 (interactive)
|
|
91 (if (and transient-mark-mode mark-active)
|
|
92 (progn
|
|
93 ;; Don't beep if just deactivating the region.
|
|
94 (setq mark-active nil)
|
|
95 (run-hooks 'deactivate-mark-hook))
|
|
96 (signal 'quit nil)))
|
|
97
|
|
98 (defun minibuffer-keyboard-quit ()
|
|
99 "Abort recursive edit.
|
|
100 In Transient Mark mode, if the mark is active, just deactivate it."
|
|
101 (interactive)
|
|
102 (if (and transient-mark-mode mark-active)
|
|
103 (progn
|
|
104 ;; Don't beep if just deactivating the region.
|
|
105 (setq mark-active nil)
|
|
106 (run-hooks 'deactivate-mark-hook))
|
|
107 (abort-recursive-edit)))
|
|
108
|
|
109 (define-key minibuffer-local-map "\C-g" 'minibuffer-keyboard-quit)
|
|
110
|
|
111 (provide 'pending-del)
|
|
112
|
|
113 ;; End of pending-del.el.
|