annotate lisp/terminal.el @ 640:36e7f4e402bd

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