123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- (provide 'keypad)
- (defcustom keypad-setup nil
- "Specifies the keypad setup for unshifted keypad keys when NumLock is off.
- When selecting the plain numeric keypad setup, the character returned by the
- decimal key must be specified."
- :set (lambda (symbol value)
- (if value
- (keypad-setup value nil nil value)))
- :initialize 'custom-initialize-default
- :link '(emacs-commentary-link "keypad.el")
- :version "22.1"
- :type '(choice (const :tag "Plain numeric keypad" numeric)
- (character :tag "Numeric Keypad with Decimal Key"
- :match (lambda (widget value) (integerp value))
- :value ?.)
- (const :tag "Numeric prefix arguments" prefix)
- (const :tag "Cursor keys" cursor)
- (const :tag "Shifted cursor keys" S-cursor)
- (const :tag "Unspecified/User-defined" none)
- (other :tag "Keep existing bindings" nil))
- :require 'keypad
- :group 'keyboard)
- (defcustom keypad-numlock-setup nil
- "Specifies the keypad setup for unshifted keypad keys when NumLock is on.
- When selecting the plain numeric keypad setup, the character returned by the
- decimal key must be specified."
- :set (lambda (symbol value)
- (if value
- (keypad-setup value t nil value)))
- :initialize 'custom-initialize-default
- :link '(emacs-commentary-link "keypad.el")
- :version "22.1"
- :type '(choice (const :tag "Plain numeric keypad" numeric)
- (character :tag "Numeric Keypad with Decimal Key"
- :match (lambda (widget value) (integerp value))
- :value ?.)
- (const :tag "Numeric prefix arguments" prefix)
- (const :tag "Cursor keys" cursor)
- (const :tag "Shifted cursor keys" S-cursor)
- (const :tag "Unspecified/User-defined" none)
- (other :tag "Keep existing bindings" nil))
- :require 'keypad
- :group 'keyboard)
- (defcustom keypad-shifted-setup nil
- "Specifies the keypad setup for shifted keypad keys when NumLock is off.
- When selecting the plain numeric keypad setup, the character returned by the
- decimal key must be specified."
- :set (lambda (symbol value)
- (if value
- (keypad-setup value nil t value)))
- :initialize 'custom-initialize-default
- :link '(emacs-commentary-link "keypad.el")
- :version "22.1"
- :type '(choice (const :tag "Plain numeric keypad" numeric)
- (character :tag "Numeric Keypad with Decimal Key"
- :match (lambda (widget value) (integerp value))
- :value ?.)
- (const :tag "Numeric prefix arguments" prefix)
- (const :tag "Cursor keys" cursor)
- (const :tag "Shifted cursor keys" S-cursor)
- (const :tag "Unspecified/User-defined" none)
- (other :tag "Keep existing bindings" nil))
- :require 'keypad
- :group 'keyboard)
- (defcustom keypad-numlock-shifted-setup nil
- "Specifies the keypad setup for shifted keypad keys when NumLock is off.
- When selecting the plain numeric keypad setup, the character returned by the
- decimal key must be specified."
- :set (lambda (symbol value)
- (if value
- (keypad-setup value t t value)))
- :initialize 'custom-initialize-default
- :link '(emacs-commentary-link "keypad.el")
- :version "22.1"
- :type '(choice (const :tag "Plain numeric keypad" numeric)
- (character :tag "Numeric Keypad with Decimal Key"
- :match (lambda (widget value) (integerp value))
- :value ?.)
- (const :tag "Numeric prefix arguments" prefix)
- (const :tag "Cursor keys" cursor)
- (const :tag "Shifted cursor keys" S-cursor)
- (const :tag "Unspecified/User-defined" none)
- (other :tag "Keep existing bindings" nil))
- :require 'keypad
- :group 'keyboard)
- (defun keypad-setup (setup &optional numlock shift decimal)
- "Set keypad bindings in `function-key-map' according to SETUP.
- If optional second argument NUMLOCK is non-nil, the NumLock On bindings
- are changed. Otherwise, the NumLock Off bindings are changed.
- If optional third argument SHIFT is non-nil, the shifted keypad
- keys are bound.
- Setup Binding
- -------------------------------------------------------------
- 'prefix Command prefix argument, i.e. M-0 .. M-9 and M--
- 'S-cursor Bind shifted keypad keys to the shifted cursor movement keys.
- 'cursor Bind keypad keys to the cursor movement keys.
- 'numeric Plain numeric keypad, i.e. 0 .. 9 and . (or DECIMAL arg)
- 'none Removes all bindings for keypad keys in function-key-map;
- this enables any user-defined bindings for the keypad keys
- in the global and local keymaps.
- If SETUP is 'numeric and the optional fourth argument DECIMAL is non-nil,
- the decimal key on the keypad is mapped to DECIMAL instead of `.'"
- (let* ((i 0)
- (var (cond
- ((and (not numlock) (not shift)) 'keypad-setup)
- ((and (not numlock) shift) 'keypad-shifted-setup)
- ((and numlock (not shift)) 'keypad-numlock-setup)
- ((and numlock shift) 'keypad-numlock-shifted-setup)))
- (kp (cond
- ((eq var 'keypad-setup)
- [kp-delete kp-insert kp-end kp-down kp-next kp-left
- kp-space kp-right kp-home kp-up kp-prior])
- ((eq var 'keypad-shifted-setup)
- [S-kp-decimal S-kp-0 S-kp-1 S-kp-2 S-kp-3 S-kp-4
- S-kp-5 S-kp-6 S-kp-7 S-kp-8 S-kp-9])
- ((eq var 'keypad-numlock-setup)
- [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4
- kp-5 kp-6 kp-7 kp-8 kp-9])
- ((eq var 'keypad-numlock-shifted-setup)
- [S-kp-delete S-kp-insert S-kp-end S-kp-down S-kp-next S-kp-left
- S-kp-space S-kp-right S-kp-home S-kp-up S-kp-prior])))
- (bind
- (cond
- ((or (eq setup 'numeric)
- (characterp setup))
- (if (eq decimal 'numeric)
- (setq decimal nil))
- (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
- ((eq setup 'prefix)
- [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4
- ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9])
- ((eq setup 'cursor)
- [delete insert end down next left
- space right home up prior])
- ((eq setup 'S-cursor)
- [S-delete S-insert S-end S-down S-next S-left
- S-space S-right S-home S-up S-prior])
- ((eq setup 'none)
- nil)
- (t
- (signal 'error (list "Unknown keypad setup: " setup))))))
- (set var setup)
-
-
- (if (not (boundp 'function-key-map))
- (setq function-key-map (make-sparse-keymap)))
- (while (< i 11)
- (define-key function-key-map (vector (aref kp i))
- (if bind (vector (aref bind i))))
- (if (= i 6)
- (cond ((eq (aref kp i) 'kp-space)
- (define-key function-key-map [kp-begin]
- (if bind (vector (aref bind i)))))
- ((eq (aref kp i) 'S-kp-space)
- (define-key function-key-map [S-kp-begin]
- (if bind (vector (aref bind i)))))))
- (setq i (1+ i)))))
|