Mercurial > emacs
comparison lisp/obsolete/s-region.el @ 107437:0a2bb00a71bd
* s-region.el: Move to obsolete.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sat, 20 Mar 2010 03:29:12 +0200 |
parents | lisp/s-region.el@1d1d5d9bd884 |
children | e090b66f115c 417b1e4d63cd |
comparison
equal
deleted
inserted
replaced
107436:ba737243d8d2 | 107437:0a2bb00a71bd |
---|---|
1 ;;; s-region.el --- set region using shift key | |
2 | |
3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, | |
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | |
5 | |
6 ;; Author: Morten Welinder <terra@diku.dk> | |
7 ;; Keywords: terminals | |
8 ;; Favourite-brand-of-beer: None, I hate beer. | |
9 ;; Obsolete-since: 24.1 | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation, either version 3 of the License, or | |
16 ;; (at your option) any later version. | |
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 | |
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
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 | |
30 ;; functionality provided by this code is similar to that provided by | |
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 | |
38 ;; If the following keys are not already bound then... | |
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 | |
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 | |
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 | |
79 (setq this-command 's-region-move) | |
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) | |
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 second 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))))) | |
105 | |
106 ;; Single keys (plus modifiers) only! | |
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 | |
115 (or (global-key-binding [C-insert]) | |
116 (global-set-key [C-insert] 'copy-region-as-kill)) | |
117 (or (global-key-binding [S-delete]) | |
118 (global-set-key [S-delete] 'kill-region)) | |
119 (or (global-key-binding [S-insert]) | |
120 (global-set-key [S-insert] 'yank)) | |
121 | |
122 (provide 's-region) | |
123 | |
124 ;; arch-tag: a471e912-18d7-4247-a29b-2100bca180ff | |
125 ;;; s-region.el ends here |