Mercurial > emacs
annotate lisp/s-region.el @ 8765:77933f36ddc2
(mouse-save-then-kill, mouse-secondary-save-then-kill): Use the kill-new
interface; don't manipulate kill-ring directly.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 15 Sep 1994 21:51:14 +0000 |
parents | f2e16be5a263 |
children | 5416e2c64d19 |
rev | line source |
---|---|
6220 | 1 ;;; s-region.el --- set region using shift key. |
2 ;;; Copyright (C) 1994 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Morten Welinder (terra@diku.dk) | |
5 ;; Version: 1.00 | |
6 ;; Keywords: terminals | |
7 ;; Favourite-brand-of-beer: None, I hate beer. | |
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 | |
25 ;;; Commentary: | |
26 | |
27 ;; Having loaded this code you can set the region by holding down the | |
28 ;; shift key and move the cursor to the other end of the region. The | |
29 ;; functionallity provided by this code is similar to that provided by | |
30 ;; the editors of Borland International's compilers for ms-dos. | |
31 | |
32 ;; Currently, s-region-move may be bound only to events that are vectors | |
33 ;; of length one and whose last element is a symbol. Also, the functions | |
34 ;; that are given this kind of overlay should be (interactive "p") | |
35 ;; functions. | |
36 | |
7991
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
37 ;; If the following keys are not already bound then... |
6220 | 38 ;; C-insert is bound to copy-region-as-kill |
39 ;; S-delete is bound to kill-region | |
40 ;; S-insert is bound to yank | |
41 | |
42 ;;; Code: | |
43 | |
44 (defvar s-region-overlay (make-overlay 1 1)) | |
45 (overlay-put s-region-overlay 'face 'region) | |
46 (overlay-put s-region-overlay 'priority 1000000) ; for hilit19 | |
47 | |
48 (defun s-region-unshift (key) | |
49 "Remove shift modifier from last keypress KEY and return that as a key." | |
50 (if (vectorp key) | |
51 (let ((last (aref key (1- (length key))))) | |
52 (if (symbolp last) | |
53 (let* ((keyname (symbol-name last)) | |
54 (pos (string-match "S-" keyname))) | |
55 (if pos | |
56 ;; We skip all initial parts of the event assuming that | |
57 ;; those are setting up the prefix argument to the command. | |
58 (vector (intern (concat (substring keyname 0 pos) | |
59 (substring keyname (+ 2 pos))))) | |
60 (error "Non-shifted key: %S" key))) | |
61 (error "Key does not end in a symbol: %S" key))) | |
62 (error "Non-vector key: %S" key))) | |
63 | |
64 (defun s-region-move (&rest arg) | |
65 "This is an overlay function to point-moving keys." | |
66 (interactive "p") | |
67 (if (if mark-active (not (equal last-command 's-region-move)) t) | |
68 (set-mark-command nil) | |
69 (message "")) ; delete the "Mark set" message | |
70 (apply (key-binding (s-region-unshift (this-command-keys))) arg) | |
71 (move-overlay s-region-overlay (mark) (point) (current-buffer)) | |
72 (sit-for 1) | |
73 (delete-overlay s-region-overlay)) | |
74 | |
75 (defun s-region-bind (keylist &optional map) | |
76 "Bind keys in KEYLIST to `s-region-move'. | |
77 Each key in KEYLIST is bound to `s-region-move' | |
78 provided it is already bound to some command or other. | |
79 Optional second argument MAP specifies keymap to | |
80 add binding to, defaulting to global keymap." | |
81 (or map (setq map global-map)) | |
82 (while keylist | |
83 (if (commandp (key-binding (car keylist))) | |
84 (define-key | |
85 map | |
86 (vector (intern (concat "S-" (symbol-name (aref (car keylist) 0))))) | |
87 's-region-move)) | |
88 (setq keylist (cdr keylist)))) | |
89 | |
90 (s-region-bind | |
91 (list [right] [left] [up] [down] | |
92 [C-left] [C-right] [C-up] [C-down] | |
93 [M-left] [M-right] [M-up] [M-down] | |
94 [next] [previous] [home] [end] | |
95 [C-next] [C-previous] [C-home] [C-end] | |
96 [M-next] [M-previous] [M-home] [M-end])) | |
97 | |
7991
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
98 (or (global-key-binding [C-insert]) |
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
99 (global-set-key [C-insert] 'copy-region-as-kill)) |
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
100 (or (global-key-binding [C-delete]) |
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
101 (global-set-key [S-delete] 'kill-region)) |
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
102 (or (global-key-binding [S-insert]) |
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
103 (global-set-key [S-insert] 'yank)) |
6220 | 104 |
105 (provide 's-region) | |
106 | |
107 ;; s-region.el ends here. |