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