Mercurial > emacs
annotate lisp/terminal.el @ 12111:832023e90d4d
(x_real_positions): Uncatch and recatch X errors in the loop.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 07 Jun 1995 21:02:00 +0000 |
parents | a2b107c4f2f1 |
children | 5c78211aa9e0 |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
630
diff
changeset
|
1 ;;; terminal.el --- terminal emulator for GNU Emacs. |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
630
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1986,87,88,89,93,94 Free Software Foundation, Inc. |
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
751
diff
changeset
|
5 ;; Author: Richard Mlynarik <mly@eddie.mit.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
751
diff
changeset
|
6 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2030
diff
changeset
|
7 ;; Keywords: comm, terminals |
161 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
751
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
161 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
751
diff
changeset
|
25 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
751
diff
changeset
|
26 |
161 | 27 ;;>>TODO |
28 ;;>> ** Nothing can be done about emacs' meta-lossage ** | |
29 ;;>> (without redoing keymaps `sanely' -- ask Mly for details) | |
30 | |
31 ;;>> One probably wants to do setenv MORE -c when running with | |
32 ;;>> more-processing enabled. | |
33 | |
34 (require 'ehelp) | |
35 | |
36 (defvar terminal-escape-char ?\C-^ | |
37 "*All characters except for this are passed verbatim through the | |
38 terminal-emulator. This character acts as a prefix for commands | |
39 to the emulator program itself. Type this character twice to send | |
40 it through the emulator. Type ? after typing it for a list of | |
41 possible commands. | |
42 This variable is local to each terminal-emulator buffer.") | |
43 | |
44 (defvar terminal-scrolling t ;;>> Setting this to T sort-of defeats my whole aim in writing this package... | |
45 "*If non-nil, the terminal-emulator will losingly `scroll' when output occurs | |
46 past the bottom of the screen. If nil, output will win and `wrap' to the top | |
47 of the screen. | |
48 This variable is local to each terminal-emulator buffer.") | |
49 | |
50 (defvar terminal-more-processing t | |
51 "*If non-nil, do more-processing. | |
52 This variable is local to each terminal-emulator buffer.") | |
53 | |
54 ;; If you are the sort of loser who uses scrolling without more breaks | |
55 ;; and expects to actually see anything, you should probably set this to | |
56 ;; around 400 | |
57 (defvar terminal-redisplay-interval 5000 | |
58 "*Maximum number of characters which will be processed by the | |
59 terminal-emulator before a screen redisplay is forced. | |
60 Set this to a large value for greater throughput, | |
61 set it smaller for more frequent updates but overall slower | |
62 performance.") | |
63 | |
64 (defvar terminal-more-break-insertion | |
65 "*** More break -- Press space to continue ***") | |
66 | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
67 (defvar terminal-meta-map nil) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
68 (if terminal-meta-map |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
69 nil |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
70 (let ((map (make-sparse-keymap))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
71 (define-key map [t] 'te-pass-through) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
72 (setq terminal-meta-map map))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
73 |
161 | 74 (defvar terminal-map nil) |
75 (if terminal-map | |
76 nil | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
77 (let ((map (make-sparse-keymap))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
78 (define-key map [t] 'te-pass-through) |
8852
90a35a24cde1
(terminal-map): Define switch-frame.
Richard M. Stallman <rms@gnu.org>
parents:
7374
diff
changeset
|
79 (define-key map [switch-frame] 'handle-switch-frame) |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
80 (define-key map "\e" terminal-meta-map) |
161 | 81 ;(define-key map "\C-l" |
82 ; '(lambda () (interactive) (te-pass-through) (redraw-display))) | |
83 (setq terminal-map map))) | |
84 | |
2587
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
85 (defvar terminal-escape-map nil) |
161 | 86 (if terminal-escape-map |
87 nil | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
88 (let ((map (make-sparse-keymap))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
89 (define-key map [t] 'undefined) |
161 | 90 (let ((s "0")) |
91 (while (<= (aref s 0) ?9) | |
92 (define-key map s 'digit-argument) | |
93 (aset s 0 (1+ (aref s 0))))) | |
94 (define-key map "b" 'switch-to-buffer) | |
95 (define-key map "o" 'other-window) | |
96 (define-key map "e" 'te-set-escape-char) | |
97 (define-key map "\C-l" 'redraw-display) | |
98 (define-key map "\C-o" 'te-flush-pending-output) | |
99 (define-key map "m" 'te-toggle-more-processing) | |
100 (define-key map "x" 'te-escape-extended-command) | |
101 ;;>> What use is this? Why is it in the default terminal-emulator map? | |
102 (define-key map "w" 'te-edit) | |
103 (define-key map "?" 'te-escape-help) | |
104 (define-key map (char-to-string help-char) 'te-escape-help) | |
105 (setq terminal-escape-map map))) | |
106 | |
2587
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
107 (defvar te-escape-command-alist nil) |
161 | 108 (if te-escape-command-alist |
109 nil | |
110 (setq te-escape-command-alist | |
111 '(("Set Escape Character" . te-set-escape-char) | |
112 ;;>> What use is this? Why is it in the default terminal-emulator map? | |
113 ("Edit" . te-edit) | |
114 ("Refresh" . redraw-display) | |
115 ("Record Output" . te-set-output-log) | |
116 ("Photo" . te-set-output-log) | |
117 ("Tofu" . te-tofu) ;; confuse the uninitiated | |
118 ("Stuff Input" . te-stuff-string) | |
119 ("Flush Pending Output" . te-flush-pending-output) | |
120 ("Enable More Processing" . te-enable-more-processing) | |
121 ("Disable More Processing" . te-disable-more-processing) | |
122 ("Scroll at end of page" . te-do-scrolling) | |
123 ("Wrap at end of page" . te-do-wrapping) | |
124 ("Switch To Buffer" . switch-to-buffer) | |
125 ("Other Window" . other-window) | |
126 ("Kill Buffer" . kill-buffer) | |
127 ("Help" . te-escape-help) | |
128 ("Set Redisplay Interval" . te-set-redisplay-interval) | |
129 ))) | |
130 | |
2587
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
131 (defvar terminal-more-break-map nil) |
161 | 132 (if terminal-more-break-map |
133 nil | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
134 (let ((map (make-sparse-keymap))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
135 (define-key map [t] 'te-more-break-unread) |
161 | 136 (define-key map (char-to-string help-char) 'te-more-break-help) |
137 (define-key map " " 'te-more-break-resume) | |
138 (define-key map "\C-l" 'redraw-display) | |
139 (define-key map "\C-o" 'te-more-break-flush-pending-output) | |
140 ;;>>> this isn't right | |
141 ;(define-key map "\^?" 'te-more-break-flush-pending-output) ;DEL | |
142 (define-key map "\r" 'te-more-break-advance-one-line) | |
143 | |
144 (setq terminal-more-break-map map))) | |
145 | |
146 | |
2587
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
147 ;;; Pacify the byte compiler |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
148 (defvar te-process nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
149 (defvar te-log-buffer nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
150 (defvar te-height nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
151 (defvar te-width nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
152 (defvar te-more-count nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
153 (defvar te-redisplay-count nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
154 (defvar te-pending-output nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
155 (defvar te-saved-point) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
156 (defvar te-more-old-point nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
157 (defvar te-more-old-local-map nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
158 (defvar te-more-old-filter nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
159 (defvar te-more-old-mode-line-format nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
160 (defvar te-pending-output-info nil) |
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
161 |
10294 | 162 ;; Required to support terminfo systems |
163 (defconst te-terminal-name-prefix "emacs-virtual") | |
164 (defvar te-terminal-name nil) | |
2587
1cad2ff5ab80
I started to clean this up and make it work under System V, until I hit a wall.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
165 |
161 | 166 ;;;; escape map |
167 | |
168 (defun te-escape () | |
169 (interactive) | |
170 (let (s | |
171 (local (current-local-map)) | |
172 (global (current-global-map))) | |
173 (unwind-protect | |
174 (progn | |
175 (use-global-map terminal-escape-map) | |
176 (use-local-map terminal-escape-map) | |
177 (setq s (read-key-sequence | |
10848
e591f74ac16e
(te-escape): Use current-prefix-arg, not prefix-arg.
Karl Heuer <kwzh@gnu.org>
parents:
10694
diff
changeset
|
178 (if current-prefix-arg |
161 | 179 (format "Emacs Terminal escape> %d " |
10848
e591f74ac16e
(te-escape): Use current-prefix-arg, not prefix-arg.
Karl Heuer <kwzh@gnu.org>
parents:
10694
diff
changeset
|
180 (prefix-numeric-value current-prefix-arg)) |
161 | 181 "Emacs Terminal escape> ")))) |
182 (use-global-map global) | |
183 (use-local-map local)) | |
184 (message "") | |
185 (cond ((string= s (make-string 1 terminal-escape-char)) | |
186 (setq last-command-char terminal-escape-char) | |
187 (let ((terminal-escape-char -259)) | |
188 (te-pass-through))) | |
189 ((setq s (lookup-key terminal-escape-map s)) | |
190 (call-interactively s))))) | |
191 | |
192 (defun te-escape-help () | |
193 "Provide help on commands available after terminal-escape-char is typed." | |
194 (interactive) | |
195 (message "Terminal emulator escape help...") | |
196 (let ((char (single-key-description terminal-escape-char))) | |
197 (with-electric-help | |
198 (function (lambda () | |
199 (princ (format "Terminal-emulator escape, invoked by \"%s\" | |
200 Type \"%s\" twice to send a single \"%s\" through. | |
201 | |
202 Other chars following \"%s\" are interpreted as follows:\n" | |
203 char char char char)) | |
204 | |
205 (princ (substitute-command-keys "\\{terminal-escape-map}\n")) | |
206 (princ (format "\nSubcommands of \"%s\" (%s)\n" | |
207 (where-is-internal 'te-escape-extended-command | |
5774
b57901dfbd40
(te-escape-help, te-more-break-help, terminal-emulator):
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
208 terminal-escape-map t) |
161 | 209 'te-escape-extended-command)) |
210 (let ((l (if (fboundp 'sortcar) | |
211 (sortcar (copy-sequence te-escape-command-alist) | |
212 'string<) | |
213 (sort (copy-sequence te-escape-command-alist) | |
214 (function (lambda (a b) | |
215 (string< (car a) (car b)))))))) | |
216 (while l | |
217 (let ((doc (or (documentation (cdr (car l))) | |
218 "Not documented"))) | |
219 (if (string-match "\n" doc) | |
220 ;; just use first line of documentation | |
221 (setq doc (substring doc 0 (match-beginning 0)))) | |
222 (princ " \"") | |
223 (princ (car (car l))) | |
224 (princ "\":\n ") | |
225 (princ doc) | |
226 (write-char ?\n)) | |
227 (setq l (cdr l)))) | |
228 nil))))) | |
229 | |
230 | |
231 | |
232 (defun te-escape-extended-command () | |
233 (interactive) | |
234 (let ((c (let ((completion-ignore-case t)) | |
235 (completing-read "terminal command: " | |
236 te-escape-command-alist | |
237 nil t)))) | |
238 (if c | |
239 (catch 'foo | |
240 (setq c (downcase c)) | |
241 (let ((l te-escape-command-alist)) | |
242 (while l | |
243 (if (string= c (downcase (car (car l)))) | |
244 (throw 'foo (call-interactively (cdr (car l)))) | |
245 (setq l (cdr l))))))))) | |
246 | |
247 ;; not used. | |
248 (defun te-escape-extended-command-unread () | |
249 (interactive) | |
2030
ffe1f05d5727
(te-escape-extended-command-unread): Handle any key sequence.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
250 (setq unread-command-events (listify-key-sequence (this-command-keys))) |
161 | 251 (te-escape-extended-command)) |
252 | |
253 (defun te-set-escape-char (c) | |
254 "Change the terminal-emulator escape character." | |
255 (interactive "cSet escape character to: ") | |
256 (let ((o terminal-escape-char)) | |
257 (message (if (= o c) | |
751
db46eb163798
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
657
diff
changeset
|
258 "\"%s\" is the escape char" |
db46eb163798
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
657
diff
changeset
|
259 "\"%s\" is now the escape; \"%s\" passes through") |
161 | 260 (single-key-description c) |
261 (single-key-description o)) | |
262 (setq terminal-escape-char c))) | |
263 | |
264 | |
265 (defun te-stuff-string (string) | |
266 "Read a string to send to through the terminal emulator | |
267 as though that string had been typed on the keyboard. | |
268 | |
269 Very poor man's file transfer protocol." | |
270 (interactive "sStuff string: ") | |
271 (process-send-string te-process string)) | |
272 | |
273 (defun te-set-output-log (name) | |
274 "Record output from the terminal emulator in a buffer." | |
275 (interactive (list (if te-log-buffer | |
276 nil | |
277 (read-buffer "Record output in buffer: " | |
278 (format "%s output-log" | |
279 (buffer-name (current-buffer))) | |
280 nil)))) | |
281 (if (or (null name) (equal name "")) | |
282 (progn (setq te-log-buffer nil) | |
283 (message "Output logging off.")) | |
284 (if (get-buffer name) | |
285 nil | |
286 (save-excursion | |
287 (set-buffer (get-buffer-create name)) | |
288 (fundamental-mode) | |
289 (buffer-disable-undo (current-buffer)) | |
290 (erase-buffer))) | |
291 (setq te-log-buffer (get-buffer name)) | |
292 (message "Recording terminal emulator output into buffer \"%s\"" | |
293 (buffer-name te-log-buffer)))) | |
294 | |
295 (defun te-tofu () | |
296 "Discontinue output log." | |
297 (interactive) | |
298 (te-set-output-log nil)) | |
299 | |
300 | |
301 (defun te-toggle (sym arg) | |
302 (set sym (cond ((not (numberp arg)) arg) | |
303 ((= arg 1) (not (symbol-value sym))) | |
304 ((< arg 0) nil) | |
305 (t t)))) | |
306 | |
307 (defun te-toggle-more-processing (arg) | |
308 (interactive "p") | |
309 (message (if (te-toggle 'terminal-more-processing arg) | |
310 "More processing on" "More processing off")) | |
311 (if terminal-more-processing (setq te-more-count -1))) | |
312 | |
313 (defun te-toggle-scrolling (arg) | |
314 (interactive "p") | |
315 (message (if (te-toggle 'terminal-scrolling arg) | |
316 "Scroll at end of page" "Wrap at end of page"))) | |
317 | |
318 (defun te-enable-more-processing () | |
319 "Enable ** MORE ** processing" | |
320 (interactive) | |
321 (te-toggle-more-processing t)) | |
322 | |
323 (defun te-disable-more-processing () | |
324 "Disable ** MORE ** processing" | |
325 (interactive) | |
326 (te-toggle-more-processing nil)) | |
327 | |
328 (defun te-do-scrolling () | |
329 "Scroll at end of page (yuck)" | |
330 (interactive) | |
331 (te-toggle-scrolling t)) | |
332 | |
333 (defun te-do-wrapping () | |
334 "Wrap to top of window at end of page" | |
335 (interactive) | |
336 (te-toggle-scrolling nil)) | |
337 | |
338 | |
339 (defun te-set-redisplay-interval (arg) | |
340 "Set the maximum interval (in output characters) between screen updates. | |
341 Set this number to large value for greater throughput, | |
342 set it smaller for more frequent updates (but overall slower performance." | |
343 (interactive "NMax number of output chars between redisplay updates: ") | |
344 (setq arg (max arg 1)) | |
345 (setq terminal-redisplay-interval arg | |
346 te-redisplay-count 0)) | |
347 | |
348 ;;;; more map | |
349 | |
350 ;; every command -must- call te-more-break-unwind | |
351 ;; or grave lossage will result | |
352 | |
353 (put 'te-more-break-unread 'suppress-keymap t) | |
354 (defun te-more-break-unread () | |
355 (interactive) | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
356 (if (eq last-input-char terminal-escape-char) |
161 | 357 (call-interactively 'te-escape) |
358 (message "Continuing from more break (\"%s\" typed, %d chars output pending...)" | |
359 (single-key-description last-input-char) | |
360 (te-pending-output-length)) | |
361 (setq te-more-count 259259) | |
362 (te-more-break-unwind) | |
363 (let ((terminal-more-processing nil)) | |
364 (te-pass-through)))) | |
365 | |
366 (defun te-more-break-resume () | |
367 "Proceed past the **MORE** break, | |
368 allowing the next page of output to appear" | |
369 (interactive) | |
370 (message "Continuing from more break") | |
371 (te-more-break-unwind)) | |
372 | |
373 (defun te-more-break-help () | |
374 "Provide help on commands available in a terminal-emulator **MORE** break" | |
375 (interactive) | |
376 (message "Terminal-emulator more break help...") | |
377 (sit-for 0) | |
378 (with-electric-help | |
379 (function (lambda () | |
380 (princ "Terminal-emulator more break.\n\n") | |
381 (princ (format "Type \"%s\" (te-more-break-resume)\n%s\n" | |
382 (where-is-internal 'te-more-break-resume | |
5774
b57901dfbd40
(te-escape-help, te-more-break-help, terminal-emulator):
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
383 terminal-more-break-map t) |
161 | 384 (documentation 'te-more-break-resume))) |
385 (princ (substitute-command-keys "\\{terminal-more-break-map}\n")) | |
386 (princ "Any other key is passed through to the program | |
387 running under the terminal emulator and disables more processing until | |
388 all pending output has been dealt with.") | |
389 nil)))) | |
390 | |
391 | |
392 (defun te-more-break-advance-one-line () | |
393 "Allow one more line of text to be output before doing another more break." | |
394 (interactive) | |
395 (setq te-more-count 1) | |
396 (te-more-break-unwind)) | |
397 | |
398 (defun te-more-break-flush-pending-output () | |
399 "Discard any output which has been received by the terminal emulator but | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3387
diff
changeset
|
400 not yet processed and then proceed from the more break." |
161 | 401 (interactive) |
402 (te-more-break-unwind) | |
403 (te-flush-pending-output)) | |
404 | |
405 (defun te-flush-pending-output () | |
406 "Discard any as-yet-unprocessed output which has been received by | |
407 the terminal emulator." | |
408 (interactive) | |
409 ;; this could conceivably be confusing in the presence of | |
410 ;; escape-sequences spanning process-output chunks | |
411 (if (null (cdr te-pending-output)) | |
412 (message "(There is no output pending)") | |
413 (let ((length (te-pending-output-length))) | |
414 (message "Flushing %d chars of pending output" length) | |
415 (setq te-pending-output | |
416 (list 0 (format "\n*** %d chars of pending output flushed ***\n" | |
417 length))) | |
418 (te-update-pending-output-display) | |
419 (te-process-output nil) | |
420 (sit-for 0)))) | |
421 | |
422 | |
423 (defun te-pass-through () | |
424 "Character is passed to the program running under the terminal emulator. | |
425 One characters is treated specially: | |
426 the terminal escape character (normally C-^) | |
427 lets you type a terminal emulator command." | |
428 (interactive) | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
429 (cond ((eq last-input-char terminal-escape-char) |
161 | 430 (call-interactively 'te-escape)) |
431 (t | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
432 ;; Convert `return' to C-m, etc. |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
433 (if (and (symbolp last-input-char) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
434 (get last-input-char 'ascii-character)) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
435 (setq last-input-char (get last-input-char 'ascii-character))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
436 ;; Convert meta characters to 8-bit form for transmission. |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
437 (if (and (integerp last-input-char) |
10694
75792481da0c
(te-pass-through): Don't presume internal bit layout of non-ASCII keys.
Karl Heuer <kwzh@gnu.org>
parents:
10354
diff
changeset
|
438 (not (zerop (logand last-input-char ?\M-\^@)))) |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
439 (setq last-input-char (+ 128 (logand last-input-char 127)))) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
440 ;; Now ignore all but actual characters. |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
441 ;; (It ought to be possible to send through function |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
442 ;; keys as character sequences if we add a description |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
443 ;; to our termcap entry of what they should look like.) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
444 (if (integerp last-input-char) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
445 (progn |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
446 (and terminal-more-processing (null (cdr te-pending-output)) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
447 (te-set-more-count nil)) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
448 (send-string te-process (make-string 1 last-input-char)) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
449 (te-process-output t)) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
450 (message "Function key `%s' ignored" |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
451 (single-key-description last-input-char)))))) |
161 | 452 |
453 | |
454 (defun te-set-window-start () | |
455 (let* ((w (get-buffer-window (current-buffer))) | |
456 (h (if w (window-height w)))) | |
457 (cond ((not w)) ; buffer not displayed | |
458 ((>= h (/ (- (point) (point-min)) (1+ te-width))) | |
459 ;; this is the normal case | |
460 (set-window-start w (point-min))) | |
461 ;; this happens if some vandal shrinks our window. | |
462 ((>= h (/ (- (point-max) (point)) (1+ te-width))) | |
463 (set-window-start w (- (point-max) (* h (1+ te-width)) -1))) | |
464 ;; I give up. | |
465 (t nil)))) | |
466 | |
467 (defun te-pending-output-length () | |
468 (let ((length (car te-pending-output)) | |
469 (tem (cdr te-pending-output))) | |
470 (while tem | |
471 (setq length (+ length (length (car tem))) tem (cdr tem))) | |
472 length)) | |
473 | |
474 ;;>> What use is this terminal-edit stuff anyway? | |
475 ;;>> If nothing else, it was written by somebody who didn't | |
476 ;;>> competently understand the terminal-emulator... | |
477 | |
478 (defvar terminal-edit-map nil) | |
479 (if terminal-edit-map | |
480 nil | |
481 (setq terminal-edit-map (make-sparse-keymap)) | |
482 (define-key terminal-edit-map "\C-c\C-c" 'terminal-cease-edit)) | |
483 | |
484 ;; Terminal Edit mode is suitable only for specially formatted data. | |
485 (put 'terminal-edit-mode 'mode-class 'special) | |
486 | |
487 (defun terminal-edit-mode () | |
488 "Major mode for editing the contents of a terminal-emulator buffer. | |
489 The editing commands are the same as in Fundamental mode, | |
7374 | 490 together with a command \\<terminal-edit-map>to return to terminal emulation: \\[terminal-cease-edit]." |
161 | 491 (use-local-map terminal-edit-map) |
492 (setq major-mode 'terminal-edit-mode) | |
493 (setq mode-name "Terminal Edit") | |
494 (setq mode-line-modified (default-value 'mode-line-modified)) | |
495 (setq mode-line-process nil) | |
496 (run-hooks 'terminal-edit-mode-hook)) | |
497 | |
498 (defun te-edit () | |
499 "Start editing the terminal emulator buffer with ordinary Emacs commands." | |
500 (interactive) | |
501 (terminal-edit-mode) | |
11569
a2b107c4f2f1
(te-edit, te-more-break-unwind): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
10848
diff
changeset
|
502 (force-mode-line-update) |
161 | 503 ;; Make mode line update. |
504 (if (eq (key-binding "\C-c\C-c") 'terminal-cease-edit) | |
505 (message "Editing: Type C-c C-c to return to Terminal") | |
506 (message (substitute-command-keys | |
507 "Editing: Type \\[terminal-cease-edit] to return to Terminal")))) | |
508 | |
509 (defun terminal-cease-edit () | |
510 "Finish editing message; switch back to Terminal proper." | |
511 (interactive) | |
512 | |
513 ;;>> emulator will blow out if buffer isn't exactly te-width x te-height | |
514 (let ((buffer-read-only nil)) | |
515 (widen) | |
516 (let ((opoint (point-marker)) | |
517 (width te-width) | |
518 (h (1- te-height))) | |
519 (goto-char (point-min)) | |
520 (while (>= h 0) | |
521 (let ((p (point))) | |
522 (cond ((search-forward "\n" (+ p width) 'move) | |
523 (forward-char -1) | |
524 (insert-char ?\ (- width (- (point) p))) | |
525 (forward-char 1)) | |
526 ((eobp) | |
527 (insert-char ?\ (- width (- (point) p)))) | |
528 ((= (following-char) ?\n) | |
529 (forward-char 1)) | |
530 (t | |
531 (setq p (point)) | |
532 (if (search-forward "\n" nil t) | |
533 (delete-region p (1- (point))) | |
534 (delete-region p (point-max)))))) | |
535 (if (= h 0) | |
536 (if (not (eobp)) (delete-region (point) (point-max))) | |
537 (if (eobp) (insert ?\n))) | |
538 (setq h (1- h))) | |
539 (goto-char opoint) | |
540 (set-marker opoint nil nil) | |
541 (setq te-saved-point (point)) | |
542 (setq te-redisplay-count 0) | |
543 (setq te-more-count -1))) | |
544 | |
545 (setq mode-line-modified (default-value 'mode-line-modified)) | |
7374 | 546 (use-local-map terminal-map) |
161 | 547 (setq major-mode 'terminal-mode) |
548 (setq mode-name "terminal") | |
7077
4c0af7fbb42e
(terminal-cease-edit, terminal-mode):
Richard M. Stallman <rms@gnu.org>
parents:
6423
diff
changeset
|
549 (setq mode-line-process '(":%s"))) |
161 | 550 |
551 ;;;; more break hair | |
552 | |
553 (defun te-more-break () | |
554 (te-set-more-count t) | |
555 (make-local-variable 'te-more-old-point) | |
556 (setq te-more-old-point (point)) | |
557 (make-local-variable 'te-more-old-local-map) | |
558 (setq te-more-old-local-map (current-local-map)) | |
559 (use-local-map terminal-more-break-map) | |
560 (make-local-variable 'te-more-old-filter) | |
561 (setq te-more-old-filter (process-filter te-process)) | |
562 (make-local-variable 'te-more-old-mode-line-format) | |
563 (setq te-more-old-mode-line-format mode-line-format | |
564 mode-line-format (list "-- **MORE** " | |
565 mode-line-buffer-identification | |
566 "%-")) | |
567 (set-process-filter te-process | |
568 (function (lambda (process string) | |
569 (save-excursion | |
570 (set-buffer (process-buffer process)) | |
571 (setq te-pending-output (nconc te-pending-output | |
572 (list string)))) | |
573 (te-update-pending-output-display)))) | |
574 (te-update-pending-output-display) | |
575 (if (eq (window-buffer (selected-window)) (current-buffer)) | |
576 (message "More break ")) | |
577 (or (eobp) | |
578 (null terminal-more-break-insertion) | |
579 (save-excursion | |
580 (forward-char 1) | |
581 (delete-region (point) (+ (point) te-width)) | |
582 (insert terminal-more-break-insertion))) | |
583 (run-hooks 'terminal-more-break-hook) | |
584 (sit-for 0) ;get display to update | |
585 (throw 'te-process-output t)) | |
586 | |
587 (defun te-more-break-unwind () | |
588 (use-local-map te-more-old-local-map) | |
589 (set-process-filter te-process te-more-old-filter) | |
590 (goto-char te-more-old-point) | |
591 (setq mode-line-format te-more-old-mode-line-format) | |
11569
a2b107c4f2f1
(te-edit, te-more-break-unwind): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
10848
diff
changeset
|
592 (force-mode-line-update) |
161 | 593 (let ((buffer-read-only nil)) |
594 (cond ((eobp)) | |
595 (terminal-more-break-insertion | |
596 (forward-char 1) | |
597 (delete-region (point) | |
598 (+ (point) (length terminal-more-break-insertion))) | |
599 (insert-char ?\ te-width) | |
600 (goto-char te-more-old-point))) | |
601 (setq te-more-old-point nil) | |
602 (let ((te-more-count 259259)) | |
603 (te-newline))) | |
604 ;(sit-for 0) | |
605 (te-process-output t)) | |
606 | |
607 (defun te-set-more-count (newline) | |
608 (let ((line (/ (- (point) (point-min)) (1+ te-width)))) | |
609 (if newline (setq line (1+ line))) | |
610 (cond ((= line te-height) | |
611 (setq te-more-count te-height)) | |
612 ;>>>> something is strange. Investigate this! | |
613 ((= line (1- te-height)) | |
614 (setq te-more-count te-height)) | |
615 ((or (< line (/ te-height 2)) | |
616 (> (- te-height line) 10)) | |
617 ;; break at end of this page | |
618 (setq te-more-count (- te-height line))) | |
619 (t | |
620 ;; migrate back towards top (ie bottom) of screen. | |
621 (setq te-more-count (- te-height | |
622 (if (> te-height 10) 2 1))))))) | |
623 | |
624 | |
625 ;;;; More or less straight-forward terminal escapes | |
626 | |
627 ;; ^j, meaning `newline' to non-display programs. | |
628 ;; (Who would think of ever writing a system which doesn't understand | |
629 ;; display terminals natively? Un*x: The Operating System of the Future.) | |
630 (defun te-newline () | |
631 "Move down a line, optionally do more processing, perhaps wrap/scroll, | |
632 move to start of new line, clear to end of line." | |
633 (end-of-line) | |
634 (cond ((not terminal-more-processing)) | |
635 ((< (setq te-more-count (1- te-more-count)) 0) | |
636 (te-set-more-count t)) | |
637 ((eql te-more-count 0) | |
638 ;; this doesn't return | |
639 (te-more-break))) | |
640 (if (eobp) | |
641 (progn | |
642 (delete-region (point-min) (+ (point-min) te-width)) | |
643 (goto-char (point-min)) | |
644 (if terminal-scrolling | |
645 (progn (delete-char 1) | |
646 (goto-char (point-max)) | |
647 (insert ?\n)))) | |
648 (forward-char 1) | |
649 (delete-region (point) (+ (point) te-width))) | |
650 (insert-char ?\ te-width) | |
651 (beginning-of-line) | |
652 (te-set-window-start)) | |
653 | |
654 ; ^p = x+32 y+32 | |
655 (defun te-move-to-position () | |
656 ;; must offset by #o40 since cretinous unix won't send a 004 char through | |
657 (let ((y (- (te-get-char) 32)) | |
658 (x (- (te-get-char) 32))) | |
659 (if (or (> x te-width) | |
660 (> y te-height)) | |
661 () | |
662 (goto-char (+ (point-min) x (* y (1+ te-width)))) | |
663 ;(te-set-window-start?) | |
664 )) | |
665 (setq te-more-count -1)) | |
666 | |
667 | |
668 | |
669 ;; ^p c | |
670 (defun te-clear-rest-of-line () | |
671 (save-excursion | |
672 (let ((n (- (point) (progn (end-of-line) (point))))) | |
673 (delete-region (point) (+ (point) n)) | |
674 (insert-char ?\ (- n))))) | |
675 | |
676 | |
677 ;; ^p C | |
678 (defun te-clear-rest-of-screen () | |
679 (save-excursion | |
680 (te-clear-rest-of-line) | |
681 (while (progn (end-of-line) (not (eobp))) | |
682 (forward-char 1) (end-of-line) | |
683 (delete-region (- (point) te-width) (point)) | |
684 (insert-char ?\ te-width)))) | |
685 | |
686 | |
687 ;; ^p ^l | |
688 (defun te-clear-screen () | |
689 ;; regenerate buffer to compensate for (nonexistent!!) bugs. | |
690 (erase-buffer) | |
691 (let ((i 0)) | |
692 (while (< i te-height) | |
693 (setq i (1+ i)) | |
694 (insert-char ?\ te-width) | |
695 (insert ?\n))) | |
696 (delete-region (1- (point-max)) (point-max)) | |
697 (goto-char (point-min)) | |
698 (setq te-more-count -1)) | |
699 | |
700 | |
701 ;; ^p ^o count+32 | |
702 (defun te-insert-lines () | |
703 (if (not (bolp)) | |
704 ();(error "fooI") | |
705 (save-excursion | |
706 (let* ((line (- te-height (/ (- (point) (point-min)) (1+ te-width)) -1)) | |
707 (n (min (- (te-get-char) ?\ ) line)) | |
708 (i 0)) | |
709 (delete-region (- (point-max) (* n (1+ te-width))) (point-max)) | |
710 (if (eql (point) (point-max)) (insert ?\n)) | |
711 (while (< i n) | |
712 (setq i (1+ i)) | |
713 (insert-char ?\ te-width) | |
714 (or (eql i line) (insert ?\n)))))) | |
715 (setq te-more-count -1)) | |
716 | |
717 | |
718 ;; ^p ^k count+32 | |
719 (defun te-delete-lines () | |
720 (if (not (bolp)) | |
721 ();(error "fooD") | |
722 (let* ((line (- te-height (/ (- (point) (point-min)) (1+ te-width)) -1)) | |
723 (n (min (- (te-get-char) ?\ ) line)) | |
724 (i 0)) | |
725 (delete-region (point) | |
726 (min (+ (point) (* n (1+ te-width))) (point-max))) | |
727 (save-excursion | |
728 (goto-char (point-max)) | |
729 (while (< i n) | |
730 (setq i (1+ i)) | |
731 (insert-char ?\ te-width) | |
732 (or (eql i line) (insert ?\n)))))) | |
733 (setq te-more-count -1)) | |
734 | |
735 ;; ^p ^a | |
736 (defun te-beginning-of-line () | |
737 (beginning-of-line)) | |
738 | |
739 ;; ^p ^b | |
740 (defun te-backward-char () | |
741 (if (not (bolp)) | |
742 (backward-char 1))) | |
743 | |
744 ;; ^p ^f | |
745 (defun te-forward-char () | |
746 (if (not (eolp)) | |
747 (forward-char 1))) | |
748 | |
749 | |
750 ;; 0177 | |
751 (defun te-delete () | |
752 (if (bolp) | |
753 () | |
754 (delete-region (1- (point)) (point)) | |
755 (insert ?\ ) | |
756 (forward-char -1))) | |
757 | |
758 ;; ^p ^g | |
759 (defun te-beep () | |
760 (beep)) | |
761 | |
762 | |
763 ;; ^p _ count+32 | |
764 (defun te-insert-spaces () | |
765 (let* ((p (point)) | |
766 (n (min (- (te-get-char) 32) | |
767 (- (progn (end-of-line) (point)) p)))) | |
768 (if (<= n 0) | |
769 nil | |
770 (delete-char (- n)) | |
771 (goto-char p) | |
772 (insert-char ?\ n)) | |
773 (goto-char p))) | |
774 | |
775 ;; ^p d count+32 (should be ^p ^d but cretinous un*x won't send ^d chars!!!) | |
776 (defun te-delete-char () | |
777 (let* ((p (point)) | |
778 (n (min (- (te-get-char) 32) | |
779 (- (progn (end-of-line) (point)) p)))) | |
780 (if (<= n 0) | |
781 nil | |
782 (insert-char ?\ n) | |
783 (goto-char p) | |
784 (delete-char n)) | |
785 (goto-char p))) | |
786 | |
787 | |
788 | |
789 ;; disgusting unix-required shit | |
790 ;; Are we living twenty years in the past yet? | |
791 | |
792 (defun te-losing-unix () | |
793 nil) | |
794 | |
795 ;; ^i | |
796 (defun te-output-tab () | |
797 (let* ((p (point)) | |
798 (x (- p (progn (beginning-of-line) (point)))) | |
799 (l (min (- 8 (logand x 7)) | |
800 (progn (end-of-line) (- (point) p))))) | |
801 (goto-char (+ p l)))) | |
802 | |
803 ;; ^p ^j | |
804 ;; Handle the `do' or `nl' termcap capability. | |
805 ;;>> I am not sure why this broken, obsolete, capability is here. | |
806 ;;>> Perhaps it is for VIle. No comment was made about why it | |
807 ;;>> was added (in "Sun Dec 6 01:22:27 1987 Richard Stallman") | |
808 (defun te-down-vertically-or-scroll () | |
809 "Move down a line vertically, or scroll at bottom." | |
810 (let ((column (current-column))) | |
811 (end-of-line) | |
812 (if (eobp) | |
813 (progn | |
814 (delete-region (point-min) (+ (point-min) te-width)) | |
815 (goto-char (point-min)) | |
816 (delete-char 1) | |
817 (goto-char (point-max)) | |
818 (insert ?\n) | |
819 (insert-char ?\ te-width) | |
820 (beginning-of-line)) | |
821 (forward-line 1)) | |
822 (move-to-column column)) | |
823 (te-set-window-start)) | |
824 | |
825 ;; Also: | |
826 ;; ^m => beginning-of-line (for which it -should- be using ^p ^a, right?!!) | |
827 ;; ^g => te-beep (for which it should use ^p ^g) | |
828 ;; ^h => te-backward-char (for which it should use ^p ^b) | |
829 | |
830 | |
831 | |
832 (defun te-filter (process string) | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
833 (let* ((obuf (current-buffer))) |
161 | 834 ;; can't use save-excursion, as that preserves point, which we don't want |
835 (unwind-protect | |
836 (progn | |
837 (set-buffer (process-buffer process)) | |
838 (goto-char te-saved-point) | |
839 (and (bufferp te-log-buffer) | |
840 (if (null (buffer-name te-log-buffer)) | |
841 ;; killed | |
842 (setq te-log-buffer nil) | |
843 (set-buffer te-log-buffer) | |
844 (goto-char (point-max)) | |
845 (insert-before-markers string) | |
846 (set-buffer (process-buffer process)))) | |
847 (setq te-pending-output (nconc te-pending-output (list string))) | |
848 (te-update-pending-output-display) | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
849 (te-process-output (eq (current-buffer) |
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
850 (window-buffer (selected-window)))) |
161 | 851 (set-buffer (process-buffer process)) |
852 (setq te-saved-point (point))) | |
853 (set-buffer obuf)))) | |
854 | |
855 ;; (A version of the following comment which might be distractingly offensive | |
856 ;; to some readers has been moved to term-nasty.el.) | |
857 ;; unix lacks ITS-style tty control... | |
858 (defun te-process-output (preemptable) | |
859 ;;>> There seems no good reason to ever disallow preemption | |
860 (setq preemptable t) | |
861 (catch 'te-process-output | |
862 (let ((buffer-read-only nil) | |
863 (string nil) ostring start char (matchpos nil)) | |
864 (while (cdr te-pending-output) | |
865 (setq ostring string | |
866 start (car te-pending-output) | |
867 string (car (cdr te-pending-output)) | |
868 char (aref string start)) | |
869 (if (eql (setq start (1+ start)) (length string)) | |
870 (progn (setq te-pending-output | |
871 (cons 0 (cdr (cdr te-pending-output))) | |
872 start 0 | |
873 string (car (cdr te-pending-output))) | |
874 (te-update-pending-output-display)) | |
875 (setcar te-pending-output start)) | |
876 (if (and (> char ?\037) (< char ?\377)) | |
877 (cond ((eolp) | |
878 ;; unread char | |
879 (if (eql start 0) | |
880 (setq te-pending-output | |
881 (cons 0 (cons (make-string 1 char) | |
882 (cdr te-pending-output)))) | |
883 (setcar te-pending-output (1- start))) | |
884 (te-newline)) | |
885 ((null string) | |
886 (delete-char 1) (insert char) | |
887 (te-redisplay-if-necessary 1)) | |
888 (t | |
889 (let ((end (or (and (eq ostring string) matchpos) | |
890 (setq matchpos (string-match | |
891 "[\000-\037\177-\377]" | |
892 string start)) | |
893 (length string)))) | |
894 (delete-char 1) (insert char) | |
895 (setq char (point)) (end-of-line) | |
896 (setq end (min end (+ start (- (point) char)))) | |
897 (goto-char char) | |
898 (if (eql end matchpos) (setq matchpos nil)) | |
899 (delete-region (point) (+ (point) (- end start))) | |
900 (insert (if (and (eql start 0) | |
901 (eql end (length string))) | |
902 string | |
903 (substring string start end))) | |
904 (if (eql end (length string)) | |
905 (setq te-pending-output | |
906 (cons 0 (cdr (cdr te-pending-output)))) | |
907 (setcar te-pending-output end)) | |
908 (te-redisplay-if-necessary (1+ (- end start)))))) | |
909 ;; I suppose if I split the guts of this out into a separate | |
910 ;; function we could trivially emulate different terminals | |
911 ;; Who cares in any case? (Apart from stupid losers using rlogin) | |
912 (funcall | |
913 (if (eql char ?\^p) | |
914 (or (cdr (assq (te-get-char) | |
915 '((?= . te-move-to-position) | |
916 (?c . te-clear-rest-of-line) | |
917 (?C . te-clear-rest-of-screen) | |
918 (?\C-o . te-insert-lines) | |
919 (?\C-k . te-delete-lines) | |
920 ;; not necessary, but help sometimes. | |
921 (?\C-a . te-beginning-of-line) | |
922 (?\C-b . te-backward-char) | |
923 ;; should be C-d, but un*x | |
924 ;; pty's won't send \004 through! | |
925 ;; Can you believe this? | |
926 (?d . te-delete-char) | |
927 (?_ . te-insert-spaces) | |
928 ;; random | |
929 (?\C-f . te-forward-char) | |
930 (?\C-g . te-beep) | |
931 (?\C-j . te-down-vertically-or-scroll) | |
932 (?\C-l . te-clear-screen) | |
933 ))) | |
934 'te-losing-unix) | |
935 (or (cdr (assq char | |
936 '((?\C-j . te-newline) | |
937 (?\177 . te-delete) | |
938 ;; Did I ask to be sent these characters? | |
939 ;; I don't remember doing so, either. | |
940 ;; (Perhaps some operating system or | |
941 ;; other is completely incompetent...) | |
942 (?\C-m . te-beginning-of-line) | |
943 (?\C-g . te-beep) | |
944 (?\C-h . te-backward-char) | |
945 (?\C-i . te-output-tab)))) | |
946 'te-losing-unix))) | |
947 (te-redisplay-if-necessary 1)) | |
948 (and preemptable | |
949 (input-pending-p) | |
950 ;; preemptable output! Oh my!! | |
951 (throw 'te-process-output t))))) | |
952 ;; We must update window-point in every window displaying our buffer | |
953 (let* ((s (selected-window)) | |
954 (w s)) | |
955 (while (not (eq s (setq w (next-window w)))) | |
956 (if (eq (window-buffer w) (current-buffer)) | |
957 (set-window-point w (point)))))) | |
958 | |
959 (defun te-get-char () | |
960 (if (cdr te-pending-output) | |
961 (let ((start (car te-pending-output)) | |
962 (string (car (cdr te-pending-output)))) | |
963 (prog1 (aref string start) | |
964 (if (eql (setq start (1+ start)) (length string)) | |
965 (setq te-pending-output (cons 0 (cdr (cdr te-pending-output)))) | |
966 (setcar te-pending-output start)))) | |
967 (catch 'char | |
968 (let ((filter (process-filter te-process))) | |
969 (unwind-protect | |
970 (progn | |
971 (set-process-filter te-process | |
972 (function (lambda (p s) | |
973 (or (eql (length s) 1) | |
974 (setq te-pending-output (list 1 s))) | |
975 (throw 'char (aref s 0))))) | |
976 (accept-process-output te-process)) | |
977 (set-process-filter te-process filter)))))) | |
978 | |
979 | |
980 (defun te-redisplay-if-necessary (length) | |
981 (and (<= (setq te-redisplay-count (- te-redisplay-count length)) 0) | |
982 (eq (current-buffer) (window-buffer (selected-window))) | |
983 (waiting-for-user-input-p) | |
984 (progn (te-update-pending-output-display) | |
985 (sit-for 0) | |
986 (setq te-redisplay-count terminal-redisplay-interval)))) | |
987 | |
988 (defun te-update-pending-output-display () | |
989 (if (null (cdr te-pending-output)) | |
990 (setq te-pending-output-info "") | |
991 (let ((length (te-pending-output-length))) | |
992 (if (< length 1500) | |
993 (setq te-pending-output-info "") | |
994 (setq te-pending-output-info (format "(%dK chars output pending) " | |
995 (/ (+ length 512) 1024)))))) | |
11569
a2b107c4f2f1
(te-edit, te-more-break-unwind): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
10848
diff
changeset
|
996 (force-mode-line-update)) |
161 | 997 |
998 | |
999 (defun te-sentinel (process message) | |
1000 (cond ((eq (process-status process) 'run)) | |
1001 ((null (buffer-name (process-buffer process)))) ;deleted | |
1002 (t (let ((b (current-buffer))) | |
1003 (save-excursion | |
1004 (set-buffer (process-buffer process)) | |
1005 (setq buffer-read-only nil) | |
1006 (fundamental-mode) | |
1007 (goto-char (point-max)) | |
1008 (delete-blank-lines) | |
1009 (delete-horizontal-space) | |
1010 (insert "\n*******\n" message "*******\n")) | |
1011 (if (and (eq b (process-buffer process)) | |
1012 (waiting-for-user-input-p)) | |
1013 (progn (goto-char (point-max)) | |
1014 (recenter -1))))))) | |
1015 | |
2748
fef642d4f5c0
(te-pass-through): Handle meta chars and non-char events.
Richard M. Stallman <rms@gnu.org>
parents:
2587
diff
changeset
|
1016 (defvar te-stty-string "stty -nl erase '^?' kill '^u' intr '^c' echo pass8" |
357 | 1017 "Shell command to set terminal modes for terminal emulator.") |
1018 ;; This used to have `new' in it, but that loses outside BSD | |
1019 ;; and it's apparently not needed in BSD. | |
161 | 1020 |
1021 (defvar explicit-shell-file-name nil | |
1022 "*If non-nil, is file name to use for explicitly requested inferior shell.") | |
1023 | |
256 | 1024 ;;;###autoload |
161 | 1025 (defun terminal-emulator (buffer program args &optional width height) |
1026 "Under a display-terminal emulator in BUFFER, run PROGRAM on arguments ARGS. | |
1027 ARGS is a list of argument-strings. Remaining arguments are WIDTH and HEIGHT. | |
1028 BUFFER's contents are made an image of the display generated by that program, | |
1029 and any input typed when BUFFER is the current Emacs buffer is sent to that | |
1030 program an keyboard input. | |
1031 | |
1032 Interactively, BUFFER defaults to \"*terminal*\" and PROGRAM and ARGS | |
1033 are parsed from an input-string using your usual shell. | |
1034 WIDTH and HEIGHT are determined from the size of the current window | |
1035 -- WIDTH will be one less than the window's width, HEIGHT will be its height. | |
1036 | |
1037 To switch buffers and leave the emulator, or to give commands | |
1038 to the emulator itself (as opposed to the program running under it), | |
1039 type Control-^. The following character is an emulator command. | |
1040 Type Control-^ twice to send it to the subprogram. | |
1041 This escape character may be changed using the variable `terminal-escape-char'. | |
1042 | |
1043 `Meta' characters may not currently be sent through the terminal emulator. | |
1044 | |
1045 Here is a list of some of the variables which control the behaviour | |
1046 of the emulator -- see their documentation for more information: | |
1047 terminal-escape-char, terminal-scrolling, terminal-more-processing, | |
1048 terminal-redisplay-interval. | |
1049 | |
1050 This function calls the value of terminal-mode-hook if that exists | |
1051 and is non-nil after the terminal buffer has been set up and the | |
10294 | 1052 subprocess started." |
161 | 1053 (interactive |
1054 (cons (save-excursion | |
1055 (set-buffer (get-buffer-create "*terminal*")) | |
1056 (buffer-name (if (or (not (boundp 'te-process)) | |
1057 (null te-process) | |
1058 (not (eq (process-status te-process) | |
1059 'run))) | |
1060 (current-buffer) | |
1061 (generate-new-buffer "*terminal*")))) | |
1062 (append | |
1063 (let* ((default-s | |
1064 ;; Default shell is same thing M-x shell uses. | |
1065 (or explicit-shell-file-name | |
1066 (getenv "ESHELL") | |
1067 (getenv "SHELL") | |
1068 "/bin/sh")) | |
1069 (s (read-string | |
1070 (format "Run program in emulator: (default %s) " | |
1071 default-s)))) | |
1072 (if (equal s "") | |
1073 (list default-s '()) | |
1074 (te-parse-program-and-args s)))))) | |
1075 (switch-to-buffer buffer) | |
1076 (if (null width) (setq width (- (window-width (selected-window)) 1))) | |
1077 (if (null height) (setq height (- (window-height (selected-window)) 1))) | |
1078 (terminal-mode) | |
1079 (setq te-width width te-height height) | |
10294 | 1080 (setq te-terminal-name (concat te-terminal-name-prefix "-" te-width |
1081 te-height)) | |
161 | 1082 (setq mode-line-buffer-identification |
1083 (list (format "Emacs terminal %dx%d: %%b " te-width te-height) | |
1084 'te-pending-output-info)) | |
1085 (let ((buffer-read-only nil)) | |
1086 (te-clear-screen)) | |
1087 (let (process) | |
1088 (while (setq process (get-buffer-process (current-buffer))) | |
1089 (if (y-or-n-p (format "Kill process %s? " (process-name process))) | |
1090 (delete-process process) | |
1091 (error "Process %s not killed" (process-name process))))) | |
1092 (condition-case err | |
10294 | 1093 (let ((process-environment |
1094 (cons (concat "TERM=" te-terminal-name) | |
1095 (cons (concat "TERMCAP=" (te-create-termcap)) | |
1096 (cons (concat "TERMINFO=" (te-create-terminfo)) | |
1097 process-environment))))) | |
1098 (setq te-process | |
1099 (start-process "terminal-emulator" (current-buffer) | |
1100 "/bin/sh" "-c" | |
1101 ;; Yuck!!! Start a shell to set some terminal | |
1102 ;; control characteristics. Then start the | |
1103 ;; "env" program to setup the terminal type | |
1104 ;; Then finally start the program we wanted. | |
1105 (format "%s; exec %s" | |
1106 te-stty-string | |
1107 (mapconcat 'te-quote-arg-for-sh | |
1108 (cons program args) " ")))) | |
630
a904e831b60f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
584
diff
changeset
|
1109 (set-process-filter te-process 'te-filter) |
a904e831b60f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
584
diff
changeset
|
1110 (set-process-sentinel te-process 'te-sentinel)) |
161 | 1111 (error (fundamental-mode) |
1112 (signal (car err) (cdr err)))) | |
1113 (setq inhibit-quit t) ;sport death | |
1114 (use-local-map terminal-map) | |
1115 (run-hooks 'terminal-mode-hook) | |
1116 (message "Entering emacs terminal-emulator... Type %s %s for help" | |
1117 (single-key-description terminal-escape-char) | |
1118 (mapconcat 'single-key-description | |
5774
b57901dfbd40
(te-escape-help, te-more-break-help, terminal-emulator):
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1119 (where-is-internal 'te-escape-help terminal-escape-map t) |
161 | 1120 " "))) |
1121 | |
1122 | |
1123 (defun te-parse-program-and-args (s) | |
6310
c40e283c262b
Put hyphen in a safer place in the character class.
Karl Heuer <kwzh@gnu.org>
parents:
5774
diff
changeset
|
1124 (cond ((string-match "\\`\\([-a-zA-Z0-9+=_.@/:]+[ \t]*\\)+\\'" s) |
161 | 1125 (let ((l ()) (p 0)) |
1126 (while p | |
1127 (setq l (cons (if (string-match | |
6310
c40e283c262b
Put hyphen in a safer place in the character class.
Karl Heuer <kwzh@gnu.org>
parents:
5774
diff
changeset
|
1128 "\\([-a-zA-Z0-9+=_.@/:]+\\)\\([ \t]+\\)*" |
161 | 1129 s p) |
1130 (prog1 (substring s p (match-end 1)) | |
1131 (setq p (match-end 0)) | |
1132 (if (eql p (length s)) (setq p nil))) | |
1133 (prog1 (substring s p) | |
1134 (setq p nil))) | |
1135 l))) | |
1136 (setq l (nreverse l)) | |
1137 (list (car l) (cdr l)))) | |
1138 ((and (string-match "[ \t]" s) (not (file-exists-p s))) | |
1139 (list shell-file-name (list "-c" (concat "exec " s)))) | |
1140 (t (list s ())))) | |
1141 | |
1142 (put 'terminal-mode 'mode-class 'special) | |
1143 ;; This is only separated out from function terminal-emulator | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3387
diff
changeset
|
1144 ;; to keep the latter a little more manageable. |
161 | 1145 (defun terminal-mode () |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3387
diff
changeset
|
1146 "Set up variables for use with the terminal-emulator. |
161 | 1147 One should not call this -- it is an internal function |
1148 of the terminal-emulator" | |
1149 (kill-all-local-variables) | |
1150 (buffer-disable-undo (current-buffer)) | |
1151 (setq major-mode 'terminal-mode) | |
1152 (setq mode-name "terminal") | |
1153 ; (make-local-variable 'Helper-return-blurb) | |
1154 ; (setq Helper-return-blurb "return to terminal simulator") | |
7077
4c0af7fbb42e
(terminal-cease-edit, terminal-mode):
Richard M. Stallman <rms@gnu.org>
parents:
6423
diff
changeset
|
1155 (setq mode-line-process '(":%s")) |
161 | 1156 (setq buffer-read-only t) |
1157 (setq truncate-lines t) | |
1158 (make-local-variable 'terminal-escape-char) | |
1159 (setq terminal-escape-char (default-value 'terminal-escape-char)) | |
1160 (make-local-variable 'terminal-scrolling) | |
1161 (setq terminal-scrolling (default-value 'terminal-scrolling)) | |
1162 (make-local-variable 'terminal-more-processing) | |
1163 (setq terminal-more-processing (default-value 'terminal-more-processing)) | |
1164 (make-local-variable 'terminal-redisplay-interval) | |
1165 (setq terminal-redisplay-interval (default-value 'terminal-redisplay-interval)) | |
1166 (make-local-variable 'te-width) | |
1167 (make-local-variable 'te-height) | |
1168 (make-local-variable 'te-process) | |
1169 (make-local-variable 'te-pending-output) | |
1170 (setq te-pending-output (list 0)) | |
1171 (make-local-variable 'te-saved-point) | |
1172 (setq te-saved-point (point-min)) | |
1173 (make-local-variable 'te-pending-output-info) ;for the mode line | |
1174 (setq te-pending-output-info "") | |
1175 (make-local-variable 'inhibit-quit) | |
1176 ;(setq inhibit-quit t) | |
1177 (make-local-variable 'te-log-buffer) | |
1178 (setq te-log-buffer nil) | |
1179 (make-local-variable 'te-more-count) | |
1180 (setq te-more-count -1) | |
1181 (make-local-variable 'te-redisplay-count) | |
1182 (setq te-redisplay-count terminal-redisplay-interval) | |
1183 ;(use-local-map terminal-mode-map) | |
1184 ;; terminal-mode-hook is called above in function terminal-emulator | |
1185 ) | |
1186 | |
1187 ;;;; what a complete loss | |
1188 | |
1189 (defun te-quote-arg-for-sh (string) | |
6310
c40e283c262b
Put hyphen in a safer place in the character class.
Karl Heuer <kwzh@gnu.org>
parents:
5774
diff
changeset
|
1190 (cond ((string-match "\\`[-a-zA-Z0-9+=_.@/:]+\\'" |
161 | 1191 string) |
1192 string) | |
1193 ((not (string-match "[$]" string)) | |
1194 ;; "[\"\\]" are special to sh and the lisp reader in the same way | |
1195 (prin1-to-string string)) | |
1196 (t | |
1197 (let ((harder "") | |
1198 (start 0) | |
1199 (end 0)) | |
1200 (while (cond ((>= start (length string)) | |
1201 nil) | |
1202 ;; this is the set of chars magic with "..." in `sh' | |
1203 ((setq end (string-match "[\"\\$]" | |
1204 string start)) | |
1205 t) | |
1206 (t (setq harder (concat harder | |
1207 (substring string start))) | |
1208 nil)) | |
1209 (setq harder (concat harder (substring string start end) | |
1210 ;; Can't use ?\\ since `concat' | |
1211 ;; unfortunately does prin1-to-string | |
1212 ;; on fixna. Amazing. | |
1213 "\\" | |
1214 (substring string | |
1215 end | |
1216 (1+ end))) | |
1217 start (1+ end))) | |
256 | 1218 (concat "\"" harder "\""))))) |
584 | 1219 |
10294 | 1220 (defun te-create-terminfo () |
1221 "Create and compile a terminfo entry for the virtual terminal. This is kept | |
1222 in the /tmp directory" | |
10354
a4b616f7745c
(te-terminfo-systems-regexp): Variable deleted.
Richard M. Stallman <rms@gnu.org>
parents:
10295
diff
changeset
|
1223 (if (and system-uses-terminfo |
10294 | 1224 (not (file-exists-p (concat "/tmp/" |
1225 (substring te-terminal-name-prefix 0 1) | |
1226 "/" te-terminal-name)))) | |
1227 (let ( (terminfo | |
1228 (concat | |
1229 (format "%s,mir, xon,cols#%d, lines#%d," | |
1230 te-terminal-name te-width te-height) | |
1231 "bel=^P^G, clear=^P\\f, cr=^P^A, cub1=^P^B, cud1=^P\\n," | |
1232 "cuf1=^P^F, cup=^P=%p1%'\\s'%+%c%p2%'\\s'%+%c," | |
1233 "dch=^Pd%p1%'\\s'%+%c, dch1=^Pd!, dl=^P^K%p1%'\\s'%+%c," | |
1234 "dl1=^P^K!, ed=^PC, el=^Pc, home=^P=\\s\\s," | |
1235 "ich=^P_%p1%'\\s'%+%c, ich1=^P_!, il=^P^O%p1%'\\s'%+%c," | |
1236 "il1=^P^O!, ind=^P\\n, nel=\\n,")) | |
1237 (file-name (concat "/tmp/" te-terminal-name ".tif")) ) | |
1238 (save-excursion | |
1239 (set-buffer (create-file-buffer file-name)) | |
1240 (insert terminfo) | |
1241 (write-file file-name) | |
1242 (kill-buffer nil) | |
1243 ) | |
1244 (let ( (process-environment | |
1245 (cons (concat "TERMINFO=" "/tmp") | |
1246 process-environment)) ) | |
1247 (set-process-sentinel (start-process "tic" nil "tic" file-name) | |
1248 'te-tic-sentinel)))) | |
1249 "/tmp" | |
1250 ) | |
1251 | |
1252 (defun te-create-termcap () | |
1253 "Create a termcap entry for the virtual terminal" | |
1254 ;; Because of Unix Brain Death(tm), we can't change | |
1255 ;; the terminal type of a running process, and so | |
1256 ;; terminal size and scrollability are wired-down | |
1257 ;; at this point. ("Detach? What's that?") | |
1258 (concat (format "%s:co#%d:li#%d:%s" | |
1259 ;; Sigh. These can't be dynamically changed. | |
1260 te-terminal-name te-width te-height (if terminal-scrolling | |
1261 "" "ns:")) | |
1262 ;;-- Basic things | |
1263 ;; cursor-motion, bol, forward/backward char | |
1264 "cm=^p=%+ %+ :cr=^p^a:le=^p^b:nd=^p^f:" | |
1265 ;; newline, clear eof/eof, audible bell | |
1266 "nw=^j:ce=^pc:cd=^pC:cl=^p^l:bl=^p^g:" | |
1267 ;; insert/delete char/line | |
1268 "IC=^p_%+ :DC=^pd%+ :AL=^p^o%+ :DL=^p^k%+ :" | |
1269 ;;-- Not-widely-known (ie nonstandard) flags, which mean | |
1270 ;; o writing in the last column of the last line | |
1271 ;; doesn't cause idiotic scrolling, and | |
1272 ;; o don't use idiotische c-s/c-q sogenannte | |
1273 ;; ``flow control'' auf keinen Fall. | |
1274 "LP:NF:" | |
1275 ;;-- For stupid or obsolete programs | |
1276 "ic=^p_!:dc=^pd!:al=^p^o!:dl=^p^k!:ho=^p= :" | |
1277 ;;-- For disgusting programs. | |
1278 ;; (VI? What losers need these, I wonder?) | |
1279 "im=:ei=:dm=:ed=:mi:do=^p^j:nl=^p^j:bs:") | |
1280 ) | |
1281 | |
1282 (defun te-tic-sentinel (proc state-change) | |
1283 "If tic has finished, delete the .tif file" | |
1284 (if (equal state-change "finished | |
1285 ") | |
1286 (delete-file (concat "/tmp/" te-terminal-name ".tif")))) | |
1287 | |
584 | 1288 (provide 'terminal) |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
630
diff
changeset
|
1289 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
630
diff
changeset
|
1290 ;;; terminal.el ends here |