*** empty log message ***
[bpt/emacs.git] / lisp / term / wyse50.el
1 ; Like all the other files in this dir, this one needs to be redone
2 ; for the new way of handling function keys.
3
4 ; Terminal mode for Wyse 50
5 ; should work well for Televideo Tvi 925 though it's an overkill
6 ; Author Daniel Pfeiffer <pfeiffer@cix.cict.fr> january 1991
7
8 (require 'keypad)
9
10 ; at least some of these should be transferred to keypad.el
11 (keypad-default "A" '(lambda () (interactive)
12 ; actually insert an empty line
13 (beginning-of-line)
14 (open-line 1)))
15 (keypad-default "E" 'kill-line)
16 ; (keypad-default "h" 'execute-extended-command)
17 (define-key function-keymap "h" 'execute-extended-command) ; bad, bad !!
18 (keypad-default "H" 'shell-command)
19 (keypad-default "I" '(lambda () (interactive)
20 (insert ? ))) ; works even in overwrite-mode
21 (keypad-default "L" '(lambda () (interactive)
22 ; delete the whole line
23 (beginning-of-line)
24 (kill-line 1)))
25 (keypad-default "M" 'overwrite-mode)
26 (keypad-default "\^e" 'shell) ; F5
27 (keypad-default "\^f" 'dired) ; F6
28 (keypad-default "\^g" 'rnews) ; F7
29 (keypad-default "\^h" 'rmail) ; F8
30
31 (keypad-default "\^i" 'delete-other-windows) ; F9
32 (keypad-default "\^j" 'other-window) ; F10
33 (keypad-default "\^k" 'split-window-vertically) ; F11
34
35 (keypad-default "\^m" 'help-for-help) ; F13
36 (keypad-default "\^n" 'toggle-screen-width) ; F14
37 (keypad-default "\^o" 'set-function-key) ; F15
38
39
40 ; Keys that don't conflict with Emacs defaults
41 ; I write \M-x and \C-x for what the user types, \ex and \^x for key sequences
42 (setup-terminal-keymap global-map
43 '(("\M-?" . ?\?) ; Esc ?
44 ("\eI" . ?T) ; Shift Tab
45 ("\eJ" . ?P) ; Shift Prev PAGE
46 ("\eK" . ?N) ; PAGE Next
47 ("\eY" . ?C) ; Shift Scrn CLR
48 ("\eT" . ?E) ; CLR Line
49 ("\^^" . ?h) ; Home
50 ("\M-\^^" . ?H) ; Esc Home
51 ("\eQ" . ?I) ; INS Char
52 ("\eE" . ?A) ; Shift Line INS
53 ("\eW" . ?D) ; DEL Char
54 ("\eR" . ?L))) ; Shift Line DEL
55
56 ; Print -- put in some extra security
57 (global-set-key "\eP" '(lambda () (interactive)
58 (if (y-or-n-p
59 (concat "Print buffer "
60 (buffer-name) "? "))
61 (print-buffer))))
62
63
64 ; this is an ugly hack for a nasty problem:
65 ; Wyse 50 takes one character cell to store video attributes (which seems to
66 ; explain width 79 rather than 80, column 1 is not used!!!).
67 ; On killing (C-x C-c) the end inverse code (on column 1 of line 24)
68 ; of the mode line is overwritten AFTER all the y-or-n questions.
69 ; This causes the attribute to remain in effect until the mode line has
70 ; scrolled of the screen. Suspending (C-z) does not cause this problem.
71 ; On such terminals, Emacs should sacrifice the first and last character of
72 ; each mode line, rather than a whole screen column!
73 (setq kill-emacs-hook '(lambda () (interactive)
74 (send-string-to-terminal
75 (concat "\ea23R" (1+ (screen-width)) "C\eG0"))))
76
77
78 ; This function does more than its name which was copied from term/vt100.el
79 ; Some more neutral name should be used thru-out term/*.el to simplify
80 ; programming term-setup-hook
81 (defun enable-arrow-keys ()
82 "To be called by term-setup-hook. Overrides 6 Emacs standard keys
83 whose functions are then typed as follows:
84 C-a Funct left-arrow, C-a C-a
85 C-h M-?
86 LFD Funct Return, some modes override down-arrow via LFD
87 C-k CLR Line
88 C-l Shift Scrn CLR
89 M-r M-x move-to-window-line, Funct up-arrow or down-arrow are similar
90 All special keys except Send, Shift Ins, Shift Home and shifted functions keys
91 are assigned some hopefully useful meaning."
92 (interactive)
93
94 ; Function keys
95 (define-key global-map "\^a" (define-prefix-command 'Funct-prefix))
96
97 ; Arrow keys
98 (setup-terminal-keymap global-map
99 '(("\C-a\C-a" . beginning-of-line) ; for auld lang syne
100 ("\^a\^m\^m" . newline-and-indent)
101
102 ("\^k" . ?u) ; up-arrow
103 ("\^j" . ?d) ; down-arrow
104 ("\^l" . ?r) ; right-arrow
105 ("\^h" . ?l) ; left-arrow
106
107 ; Terminal needs both Ins and Repl but Emacs knows how to toggle
108 ; with just one key. No need to override Ins which is "\eq".
109 ("\er" . ?M) ; Repl
110
111 ("\^a\^i\^m" . ?t) ; Funct Tab
112
113 ; Function keys F1 thru F16 (we don't define shifted function keys,
114 ; they send the same code with the middle character in lowercase.
115 ; eg. "Shift F2" is the same as "Funct a" which is more mnemonic but
116 ; keypad.el doesn't provide enough codes to accomodate all these)
117 ("\^a@\^m" . 1) ("\^aH\^m" . 9)
118 ("\^aA\^m" . 2) ("\^aI\^m" . 10)
119 ("\^aB\^m" . 3) ("\^aJ\^m" . 11)
120 ("\^aC\^m" . 4) ("\^aK\^m" . 12)
121 ("\^aD\^m" . 5) ("\^aL\^m" . 13)
122 ("\^aE\^m" . 6) ("\^aM\^m" . 14)
123 ("\^aF\^m" . 7) ("\^aN\^m" . 15)
124 ("\^aG\^m" . 8) ("\^aO\^m" . 16)
125
126 ; Funct Arrow keys
127 ("\^a\^k\^m" . (lambda (n) (interactive "p")
128 (move-to-window-line (1- n))))
129 ("\^a\^j\^m" . (lambda (n) (interactive "p")
130 (move-to-window-line (- n))))
131 ("\^a\^h\^m" . beginning-of-line)
132 ("\^a\^l\^m" . end-of-line)))
133
134 ; forget self to put memory to some serious use
135 (fmakunbound 'enable-arrow-keys))
136
137
138 (defun toggle-screen-width ()
139 "Alternate between 80 and 132 columns."
140 (interactive)
141 (if (<= (screen-width) 80)
142 (progn
143 (send-string-to-terminal "\e`;")
144 (set-screen-width 131))
145 (send-string-to-terminal "\e`:")
146 (set-screen-width 79)))
147
148 ;-----------------------------------------------------------------------------
149 ; this function is completely independent of wyse, it should be auto-loadable
150 ; (presumably from keypad.el) for use in ~/emacs. It should be the only thing
151 ; users need to know about all this unintelligible "forwarding" gibberish.
152 ; This paves the way for a save-function-keys (some day or sleepless night)
153 ; that will edit calls like (set-function-key ?x 'do-whatever) in ~/.emacs.
154 (defun set-function-key (key &optional def)
155 "Prompt for a function or other special key and assign it a meaning.
156 The key must have been \"forwarded\" to a character by term/*.el.
157
158 As a function takes two args CHAR and DEF, with DEF as in define-key.
159 If your terminals term/*.el forwards a physical key to CHAR (before or after
160 calling this function), then that key will mean DEF, else it is ignored.
161 CHAR is one of the following:
162 For numbered function keys
163 0, 1, ..., 24 (or ?\\^@, ?\\^a, ..., ?\\^x which is the same)
164 For keypad keys in application mode
165 ?0, ?1, ..., ?9 -- keypad key labelled with that digit,
166 but only if that key is not an arrow key (see ?u, ?d, ?r, ?l).
167 ?- -- keypad key labelled `-'.
168 ?. -- keypad key labelled `.'.
169 ?, -- keypad key labelled `,'.
170 ?e -- key labelled enter.
171 For keys labelled with some words or a symbol
172 ?a -- clear all tabs key.
173 ?A -- insert line key.
174 ?C -- clear screen key.
175 ?c -- erase key.
176 ?D -- delete character key.
177 ?d -- down-arrow.
178 ?E -- clear to end of line key.
179 ?e -- key labelled enter.
180 ?f -- find key or search key.
181 ?F -- scroll forward key.
182 ?H -- home-down.
183 ?h -- home-position key.
184 ?I -- insert character key
185 If there is just an \"insert\" key, it should be this.
186 ?k -- delete key or remove key.
187 ?L -- delete line key.
188 ?l -- left-arrow.
189 ?M -- exit insert mode key.
190 ?N -- next page key.
191 ?p -- portrait mode.
192 ?P -- previous page key.
193 ?q -- landscape mode.
194 ?r -- right-arrow.
195 ?R -- scroll reverse key.
196 ?S -- clear to end of screen key.
197 ?s -- select key.
198 ?t -- clear tab this column key.
199 ?T -- set tab this column key.
200 ?u -- up-arrow.
201 ?x -- do key.
202 ?\\? -- help."
203 (interactive "kHit key to redefine")
204 (let ((map function-keymap))
205 (if (integerp key)
206 ()
207 ; reinvent lookup-key to get (map . char) instead of def of char in map
208 (setq map (or (lookup-key global-map
209 (substring key 0 (1- (length key))))
210 global-map)
211 key (string-to-char (substring key (1- (length key)))))
212 (while (symbolp map)
213 (setq map (symbol-function map)))
214 (setq map (if (listp map)
215 (cdr (assq key (cdr map)))
216 (aref map key)))
217 (if (and (consp map)
218 (integerp (cdr map)))
219 (setq key (cdr map)
220 map (car map)) ; function-keymap usually
221 (error "Key is not a \"forwarded\" definition.")))
222 (if def
223 ()
224 (setq def (read-command "command (default last keyboard macro): "))
225 (if (string-equal (symbol-name def) "")
226 (setq def last-kbd-macro))
227 (setq command-history ; nonsense really, since you don't see
228 (cons ; key as in a function call (?char)
229 (list 'set-function-key key
230 (if (stringp def) def (list 'quote def)))
231 command-history)))
232 ; all we do when called as a function
233 (define-key map (char-to-string key) def)))
234
235