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