Mercurial > emacs
annotate lisp/s-region.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | 727cf56647a4 |
children | b174db545cfd |
rev | line source |
---|---|
6220 | 1 ;;; s-region.el --- set region using shift key. |
14169 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
6220 | 4 |
17977 | 5 ;; Author: Morten Welinder <terra@diku.dk> |
6220 | 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 | |
14169 | 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. | |
6220 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; Having loaded this code you can set the region by holding down the | |
29 ;; shift key and move the cursor to the other end of the region. The | |
14040 | 30 ;; functionality provided by this code is similar to that provided by |
6220 | 31 ;; the editors of Borland International's compilers for ms-dos. |
32 | |
33 ;; Currently, s-region-move may be bound only to events that are vectors | |
34 ;; of length one and whose last element is a symbol. Also, the functions | |
35 ;; that are given this kind of overlay should be (interactive "p") | |
36 ;; functions. | |
37 | |
7991
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
38 ;; If the following keys are not already bound then... |
6220 | 39 ;; C-insert is bound to copy-region-as-kill |
40 ;; S-delete is bound to kill-region | |
41 ;; S-insert is bound to yank | |
42 | |
43 ;;; Code: | |
44 | |
45 (defvar s-region-overlay (make-overlay 1 1)) | |
46 (overlay-put s-region-overlay 'face 'region) | |
47 (overlay-put s-region-overlay 'priority 1000000) ; for hilit19 | |
48 | |
49 (defun s-region-unshift (key) | |
50 "Remove shift modifier from last keypress KEY and return that as a key." | |
51 (if (vectorp key) | |
52 (let ((last (aref key (1- (length key))))) | |
53 (if (symbolp last) | |
54 (let* ((keyname (symbol-name last)) | |
55 (pos (string-match "S-" keyname))) | |
56 (if pos | |
57 ;; We skip all initial parts of the event assuming that | |
58 ;; those are setting up the prefix argument to the command. | |
59 (vector (intern (concat (substring keyname 0 pos) | |
60 (substring keyname (+ 2 pos))))) | |
61 (error "Non-shifted key: %S" key))) | |
62 (error "Key does not end in a symbol: %S" key))) | |
63 (error "Non-vector key: %S" key))) | |
64 | |
12103 | 65 (defun s-region-move-p1 (&rest arg) |
66 "This is an overlay function to point-moving keys that are interactive \"p\"" | |
67 (interactive "p") | |
68 (apply (function s-region-move) arg)) | |
69 | |
70 (defun s-region-move-p2 (&rest arg) | |
71 "This is an overlay function to point-moving keys that are interactive \"P\"" | |
72 (interactive "P") | |
73 (apply (function s-region-move) arg)) | |
74 | |
6220 | 75 (defun s-region-move (&rest arg) |
76 (if (if mark-active (not (equal last-command 's-region-move)) t) | |
77 (set-mark-command nil) | |
78 (message "")) ; delete the "Mark set" message | |
12103 | 79 (setq this-command 's-region-move) |
6220 | 80 (apply (key-binding (s-region-unshift (this-command-keys))) arg) |
81 (move-overlay s-region-overlay (mark) (point) (current-buffer)) | |
82 (sit-for 1) | |
83 (delete-overlay s-region-overlay)) | |
84 | |
85 (defun s-region-bind (keylist &optional map) | |
12103 | 86 "Bind shifted keys in KEYLIST to s-region-move-p1 or s-region-move-p2. |
87 Each key in KEYLIST is shifted and bound to one of the s-region-move | |
88 functions provided it is already bound to some command or other. | |
89 Optional third argument MAP specifies keymap to add binding to, defaulting | |
90 to global keymap." | |
91 (let ((p2 (list 'scroll-up 'scroll-down | |
92 'beginning-of-buffer 'end-of-buffer))) | |
93 (or map (setq map global-map)) | |
94 (while keylist | |
95 (let* ((key (car keylist)) | |
96 (binding (key-binding key))) | |
97 (if (commandp binding) | |
98 (define-key | |
99 map | |
100 (vector (intern (concat "S-" (symbol-name (aref key 0))))) | |
101 (cond ((memq binding p2) | |
102 's-region-move-p2) | |
103 (t 's-region-move-p1))))) | |
104 (setq keylist (cdr keylist))))) | |
6220 | 105 |
12103 | 106 ;; Single keys (plus modifiers) only! |
6220 | 107 (s-region-bind |
108 (list [right] [left] [up] [down] | |
109 [C-left] [C-right] [C-up] [C-down] | |
110 [M-left] [M-right] [M-up] [M-down] | |
111 [next] [previous] [home] [end] | |
112 [C-next] [C-previous] [C-home] [C-end] | |
113 [M-next] [M-previous] [M-home] [M-end])) | |
114 | |
7991
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
115 (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
|
116 (global-set-key [C-insert] 'copy-region-as-kill)) |
11653
5416e2c64d19
(S-delete): Fix typo (was C-delete).
Richard M. Stallman <rms@gnu.org>
parents:
7991
diff
changeset
|
117 (or (global-key-binding [S-delete]) |
7991
f2e16be5a263
Don't bind keys C-insert, C-delete, and
Richard M. Stallman <rms@gnu.org>
parents:
6220
diff
changeset
|
118 (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
|
119 (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
|
120 (global-set-key [S-insert] 'yank)) |
6220 | 121 |
122 (provide 's-region) | |
123 | |
124 ;; s-region.el ends here. |