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