/[emacs]/emacs/lisp/emulation/keypad.el
ViewVC logotype

Diff of /emacs/lisp/emulation/keypad.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by kfstorm, Sun Apr 28 21:48:39 2002 UTC revision 1.2 by kfstorm, Tue May 14 20:30:55 2002 UTC
# Line 28  Line 28 
28  ;; various commonly used sets of commands.  ;; various commonly used sets of commands.
29  ;;  ;;
30  ;; With the following setup, the keypad can be used for numeric data  ;; With the following setup, the keypad can be used for numeric data
31  ;; entry, or to give numeric prefix arguments to emacs commands.  ;; entry when NumLock is off, and to give numeric prefix arguments to
32    ;; emacs commands, when NumLock on on.
33  ;;  ;;
34  ;;  (keypad-setup 'numeric)  ;;  keypad-setup         => Plain Numeric Keypad
35  ;;  (keypad-setup 'prefix t)  ;;  keypad-numlock-setup => Prefix numeric args
36  ;;  ;;
37  ;;    +--------+--------+--------+  ;;    +--------+--------+--------+
38  ;;    |  M-7   |  M-8   |  M-9   |  ;;    |  M-7   |  M-8   |  M-9   | <- numlock on
39  ;;    |   7    |   8    |   9    |  ;;    |   7    |   8    |   9    | <- numlock off
40  ;;    +--------+--------+--------+  ;;    +--------+--------+--------+
41  ;;    |  M-4   |  M-5   |  M-6   |  ;;    |  M-4   |  M-5   |  M-6   |
42  ;;    |   4    |   5    |   6    |  ;;    |   4    |   5    |   6    |
# Line 47  Line 48 
48  ;;    |        0        |   .    |  ;;    |        0        |   .    |
49  ;;    +-----------------+--------+  ;;    +-----------------+--------+
50    
51  ;; The following keypad setup is used for navigation:  ;; The following keypad setup is used for navigation together with
52    ;; modes like cua-mode which uses shifted movement keys to extend the
53    ;; region.
54  ;;  ;;
55  ;;  (keypad-setup 'cursor)  ;;  keypad-setup         => Cursor keys
56  ;;  (keypad-setup 'S-cursor t)  ;;  keypad-shifted-setup => Shifted cursor keys
57  ;;  ;;
58  ;;    +--------+--------+--------+  ;;    +--------+--------+--------+
59  ;;    | S-home | S-up   | S-PgUp |  ;;    | S-home | S-up   | S-PgUp | <- shifted, numlock off
60  ;;    |  Home  |  up    |  PgUp  |  ;;    |  Home  |  up    |  PgUp  | <- unshifted, numlock off
61  ;;    +--------+--------+--------+  ;;    +--------+--------+--------+
62  ;;    | S-left |S-space |S-right |  ;;    | S-left |S-space |S-right |
63  ;;    |  left  | space  | right  |  ;;    |  left  | space  | right  |
# Line 66  Line 69 
69  ;;    |     insert      | delete |  ;;    |     insert      | delete |
70  ;;    +-----------------+--------+  ;;    +-----------------+--------+
71    
72    ;; The following setup binds the unshifted keypad keys to plain
73    ;; numeric keys when NumLock is either on or off, but the decimal key
74    ;; produces either a . (NumLock off) or a , (NumLock on).  This is
75    ;; useful for e.g. Danish users where the decimal separator is a
76    ;; comma.
77    ;;
78    ;;  keypad-setup         => Plain Numeric Keypad
79    ;;  keypad-numlock-setup => Numeric Keypad with Decimal key: ,
80    ;;
81    ;;    +--------+--------+--------+
82    ;;    |   7    |   8    |   9    | <- numlock on
83    ;;    |   7    |   8    |   9    | <- numlock off
84    ;;    +--------+--------+--------+
85    ;;    |   4    |   5    |   6    |
86    ;;    |   4    |   5    |   6    |
87    ;;    +--------+--------+--------+
88    ;;    |   1    |   2    |   3    |
89    ;;    |   1    |   2    |   3    |
90    ;;    +--------+--------+--------+
91    ;;    |        0        |   ,    |
92    ;;    |        0        |   .    |
93    ;;    +-----------------+--------+
94    
95  ;;; Code:  ;;; Code:
96    
# Line 75  Line 100 
100    
101  ;;;###autoload  ;;;###autoload
102  (defcustom keypad-setup nil  (defcustom keypad-setup nil
103    "Specifies the keypad setup for unshifted keypad keys.    "Specifies the keypad setup for unshifted keypad keys when NumLock is off.
104  The options are:  When selecting the plain numeric keypad setup, the character returned by the
105   'prefix   Numeric prefix argument, i.e.  M-0 .. M-9 and M--  decimal key must be specified."
  'cursor   Cursor movement keys.  
  'S-cursor Shifted cursor movement keys.  
  'numeric  Plain numeric, i.e. 0 .. 9 and .  (or DECIMAL arg)  
  'none     Removes all bindings for keypad keys in function-key-map.  
  nil       Keep existing bindings for the keypad keys."  
106    :set (lambda (symbol value)    :set (lambda (symbol value)
107           (if value           (if value
108               (keypad-setup value nil keypad-decimal-key)))               (keypad-setup value nil nil value)))
109    :initialize 'custom-initialize-default    :initialize 'custom-initialize-default
   :set-after '(keypad-decimal-key)  
   :require 'keypad  
110    :link '(emacs-commentary-link "keypad.el")    :link '(emacs-commentary-link "keypad.el")
111    :version "21.4"    :version "21.4"
112    :type '(choice (const :tag "Numeric prefix arguments" prefix)    :type '(choice (const :tag "Plain numeric keypad" numeric)
113                     (character :tag "Numeric Keypad with Decimal Key"
114                                :match (lambda (widget value) (integerp value))
115                                :value ?.)
116                     (const :tag "Numeric prefix arguments" prefix)
117                   (const :tag "Cursor keys" cursor)                   (const :tag "Cursor keys" cursor)
118                   (const :tag "Shifted cursor keys" S-cursor)                   (const :tag "Shifted cursor keys" S-cursor)
                  (const :tag "Plain Numeric Keypad" numeric)  
119                   (const :tag "Remove bindings" none)                   (const :tag "Remove bindings" none)
120                   (other :tag "Keep existing bindings" :value nil))                   (other :tag "Keep existing bindings" nil))
121    :group 'keyboard)    :group 'keyboard)
122    
123  (defcustom keypad-decimal-key ?.  ;;;###autoload
124    "Character produced by the unshifted decimal key on the keypad."  (defcustom keypad-numlock-setup nil
125    :type 'character    "Specifies the keypad setup for unshifted keypad keys when NumLock is on.
126    When selecting the plain numeric keypad setup, the character returned by the
127    decimal key must be specified."
128      :set (lambda (symbol value)
129             (if value
130                 (keypad-setup value t nil value)))
131      :initialize 'custom-initialize-default
132      :link '(emacs-commentary-link "keypad.el")
133      :version "21.4"
134      :type '(choice (const :tag "Plain numeric keypad" numeric)
135                     (character :tag "Numeric Keypad with Decimal Key"
136                                :match (lambda (widget value) (integerp value))
137                                :value ?.)
138                     (const :tag "Numeric prefix arguments" prefix)
139                     (const :tag "Cursor keys" cursor)
140                     (const :tag "Shifted cursor keys" S-cursor)
141                     (const :tag "Remove bindings" none)
142                     (other :tag "Keep existing bindings" nil))
143    :group 'keyboard)    :group 'keyboard)
144    
145  ;;;###autoload  ;;;###autoload
146  (defcustom keypad-shifted-setup nil  (defcustom keypad-shifted-setup nil
147    "Specifies the keypad setup for shifted keypad keys.    "Specifies the keypad setup for shifted keypad keys when NumLock is off.
148  See `keypad-setup' for available options."  When selecting the plain numeric keypad setup, the character returned by the
149    decimal key must be specified."
150    :set (lambda (symbol value)    :set (lambda (symbol value)
151           (if value           (if value
152               (keypad-setup value t keypad-shifted-decimal-key)))               (keypad-setup value nil t value)))
153    :initialize 'custom-initialize-default    :initialize 'custom-initialize-default
   :set-after '(keypad-shifted-decimal-key)  
   :require 'keypad  
154    :link '(emacs-commentary-link "keypad.el")    :link '(emacs-commentary-link "keypad.el")
155    :version "21.4"    :version "21.4"
156    :type '(choice (const :tag "Numeric prefix arguments" prefix)    :type '(choice (const :tag "Plain numeric keypad" numeric)
157                     (character :tag "Numeric Keypad with Decimal Key"
158                                :match (lambda (widget value) (integerp value))
159                                :value ?.)
160                     (const :tag "Numeric prefix arguments" prefix)
161                   (const :tag "Cursor keys" cursor)                   (const :tag "Cursor keys" cursor)
162                   (const :tag "Shifted cursor keys" S-cursor)                   (const :tag "Shifted cursor keys" S-cursor)
                  (const :tag "Plain Numeric Keypad" numeric)  
163                   (const :tag "Remove bindings" none)                   (const :tag "Remove bindings" none)
164                   (other :tag "Keep existing bindings" :value nil))                   (other :tag "Keep existing bindings" nil))
165    :group 'keyboard)    :group 'keyboard)
166    
167  (defcustom keypad-shifted-decimal-key ?.  ;;;###autoload
168    "Character produced by the unshifted decimal key on the keypad."  (defcustom keypad-numlock-shifted-setup nil
169    :type 'character    "Specifies the keypad setup for shifted keypad keys when NumLock is off.
170    When selecting the plain numeric keypad setup, the character returned by the
171    decimal key must be specified."
172      :set (lambda (symbol value)
173             (if value
174                 (keypad-setup value t t value)))
175      :initialize 'custom-initialize-default
176      :link '(emacs-commentary-link "keypad.el")
177      :version "21.4"
178      :type '(choice (const :tag "Plain numeric keypad" numeric)
179                     (character :tag "Numeric Keypad with Decimal Key"
180                                :match (lambda (widget value) (integerp value))
181                                :value ?.)
182                     (const :tag "Numeric prefix arguments" prefix)
183                     (const :tag "Cursor keys" cursor)
184                     (const :tag "Shifted cursor keys" S-cursor)
185                     (const :tag "Remove bindings" none)
186                     (other :tag "Keep existing bindings" nil))
187    :group 'keyboard)    :group 'keyboard)
188    
189    
190  ;;;###autoload  ;;;###autoload
191  (defun keypad-setup (setup &optional numlock decimal)  (defun keypad-setup (setup &optional numlock shift decimal)
192    "Set keypad bindings in function-key-map according to SETUP.    "Set keypad bindings in function-key-map according to SETUP.
193  If optional second argument NUMLOCK is non-nil, the NumLock On bindings  If optional second argument NUMLOCK is non-nil, the NumLock On bindings
194  are changed. Otherwise, the NumLock Off bindings are changed.  are changed. Otherwise, the NumLock Off bindings are changed.
195    If optional third argument SHIFT is non-nil, the shifted keypad
196    keys are bound.
197    
198   Setup      Binding   Setup      Binding
199   -------------------------------------------------------------   -------------------------------------------------------------
200   'prefix   Command prefix argument, i.e.  M-0 .. M-9 and M--   'prefix   Command prefix argument, i.e.  M-0 .. M-9 and M--
201   'S-cursor Bind shifted keypad keys to the shifted cursor movement keys.   'S-cursor Bind shifted keypad keys to the shifted cursor movement keys.
202   'cursor   Bind keypad keys to the cursor movement keys.   'cursor   Bind keypad keys to the cursor movement keys.
203   'numeric  Plain numeric, i.e. 0 .. 9 and .  (or DECIMAL arg)   'numeric  Plain numeric keypad, i.e. 0 .. 9 and .  (or DECIMAL arg)
204   'none     Removes all bindings for keypad keys in function-key-map.   'none     Removes all bindings for keypad keys in function-key-map.
205    
206  If SETUP is 'numeric and the optional third argument DECIMAL is non-nil,  If SETUP is 'numeric and the optional fourth argument DECIMAL is non-nil,
207  the decimal key on the keypad is mapped to DECIMAL instead of `.'"  the decimal key on the keypad is mapped to DECIMAL instead of `.'"
208    (let ((i 0)    (let* ((i 0)
209          (kp           (var (cond
210           (cond                 ((and (not numlock) (not shift)) 'keypad-setup)
211            (numlock                 ((and (not numlock) shift) 'keypad-shifted-setup)
212             [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4                 ((and numlock (not shift)) 'keypad-numlock-setup)
213                         kp-5 kp-6 kp-7 kp-8 kp-9])                 ((and numlock shift) 'keypad-numlock-shifted-setup)))
214            (t           (kp (cond
215             [kp-delete kp-insert kp-end kp-down kp-next kp-left                ((eq var 'keypad-setup)
216                        kp-space kp-right kp-home kp-up kp-prior])))                 [kp-delete kp-insert kp-end kp-down kp-next kp-left
217          (bind                            kp-space kp-right kp-home kp-up kp-prior])
218           (cond                ((eq var 'keypad-shifted-setup)
219            ((eq setup 'numeric)                 [S-kp-decimal S-kp-0 S-kp-1 S-kp-2 S-kp-3 S-kp-4
220             (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))                               S-kp-5 S-kp-6 S-kp-7 S-kp-8 S-kp-9])
221            ((eq setup 'prefix)                ((eq var 'keypad-numlock-setup)
222             [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4                 [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4
223                    ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9])                             kp-5 kp-6 kp-7 kp-8 kp-9])
224            ((eq setup 'cursor)                ((eq var 'keypad-numlock-shifted-setup)
225             [delete insert end down next left                 [S-kp-delete S-kp-insert S-kp-end S-kp-down S-kp-next S-kp-left
226                    space right home up prior])                              S-kp-space S-kp-right S-kp-home S-kp-up S-kp-prior])))
227            ((eq setup 'S-cursor)           (bind
228             [S-delete S-insert S-end S-down S-next S-left            (cond
229                       S-space S-right S-home S-up S-prior])             ((or (eq setup 'numeric)
230            ((eq setup 'none)                  (char-valid-p setup))
231             nil)              (if (eq decimal 'numeric)
232            (t                  (setq decimal nil))
233             (signal 'error (list "Unknown keypad setup: " setup))))))              (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
234               ((eq setup 'prefix)
235                [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4
236                       ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9])
237               ((eq setup 'cursor)
238                [delete insert end down next left
239                        space right home up prior])
240               ((eq setup 'S-cursor)
241                [S-delete S-insert S-end S-down S-next S-left
242                          S-space S-right S-home S-up S-prior])
243               ((eq setup 'none)
244                nil)
245               (t
246                (signal 'error (list "Unknown keypad setup: " setup))))))
247    
248        (set var setup)
249    
250      ;; Bind the keys in KP list to BIND list in function-key-map.      ;; Bind the keys in KP list to BIND list in function-key-map.
251      ;; If BIND is nil, all bindings for the keys are removed.      ;; If BIND is nil, all bindings for the keys are removed.

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26