Mercurial > emacs
annotate lisp/obsolete/s-region.el @ 110211:6cdcc53703e4
mail-source.el (mail-source-fetch): Don't message if we're fetching mail from a file, and the file doesn't exist.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Sun, 05 Sep 2010 23:38:33 +0000 |
parents | 0a2bb00a71bd |
children | e090b66f115c 417b1e4d63cd |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
17977
diff
changeset
|
1 ;;; s-region.el --- set region using shift key |
14169 | 2 |
74442 | 3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
6220 | 5 |
17977 | 6 ;; Author: Morten Welinder <terra@diku.dk> |
6220 | 7 ;; Keywords: terminals |
8 ;; Favourite-brand-of-beer: None, I hate beer. | |
107437
0a2bb00a71bd
* s-region.el: Move to obsolete.
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
9 ;; Obsolete-since: 24.1 |
6220 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
6220 | 14 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
6220 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
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 | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38436
diff
changeset
|
35 ;; that are given this kind of overlay should be (interactive "p") |
6220 | 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) |
64547
8eafe3e25a6c
(s-region-bind): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
66 "This is an overlay function to point-moving keys that are interactive \"p\"." |
12103 | 67 (interactive "p") |
68 (apply (function s-region-move) arg)) | |
69 | |
70 (defun s-region-move-p2 (&rest arg) | |
64547
8eafe3e25a6c
(s-region-bind): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
71 "This is an overlay function to point-moving keys that are interactive \"P\"." |
12103 | 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) | |
64547
8eafe3e25a6c
(s-region-bind): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
86 "Bind shifted keys in KEYLIST to `s-region-move-p1' or `s-region-move-p2'. |
8eafe3e25a6c
(s-region-bind): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
87 Each key in KEYLIST is shifted and bound to one of the `s-region-move' |
12103 | 88 functions provided it is already bound to some command or other. |
64547
8eafe3e25a6c
(s-region-bind): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
89 Optional second argument MAP specifies keymap to add binding to, defaulting |
12103 | 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 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
124 ;; arch-tag: a471e912-18d7-4247-a29b-2100bca180ff |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
17977
diff
changeset
|
125 ;;; s-region.el ends here |