comparison lisp/emulation/keypad.el @ 44938:358d42530d42

Added cua-mode based files [split from original cua.el]: cua-base.el, cua-rect.el, cua-gmrk.el, and keypad.el
author Kim F. Storm <storm@cua.dk>
date Sun, 28 Apr 2002 21:48:39 +0000
parents
children eb7082dc04a0
comparison
equal deleted inserted replaced
44937:75c89848438b 44938:358d42530d42
1 ;;; keypad.el --- simplified keypad bindings
2
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
4
5 ;; Author: Kim F. Storm <storm@cua.dk>
6 ;; Keywords: keyboard convenience
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; The keypad package allows easy binding of the keypad keys to
28 ;; various commonly used sets of commands.
29 ;;
30 ;; With the following setup, the keypad can be used for numeric data
31 ;; entry, or to give numeric prefix arguments to emacs commands.
32 ;;
33 ;; (keypad-setup 'numeric)
34 ;; (keypad-setup 'prefix t)
35 ;;
36 ;; +--------+--------+--------+
37 ;; | M-7 | M-8 | M-9 |
38 ;; | 7 | 8 | 9 |
39 ;; +--------+--------+--------+
40 ;; | M-4 | M-5 | M-6 |
41 ;; | 4 | 5 | 6 |
42 ;; +--------+--------+--------+
43 ;; | M-1 | M-2 | M-3 |
44 ;; | 1 | 2 | 3 |
45 ;; +--------+--------+--------+
46 ;; | M-0 | M-- |
47 ;; | 0 | . |
48 ;; +-----------------+--------+
49
50 ;; The following keypad setup is used for navigation:
51 ;;
52 ;; (keypad-setup 'cursor)
53 ;; (keypad-setup 'S-cursor t)
54 ;;
55 ;; +--------+--------+--------+
56 ;; | S-home | S-up | S-PgUp |
57 ;; | Home | up | PgUp |
58 ;; +--------+--------+--------+
59 ;; | S-left |S-space |S-right |
60 ;; | left | space | right |
61 ;; +--------+--------+--------+
62 ;; | S-end | S-down | S-PgDn |
63 ;; | end | down | PgDn |
64 ;; +--------+--------+--------+
65 ;; | S-insert |S-delete|
66 ;; | insert | delete |
67 ;; +-----------------+--------+
68
69
70 ;;; Code:
71
72 (provide 'keypad)
73
74 ;;; Customization
75
76 ;;;###autoload
77 (defcustom keypad-setup nil
78 "Specifies the keypad setup for unshifted keypad keys.
79 The options are:
80 'prefix Numeric prefix argument, i.e. M-0 .. M-9 and M--
81 'cursor Cursor movement keys.
82 'S-cursor Shifted cursor movement keys.
83 'numeric Plain numeric, i.e. 0 .. 9 and . (or DECIMAL arg)
84 'none Removes all bindings for keypad keys in function-key-map.
85 nil Keep existing bindings for the keypad keys."
86 :set (lambda (symbol value)
87 (if value
88 (keypad-setup value nil keypad-decimal-key)))
89 :initialize 'custom-initialize-default
90 :set-after '(keypad-decimal-key)
91 :require 'keypad
92 :link '(emacs-commentary-link "keypad.el")
93 :version "21.4"
94 :type '(choice (const :tag "Numeric prefix arguments" prefix)
95 (const :tag "Cursor keys" cursor)
96 (const :tag "Shifted cursor keys" S-cursor)
97 (const :tag "Plain Numeric Keypad" numeric)
98 (const :tag "Remove bindings" none)
99 (other :tag "Keep existing bindings" :value nil))
100 :group 'keyboard)
101
102 (defcustom keypad-decimal-key ?.
103 "Character produced by the unshifted decimal key on the keypad."
104 :type 'character
105 :group 'keyboard)
106
107 ;;;###autoload
108 (defcustom keypad-shifted-setup nil
109 "Specifies the keypad setup for shifted keypad keys.
110 See `keypad-setup' for available options."
111 :set (lambda (symbol value)
112 (if value
113 (keypad-setup value t keypad-shifted-decimal-key)))
114 :initialize 'custom-initialize-default
115 :set-after '(keypad-shifted-decimal-key)
116 :require 'keypad
117 :link '(emacs-commentary-link "keypad.el")
118 :version "21.4"
119 :type '(choice (const :tag "Numeric prefix arguments" prefix)
120 (const :tag "Cursor keys" cursor)
121 (const :tag "Shifted cursor keys" S-cursor)
122 (const :tag "Plain Numeric Keypad" numeric)
123 (const :tag "Remove bindings" none)
124 (other :tag "Keep existing bindings" :value nil))
125 :group 'keyboard)
126
127 (defcustom keypad-shifted-decimal-key ?.
128 "Character produced by the unshifted decimal key on the keypad."
129 :type 'character
130 :group 'keyboard)
131
132 ;;;###autoload
133 (defun keypad-setup (setup &optional numlock decimal)
134 "Set keypad bindings in function-key-map according to SETUP.
135 If optional second argument NUMLOCK is non-nil, the NumLock On bindings
136 are changed. Otherwise, the NumLock Off bindings are changed.
137
138 Setup Binding
139 -------------------------------------------------------------
140 'prefix Command prefix argument, i.e. M-0 .. M-9 and M--
141 'S-cursor Bind shifted keypad keys to the shifted cursor movement keys.
142 'cursor Bind keypad keys to the cursor movement keys.
143 'numeric Plain numeric, i.e. 0 .. 9 and . (or DECIMAL arg)
144 'none Removes all bindings for keypad keys in function-key-map.
145
146 If SETUP is 'numeric and the optional third argument DECIMAL is non-nil,
147 the decimal key on the keypad is mapped to DECIMAL instead of `.'"
148 (let ((i 0)
149 (kp
150 (cond
151 (numlock
152 [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4
153 kp-5 kp-6 kp-7 kp-8 kp-9])
154 (t
155 [kp-delete kp-insert kp-end kp-down kp-next kp-left
156 kp-space kp-right kp-home kp-up kp-prior])))
157 (bind
158 (cond
159 ((eq setup 'numeric)
160 (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
161 ((eq setup 'prefix)
162 [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4
163 ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9])
164 ((eq setup 'cursor)
165 [delete insert end down next left
166 space right home up prior])
167 ((eq setup 'S-cursor)
168 [S-delete S-insert S-end S-down S-next S-left
169 S-space S-right S-home S-up S-prior])
170 ((eq setup 'none)
171 nil)
172 (t
173 (signal 'error (list "Unknown keypad setup: " setup))))))
174
175 ;; Bind the keys in KP list to BIND list in function-key-map.
176 ;; If BIND is nil, all bindings for the keys are removed.
177 (if (not (boundp 'function-key-map))
178 (setq function-key-map (make-sparse-keymap)))
179
180 (while (< i 11)
181 (define-key function-key-map (vector (aref kp i))
182 (if bind (vector (aref bind i))))
183 (setq i (1+ i)))))
184
185 ;;; keypad.el ends here