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