annotate lisp/hyperbole/hmouse-mod.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: hmouse-mod.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Action Key acts as CONTROL modifier and Assist Key as META modifier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: hypermedia, mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Motorola, Inc., PPG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 8-Oct-92 at 19:08:31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 14-Apr-95 at 16:06:26 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1992-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; This module is meant to be used with a chord keyboard in one hand for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; typing and a mouse in the other. It requires that Hyperbole be loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; in order to work. Hyperbole defines two Smart Keys, the Action Key and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; the Assist Key, on the middle and right buttons by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; If the Action Key is held down while alpha characters are typed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; they are translated into Control keys instead. The Assist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Key translates them into Meta keys. When both Smart Keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; are depressed, Control-Meta keys are produced. The commands bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; to the characters produced are then run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; So the Smart Keys modify the keys typed, e.g. Action Key + {a}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; runs the function for {C-a}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; If no keys are typed while the Smart Keys are down, they operate as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; normally under Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; TO INVOKE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; (hmouse-mod-set-global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (require 'hyperbole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defvar hmouse-mod-global-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Global key map installed by hmouse-mod-set-global-map function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 Translates self-insert-command characters into control and meta characters if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 the Action or Assist Keys are depressed at the time of key press.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defun hmouse-mod-insert-command (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "Surrogate function for self-insert-command. Accounts for modifier Smart Keys."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (and (boundp 'action-key-depressed-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (boundp 'assist-key-depressed-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (cond ((and action-key-depressed-flag assist-key-depressed-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setq action-key-cancelled t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 assist-key-cancelled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (let* ((c (downcase last-command-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (key (char-to-string (+ 128 (% (- c ?\`) 128)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (if (and (or (= c ?\C-@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (>= c ?a) (<= c ?z)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (hmouse-mod-execute-command key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; Control keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (action-key-depressed-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (setq action-key-cancelled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (let ((c (downcase last-command-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (and (or (= c ?\C-@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (>= c ?a) (<= c ?z)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (hmouse-mod-execute-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (char-to-string (- c ?\`)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; Meta keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (assist-key-depressed-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq assist-key-cancelled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (hmouse-mod-execute-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (char-to-string (+ 128 (% last-command-char 128))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (t (call-interactively 'self-insert-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (call-interactively 'self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun hmouse-mod-keyboard-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "Surrogate function for keyboard-quit. Cancels any hmouse-mod-prefix."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq hmouse-mod-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (keyboard-quit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun hmouse-mod-set-global-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Creates 'hmouse-mod-global-map' and installs as current global map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 It accounts for modifier Smart Keys."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq hmouse-mod-global-map (copy-keymap global-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (substitute-key-definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 'self-insert-command 'hmouse-mod-insert-command hmouse-mod-global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (substitute-key-definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 'keyboard-quit 'hmouse-mod-keyboard-quit hmouse-mod-global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (use-global-map hmouse-mod-global-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun hmouse-mod-execute-command (key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "Executes command associated with keyboard KEY or if KEY prefix, records it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq key (concat hmouse-mod-prefix key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((binding (key-binding key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (cond ((and (not (or (vectorp binding) (stringp binding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (commandp binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (> (length key) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (or noninteractive (message (key-description key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq hmouse-mod-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (call-interactively binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ((symbolp binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq hmouse-mod-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (error "(hmouse-mod-execute-command): {%s} not bound to a command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (key-description key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ((integerp binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq hmouse-mod-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (error "(hmouse-mod-execute-command): {%s} invalid key sequence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (key-description key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (t (or noninteractive (message (key-description key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq hmouse-mod-prefix key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar hmouse-mod-prefix nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Prefix key part of current key sequence.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (provide 'hmouse-mod)