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