comparison lisp/term.el @ 17283:fcb47395bde7

Added a lot of new faces, they all start with term- and follow a simple lexicographical convention. Note that each change is commented: just search for -mm in the source. (term-char-mode): Added all the "grey-keys" to term-raw-map. (term-send-up): Similar, decided to go for the more xterm-like \eOA bindings in place of the previous \e[A. (term-buffer-maximum-size): New variable. (term-mode): Added some make-local: now term-buffer-maximum-size, ange-ftp-default-user/password/an-pwd. (term-emulate-terminal): Quite some modifications to allow multiple outstanding ANSI style commands: notably all the -previous-parameter stuff. Call term-handle-ansi-terminal-messages. (term-emulate-terminal): Added simple trimming function: at the end we simply check if the buffer is > term-buffer-maximum-size and cut it accordingly. (term-handle-colors-array): New function. (term-handle-ansi-terminal-messages): New function. (term-handle-ansi-escape): Modified to allow ANSI coloring (ansi-term): New function that creates multiple terminals. Put in the standard C-x map too: I'm quite used to C-x C-f and C-c C-f was too awkward.
author Richard M. Stallman <rms@gnu.org>
date Wed, 02 Apr 1997 03:46:39 +0000
parents 2824e1f84717
children ae0ba78d6c07
comparison
equal deleted inserted replaced
17282:5023bea28298 17283:fcb47395bde7
1 ;;; term.el --- general command interpreter in a window stuff 1 ;;; term.el --- general command interpreter in a window stuff
2 2
3 ;; Copyright (C) 1988, 1990, 1992, 1994, 1995 Free Software Foundation, Inc. 3 ;;; Copyright (C) 1988, 1990, 1992, 1994, 1995 Free Software Foundation, Inc.
4 4
5 ;; Author: Per Bothner <bothner@cygnus.com> 5 ;;; Author: Per Bothner <bothner@cygnus.com>
6 ;; Based on comint mode written by: Olin Shivers <shivers@cs.cmu.edu> 6 ;;; Based on comint mode written by: Olin Shivers <shivers@cs.cmu.edu>
7 ;; Keyword: processes 7 ;;; Keyword: processes
8 8
9 ;; This file is part of GNU Emacs. 9 ;;; Dir/Hostname tracking and ANSI colorization by
10 10 ;;; Marco Melgazzi <marco@techie.com>.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 11
12 ;; it under the terms of the GNU General Public License as published by 12 ;;; To see what I've modified and where it came from search for '-mm'
13 ;; the Free Software Foundation; either version 2, or (at your option) 13
14 ;; any later version. 14 ;;; Speed considerations and a few caveats
15 15 ;;; --------------------------------------
16 ;; GNU Emacs is distributed in the hope that it will be useful, 16 ;;;
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ;;; While the message passing and the colorization surely introduce some
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ;;; overhead this has became so small that IMHO is surely outweighted by
19 ;; GNU General Public License for more details. 19 ;;; the benefits you get but, as usual, YMMV
20 20 ;;;
21 ;; You should have received a copy of the GNU General Public License 21 ;;; Important caveat, when deciding the cursor/'grey keys' keycodes I had to
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 22 ;;; make a choice: on my Linux box this choice allows me to run all the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;;; ncurses applications without problems but make these keys
24 ;; Boston, MA 02111-1307, USA. 24 ;;; uncomprehensible to all the cursesX programs. Your mileage may vary so
25 25 ;;; you may consider changing the default 'emulation'. Just search for this
26 ;;; Commentary: 26 ;;; piece of code and modify it as you like:
27 ;;;
28 ;;; ;; Which would be better: "\e[A" or "\eOA"? readline accepts either.
29 ;;; ;; For my configuration it's definitely better \eOA but YMMV. -mm
30 ;;; ;; For example: vi works with \eOA while elm wants \e[A ...
31 ;;; (defun term-send-up () (interactive) (term-send-raw-string "\eOA"))
32 ;;; (defun term-send-down () (interactive) (term-send-raw-string "\eOB"))
33 ;;; (defun term-send-right () (interactive) (term-send-raw-string "\eOC"))
34 ;;; (defun term-send-left () (interactive) (term-send-raw-string "\eOD"))
35 ;;;
36 ;;;
37 ;;; IMPORTANT: additions & changes
38 ;;; ------------------------------
39 ;;;
40 ;;; With this enhanced ansi-term.el you will get a reliable mechanism of
41 ;;; directory/username/host tracking: the only drawback is that you will
42 ;;; have to modify your shell start-up script. It's worth it, believe me :).
43 ;;;
44 ;;; When you rlogin/su/telnet and the account you access has a modified
45 ;;; startup script, you will be able to access the remote files as usual
46 ;;; with C-x C-f, if it's needed you will have to enter a password,
47 ;;; otherwise the file should get loaded straight away.
48 ;;;
49 ;;; This is useful even if you work only on one host: it often happens that,
50 ;;; for maintenance reasons, you have to edit files 'as root': before
51 ;;; patching term.el, I su-ed in a term.el buffer and used vi :), now I
52 ;;; simply do a C-x C-f and, via ange-ftp, the file is automatically loaded
53 ;;; 'as-root'. ( If you don't want to enter the root password every time you
54 ;;; can put it in your .netrc: note that this is -not- advisable if you're
55 ;;; connected to the internet or if somebody else works on your workstation!)
56 ;;;
57 ;;; If you use wu-ftpd you can use some of its features to avoid root ftp
58 ;;; access to the rest of the world: just put in /etc/ftphosts something like
59 ;;;
60 ;;; # Local access
61 ;;; allow root 127.0.0.1
62 ;;;
63 ;;; # By default nobody can't do anything
64 ;;; deny root *
65 ;;;
66 ;;;
67 ;;; ----------------------------------------
68 ;;;
69 ;;; If, instead of 'term', you call 'ansi-term', you get multiple term
70 ;;; buffers, after every new call ansi-term opens a new *ansi-term*<xx> window,
71 ;;; where <xx> is, as usual, a number...
72 ;;;
73 ;;; ----------------------------------------
74 ;;;
75 ;;; With the term-buffer-maximum-size you can finally decide how many
76 ;;; scrollback lines to keep: its default is 2048 but you can change it as
77 ;;; usual.
78 ;;;
79 ;;; ----------------------------------------
80 ;;;
81 ;;;
82 ;;; ANSI colorization should work well, I've decided to limit the interpreter
83 ;;; to five outstanding commands (like ESC [ 01;04;32;41;07m.
84 ;;; You shouldn't need more, if you do, tell me and I'll increase it. It's
85 ;;; so easy you could do it yourself...
86 ;;;
87 ;;; Blink, is not supported. Currently it's mapped as bold.
88 ;;;
89 ;;; Important caveat:
90 ;;; -----------------
91 ;;; if you want custom colors in term.el redefine term-default-fg-color
92 ;;; and term-default-bg-color BEFORE loading it.
93 ;;;
94 ;;; ----------------------------------------
95 ;;;
96 ;;; If you'd like to check out my complete configuration, you can download
97 ;;; it from http://www.polito.it/~s64912/things.html, it's ~500k in size and
98 ;;; contains my .cshrc, .emacs and my whole site-lisp subdirectory. (notice
99 ;;; that this term.el may be newer/older than the one in there, please
100 ;;; check!)
101 ;;;
102 ;;; This complete configuration contains, among other things, a complete
103 ;;; rectangular marking solution (based on rect-mark.el and
104 ;;; pc-bindings.el) and should be a good example of how extensively Emacs
105 ;;; can be configured on a ppp-connected ws.
106 ;;;
107 ;;; ----------------------------------------
108 ;;;
109 ;;; TODO:
110 ;;;
111 ;;; - Add hooks to allow raw-mode keys to be configurable
112 ;;; - Which keys are better ? \eOA or \e[A ?
113 ;;;
114 ;;;
115 ;;; Changes:
116 ;;;
117 ;;; V4.0 January 1997
118 ;;;
119 ;;; - Huge reworking of the faces code: now we only have roughly 20-30
120 ;;; faces for everything so we're even faster than the old md-term.el !
121 ;;; - Finished removing all the J-Shell code.
122 ;;;
123 ;;; V3.0 January 1997
124 ;;;
125 ;;; - Now all the supportable ANSI commands work well.
126 ;;; - Reworked a little the code: much less jsh-inspired stuff
127 ;;;
128 ;;; V2.3 November
129 ;;;
130 ;;; - Now all the faces are accessed through an array: much cleaner code.
131 ;;;
132 ;;; V2.2 November 4 1996
133 ;;;
134 ;;; - Implemented ANSI output colorization ( a bit rough but enough for
135 ;;; color_ls )
136 ;;;
137 ;;; - Implemented a maximum limit for the scroll buffer (stolen from
138 ;;; comint.el)
139 ;;;
140 ;;; v2.1 October 28 1996, first public release
141 ;;;
142 ;;; - Some new keybindings for term-char mode ( notably home/end/...)
143 ;;; - Directory, hostname and username tracking via ange-ftp
144 ;;; - Multi-term capability via the ansi-term call
145 ;;;
146 ;;; ----------------------------------------------------------------
147 ;;; You should/could have something like this in your .emacs to take
148 ;;; full advantage of this package
149 ;;;
150 ;;; (add-hook 'term-mode-hook
151 ;;; (function
152 ;;; (lambda ()
153 ;;; (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
154 ;;; (make-local-variable 'mouse-yank-at-point)
155 ;;; (make-local-variable 'transient-mark-mode)
156 ;;; (setq mouse-yank-at-point t)
157 ;;; (setq transient-mark-mode nil)
158 ;;; (auto-fill-mode -1)
159 ;;; (setq tab-width 8 ))))
160 ;;;
161 ;;;
162 ;;; ----------------------------------------
163 ;;;
164 ;;; If you want to use color ls the best setup is to have a different file
165 ;;; when you use eterm ( see above, mine is named .emacs_dircolors ). This
166 ;;; is necessary because some terminals, rxvt for example, need non-ansi
167 ;;; hacks to work ( for example on my rxvt white is wired to fg, and to
168 ;;; obtain normal white I have to do bold-white :)
169 ;;;
170 ;;; ----------------------------------------
171 ;;;
172 ;;;
173 ;;; # Configuration file for the color ls utility
174 ;;; # This file goes in the /etc directory, and must be world readable.
175 ;;; # You can copy this file to .dir_colors in your $HOME directory to
176 ;;; # override the system defaults.
177 ;;;
178 ;;; # COLOR needs one of these arguments: 'tty' colorizes output to ttys, but
179 ;;; # not pipes. 'all' adds color characters to all output. 'none' shuts
180 ;;; # colorization off.
181 ;;; COLOR tty
182 ;;; OPTIONS -F
183 ;;;
184 ;;; # Below, there should be one TERM entry for each termtype that is
185 ;;; # colorizable
186 ;;; TERM eterm
187 ;;;
188 ;;; # EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
189 ;;; EIGHTBIT 1
190 ;;;
191 ;;; # Below are the color init strings for the basic file types. A color init
192 ;;; # string consists of one or more of the following numeric codes:
193 ;;; # Attribute codes:
194 ;;; # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
195 ;;; # Text color codes:
196 ;;; # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
197 ;;; # Background color codes:
198 ;;; # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
199 ;;; NORMAL 00 # global default, although everything should be something.
200 ;;; FILE 00 # normal file
201 ;;; DIR 00;37 # directory
202 ;;; LINK 00;36 # symbolic link
203 ;;; FIFO 00;37 # pipe
204 ;;; SOCK 40;35 # socket
205 ;;; BLK 33;01 # block device driver
206 ;;; CHR 33;01 # character device driver
207 ;;;
208 ;;; # This is for files with execute permission:
209 ;;; EXEC 00;32
210 ;;;
211 ;;; # List any file extensions like '.gz' or '.tar' that you would like ls
212 ;;; # to colorize below. Put the extension, a space, and the color init
213 ;;; # string. (and any comments you want to add after a '#')
214 ;;; .tar 01;33 # archives or compressed
215 ;;; .tgz 01;33
216 ;;; .arj 01;33
217 ;;; .taz 01;33
218 ;;; .lzh 01;33
219 ;;; .zip 01;33
220 ;;; .z 01;33
221 ;;; .Z 01;33
222 ;;; .gz 01;33
223 ;;; .jpg 01;35 # image formats
224 ;;; .gif 01;35
225 ;;; .bmp 01;35
226 ;;; .xbm 01;35
227 ;;; .xpm 01;35
228 ;;;
229 ;;;
230 ;;; ----------------------------------------
231 ;;;
232 ;;; Notice: for directory/host/user tracking you need to have something
233 ;;; like this in your shell startup script ( this is for tcsh but should
234 ;;; be quite easy to port to other shells )
235 ;;;
236 ;;; ----------------------------------------
237 ;;;
238 ;;;
239 ;;; set os = `uname`
240 ;;; set host = `hostname`
241 ;;; set date = `date`
242 ;;;
243 ;;; # su does not change this but I'd like it to
244 ;;;
245 ;;; set user = `whoami`
246 ;;;
247 ;;; # ...
248 ;;;
249 ;;; if ( eterm =~ $TERM ) then
250 ;;;
251 ;;; echo --------------------------------------------------------------
252 ;;; echo Hello $user
253 ;;; echo Today is $date
254 ;;; echo We are on $host running $os under Emacs term mode
255 ;;; echo --------------------------------------------------------------
256 ;;;
257 ;;; setenv EDITOR emacsclient
258 ;;;
259 ;;; # Notice: $host and $user have been set before to 'hostname' and 'whoami'
260 ;;; # this is necessary because, f.e., certain versions of 'su' do not change
261 ;;; # $user, YMMV: if you don't want to fiddle with them define a couple
262 ;;; # of new variables and use these instead.
263 ;;; # NOTICE that there is a space between "AnSiT?" and $whatever NOTICE
264 ;;;
265 ;;; # These are because we want the real cwd in the messages, not the login
266 ;;; # time one !
267 ;;;
268 ;;; set cwd_hack='$cwd'
269 ;;; set host_hack='$host'
270 ;;; set user_hack='$user'
271 ;;;
272 ;;; # Notice that the ^[ character is an ESC, not two chars. You can
273 ;;; # get it in various ways, for example by typing
274 ;;; # echo -e '\033' > escape.file
275 ;;; # or by using your favourite editor
276 ;;;
277 ;;; foreach temp (cd pushd)
278 ;;; alias $temp "$temp \!* ; echo 'AnSiTc' $cwd_hack"
279 ;;; end
280 ;;; alias popd 'popd ;echo "AnSiTc" $cwd'
281 ;;;
282 ;;; # Every command that can modify the user/host/directory should be aliased
283 ;;; # as follows for the tracking mechanism to work.
284 ;;;
285 ;;; foreach temp ( rlogin telnet rsh sh ksh csh tcsh zsh bash tcl su )
286 ;;; alias $temp "$temp \!* ; echo 'AnSiTh' $host_hack ; \
287 ;;; echo 'AnSiTu' $user_hack ;echo 'AnSiTc' $cwd_hack"
288 ;;; end
289 ;;;
290 ;;; # Start up & use color ls
291 ;;;
292 ;;; echo "AnSiTh" $host
293 ;;; echo "AnSiTu" $user
294 ;;; echo "AnSiTc" $cwd
295 ;;;
296 ;;; # some housekeeping
297 ;;;
298 ;;; unset cwd_hack
299 ;;; unset host_hack
300 ;;; unset user_hack
301 ;;; unset temp
302 ;;;
303 ;;; eval `/bin/dircolors /home/marco/.emacs_dircolors`
304 ;;; endif
305 ;;;
306 ;;; # ...
307 ;;;
308 ;;; # Let's not clutter user space
309 ;;;
310 ;;; unset os
311 ;;; unset date
312 ;;;
313 ;;;
314
315 ;;; Original Commentary:
316 ;;; --------------------
27 317
28 ;; The changelog is at the end of this file. 318 ;; The changelog is at the end of this file.
29 319
30 ;; Please send me bug reports, bug fixes, and extensions, so that I can 320 ;; Please send me bug reports, bug fixes, and extensions, so that I can
31 ;; merge them into the master source. 321 ;; merge them into the master source.
32 ;; - Per Bothner (bothner@cygnus.com) 322 ;; - Per Bothner (bothner@cygnus.com)
33 323
34 ;; This file defines a general command-interpreter-in-a-buffer package 324 ;; This file defines a general command-interpreter-in-a-buffer package
35 ;; (term mode). The idea is that you can build specific process-in-a-buffer 325 ;; (term mode). The idea is that you can build specific process-in-a-buffer
36 ;; modes on top of term mode -- e.g., lisp, shell, scheme, T, soar, .... 326 ;; modes on top of term mode -- e.g., lisp, shell, scheme, T, soar, ....
37 ;; This way, all these specific packages share a common base functionality, 327 ;; This way, all these specific packages share a common base functionality,
38 ;; and a common set of bindings, which makes them easier to use (and 328 ;; and a common set of bindings, which makes them easier to use (and
39 ;; saves code, implementation time, etc., etc.). 329 ;; saves code, implementation time, etc., etc.).
40 330
41 ;; For hints on converting existing process modes (e.g., tex-mode, 331 ;; For hints on converting existing process modes (e.g., tex-mode,
42 ;; background, dbx, gdb, kermit, prolog, telnet) to use term-mode 332 ;; background, dbx, gdb, kermit, prolog, telnet) to use term-mode
72 ;; term-replace-by-expanded-filename Expand and complete filename at point; 362 ;; term-replace-by-expanded-filename Expand and complete filename at point;
73 ;; replace with expanded/completed name. 363 ;; replace with expanded/completed name.
74 ;; term-kill-subjob No mercy. 364 ;; term-kill-subjob No mercy.
75 ;; term-show-maximum-output Show as much output as possible. 365 ;; term-show-maximum-output Show as much output as possible.
76 ;; term-continue-subjob Send CONT signal to buffer's process 366 ;; term-continue-subjob Send CONT signal to buffer's process
77 ;; group. Useful if you accidentally 367 ;; group. Useful if you accidentally
78 ;; suspend your process (with C-c C-z). 368 ;; suspend your process (with C-c C-z).
79 369
80 ;; term-mode-hook is the term mode hook. Basically for your keybindings. 370 ;; term-mode-hook is the term mode hook. Basically for your keybindings.
81 ;; term-load-hook is run after loading in this package. 371 ;; term-load-hook is run after loading in this package.
82 372
83 ;; Code: 373 ;; Code:
84 374
85 ;; This is passed to the inferior in the EMACS environment variable, 375 ;; This is passed to the inferior in the EMACS environment variable,
104 ;;; term-input-autoexpand - symbol ... 394 ;;; term-input-autoexpand - symbol ...
105 ;;; term-input-ignoredups - boolean ... 395 ;;; term-input-ignoredups - boolean ...
106 ;;; term-last-input-match - string ... 396 ;;; term-last-input-match - string ...
107 ;;; term-dynamic-complete-functions - hook For the completion mechanism 397 ;;; term-dynamic-complete-functions - hook For the completion mechanism
108 ;;; term-completion-fignore - list ... 398 ;;; term-completion-fignore - list ...
109 ;;; term-get-old-input - function Hooks for specific 399 ;;; term-get-old-input - function Hooks for specific
110 ;;; term-input-filter-functions - hook process-in-a-buffer 400 ;;; term-input-filter-functions - hook process-in-a-buffer
111 ;;; term-input-filter - function modes. 401 ;;; term-input-filter - function modes.
112 ;;; term-input-send - function 402 ;;; term-input-send - function
113 ;;; term-scroll-to-bottom-on-output - symbol ... 403 ;;; term-scroll-to-bottom-on-output - symbol ...
114 ;;; term-scroll-show-maximum-output - boolean... 404 ;;; term-scroll-show-maximum-output - boolean...
135 ;; state 4: term-terminal-parameter contains pending output. 425 ;; state 4: term-terminal-parameter contains pending output.
136 (defvar term-kill-echo-list nil) ;; A queue of strings whose echo 426 (defvar term-kill-echo-list nil) ;; A queue of strings whose echo
137 ;; we want suppressed. 427 ;; we want suppressed.
138 (defvar term-terminal-parameter) 428 (defvar term-terminal-parameter)
139 (defvar term-terminal-previous-parameter) 429 (defvar term-terminal-previous-parameter)
140 (defvar term-current-face 'default) 430 (defvar term-current-face 'term-default)
141 (defvar term-scroll-start 0) ;; Top-most line (inclusive) of scrolling region. 431 (defvar term-scroll-start 0) ;; Top-most line (inclusive) of scrolling region.
142 (defvar term-scroll-end) ;; Number of line (zero-based) after scrolling region. 432 (defvar term-scroll-end) ;; Number of line (zero-based) after scrolling region.
143 (defvar term-pager-count nil) ;; If nil, paging is disabled. 433 (defvar term-pager-count nil) ;; If nil, paging is disabled.
144 ;; Otherwise, number of lines before we need to page. 434 ;; Otherwise, number of lines before we need to page.
145 (defvar term-saved-cursor nil) 435 (defvar term-saved-cursor nil)
250 540
251 (defvar term-input-filter 541 (defvar term-input-filter
252 (function (lambda (str) (not (string-match "\\`\\s *\\'" str)))) 542 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
253 "Predicate for filtering additions to input history. 543 "Predicate for filtering additions to input history.
254 Only inputs answering true to this function are saved on the input 544 Only inputs answering true to this function are saved on the input
255 history list. Default is to save anything that isn't all whitespace") 545 history list. Default is to save anything that isn't all whitespace")
256 546
257 (defvar term-input-filter-functions '() 547 (defvar term-input-filter-functions '()
258 "Functions to call before input is sent to the process. 548 "Functions to call before input is sent to the process.
259 These functions get one argument, a string containing the text to send. 549 These functions get one argument, a string containing the text to send.
260 550
261 This variable is buffer-local.") 551 This variable is buffer-local.")
262 552
263 (defvar term-input-sender (function term-simple-send) 553 (defvar term-input-sender (function term-simple-send)
264 "Function to actually send to PROCESS the STRING submitted by user. 554 "Function to actually send to PROCESS the STRING submitted by user.
265 Usually this is just 'term-simple-send, but if your mode needs to 555 Usually this is just 'term-simple-send, but if your mode needs to
266 massage the input string, this is your hook. This is called from 556 massage the input string, this is your hook. This is called from
267 the user command term-send-input. term-simple-send just sends 557 the user command term-send-input. term-simple-send just sends
268 the string plus a newline.") 558 the string plus a newline.")
269 559
270 (defvar term-eol-on-send t 560 (defvar term-eol-on-send t
271 "*Non-nil means go to the end of the line before sending input. 561 "*Non-nil means go to the end of the line before sending input.
272 See `term-send-input'.") 562 See `term-send-input'.")
277 567
278 (defvar term-exec-hook '() 568 (defvar term-exec-hook '()
279 "Called each time a process is exec'd by term-exec. 569 "Called each time a process is exec'd by term-exec.
280 This is called after the process is cranked up. It is useful for things that 570 This is called after the process is cranked up. It is useful for things that
281 must be done each time a process is executed in a term-mode buffer (e.g., 571 must be done each time a process is executed in a term-mode buffer (e.g.,
282 \(process-kill-without-query)). In contrast, the term-mode-hook is only 572 \(process-kill-without-query)). In contrast, the term-mode-hook is only
283 executed once when the buffer is created.") 573 executed once when the buffer is created.")
284 574
285 (defvar term-mode-map nil) 575 (defvar term-mode-map nil)
286 (defvar term-raw-map nil 576 (defvar term-raw-map nil
287 "Keyboard map for sending characters directly to the inferior process.") 577 "Keyboard map for sending characters directly to the inferior process.")
292 582
293 (defvar term-pager-break-map nil) 583 (defvar term-pager-break-map nil)
294 584
295 (defvar term-ptyp t 585 (defvar term-ptyp t
296 "True if communications via pty; false if by pipe. Buffer local. 586 "True if communications via pty; false if by pipe. Buffer local.
297 This is to work around a bug in emacs process signaling.") 587 This is to work around a bug in Emacs process signaling.")
298 588
299 (defvar term-last-input-match "" 589 (defvar term-last-input-match ""
300 "Last string searched for by term input history search, for defaulting. 590 "Last string searched for by term input history search, for defaulting.
301 Buffer local variable.") 591 Buffer local variable.")
302 592
303 (defvar term-input-ring nil) 593 (defvar term-input-ring nil)
304 (defvar term-last-input-start) 594 (defvar term-last-input-start)
305 (defvar term-last-input-end) 595 (defvar term-last-input-end)
306 (defvar term-input-ring-index nil 596 (defvar term-input-ring-index nil
307 "Index of last matched history element.") 597 "Index of last matched history element.")
308 (defvar term-matching-input-from-input-string "" 598 (defvar term-matching-input-from-input-string ""
309 "Input previously used to match input history.") 599 "Input previously used to match input history.")
310 ; This argument to set-process-filter disables reading from the process, 600 ; This argument to set-process-filter disables reading from the process,
311 ; assuming this is emacs-19.20 or newer. 601 ; assuming this is Emacs 19.20 or newer.
312 (defvar term-pager-filter t) 602 (defvar term-pager-filter t)
313 603
314 (put 'term-replace-by-expanded-history 'menu-enable 'term-input-autoexpand) 604 (put 'term-replace-by-expanded-history 'menu-enable 'term-input-autoexpand)
315 (put 'term-input-ring 'permanent-local t) 605 (put 'term-input-ring 'permanent-local t)
316 (put 'term-input-ring-index 'permanent-local t) 606 (put 'term-input-ring-index 'permanent-local t)
321 (put 'term-ptyp 'permanent-local t) 611 (put 'term-ptyp 'permanent-local t)
322 612
323 ;; Do FORMS if running under Emacs-19. 613 ;; Do FORMS if running under Emacs-19.
324 (defmacro term-if-emacs19 (&rest forms) 614 (defmacro term-if-emacs19 (&rest forms)
325 (if (string-match "^19" emacs-version) (cons 'progn forms))) 615 (if (string-match "^19" emacs-version) (cons 'progn forms)))
326 ;; True if running under XEmacs (previously Lucid emacs). 616 ;; True if running under XEmacs (previously Lucid Emacs).
327 (defmacro term-is-xemacs () '(string-match "Lucid" emacs-version)) 617 (defmacro term-is-xemacs () '(string-match "Lucid" emacs-version))
328 ;; Do FORM if running under XEmacs (previously Lucid emacs). 618 ;; Do FORM if running under XEmacs (previously Lucid Emacs).
329 (defmacro term-if-xemacs (&rest forms) 619 (defmacro term-if-xemacs (&rest forms)
330 (if (term-is-xemacs) (cons 'progn forms))) 620 (if (term-is-xemacs) (cons 'progn forms)))
331 ;; Do FORM if NOT running under XEmacs (previously Lucid emacs). 621 ;; Do FORM if NOT running under XEmacs (previously Lucid Emacs).
332 (defmacro term-ifnot-xemacs (&rest forms) 622 (defmacro term-ifnot-xemacs (&rest forms)
333 (if (not (term-is-xemacs)) (cons 'progn forms))) 623 (if (not (term-is-xemacs)) (cons 'progn forms)))
334 624
335 (defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map)) 625 (defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map))
336 (defmacro term-in-line-mode () '(not (term-in-char-mode))) 626 (defmacro term-in-line-mode () '(not (term-in-char-mode)))
339 (defmacro term-handling-pager () 'term-pager-old-local-map) 629 (defmacro term-handling-pager () 'term-pager-old-local-map)
340 (defmacro term-using-alternate-sub-buffer () 'term-saved-home-marker) 630 (defmacro term-using-alternate-sub-buffer () 'term-saved-home-marker)
341 631
342 (defvar term-signals-menu) 632 (defvar term-signals-menu)
343 (defvar term-terminal-menu) 633 (defvar term-terminal-menu)
634
635 ;;; Let's silence the byte-compiler -mm
636 (defvar term-ansi-at-eval-string nil)
637 (defvar term-ansi-at-host nil)
638 (defvar term-ansi-at-dir nil)
639 (defvar term-ansi-at-user nil)
640 (defvar term-ansi-at-message nil)
641 (defvar term-ansi-at-save-user nil)
642 (defvar term-ansi-at-save-pwd nil)
643 (defvar term-ansi-at-save-anon nil)
644 (defvar term-ansi-current-bold 0)
645 (defvar term-ansi-current-color 0)
646 (defvar term-ansi-face-alredy-done 0)
647 (defvar term-ansi-current-bg-color 0)
648 (defvar term-ansi-current-underline 0)
649 (defvar term-ansi-current-highlight 0)
650 (defvar term-ansi-current-reverse 0)
651 (defvar term-ansi-current-invisible 0)
652 (defvar term-ansi-default-fg 0)
653 (defvar term-ansi-default-bg 0)
654 (defvar term-ansi-current-temp 0)
655 (defvar term-ansi-fg-faces-vector nil)
656 (defvar term-ansi-bg-faces-vector nil)
657 (defvar term-ansi-inv-fg-faces-vector nil)
658 (defvar term-ansi-inv-bg-faces-vector nil)
659 (defvar term-ansi-reverse-faces-vector nil)
660
661 ;;; Four should be enough, if you want more, just add. -mm
662 (defvar term-terminal-more-parameters 0)
663 (defvar term-terminal-previous-parameter-2 -1)
664 (defvar term-terminal-previous-parameter-3 -1)
665 (defvar term-terminal-previous-parameter-4 -1)
666 ;;;
667
668 ;;; faces -mm
669
670
671 (defvar term-default-fg-color "azure3")
672 (defvar term-default-bg-color "SkyBlue4")
673
674 ;;; --- Simple faces ---
675 (make-face 'term-default-fg)
676 (make-face 'term-default-bg)
677 (make-face 'term-default-fg-inv)
678 (make-face 'term-default-bg-inv)
679 (make-face 'term-bold)
680 (make-face 'term-underline)
681 (make-face 'term-invisible)
682 (make-face 'term-invisible-inv)
683
684 (copy-face 'default 'term-default-fg)
685 (copy-face 'default 'term-default-bg)
686 (set-face-foreground 'term-default-fg term-default-fg-color)
687 (set-face-background 'term-default-bg term-default-bg-color)
688
689 (copy-face 'default 'term-default-fg-inv)
690 (copy-face 'default 'term-default-bg-inv)
691 (set-face-foreground 'term-default-fg-inv term-default-bg-color)
692 (set-face-background 'term-default-bg-inv term-default-fg-color)
693
694 (copy-face 'default 'term-invisible)
695 (set-face-background 'term-invisible term-default-bg-color)
696 (set-face-background 'term-invisible term-default-bg-color)
697
698 (copy-face 'default 'term-invisible-inv)
699 (set-face-background 'term-invisible-inv term-default-fg-color)
700 (set-face-background 'term-invisible-inv term-default-fg-color)
701
702 (copy-face 'default 'term-bold)
703 (make-face-bold 'term-bold)
704
705 (copy-face 'default 'term-underline)
706 (set-face-underline-p 'term-underline t)
707
708 ;;; --- Fg faces ---
709 (make-face 'term-black)
710 (make-face 'term-red)
711 (make-face 'term-green)
712 (make-face 'term-yellow)
713 (make-face 'term-blue)
714 (make-face 'term-magenta)
715 (make-face 'term-cyan)
716 (make-face 'term-white)
717
718 (copy-face 'default 'term-black)
719 (set-face-foreground 'term-black "black")
720 (copy-face 'default 'term-red)
721 (set-face-foreground 'term-red "red")
722 (copy-face 'default 'term-green)
723 (set-face-foreground 'term-green "green")
724 (copy-face 'default 'term-yellow)
725 (set-face-foreground 'term-yellow "yellow")
726 (copy-face 'default 'term-blue)
727 (set-face-foreground 'term-blue "blue")
728 (copy-face 'default 'term-magenta)
729 (set-face-foreground 'term-magenta "magenta")
730 (copy-face 'default 'term-cyan)
731 (set-face-foreground 'term-cyan "cyan")
732 (copy-face 'default 'term-white)
733 (set-face-foreground 'term-white "white")
734
735 ;;; --- Bg faces ---
736 (make-face 'term-blackbg)
737 (make-face 'term-redbg)
738 (make-face 'term-greenbg)
739 (make-face 'term-yellowbg)
740 (make-face 'term-bluebg)
741 (make-face 'term-magentabg)
742 (make-face 'term-cyanbg)
743 (make-face 'term-whitebg)
744
745 (copy-face 'default 'term-blackbg)
746 (set-face-background 'term-blackbg "black")
747 (copy-face 'default 'term-redbg)
748 (set-face-background 'term-redbg "red")
749 (copy-face 'default 'term-greenbg)
750 (set-face-background 'term-greenbg "green")
751 (copy-face 'default 'term-yellowbg)
752 (set-face-background 'term-yellowbg "yellow")
753 (copy-face 'default 'term-bluebg)
754 (set-face-background 'term-bluebg "blue")
755 (copy-face 'default 'term-magentabg)
756 (set-face-background 'term-magentabg "magenta")
757 (copy-face 'default 'term-cyanbg)
758 (set-face-background 'term-cyanbg "cyan")
759 (copy-face 'default 'term-whitebg)
760 (set-face-background 'term-whitebg "white")
761
762 (setq ansi-term-fg-faces-vector
763 [term-default-fg term-black term-red term-green term-yellow term-blue
764 term-magenta term-cyan term-white])
765
766 (setq ansi-term-bg-faces-vector
767 [term-default-bg term-blackbg term-redbg term-greenbg term-yellowbg
768 term-bluebg term-magentabg term-cyanbg term-whitebg])
769
770 (setq ansi-term-inv-bg-faces-vector
771 [term-default-fg-inv term-black term-red term-green term-yellow term-blue
772 term-magenta term-cyan term-white])
773
774 (setq ansi-term-inv-fg-faces-vector
775 [term-default-bg-inv term-blackbg term-redbg term-greenbg term-yellowbg
776 term-bluebg term-magentabg term-cyanbg term-whitebg])
777
778 ;;; Inspiration came from comint.el -mm
779 (defvar term-buffer-maximum-size 2048
780 "*The maximum size in lines for term buffers.
781 Term buffers are truncated from the top to be no greater than this number.
782 Notice that a setting of 0 means 'don't truncate anything'. This variable
783 is buffer-local.")
784 ;;;
344 785
345 (term-if-xemacs 786 (term-if-xemacs
346 (defvar term-terminal-menu 787 (defvar term-terminal-menu
347 '("Terminal" 788 '("Terminal"
348 [ "Character mode" term-char-mode (term-in-line-mode)] 789 [ "Character mode" term-char-mode (term-in-line-mode)]
357 while return not at end copies rest of line to end and sends it. 798 while return not at end copies rest of line to end and sends it.
358 In char sub-mode, each character (except `term-escape-char`) is 799 In char sub-mode, each character (except `term-escape-char`) is
359 set immediately. 800 set immediately.
360 801
361 This mode is typically customised to create inferior-lisp-mode, 802 This mode is typically customised to create inferior-lisp-mode,
362 shell-mode, etc.. This can be done by setting the hooks 803 shell-mode, etc.. This can be done by setting the hooks
363 term-input-filter-functions, term-input-filter, term-input-sender and 804 term-input-filter-functions, term-input-filter, term-input-sender and
364 term-get-old-input to appropriate functions, and the variable 805 term-get-old-input to appropriate functions, and the variable
365 term-prompt-regexp to the appropriate regular expression. 806 term-prompt-regexp to the appropriate regular expression.
366 807
367 An input history is maintained of size `term-input-ring-size', and 808 An input history is maintained of size `term-input-ring-size', and
368 can be accessed with the commands \\[term-next-input], \\[term-previous-input], and \\[term-dynamic-list-input-ring]. 809 can be accessed with the commands \\[term-next-input],
810 \\[term-previous-input], and \\[term-dynamic-list-input-ring].
369 Input ring history expansion can be achieved with the commands 811 Input ring history expansion can be achieved with the commands
370 \\[term-replace-by-expanded-history] or \\[term-magic-space]. 812 \\[term-replace-by-expanded-history] or \\[term-magic-space].
371 Input ring expansion is controlled by the variable `term-input-autoexpand', 813 Input ring expansion is controlled by the variable `term-input-autoexpand',
372 and addition is controlled by the variable `term-input-ignoredups'. 814 and addition is controlled by the variable `term-input-ignoredups'.
373 815
413 (setq term-input-ring-index nil)) 855 (setq term-input-ring-index nil))
414 856
415 (make-local-variable 'term-command-hook) 857 (make-local-variable 'term-command-hook)
416 (setq term-command-hook (symbol-function 'term-command-hook)) 858 (setq term-command-hook (symbol-function 'term-command-hook))
417 859
860 ;;; I'm not sure these saves are necessary but, since I
861 ;;; haven't tested the whole thing on a net connected machine with
862 ;;; a properly configured ange-ftp, I've decided to be conservative
863 ;;; and put them in. -mm
864
865 (make-local-variable 'term-ansi-at-host)
866 (setq term-ansi-at-host (system-name))
867
868 (make-local-variable 'term-ansi-at-dir)
869 (setq term-ansi-at-dir default-directory)
870
871 (make-local-variable 'term-ansi-at-message)
872 (setq term-ansi-at-message nil)
873
874 ;;; For user tracking purposes -mm
875 (make-local-variable 'ange-ftp-default-user)
876 (make-local-variable 'ange-ftp-default-password)
877 (make-local-variable 'ange-ftp-generate-anonymous-password)
878
879 ;;; You may want to have different scroll-back sizes -mm
880 (make-local-variable 'term-buffer-maximum-size)
881
882 ;;; Of course these have to be buffer-local -mm
883 (make-local-variable 'term-ansi-current-bold)
884 (make-local-variable 'term-ansi-current-color)
885 (make-local-variable 'term-ansi-face-alredy-done)
886 (make-local-variable 'term-ansi-current-bg-color)
887 (make-local-variable 'term-ansi-current-underline)
888 (make-local-variable 'term-ansi-current-highlight)
889 (make-local-variable 'term-ansi-current-reverse)
890 (make-local-variable 'term-ansi-current-invisible)
891
418 (make-local-variable 'term-terminal-state) 892 (make-local-variable 'term-terminal-state)
419 (make-local-variable 'term-kill-echo-list) 893 (make-local-variable 'term-kill-echo-list)
420 (make-local-variable 'term-start-line-column) 894 (make-local-variable 'term-start-line-column)
421 (make-local-variable 'term-current-column) 895 (make-local-variable 'term-current-column)
422 (make-local-variable 'term-current-row) 896 (make-local-variable 'term-current-row)
435 (make-local-variable 'term-matching-input-from-input-string) 909 (make-local-variable 'term-matching-input-from-input-string)
436 (make-local-variable 'term-input-autoexpand) 910 (make-local-variable 'term-input-autoexpand)
437 (make-local-variable 'term-input-ignoredups) 911 (make-local-variable 'term-input-ignoredups)
438 (make-local-variable 'term-delimiter-argument-list) 912 (make-local-variable 'term-delimiter-argument-list)
439 (make-local-variable 'term-input-filter-functions) 913 (make-local-variable 'term-input-filter-functions)
440 (make-local-variable 'term-input-filter) 914 (make-local-variable 'term-input-filter)
441 (make-local-variable 'term-input-sender) 915 (make-local-variable 'term-input-sender)
442 (make-local-variable 'term-eol-on-send) 916 (make-local-variable 'term-eol-on-send)
443 (make-local-variable 'term-scroll-to-bottom-on-output) 917 (make-local-variable 'term-scroll-to-bottom-on-output)
444 (make-local-variable 'term-scroll-show-maximum-output) 918 (make-local-variable 'term-scroll-show-maximum-output)
445 (make-local-variable 'term-ptyp) 919 (make-local-variable 'term-ptyp)
464 (define-key term-mode-map "\ep" 'term-previous-input) 938 (define-key term-mode-map "\ep" 'term-previous-input)
465 (define-key term-mode-map "\en" 'term-next-input) 939 (define-key term-mode-map "\en" 'term-next-input)
466 (define-key term-mode-map "\er" 'term-previous-matching-input) 940 (define-key term-mode-map "\er" 'term-previous-matching-input)
467 (define-key term-mode-map "\es" 'term-next-matching-input) 941 (define-key term-mode-map "\es" 'term-next-matching-input)
468 (term-ifnot-xemacs 942 (term-ifnot-xemacs
469 (define-key term-mode-map [?\A-\M-r] 'term-previous-matching-input-from-input) 943 (define-key term-mode-map [?\A-\M-r]
944 'term-previous-matching-input-from-input)
470 (define-key term-mode-map [?\A-\M-s] 'term-next-matching-input-from-input)) 945 (define-key term-mode-map [?\A-\M-s] 'term-next-matching-input-from-input))
471 (define-key term-mode-map "\e\C-l" 'term-show-output) 946 (define-key term-mode-map "\e\C-l" 'term-show-output)
472 (define-key term-mode-map "\C-m" 'term-send-input) 947 (define-key term-mode-map "\C-m" 'term-send-input)
473 (define-key term-mode-map "\C-d" 'term-delchar-or-maybe-eof) 948 (define-key term-mode-map "\C-d" 'term-delchar-or-maybe-eof)
474 (define-key term-mode-map "\C-c\C-a" 'term-bol) 949 (define-key term-mode-map "\C-c\C-a" 'term-bol)
487 (define-key term-mode-map "\C-c\C-d" 'term-send-eof) 962 (define-key term-mode-map "\C-c\C-d" 'term-send-eof)
488 (define-key term-mode-map "\C-c\C-k" 'term-char-mode) 963 (define-key term-mode-map "\C-c\C-k" 'term-char-mode)
489 (define-key term-mode-map "\C-c\C-j" 'term-line-mode) 964 (define-key term-mode-map "\C-c\C-j" 'term-line-mode)
490 (define-key term-mode-map "\C-c\C-q" 'term-pager-toggle) 965 (define-key term-mode-map "\C-c\C-q" 'term-pager-toggle)
491 966
492 (copy-face 'default 'term-underline-face)
493 (set-face-underline-p 'term-underline-face t)
494 967
495 ; ;; completion: 968 ; ;; completion:
496 ; (define-key term-mode-map [menu-bar completion] 969 ; (define-key term-mode-map [menu-bar completion]
497 ; (cons "Complete" (make-sparse-keymap "Complete"))) 970 ; (cons "Complete" (make-sparse-keymap "Complete")))
498 ; (define-key term-mode-map [menu-bar completion complete-expand] 971 ; (define-key term-mode-map [menu-bar completion complete-expand]
499 ; '("Expand File Name" . term-replace-by-expanded-filename)) 972 ; '("Expand File Name" . term-replace-by-expanded-filename))
500 ; (define-key term-mode-map [menu-bar completion complete-listing] 973 ; (define-key term-mode-map [menu-bar completion complete-listing]
501 ; '("File Completion Listing" . term-dynamic-list-filename-completions)) 974 ; '("File Completion Listing" . term-dynamic-list-filename-completions))
525 '("Line mode" . term-line-mode)) 998 '("Line mode" . term-line-mode))
526 (setq term-terminal-menu (cons "Terminal" newmap)) 999 (setq term-terminal-menu (cons "Terminal" newmap))
527 1000
528 ;; completion: (line mode only) 1001 ;; completion: (line mode only)
529 (defvar term-completion-menu (make-sparse-keymap "Complete")) 1002 (defvar term-completion-menu (make-sparse-keymap "Complete"))
530 (define-key term-mode-map [menu-bar completion] 1003 (define-key term-mode-map [menu-bar completion]
531 (cons "Complete" term-completion-menu)) 1004 (cons "Complete" term-completion-menu))
532 (define-key term-completion-menu [complete-expand] 1005 (define-key term-completion-menu [complete-expand]
533 '("Expand File Name" . term-replace-by-expanded-filename)) 1006 '("Expand File Name" . term-replace-by-expanded-filename))
534 (define-key term-completion-menu [complete-listing] 1007 (define-key term-completion-menu [complete-listing]
535 '("File Completion Listing" . term-dynamic-list-filename-completions)) 1008 '("File Completion Listing" . term-dynamic-list-filename-completions))
538 (define-key term-completion-menu [menu-bar completion complete] 1011 (define-key term-completion-menu [menu-bar completion complete]
539 '("Complete Before Point" . term-dynamic-complete)) 1012 '("Complete Before Point" . term-dynamic-complete))
540 1013
541 ;; Input history: (line mode only) 1014 ;; Input history: (line mode only)
542 (defvar term-inout-menu (make-sparse-keymap "In/Out")) 1015 (defvar term-inout-menu (make-sparse-keymap "In/Out"))
543 (define-key term-mode-map [menu-bar inout] 1016 (define-key term-mode-map [menu-bar inout]
544 (cons "In/Out" term-inout-menu)) 1017 (cons "In/Out" term-inout-menu))
545 (define-key term-inout-menu [kill-output] 1018 (define-key term-inout-menu [kill-output]
546 '("Kill Current Output Group" . term-kill-output)) 1019 '("Kill Current Output Group" . term-kill-output))
547 (define-key term-inout-menu [next-prompt] 1020 (define-key term-inout-menu [next-prompt]
548 '("Forward Output Group" . term-next-prompt)) 1021 '("Forward Output Group" . term-next-prompt))
565 (define-key term-inout-menu [previous-matching-history] 1038 (define-key term-inout-menu [previous-matching-history]
566 '("Previous Matching Input..." . term-previous-matching-input)) 1039 '("Previous Matching Input..." . term-previous-matching-input))
567 (define-key term-inout-menu [next-matching-history-from-input] 1040 (define-key term-inout-menu [next-matching-history-from-input]
568 '("Next Matching Current Input" . term-next-matching-input-from-input)) 1041 '("Next Matching Current Input" . term-next-matching-input-from-input))
569 (define-key term-inout-menu [previous-matching-history-from-input] 1042 (define-key term-inout-menu [previous-matching-history-from-input]
570 '("Previous Matching Current Input" . term-previous-matching-input-from-input)) 1043 '("Previous Matching Current Input" .
1044 term-previous-matching-input-from-input))
571 (define-key term-inout-menu [next-history] 1045 (define-key term-inout-menu [next-history]
572 '("Next Input" . term-next-input)) 1046 '("Next Input" . term-next-input))
573 (define-key term-inout-menu [previous-history] 1047 (define-key term-inout-menu [previous-history]
574 '("Previous Input" . term-previous-input)) 1048 '("Previous Input" . term-previous-input))
575 (define-key term-inout-menu [list-history] 1049 (define-key term-inout-menu [list-history]
643 (setq term-pager-count (term-current-row))) 1117 (setq term-pager-count (term-current-row)))
644 (process-send-string proc chars)))) 1118 (process-send-string proc chars))))
645 1119
646 (defun term-send-raw () 1120 (defun term-send-raw ()
647 "Send the last character typed through the terminal-emulator 1121 "Send the last character typed through the terminal-emulator
648 without any interpretation." 1122 without any interpretation."
649 (interactive) 1123 (interactive)
650 ;; Convert `return' to C-m, etc. 1124 ;; Convert `return' to C-m, etc.
651 (if (and (symbolp last-input-char) 1125 (if (and (symbolp last-input-char)
652 (get last-input-char 'ascii-character)) 1126 (get last-input-char 'ascii-character))
653 (setq last-input-char (get last-input-char 'ascii-character))) 1127 (setq last-input-char (get last-input-char 'ascii-character)))
685 ((listp arg) 0) 1159 ((listp arg) 0)
686 ((eq arg '-) -1) 1160 ((eq arg '-) -1)
687 (t (1- arg))))))) 1161 (t (1- arg)))))))
688 1162
689 ;; Which would be better: "\e[A" or "\eOA"? readline accepts either. 1163 ;; Which would be better: "\e[A" or "\eOA"? readline accepts either.
690 (defun term-send-up () (interactive) (term-send-raw-string "\e[A")) 1164 ;; For my configuration it's definitely better \eOA but YMMV. -mm
691 (defun term-send-down () (interactive) (term-send-raw-string "\e[B")) 1165 ;; For example: vi works with \eOA while elm wants \e[A ...
692 (defun term-send-right () (interactive) (term-send-raw-string "\e[C")) 1166 (defun term-send-up () (interactive) (term-send-raw-string "\eOA"))
693 (defun term-send-left () (interactive) (term-send-raw-string "\e[D")) 1167 (defun term-send-down () (interactive) (term-send-raw-string "\eOB"))
1168 (defun term-send-right () (interactive) (term-send-raw-string "\eOC"))
1169 (defun term-send-left () (interactive) (term-send-raw-string "\eOD"))
1170 (defun term-send-home () (interactive) (term-send-raw-string "\e[H"))
1171 (defun term-send-end () (interactive) (term-send-raw-string "\eOw"))
1172 (defun term-send-prior () (interactive) (term-send-raw-string "\e[5~"))
1173 (defun term-send-next () (interactive) (term-send-raw-string "\e[6~"))
1174 (defun term-send-del () (interactive) (term-send-raw-string "\C-?"))
1175 (defun term-send-backspace () (interactive) (term-send-raw-string "\C-H"))
694 1176
695 (defun term-set-escape-char (c) 1177 (defun term-set-escape-char (c)
696 "Change term-escape-char and keymaps that depend on it." 1178 "Change term-escape-char and keymaps that depend on it."
697 (if term-escape-char 1179 (if term-escape-char
698 (define-key term-raw-map term-escape-char 'term-send-raw)) 1180 (define-key term-raw-map term-escape-char 'term-send-raw))
708 (define-key term-raw-escape-map c 'term-send-raw) 1190 (define-key term-raw-escape-map c 'term-send-raw)
709 (define-key term-raw-escape-map "\C-q" 'term-pager-toggle) 1191 (define-key term-raw-escape-map "\C-q" 'term-pager-toggle)
710 ;; The keybinding for term-char-mode is needed by the menubar code. 1192 ;; The keybinding for term-char-mode is needed by the menubar code.
711 (define-key term-raw-escape-map "\C-k" 'term-char-mode) 1193 (define-key term-raw-escape-map "\C-k" 'term-char-mode)
712 (define-key term-raw-escape-map "\C-j" 'term-line-mode)) 1194 (define-key term-raw-escape-map "\C-j" 'term-line-mode))
713 1195
714 (defun term-char-mode () 1196 (defun term-char-mode ()
715 "Switch to char (\"raw\") sub-mode of term mode. 1197 "Switch to char (\"raw\") sub-mode of term mode.
716 Each character you type is sent directly to the inferior without 1198 Each character you type is sent directly to the inferior without
717 intervention from emacs, except for the escape character (usually C-c)." 1199 intervention from Emacs, except for the escape character (usually C-c)."
718 (interactive) 1200 (interactive)
719 (if (not term-raw-map) 1201 (if (not term-raw-map)
720 (let* ((map (make-keymap)) 1202 (let* ((map (make-keymap))
721 (esc-map (make-keymap)) 1203 (esc-map (make-keymap))
722 (i 0)) 1204 (i 0))
726 (setq i (1+ i))) 1208 (setq i (1+ i)))
727 (define-key map "\e" esc-map) 1209 (define-key map "\e" esc-map)
728 (setq term-raw-map map) 1210 (setq term-raw-map map)
729 (setq term-raw-escape-map 1211 (setq term-raw-escape-map
730 (copy-keymap (lookup-key (current-global-map) "\C-x"))) 1212 (copy-keymap (lookup-key (current-global-map) "\C-x")))
1213
1214 ;;; Added nearly all the 'grey keys' -mm
1215
731 (term-if-emacs19 1216 (term-if-emacs19
732 (term-if-xemacs 1217 (term-if-xemacs
733 (define-key term-raw-map [button2] 'term-mouse-paste)) 1218 (define-key term-raw-map [button2] 'term-mouse-paste))
734 (term-ifnot-xemacs 1219 (term-ifnot-xemacs
735 (define-key term-raw-map [mouse-2] 'term-mouse-paste) 1220 (define-key term-raw-map [mouse-2] 'term-mouse-paste)
736 (define-key term-raw-map [menu-bar terminal] term-terminal-menu) 1221 (define-key term-raw-map [menu-bar terminal] term-terminal-menu)
737 (define-key term-raw-map [menu-bar signals] term-signals-menu)) 1222 (define-key term-raw-map [menu-bar signals] term-signals-menu))
738 (define-key term-raw-map [up] 'term-send-up) 1223 (define-key term-raw-map [up] 'term-send-up)
739 (define-key term-raw-map [down] 'term-send-down) 1224 (define-key term-raw-map [down] 'term-send-down)
740 (define-key term-raw-map [right] 'term-send-right) 1225 (define-key term-raw-map [right] 'term-send-right)
741 (define-key term-raw-map [left] 'term-send-left)) 1226 (define-key term-raw-map [left] 'term-send-left)
1227 (define-key term-raw-map [delete] 'term-send-del)
1228 (define-key term-raw-map [backspace] 'term-send-backspace)
1229 (define-key term-raw-map [home] 'term-send-home)
1230 (define-key term-raw-map [end] 'term-send-end)
1231 (define-key term-raw-map [prior] 'term-send-prior)
1232 (define-key term-raw-map [next] 'term-send-next))
1233
1234
742 (term-set-escape-char ?\C-c))) 1235 (term-set-escape-char ?\C-c)))
743 ;; FIXME: Emit message? Cfr ilisp-raw-message 1236 ;; FIXME: Emit message? Cfr ilisp-raw-message
744 (if (term-in-line-mode) 1237 (if (term-in-line-mode)
745 (progn 1238 (progn
746 (setq term-old-mode-map (current-local-map)) 1239 (setq term-old-mode-map (current-local-map))
759 (setq term-input-sender save-input-sender)))) 1252 (setq term-input-sender save-input-sender))))
760 (term-update-mode-line)))) 1253 (term-update-mode-line))))
761 1254
762 (defun term-line-mode () 1255 (defun term-line-mode ()
763 "Switch to line (\"cooked\") sub-mode of term mode. 1256 "Switch to line (\"cooked\") sub-mode of term mode.
764 This means that emacs editing commands work as normally, until 1257 This means that Emacs editing commands work as normally, until
765 you type \\[term-send-input] which sends the current line to the inferior." 1258 you type \\[term-send-input] which sends the current line to the inferior."
766 (interactive) 1259 (interactive)
767 (if (term-in-char-mode) 1260 (if (term-in-char-mode)
768 (progn 1261 (progn
769 (use-local-map term-old-mode-map) 1262 (use-local-map term-old-mode-map)
776 (if (term-pager-enabled) '(": line page %s") '(": line %s")))) 1269 (if (term-pager-enabled) '(": line page %s") '(": line %s"))))
777 (force-mode-line-update)) 1270 (force-mode-line-update))
778 1271
779 (defun term-check-proc (buffer) 1272 (defun term-check-proc (buffer)
780 "True if there is a process associated w/buffer BUFFER, and 1273 "True if there is a process associated w/buffer BUFFER, and
781 it is alive (status RUN or STOP). BUFFER can be either a buffer or the 1274 it is alive (status RUN or STOP). BUFFER can be either a buffer or the
782 name of one" 1275 name of one"
783 (let ((proc (get-buffer-process buffer))) 1276 (let ((proc (get-buffer-process buffer)))
784 (and proc (memq (process-status proc) '(run stop))))) 1277 (and proc (memq (process-status proc) '(run stop)))))
785 1278
786 ;;;###autoload 1279 ;;;###autoload
787 (defun make-term (name program &optional startfile &rest switches) 1280 (defun make-term (name program &optional startfile &rest switches)
788 "Make a term process NAME in a buffer, running PROGRAM. 1281 "Make a term process NAME in a buffer, running PROGRAM.
789 The name of the buffer is made by surrounding NAME with `*'s. 1282 The name of the buffer is made by surrounding NAME with `*'s.
790 If there is already a running process in that buffer, it is not restarted. 1283 If there is already a running process in that buffer, it is not restarted.
791 Optional third arg STARTFILE is the name of a file to send the contents of to 1284 Optional third arg STARTFILE is the name of a file to send the contents of to
792 the process. Any more args are arguments to PROGRAM." 1285 the process. Any more args are arguments to PROGRAM."
793 (let ((buffer (get-buffer-create (concat "*" name "*")))) 1286 (let ((buffer (get-buffer-create (concat "*" name "*"))))
794 ;; If no process, or nuked process, crank up a new one and put buffer in 1287 ;; If no process, or nuked process, crank up a new one and put buffer in
795 ;; term mode. Otherwise, leave buffer and existing process alone. 1288 ;; term mode. Otherwise, leave buffer and existing process alone.
796 (cond ((not (term-check-proc buffer)) 1289 (cond ((not (term-check-proc buffer))
797 (save-excursion 1290 (save-excursion
798 (set-buffer buffer) 1291 (set-buffer buffer)
799 (term-mode)) ; Install local vars, mode, keymap, ... 1292 (term-mode)) ; Install local vars, mode, keymap, ...
800 (term-exec buffer name program startfile switches))) 1293 (term-exec buffer name program startfile switches)))
813 (term-char-mode) 1306 (term-char-mode)
814 (switch-to-buffer "*terminal*")) 1307 (switch-to-buffer "*terminal*"))
815 1308
816 (defun term-exec (buffer name command startfile switches) 1309 (defun term-exec (buffer name command startfile switches)
817 "Start up a process in buffer for term modes. 1310 "Start up a process in buffer for term modes.
818 Blasts any old process running in the buffer. Doesn't set the buffer mode. 1311 Blasts any old process running in the buffer. Doesn't set the buffer mode.
819 You can use this to cheaply run a series of processes in the same term 1312 You can use this to cheaply run a series of processes in the same term
820 buffer. The hook term-exec-hook is run after each exec." 1313 buffer. The hook term-exec-hook is run after each exec."
821 (save-excursion 1314 (save-excursion
822 (set-buffer buffer) 1315 (set-buffer buffer)
823 (let ((proc (get-buffer-process buffer))) ; Blast any old process. 1316 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
824 (if proc (delete-process proc))) 1317 (if proc (delete-process proc)))
825 ;; Crank up a new process 1318 ;; Crank up a new process
847 buffer))) 1340 buffer)))
848 1341
849 ;;; Name to use for TERM. 1342 ;;; Name to use for TERM.
850 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs. 1343 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs.
851 (defvar term-term-name "eterm") 1344 (defvar term-term-name "eterm")
852 ; Format string, usage: (format term-termcap-string emacs-term-name "TERMCAP=" 24 80) 1345 ; Format string, usage:
1346 ; (format term-termcap-string emacs-term-name "TERMCAP=" 24 80)
853 (defvar term-termcap-format 1347 (defvar term-termcap-format
854 "%s%s:li#%d:co#%d:cl=\\E[H\\E[J:cd=\\E[J:bs:am:xn:cm=\\E[%%i%%d;%%dH\ 1348 "%s%s:li#%d:co#%d:cl=\\E[H\\E[J:cd=\\E[J:bs:am:xn:cm=\\E[%%i%%d;%%dH\
855 :nd=\\E[C:up=\\E[A:ce=\\E[K:ho=\\E[H:pt\ 1349 :nd=\\E[C:up=\\E[A:ce=\\E[K:ho=\\E[H:pt\
856 :al=\\E[L:dl=\\E[M:DL=\\E[%%dM:AL=\\E[%%dL:cs=\\E[%%i%%d;%%dr:sf=\\n\ 1350 :al=\\E[L:dl=\\E[M:DL=\\E[%%dM:AL=\\E[%%dL:cs=\\E[%%i%%d;%%dr:sf=\\n\
857 :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ 1351 :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\
864 ;;; This auxiliary function cranks up the process for term-exec in 1358 ;;; This auxiliary function cranks up the process for term-exec in
865 ;;; the appropriate environment. 1359 ;;; the appropriate environment.
866 1360
867 (defun term-exec-1 (name buffer command switches) 1361 (defun term-exec-1 (name buffer command switches)
868 ;; We need to do an extra (fork-less) exec to run stty. 1362 ;; We need to do an extra (fork-less) exec to run stty.
869 ;; (This would not be needed if we had suitable emacs primitives.) 1363 ;; (This would not be needed if we had suitable Emacs primitives.)
870 ;; The 'if ...; then shift; fi' hack is because Bourne shell 1364 ;; The 'if ...; then shift; fi' hack is because Bourne shell
871 ;; loses one arg when called with -c, and newer shells (bash, ksh) don't. 1365 ;; loses one arg when called with -c, and newer shells (bash, ksh) don't.
872 ;; Thus we add an extra dummy argument "..", and then remove it. 1366 ;; Thus we add an extra dummy argument "..", and then remove it.
873 (let ((process-environment 1367 (let ((process-environment
874 (nconc 1368 (nconc
889 if [ $1 = .. ]; then shift; fi; exec \"$@\"" 1383 if [ $1 = .. ]; then shift; fi; exec \"$@\""
890 term-height term-width) 1384 term-height term-width)
891 ".." 1385 ".."
892 command switches))) 1386 command switches)))
893 1387
894 ;;; This should be in emacs, but it isn't. 1388 ;;; This should be in Emacs, but it isn't.
895 (defun term-mem (item list &optional elt=) 1389 (defun term-mem (item list &optional elt=)
896 "Test to see if ITEM is equal to an item in LIST. 1390 "Test to see if ITEM is equal to an item in LIST.
897 Option comparison function ELT= defaults to equal." 1391 Option comparison function ELT= defaults to equal."
898 (let ((elt= (or elt= (function equal))) 1392 (let ((elt= (or elt= (function equal)))
899 (done nil)) 1393 (done nil))
1078 1572
1079 (defun term-previous-input-string (arg) 1573 (defun term-previous-input-string (arg)
1080 "Return the string ARG places along the input ring. 1574 "Return the string ARG places along the input ring.
1081 Moves relative to `term-input-ring-index'." 1575 Moves relative to `term-input-ring-index'."
1082 (ring-ref term-input-ring (if term-input-ring-index 1576 (ring-ref term-input-ring (if term-input-ring-index
1083 (mod (+ arg term-input-ring-index) 1577 (mod (+ arg term-input-ring-index)
1084 (ring-length term-input-ring)) 1578 (ring-length term-input-ring))
1085 arg))) 1579 arg)))
1086 1580
1087 (defun term-previous-input (arg) 1581 (defun term-previous-input (arg)
1088 "Cycle backwards through input history." 1582 "Cycle backwards through input history."
1098 "Return the string matching REGEXP ARG places along the input ring. 1592 "Return the string matching REGEXP ARG places along the input ring.
1099 Moves relative to `term-input-ring-index'." 1593 Moves relative to `term-input-ring-index'."
1100 (let* ((pos (term-previous-matching-input-string-position regexp arg))) 1594 (let* ((pos (term-previous-matching-input-string-position regexp arg)))
1101 (if pos (ring-ref term-input-ring pos)))) 1595 (if pos (ring-ref term-input-ring pos))))
1102 1596
1103 (defun term-previous-matching-input-string-position (regexp arg &optional start) 1597 (defun term-previous-matching-input-string-position
1598 (regexp arg &optional start)
1104 "Return the index matching REGEXP ARG places along the input ring. 1599 "Return the index matching REGEXP ARG places along the input ring.
1105 Moves relative to START, or `term-input-ring-index'." 1600 Moves relative to START, or `term-input-ring-index'."
1106 (if (or (not (ring-p term-input-ring)) 1601 (if (or (not (ring-p term-input-ring))
1107 (ring-empty-p term-input-ring)) 1602 (ring-empty-p term-input-ring))
1108 (error "No history")) 1603 (error "No history"))
1138 ;; Has a match been found? 1633 ;; Has a match been found?
1139 (if (null pos) 1634 (if (null pos)
1140 (error "Not found") 1635 (error "Not found")
1141 (setq term-input-ring-index pos) 1636 (setq term-input-ring-index pos)
1142 (message "History item: %d" (1+ pos)) 1637 (message "History item: %d" (1+ pos))
1143 (delete-region 1638 (delete-region
1144 ;; Can't use kill-region as it sets this-command 1639 ;; Can't use kill-region as it sets this-command
1145 (process-mark (get-buffer-process (current-buffer))) (point)) 1640 (process-mark (get-buffer-process (current-buffer))) (point))
1146 (insert (ring-ref term-input-ring pos))))) 1641 (insert (ring-ref term-input-ring pos)))))
1147 1642
1148 (defun term-next-matching-input (regexp arg) 1643 (defun term-next-matching-input (regexp arg)
1161 (interactive "p") 1656 (interactive "p")
1162 (if (not (memq last-command '(term-previous-matching-input-from-input 1657 (if (not (memq last-command '(term-previous-matching-input-from-input
1163 term-next-matching-input-from-input))) 1658 term-next-matching-input-from-input)))
1164 ;; Starting a new search 1659 ;; Starting a new search
1165 (setq term-matching-input-from-input-string 1660 (setq term-matching-input-from-input-string
1166 (buffer-substring 1661 (buffer-substring
1167 (process-mark (get-buffer-process (current-buffer))) 1662 (process-mark (get-buffer-process (current-buffer)))
1168 (point)) 1663 (point))
1169 term-input-ring-index nil)) 1664 term-input-ring-index nil))
1170 (term-previous-matching-input 1665 (term-previous-matching-input
1171 (concat "^" (regexp-quote term-matching-input-from-input-string)) 1666 (concat "^" (regexp-quote term-matching-input-from-input-string))
1172 arg)) 1667 arg))
1185 Expansion is dependent on the value of `term-input-autoexpand'. 1680 Expansion is dependent on the value of `term-input-autoexpand'.
1186 1681
1187 This function depends on the buffer's idea of the input history, which may not 1682 This function depends on the buffer's idea of the input history, which may not
1188 match the command interpreter's idea, assuming it has one. 1683 match the command interpreter's idea, assuming it has one.
1189 1684
1190 Assumes history syntax is like typical Un*x shells'. However, since emacs 1685 Assumes history syntax is like typical Un*x shells'. However, since Emacs
1191 cannot know the interpreter's idea of input line numbers, assuming it has one, 1686 cannot know the interpreter's idea of input line numbers, assuming it has one,
1192 it cannot expand absolute input line number references. 1687 it cannot expand absolute input line number references.
1193 1688
1194 If the optional argument SILENT is non-nil, never complain 1689 If the optional argument SILENT is non-nil, never complain
1195 even if history reference seems erroneous. 1690 even if history reference seems erroneous.
1404 1899
1405 ;;; 1900 ;;;
1406 ;;; Input processing stuff [line mode] 1901 ;;; Input processing stuff [line mode]
1407 ;;; 1902 ;;;
1408 1903
1409 (defun term-send-input () 1904 (defun term-send-input ()
1410 "Send input to process. 1905 "Send input to process.
1411 After the process output mark, sends all text from the process mark to 1906 After the process output mark, sends all text from the process mark to
1412 point as input to the process. Before the process output mark, calls value 1907 point as input to the process. Before the process output mark, calls value
1413 of variable term-get-old-input to retrieve old input, copies it to the 1908 of variable term-get-old-input to retrieve old input, copies it to the
1414 process mark, and sends it. A terminal newline is also inserted into the 1909 process mark, and sends it. A terminal newline is also inserted into the
1432 1927
1433 If the interpreter is the csh, 1928 If the interpreter is the csh,
1434 term-get-old-input is the default: take the current line, discard any 1929 term-get-old-input is the default: take the current line, discard any
1435 initial string matching regexp term-prompt-regexp. 1930 initial string matching regexp term-prompt-regexp.
1436 term-input-filter-functions monitors input for \"cd\", \"pushd\", and 1931 term-input-filter-functions monitors input for \"cd\", \"pushd\", and
1437 \"popd\" commands. When it sees one, it cd's the buffer. 1932 \"popd\" commands. When it sees one, it cd's the buffer.
1438 term-input-filter is the default: returns T if the input isn't all white 1933 term-input-filter is the default: returns T if the input isn't all white
1439 space. 1934 space.
1440 1935
1441 If the term is Lucid Common Lisp, 1936 If the term is Lucid Common Lisp,
1442 term-get-old-input snarfs the sexp ending at point. 1937 term-get-old-input snarfs the sexp ending at point.
1443 term-input-filter-functions does nothing. 1938 term-input-filter-functions does nothing.
1444 term-input-filter returns NIL if the input matches input-filter-regexp, 1939 term-input-filter returns NIL if the input matches input-filter-regexp,
1445 which matches (1) all whitespace (2) :a, :c, etc. 1940 which matches (1) all whitespace (2) :a, :c, etc.
1446 1941
1524 (error "Current buffer has no process") 2019 (error "Current buffer has no process")
1525 (goto-char (process-mark process)) 2020 (goto-char (process-mark process))
1526 (insert input)))) 2021 (insert input))))
1527 2022
1528 (defun term-skip-prompt () 2023 (defun term-skip-prompt ()
1529 "Skip past the text matching regexp term-prompt-regexp. 2024 "Skip past the text matching regexp term-prompt-regexp.
1530 If this takes us past the end of the current line, don't skip at all." 2025 If this takes us past the end of the current line, don't skip at all."
1531 (let ((eol (save-excursion (end-of-line) (point)))) 2026 (let ((eol (save-excursion (end-of-line) (point))))
1532 (if (and (looking-at term-prompt-regexp) 2027 (if (and (looking-at term-prompt-regexp)
1533 (<= (match-end 0) eol)) 2028 (<= (match-end 0) eol))
1534 (goto-char (match-end 0))))) 2029 (goto-char (match-end 0)))))
1535 2030
1536 2031
1537 (defun term-after-pmark-p () 2032 (defun term-after-pmark-p ()
1538 "Is point after the process output marker?" 2033 "Is point after the process output marker?"
1539 ;; Since output could come into the buffer after we looked at the point 2034 ;; Since output could come into the buffer after we looked at the point
1540 ;; but before we looked at the process marker's value, we explicitly 2035 ;; but before we looked at the process marker's value, we explicitly
1541 ;; serialise. This is just because I don't know whether or not emacs 2036 ;; serialise. This is just because I don't know whether or not Emacs
1542 ;; services input during execution of lisp commands. 2037 ;; services input during execution of lisp commands.
1543 (let ((proc-pos (marker-position 2038 (let ((proc-pos (marker-position
1544 (process-mark (get-buffer-process (current-buffer)))))) 2039 (process-mark (get-buffer-process (current-buffer))))))
1545 (<= proc-pos (point)))) 2040 (<= proc-pos (point))))
1546 2041
1547 (defun term-simple-send (proc string) 2042 (defun term-simple-send (proc string)
1548 "Default function for sending to PROC input STRING. 2043 "Default function for sending to PROC input STRING.
1549 This just sends STRING plus a newline. To override this, 2044 This just sends STRING plus a newline. To override this,
1550 set the hook TERM-INPUT-SENDER." 2045 set the hook TERM-INPUT-SENDER."
1551 (term-send-string proc string) 2046 (term-send-string proc string)
1552 (term-send-string proc "\n")) 2047 (term-send-string proc "\n"))
1553 2048
1554 (defun term-bol (arg) 2049 (defun term-bol (arg)
1555 "Goes to the beginning of line, then skips past the prompt, if any. 2050 "Goes to the beginning of line, then skips past the prompt, if any.
1556 If a prefix argument is given (\\[universal-argument]), then no prompt skip 2051 If a prefix argument is given (\\[universal-argument]), then no prompt skip
1557 -- go straight to column 0. 2052 -- go straight to column 0.
1558 2053
1559 The prompt skip is done by skipping text matching the regular expression 2054 The prompt skip is done by skipping text matching the regular expression
1560 term-prompt-regexp, a buffer local variable." 2055 term-prompt-regexp, a buffer local variable."
1561 (interactive "P") 2056 (interactive "P")
1565 ;;; These two functions are for entering text you don't want echoed or 2060 ;;; These two functions are for entering text you don't want echoed or
1566 ;;; saved -- typically passwords to ftp, telnet, or somesuch. 2061 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
1567 ;;; Just enter m-x term-send-invisible and type in your line. 2062 ;;; Just enter m-x term-send-invisible and type in your line.
1568 2063
1569 (defun term-read-noecho (prompt &optional stars) 2064 (defun term-read-noecho (prompt &optional stars)
1570 "Read a single line of text from user without echoing, and return it. 2065 "Read a single line of text from user without echoing, and return it.
1571 Prompt with argument PROMPT, a string. Optional argument STARS causes 2066 Prompt with argument PROMPT, a string. Optional argument STARS causes
1572 input to be echoed with '*' characters on the prompt line. Input ends with 2067 input to be echoed with '*' characters on the prompt line. Input ends with
1573 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if 2068 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
1574 `inhibit-quit' is set because e.g. this function was called from a process 2069 `inhibit-quit' is set because e.g. this function was called from a process
1575 filter and C-g is pressed, this function returns nil rather than a string). 2070 filter and C-g is pressed, this function returns nil rather than a string).
1587 (message "%s%s" prompt (make-string (length ans) ?*)) 2082 (message "%s%s" prompt (make-string (length ans) ?*))
1588 (message "%s" prompt)) 2083 (message "%s" prompt))
1589 (setq c (read-char)) 2084 (setq c (read-char))
1590 (cond ((= c ?\C-g) 2085 (cond ((= c ?\C-g)
1591 ;; This function may get called from a process filter, where 2086 ;; This function may get called from a process filter, where
1592 ;; inhibit-quit is set. In later versions of emacs read-char 2087 ;; inhibit-quit is set. In later versions of Emacs read-char
1593 ;; may clear quit-flag itself and return C-g. That would make 2088 ;; may clear quit-flag itself and return C-g. That would make
1594 ;; it impossible to quit this loop in a simple way, so 2089 ;; it impossible to quit this loop in a simple way, so
1595 ;; re-enable it here (for backward-compatibility the check for 2090 ;; re-enable it here (for backward-compatibility the check for
1596 ;; quit-flag below would still be necessary, so this seems 2091 ;; quit-flag below would still be necessary, so this seems
1597 ;; like the simplest way to do things). 2092 ;; like the simplest way to do things).
1614 (message "") 2109 (message "")
1615 ans))) 2110 ans)))
1616 2111
1617 (defun term-send-invisible (str &optional proc) 2112 (defun term-send-invisible (str &optional proc)
1618 "Read a string without echoing. 2113 "Read a string without echoing.
1619 Then send it to the process running in the current buffer. A new-line 2114 Then send it to the process running in the current buffer. A new-line
1620 is additionally sent. String is not saved on term input history list. 2115 is additionally sent. String is not saved on term input history list.
1621 Security bug: your string can still be temporarily recovered with 2116 Security bug: your string can still be temporarily recovered with
1622 \\[view-lossage]." 2117 \\[view-lossage]."
1623 (interactive "P") ; Defeat snooping via C-x esc 2118 (interactive "P") ; Defeat snooping via C-x esc
1624 (if (not (stringp str)) 2119 (if (not (stringp str))
1625 (setq str (term-read-noecho "Non-echoed text: " t))) 2120 (setq str (term-read-noecho "Non-echoed text: " t)))
1639 If your process is choking on big inputs, try lowering the value.") 2134 If your process is choking on big inputs, try lowering the value.")
1640 2135
1641 (defun term-send-string (proc str) 2136 (defun term-send-string (proc str)
1642 "Send PROCESS the contents of STRING as input. 2137 "Send PROCESS the contents of STRING as input.
1643 This is equivalent to process-send-string, except that long input strings 2138 This is equivalent to process-send-string, except that long input strings
1644 are broken up into chunks of size term-input-chunk-size. Processes 2139 are broken up into chunks of size term-input-chunk-size. Processes
1645 are given a chance to output between chunks. This can help prevent processes 2140 are given a chance to output between chunks. This can help prevent processes
1646 from hanging when you send them long inputs on some OS's." 2141 from hanging when you send them long inputs on some OS's."
1647 (let* ((len (length str)) 2142 (let* ((len (length str))
1648 (i (min len term-input-chunk-size))) 2143 (i (min len term-input-chunk-size)))
1649 (process-send-string proc (substring str 0 i)) 2144 (process-send-string proc (substring str 0 i))
1650 (while (< i len) 2145 (while (< i len)
1654 (setq i next-i))))) 2149 (setq i next-i)))))
1655 2150
1656 (defun term-send-region (proc start end) 2151 (defun term-send-region (proc start end)
1657 "Sends to PROC the region delimited by START and END. 2152 "Sends to PROC the region delimited by START and END.
1658 This is a replacement for process-send-region that tries to keep 2153 This is a replacement for process-send-region that tries to keep
1659 your process from hanging on long inputs. See term-send-string." 2154 your process from hanging on long inputs. See term-send-string."
1660 (term-send-string proc (buffer-substring start end))) 2155 (term-send-string proc (buffer-substring start end)))
1661 2156
1662 2157
1663 ;;; Random input hackage 2158 ;;; Random input hackage
1664 2159
1665 (defun term-kill-output () 2160 (defun term-kill-output ()
1666 "Kill all output from interpreter since last input." 2161 "Kill all output from interpreter since last input."
1667 (interactive) 2162 (interactive)
1668 (let ((pmark (process-mark (get-buffer-process (current-buffer))))) 2163 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1669 (kill-region term-last-input-end pmark) 2164 (kill-region term-last-input-end pmark)
1670 (goto-char pmark) 2165 (goto-char pmark)
1671 (insert "*** output flushed ***\n") 2166 (insert "*** output flushed ***\n")
1672 (set-marker pmark (point)))) 2167 (set-marker pmark (point))))
1673 2168
1674 (defun term-show-output () 2169 (defun term-show-output ()
1675 "Display start of this batch of interpreter output at top of window. 2170 "Display start of this batch of interpreter output at top of window.
1697 (quit-process nil term-ptyp)) 2192 (quit-process nil term-ptyp))
1698 2193
1699 (defun term-stop-subjob () 2194 (defun term-stop-subjob ()
1700 "Stop the current subjob. 2195 "Stop the current subjob.
1701 WARNING: if there is no current subjob, you can end up suspending 2196 WARNING: if there is no current subjob, you can end up suspending
1702 the top-level process running in the buffer. If you accidentally do 2197 the top-level process running in the buffer. If you accidentally do
1703 this, use \\[term-continue-subjob] to resume the process. (This 2198 this, use \\[term-continue-subjob] to resume the process. (This
1704 is not a problem with most shells, since they ignore this signal.)" 2199 is not a problem with most shells, since they ignore this signal.)"
1705 (interactive) 2200 (interactive)
1706 (stop-process nil term-ptyp)) 2201 (stop-process nil term-ptyp))
1707 2202
1708 (defun term-continue-subjob () 2203 (defun term-continue-subjob ()
1718 (p-pos (marker-position pmark))) 2213 (p-pos (marker-position pmark)))
1719 (if (> (point) p-pos) 2214 (if (> (point) p-pos)
1720 (kill-region pmark (point))))) 2215 (kill-region pmark (point)))))
1721 2216
1722 (defun term-delchar-or-maybe-eof (arg) 2217 (defun term-delchar-or-maybe-eof (arg)
1723 "Delete ARG characters forward, or send an EOF to process if at end of buffer." 2218 "Delete ARG characters forward, or send an EOF to process if at end of
2219 buffer."
1724 (interactive "p") 2220 (interactive "p")
1725 (if (eobp) 2221 (if (eobp)
1726 (process-send-eof) 2222 (process-send-eof)
1727 (delete-char arg))) 2223 (delete-char arg)))
1728 2224
1773 2269
1774 ;;; Support for source-file processing commands. 2270 ;;; Support for source-file processing commands.
1775 ;;;============================================================================ 2271 ;;;============================================================================
1776 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have 2272 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
1777 ;;; commands that process files of source text (e.g. loading or compiling 2273 ;;; commands that process files of source text (e.g. loading or compiling
1778 ;;; files). So the corresponding process-in-a-buffer modes have commands 2274 ;;; files). So the corresponding process-in-a-buffer modes have commands
1779 ;;; for doing this (e.g., lisp-load-file). The functions below are useful 2275 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
1780 ;;; for defining these commands. 2276 ;;; for defining these commands.
1781 ;;; 2277 ;;;
1782 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme 2278 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
1783 ;;; and Soar, in that they don't know anything about file extensions. 2279 ;;; and Soar, in that they don't know anything about file extensions.
1784 ;;; So the compile/load interface gets the wrong default occasionally. 2280 ;;; So the compile/load interface gets the wrong default occasionally.
1785 ;;; The load-file/compile-file default mechanism could be smarter -- it 2281 ;;; The load-file/compile-file default mechanism could be smarter -- it
1786 ;;; doesn't know about the relationship between filename extensions and 2282 ;;; doesn't know about the relationship between filename extensions and
1787 ;;; whether the file is source or executable. If you compile foo.lisp 2283 ;;; whether the file is source or executable. If you compile foo.lisp
1788 ;;; with compile-file, then the next load-file should use foo.bin for 2284 ;;; with compile-file, then the next load-file should use foo.bin for
1789 ;;; the default, not foo.lisp. This is tricky to do right, particularly 2285 ;;; the default, not foo.lisp. This is tricky to do right, particularly
1790 ;;; because the extension for executable files varies so much (.o, .bin, 2286 ;;; because the extension for executable files varies so much (.o, .bin,
1791 ;;; .lbin, .mo, .vo, .ao, ...). 2287 ;;; .lbin, .mo, .vo, .ao, ...).
1792 2288
1793 2289
1794 ;;; TERM-SOURCE-DEFAULT -- determines defaults for source-file processing 2290 ;;; TERM-SOURCE-DEFAULT -- determines defaults for source-file processing
1802 ;;; for the file to process. 2298 ;;; for the file to process.
1803 2299
1804 ;;; (TERM-SOURCE-DEFAULT previous-dir/file source-modes) 2300 ;;; (TERM-SOURCE-DEFAULT previous-dir/file source-modes)
1805 ;;;============================================================================ 2301 ;;;============================================================================
1806 ;;; This function computes the defaults for the load-file and compile-file 2302 ;;; This function computes the defaults for the load-file and compile-file
1807 ;;; commands for tea, soar, cmulisp, and cmuscheme modes. 2303 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
1808 ;;; 2304 ;;;
1809 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last 2305 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
1810 ;;; source-file processing command. NIL if there hasn't been one yet. 2306 ;;; source-file processing command, or nil if there hasn't been one yet.
1811 ;;; - SOURCE-MODES is a list used to determine what buffers contain source 2307 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
1812 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source. 2308 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
1813 ;;; Typically, (lisp-mode) or (scheme-mode). 2309 ;;; Typically, (lisp-mode) or (scheme-mode).
1814 ;;; 2310 ;;;
1815 ;;; If the command is given while the cursor is inside a string, *and* 2311 ;;; If the command is given while the cursor is inside a string, *and*
1816 ;;; the string is an existing filename, *and* the filename is not a directory, 2312 ;;; the string is an existing filename, *and* the filename is not a directory,
1817 ;;; then the string is taken as default. This allows you to just position 2313 ;;; then the string is taken as default. This allows you to just position
1818 ;;; your cursor over a string that's a filename and have it taken as default. 2314 ;;; your cursor over a string that's a filename and have it taken as default.
1819 ;;; 2315 ;;;
1820 ;;; If the command is given in a file buffer whose major mode is in 2316 ;;; If the command is given in a file buffer whose major mode is in
1821 ;;; SOURCE-MODES, then the the filename is the default file, and the 2317 ;;; SOURCE-MODES, then the the filename is the default file, and the
1822 ;;; file's directory is the default directory. 2318 ;;; file's directory is the default directory.
1823 ;;; 2319 ;;;
1824 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer), 2320 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
1825 ;;; then the default directory & file are what was used in the last source-file 2321 ;;; then the default directory & file are what was used in the last source-file
1826 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time 2322 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
1827 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory 2323 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
1828 ;;; is the cwd, with no default file. (\"no default file\" = nil) 2324 ;;; is the cwd, with no default file. (\"no default file\" = nil)
1829 ;;; 2325 ;;;
1830 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode) 2326 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
1831 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode) 2327 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
1832 ;;; for Soar programs, etc. 2328 ;;; for Soar programs, etc.
1833 ;;; 2329 ;;;
1834 ;;; The function returns a pair: (default-directory . default-file). 2330 ;;; The function returns a pair: (default-directory . default-file).
1835 2331
1836 (defun term-source-default (previous-dir/file source-modes) 2332 (defun term-source-default (previous-dir/file source-modes)
1837 (cond ((and buffer-file-name (memq major-mode source-modes)) 2333 (cond ((and buffer-file-name (memq major-mode source-modes))
1838 (cons (file-name-directory buffer-file-name) 2334 (cons (file-name-directory buffer-file-name)
1867 ;;;============================================================================ 2363 ;;;============================================================================
1868 ;;; TERM-GET-SOURCE is used to prompt for filenames in command-interpreter 2364 ;;; TERM-GET-SOURCE is used to prompt for filenames in command-interpreter
1869 ;;; commands that process source files (like loading or compiling a file). 2365 ;;; commands that process source files (like loading or compiling a file).
1870 ;;; It prompts for the filename, provides a default, if there is one, 2366 ;;; It prompts for the filename, provides a default, if there is one,
1871 ;;; and returns the result filename. 2367 ;;; and returns the result filename.
1872 ;;; 2368 ;;;
1873 ;;; See TERM-SOURCE-DEFAULT for more on determining defaults. 2369 ;;; See TERM-SOURCE-DEFAULT for more on determining defaults.
1874 ;;; 2370 ;;;
1875 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair 2371 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
1876 ;;; from the last source processing command. SOURCE-MODES is a list of major 2372 ;;; from the last source processing command. SOURCE-MODES is a list of major
1877 ;;; modes used to determine what file buffers contain source files. (These 2373 ;;; modes used to determine what file buffers contain source files. (These
1878 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true, 2374 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
1879 ;;; then the filename reader will only accept a file that exists. 2375 ;;; then the filename reader will only accept a file that exists.
1880 ;;; 2376 ;;;
1881 ;;; A typical use: 2377 ;;; A typical use:
1882 ;;; (interactive (term-get-source "Compile file: " prev-lisp-dir/file 2378 ;;; (interactive (term-get-source "Compile file: " prev-lisp-dir/file
1883 ;;; '(lisp-mode) t)) 2379 ;;; '(lisp-mode) t))
1884 2380
1885 ;;; This is pretty stupid about strings. It decides we're in a string 2381 ;;; This is pretty stupid about strings. It decides we're in a string
1886 ;;; if there's a quote on both sides of point on the current line. 2382 ;;; if there's a quote on both sides of point on the current line.
1887 (defun term-extract-string () 2383 (defun term-extract-string ()
1888 "Returns string around POINT that starts the current line or nil." 2384 "Returns string around POINT that starts the current line or nil."
1889 (save-excursion 2385 (save-excursion
1890 (let* ((point (point)) 2386 (let* ((point (point))
1891 (bol (progn (beginning-of-line) (point))) 2387 (bol (progn (beginning-of-line) (point)))
1892 (eol (progn (end-of-line) (point))) 2388 (eol (progn (end-of-line) (point)))
1893 (start (progn (goto-char point) 2389 (start (progn (goto-char point)
1894 (and (search-backward "\"" bol t) 2390 (and (search-backward "\"" bol t)
1895 (1+ (point))))) 2391 (1+ (point)))))
1896 (end (progn (goto-char point) 2392 (end (progn (goto-char point)
1897 (and (search-forward "\"" eol t) 2393 (and (search-forward "\"" eol t)
1898 (1- (point)))))) 2394 (1- (point))))))
1899 (and start end 2395 (and start end
1917 defdir 2413 defdir
1918 (concat defdir deffile) 2414 (concat defdir deffile)
1919 mustmatch-p))) 2415 mustmatch-p)))
1920 (list (expand-file-name (substitute-in-file-name ans))))) 2416 (list (expand-file-name (substitute-in-file-name ans)))))
1921 2417
1922 ;;; I am somewhat divided on this string-default feature. It seems 2418 ;;; I am somewhat divided on this string-default feature. It seems
1923 ;;; to violate the principle-of-least-astonishment, in that it makes 2419 ;;; to violate the principle-of-least-astonishment, in that it makes
1924 ;;; the default harder to predict, so you actually have to look and see 2420 ;;; the default harder to predict, so you actually have to look and see
1925 ;;; what the default really is before choosing it. This can trip you up. 2421 ;;; what the default really is before choosing it. This can trip you up.
1926 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback 2422 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
1927 ;;; on this. 2423 ;;; on this.
1928 ;;; -Olin 2424 ;;; -Olin
1929 2425
1930 2426
1931 ;;; Simple process query facility. 2427 ;;; Simple process query facility.
1932 ;;; =========================================================================== 2428 ;;; ===========================================================================
1933 ;;; This function is for commands that want to send a query to the process 2429 ;;; This function is for commands that want to send a query to the process
1934 ;;; and show the response to the user. For example, a command to get the 2430 ;;; and show the response to the user. For example, a command to get the
1935 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query 2431 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
1936 ;;; to an inferior Common Lisp process. 2432 ;;; to an inferior Common Lisp process.
1937 ;;; 2433 ;;;
1938 ;;; This simple facility just sends strings to the inferior process and pops 2434 ;;; This simple facility just sends strings to the inferior process and pops
1939 ;;; up a window for the process buffer so you can see what the process 2435 ;;; up a window for the process buffer so you can see what the process
1940 ;;; responds with. We don't do anything fancy like try to intercept what the 2436 ;;; responds with. We don't do anything fancy like try to intercept what the
1941 ;;; process responds with and put it in a pop-up window or on the message 2437 ;;; process responds with and put it in a pop-up window or on the message
1942 ;;; line. We just display the buffer. Low tech. Simple. Works good. 2438 ;;; line. We just display the buffer. Low tech. Simple. Works good.
1943 2439
1944 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select 2440 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
1945 ;;; a window for the inferior process so that its response can be seen. 2441 ;;; a window for the inferior process so that its response can be seen.
1946 (defun term-proc-query (proc str) 2442 (defun term-proc-query (proc str)
1947 (let* ((proc-buf (process-buffer proc)) 2443 (let* ((proc-buf (process-buffer proc))
1948 (proc-mark (process-mark proc))) 2444 (proc-mark (process-mark proc)))
1949 (display-buffer proc-buf) 2445 (display-buffer proc-buf)
1951 (let ((proc-win (get-buffer-window proc-buf)) 2447 (let ((proc-win (get-buffer-window proc-buf))
1952 (proc-pt (marker-position proc-mark))) 2448 (proc-pt (marker-position proc-mark)))
1953 (term-send-string proc str) ; send the query 2449 (term-send-string proc str) ; send the query
1954 (accept-process-output proc) ; wait for some output 2450 (accept-process-output proc) ; wait for some output
1955 ;; Try to position the proc window so you can see the answer. 2451 ;; Try to position the proc window so you can see the answer.
1956 ;; This is bogus code. If you delete the (sit-for 0), it breaks. 2452 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
1957 ;; I don't know why. Wizards invited to improve it. 2453 ;; I don't know why. Wizards invited to improve it.
1958 (if (not (pos-visible-in-window-p proc-pt proc-win)) 2454 (if (not (pos-visible-in-window-p proc-pt proc-win))
1959 (let ((opoint (window-point proc-win))) 2455 (let ((opoint (window-point proc-win)))
1960 (set-window-point proc-win proc-mark) (sit-for 0) 2456 (set-window-point proc-win proc-mark) (sit-for 0)
1961 (if (not (pos-visible-in-window-p opoint proc-win)) 2457 (if (not (pos-visible-in-window-p opoint proc-win))
1962 (push-mark opoint) 2458 (push-mark opoint)
2059 (term-vertical-motion 0) 2555 (term-vertical-motion 0)
2060 (setq x (- save-col (current-column))) 2556 (setq x (- save-col (current-column)))
2061 (setq y (term-vertical-motion term-height)) 2557 (setq y (term-vertical-motion term-height))
2062 (cons x y)))) 2558 (cons x y))))
2063 2559
2560 ;;;Function that handles term messages: code by rms ( and you can see the
2561 ;;;difference ;-) -mm
2562
2563 (defun term-handle-ansi-terminal-messages (message)
2564 ;; Is there a command here?
2565 (while (string-match "\eAnSiT.+\n" message)
2566 ;; Extract the command code and the argument.
2567 (let* ((start (match-beginning 0))
2568 (end (match-end 0))
2569 (command-code (aref message (+ start 6)))
2570 (argument
2571 (save-match-data
2572 (substring message
2573 (+ start 8)
2574 (string-match "\r?\n" message
2575 (+ start 8)))))
2576 ignore)
2577 ;; Delete this command from MESSAGE.
2578 (setq message (replace-match "" t t message))
2579
2580 ;; If we recognize the type of command, set the appropriate variable.
2581 (cond ((= command-code ?c)
2582 (setq term-ansi-at-dir argument))
2583 ((= command-code ?h)
2584 (setq term-ansi-at-host argument))
2585 ((= command-code ?u)
2586 (setq term-ansi-at-user argument))
2587 ;; Otherwise ignore this one.
2588 (t
2589 (setq ignore t)))
2590
2591 ;; Update default-directory based on the changes this command made.
2592 (if ignore
2593 nil
2594 (setq default-directory
2595 (file-name-as-directory
2596 (if (and (string= term-ansi-at-host (system-name))
2597 (string= term-ansi-at-user (user-real-login-name)))
2598 (expand-file-name term-ansi-at-dir)
2599 (if (string= term-ansi-at-user (user-real-login-name))
2600 (concat "/" term-ansi-at-host ":" term-ansi-at-dir)
2601 (concat "/" term-ansi-at-user "@" term-ansi-at-host ":"
2602 term-ansi-at-dir)))))
2603
2604 ;; I'm not sure this is necessary,
2605 ;; but it's best to be on the safe side.
2606 (if (string= term-ansi-at-host (system-name))
2607 (progn
2608 (setq ange-ftp-default-user term-ansi-at-save-user)
2609 (setq ange-ftp-default-password term-ansi-at-save-pwd)
2610 (setq ange-ftp-generate-anonymous-password term-ansi-at-save-anon))
2611 (setq term-ansi-at-save-user ange-ftp-default-user)
2612 (setq term-ansi-at-save-pwd ange-ftp-default-password)
2613 (setq term-ansi-at-save-anon ange-ftp-generate-anonymous-password)
2614 (setq ange-ftp-default-user nil)
2615 (setq ange-ftp-default-password nil)
2616 (setq ange-ftp-generate-anonymous-password nil)))))
2617 message)
2618
2619
2064 ;;; Terminal emulation 2620 ;;; Terminal emulation
2065 ;;; This is the standard process filter for term buffers. 2621 ;;; This is the standard process filter for term buffers.
2066 ;;; It emulates (most of the features of) a VT100/ANSI-style terminal. 2622 ;;; It emulates (most of the features of) a VT100/ANSI-style terminal.
2067 2623
2068 (defun term-emulate-terminal (proc str) 2624 (defun term-emulate-terminal (proc str)
2072 (str-length (length str))) 2628 (str-length (length str)))
2073 (unwind-protect 2629 (unwind-protect
2074 (progn 2630 (progn
2075 (set-buffer (process-buffer proc)) 2631 (set-buffer (process-buffer proc))
2076 2632
2633 ;;; Let's handle the messages. -mm
2634
2635 (setq str (term-handle-ansi-terminal-messages str))
2636 (setq str-length (length str))
2637
2077 (if (marker-buffer term-pending-delete-marker) 2638 (if (marker-buffer term-pending-delete-marker)
2078 (progn 2639 (progn
2079 ;; Delete text following term-pending-delete-marker. 2640 ;; Delete text following term-pending-delete-marker.
2080 (delete-region term-pending-delete-marker (process-mark proc)) 2641 (delete-region term-pending-delete-marker (process-mark proc))
2081 (set-marker term-pending-delete-marker nil))) 2642 (set-marker term-pending-delete-marker nil)))
2098 ;; input line, save the line (by narrowing to leave it 2659 ;; input line, save the line (by narrowing to leave it
2099 ;; outside the restriction ) until we're done with output. 2660 ;; outside the restriction ) until we're done with output.
2100 (if (and (> (point-max) (process-mark proc)) 2661 (if (and (> (point-max) (process-mark proc))
2101 (term-in-line-mode)) 2662 (term-in-line-mode))
2102 (narrow-to-region (point-min) (process-mark proc))) 2663 (narrow-to-region (point-min) (process-mark proc)))
2103 2664
2104 (if term-log-buffer 2665 (if term-log-buffer
2105 (princ str term-log-buffer)) 2666 (princ str term-log-buffer))
2106 (cond ((eq term-terminal-state 4) ;; Have saved pending output. 2667 (cond ((eq term-terminal-state 4) ;; Have saved pending output.
2107 (setq str (concat term-terminal-parameter str)) 2668 (setq str (concat term-terminal-parameter str))
2108 (setq term-terminal-parameter nil) 2669 (setq term-terminal-parameter nil)
2109 (setq str-length (length str)) 2670 (setq str-length (length str))
2110 (setq term-terminal-state 0))) 2671 (setq term-terminal-state 0)))
2111 2672
2112 (while (< i str-length) 2673 (while (< i str-length)
2113 (setq char (aref str i)) 2674 (setq char (aref str i))
2114 (cond ((< term-terminal-state 2) 2675 (cond ((< term-terminal-state 2)
2115 ;; Look for prefix of regular chars 2676 ;; Look for prefix of regular chars
2116 (setq funny 2677 (setq funny
2215 (term-move-columns 1) 2776 (term-move-columns 1)
2216 (backward-delete-char 1) 2777 (backward-delete-char 1)
2217 (insert char)))) 2778 (insert char))))
2218 ((eq term-terminal-state 2) ; Seen Esc 2779 ((eq term-terminal-state 2) ; Seen Esc
2219 (cond ((eq char ?\133) ;; ?\133 = ?[ 2780 (cond ((eq char ?\133) ;; ?\133 = ?[
2781
2782 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm
2783 ;;; Note that now the init value of term-terminal-previous-parameter has
2784 ;;; been changed to -1
2785
2220 (make-local-variable 'term-terminal-parameter) 2786 (make-local-variable 'term-terminal-parameter)
2221 (make-local-variable 'term-terminal-previous-parameter) 2787 (make-local-variable 'term-terminal-previous-parameter)
2788 (make-local-variable 'term-terminal-previous-parameter-2)
2789 (make-local-variable 'term-terminal-previous-parameter-3)
2790 (make-local-variable 'term-terminal-previous-parameter-4)
2791 (make-local-variable 'term-terminal-more-parameters)
2222 (setq term-terminal-parameter 0) 2792 (setq term-terminal-parameter 0)
2223 (setq term-terminal-previous-parameter 0) 2793 (setq term-terminal-previous-parameter -1)
2794 (setq term-terminal-previous-parameter-2 -1)
2795 (setq term-terminal-previous-parameter-3 -1)
2796 (setq term-terminal-previous-parameter-4 -1)
2797 (setq term-terminal-more-parameters 0)
2224 (setq term-terminal-state 3)) 2798 (setq term-terminal-state 3))
2225 ((eq char ?D) ;; scroll forward 2799 ((eq char ?D) ;; scroll forward
2226 (term-handle-deferred-scroll) 2800 (term-handle-deferred-scroll)
2227 (term-down 1 t) 2801 (term-down 1 t)
2228 (setq term-terminal-state 0)) 2802 (setq term-terminal-state 0))
2244 ((eq term-terminal-state 3) ; Seen Esc [ 2818 ((eq term-terminal-state 3) ; Seen Esc [
2245 (cond ((and (>= char ?0) (<= char ?9)) 2819 (cond ((and (>= char ?0) (<= char ?9))
2246 (setq term-terminal-parameter 2820 (setq term-terminal-parameter
2247 (+ (* 10 term-terminal-parameter) (- char ?0)))) 2821 (+ (* 10 term-terminal-parameter) (- char ?0))))
2248 ((eq char ?\073 ) ; ?; 2822 ((eq char ?\073 ) ; ?;
2823 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm
2824 (setq term-terminal-more-parameters 1)
2825 (setq term-terminal-previous-parameter-4
2826 term-terminal-previous-parameter-3)
2827 (setq term-terminal-previous-parameter-3
2828 term-terminal-previous-parameter-2)
2829 (setq term-terminal-previous-parameter-2
2830 term-terminal-previous-parameter)
2249 (setq term-terminal-previous-parameter 2831 (setq term-terminal-previous-parameter
2250 term-terminal-parameter) 2832 term-terminal-parameter)
2251 (setq term-terminal-parameter 0)) 2833 (setq term-terminal-parameter 0))
2252 ((eq char ??)) ; Ignore ? 2834 ((eq char ??)) ; Ignore ?
2253 (t 2835 (t
2254 (term-handle-ansi-escape proc char) 2836 (term-handle-ansi-escape proc char)
2837 (setq term-terminal-more-parameters 0)
2838 (setq term-terminal-previous-parameter-4 -1)
2839 (setq term-terminal-previous-parameter-3 -1)
2840 (setq term-terminal-previous-parameter-2 -1)
2841 (setq term-terminal-previous-parameter -1)
2255 (setq term-terminal-state 0))))) 2842 (setq term-terminal-state 0)))))
2256 (if (term-handling-pager) 2843 (if (term-handling-pager)
2257 ;; Finish stuff to get ready to handle PAGER. 2844 ;; Finish stuff to get ready to handle PAGER.
2258 (progn 2845 (progn
2259 (if (> (% (current-column) term-width) 0) 2846 (if (> (% (current-column) term-width) 0)
2320 (save-excursion 2907 (save-excursion
2321 (goto-char (point-max)) 2908 (goto-char (point-max))
2322 (recenter -1))))) 2909 (recenter -1)))))
2323 (not (eq win selected)))) 2910 (not (eq win selected))))
2324 2911
2912 ;;; Stolen from comint.el and adapted -mm
2913 (if (> term-buffer-maximum-size 0)
2914 (save-excursion
2915 (goto-char (process-mark (get-buffer-process (current-buffer))))
2916 (forward-line (- term-buffer-maximum-size))
2917 (beginning-of-line)
2918 (delete-region (point-min) (point))))
2919 ;;;
2920
2325 (set-marker save-marker nil)) 2921 (set-marker save-marker nil))
2326 ;; unwind-protect cleanup-forms follow: 2922 ;; unwind-protect cleanup-forms follow:
2327 (set-buffer previous-buffer) 2923 (set-buffer previous-buffer)
2328 (select-window selected)))) 2924 (select-window selected))))
2329 2925
2333 (save-excursion 2929 (save-excursion
2334 (goto-char term-home-marker) 2930 (goto-char term-home-marker)
2335 (term-vertical-motion (1+ count)) 2931 (term-vertical-motion (1+ count))
2336 (set-marker term-home-marker (point)) 2932 (set-marker term-home-marker (point))
2337 (setq term-current-row (1- term-height)))))) 2933 (setq term-current-row (1- term-height))))))
2934
2935 ;;; New function to deal with ansi colorized output, as you can see you can
2936 ;;; have any bold/underline/fg/bg/reverse combination. -mm
2937
2938 (defun term-handle-colors-array (parameter)
2939 (cond
2940
2941 ;;; Bold
2942 ((eq parameter 1)
2943 (setq term-ansi-current-bold 1))
2944
2945 ;;; Underline
2946 ((eq parameter 4)
2947 (setq term-ansi-current-underline 1))
2948
2949 ;;; Blink (unsupported by Emacs), will be translated to bold.
2950 ;;; This may change in the future though.
2951 ((eq parameter 5)
2952 (setq term-ansi-current-bold 1))
2953
2954 ;;; Reverse
2955 ((eq parameter 7)
2956 (setq term-ansi-current-reverse 1))
2957
2958 ;;; Invisible
2959 ((eq parameter 8)
2960 (setq term-ansi-current-invisible 1))
2961
2962 ((and (>= parameter 30) (<= parameter 37))
2963 (setq term-ansi-current-color (- parameter 29)))
2964
2965 ((and (>= parameter 40) (<= parameter 47))
2966 (setq term-ansi-current-bg-color (- parameter 39)))
2967
2968 ;;; 0 (Reset) or unknown (reset anyway)
2969 (t
2970 (setq term-current-face
2971 (list 'term-default-fg 'term-default-bg))
2972 (setq term-ansi-current-underline 0)
2973 (setq term-ansi-current-bold 0)
2974 (setq term-ansi-current-reverse 0)
2975 (setq term-ansi-current-color 0)
2976 (setq term-ansi-current-invisible 0)
2977 (setq term-ansi-face-alredy-done 1)
2978 (setq term-ansi-current-bg-color 0)))
2979
2980 ; (message "Debug: U-%d R-%d B-%d I-%d D-%d F-%d B-%d"
2981 ; term-ansi-current-underline
2982 ; term-ansi-current-reverse
2983 ; term-ansi-current-bold
2984 ; term-ansi-current-invisible
2985 ; term-ansi-face-alredy-done
2986 ; term-ansi-current-color
2987 ; term-ansi-current-bg-color)
2988
2989
2990 (if (= term-ansi-face-alredy-done 0)
2991 (if (= term-ansi-current-reverse 1)
2992 (progn
2993 (if (= term-ansi-current-invisible 1)
2994 (if (= term-ansi-current-color 0)
2995 (setq term-current-face
2996 '(term-default-bg-inv term-default-fg))
2997 (setq term-current-face
2998 (list (elt ansi-term-inv-fg-faces-vector term-ansi-current-color)
2999 (elt ansi-term-inv-bg-faces-vector term-ansi-current-color))))
3000 ;; No need to bother with anything else if it's invisible
3001 (progn
3002 (setq term-current-face
3003 (list (elt ansi-term-inv-fg-faces-vector term-ansi-current-color)
3004 (elt ansi-term-inv-bg-faces-vector term-ansi-current-bg-color)))
3005 (if (= term-ansi-current-bold 1)
3006 (setq term-current-face
3007 (append '(term-bold) term-current-face)))
3008 (if (= term-ansi-current-underline 1)
3009 (setq term-current-face
3010 (append '(term-underline) term-current-face))))))
3011 (progn
3012 (if (= term-ansi-current-invisible 1)
3013 (if (= term-ansi-current-bg-color 0)
3014 (setq term-current-face
3015 '(term-default-fg-inv term-default-bg))
3016 (setq term-current-face
3017 (list (elt ansi-term-fg-faces-vector term-ansi-current-bg-color)
3018 (elt ansi-term-bg-faces-vector term-ansi-current-bg-color))))
3019 ;; No need to bother with anything else if it's invisible
3020 (progn
3021 (setq term-current-face
3022 (list (elt ansi-term-fg-faces-vector term-ansi-current-color)
3023 (elt ansi-term-bg-faces-vector term-ansi-current-bg-color)))
3024 (if (= term-ansi-current-bold 1)
3025 (setq term-current-face
3026 (append '(term-bold) term-current-face)))
3027 (if (= term-ansi-current-underline 1)
3028 (setq term-current-face
3029 (append '(term-underline) term-current-face))))))))
3030
3031 ; (message "Debug %S" term-current-face)
3032
3033 (setq term-ansi-face-alredy-done 0))
3034
2338 3035
2339 ;;; Handle a character assuming (eq terminal-state 2) - 3036 ;;; Handle a character assuming (eq terminal-state 2) -
2340 ;;; i.e. we have previously seen Escape followed by ?[. 3037 ;;; i.e. we have previously seen Escape followed by ?[.
2341 3038
2342 (defun term-handle-ansi-escape (proc char) 3039 (defun term-handle-ansi-escape (proc char)
2394 ((eq char ?l) 3091 ((eq char ?l)
2395 (cond ((eq term-terminal-parameter 4) 3092 (cond ((eq term-terminal-parameter 4)
2396 (setq term-insert-mode nil)) 3093 (setq term-insert-mode nil))
2397 ((eq term-terminal-parameter 47) 3094 ((eq term-terminal-parameter 47)
2398 (term-switch-to-alternate-sub-buffer nil)))) 3095 (term-switch-to-alternate-sub-buffer nil))))
3096
3097 ;;; Modified to allow ansi coloring -mm
2399 ;; \E[m - Set/reset standard mode 3098 ;; \E[m - Set/reset standard mode
2400 ((eq char ?m) 3099 ((eq char ?m)
2401 (cond ((eq term-terminal-parameter 7) 3100 (progn
2402 (setq term-current-face 'highlight)) 3101 ; (message "Debug: Current param stack 4)%d 3)%d 2)%d 1)%d 0)%d"
2403 ((eq term-terminal-parameter 4) 3102 ; term-terminal-previous-parameter-4
2404 (setq term-current-face 'term-underline-face)) 3103 ; term-terminal-previous-parameter-3
2405 ((eq term-terminal-parameter 1) 3104 ; term-terminal-previous-parameter-2
2406 (setq term-current-face 'bold)) 3105 ; term-terminal-previous-parameter
2407 (t (setq term-current-face 'default)))) 3106 ; term-terminal-parameter)
3107
3108 (if (= term-terminal-more-parameters 1)
3109 (progn (if (>= term-terminal-previous-parameter-4 0)
3110 (term-handle-colors-array term-terminal-previous-parameter-4))
3111 (if (>= term-terminal-previous-parameter-3 0)
3112 (term-handle-colors-array term-terminal-previous-parameter-3))
3113 (if (>= term-terminal-previous-parameter-2 0)
3114 (term-handle-colors-array term-terminal-previous-parameter-2))
3115 (term-handle-colors-array term-terminal-previous-parameter)))
3116 (term-handle-colors-array term-terminal-parameter)))
3117
3118
3119
2408 ;; \E[6n - Report cursor position 3120 ;; \E[6n - Report cursor position
2409 ((eq char ?n) 3121 ((eq char ?n)
2410 (term-handle-deferred-scroll) 3122 (term-handle-deferred-scroll)
2411 (process-send-string proc 3123 (process-send-string proc
2412 (format "\e[%s;%sR" 3124 (format "\e[%s;%sR"
2438 (= term-scroll-end term-height)))))) 3150 (= term-scroll-end term-height))))))
2439 3151
2440 (defun term-switch-to-alternate-sub-buffer (set) 3152 (defun term-switch-to-alternate-sub-buffer (set)
2441 ;; If asked to switch to (from) the alternate sub-buffer, and already (not) 3153 ;; If asked to switch to (from) the alternate sub-buffer, and already (not)
2442 ;; using it, do nothing. This test is needed for some programs (including 3154 ;; using it, do nothing. This test is needed for some programs (including
2443 ;; emacs) that emit the ti termcap string twice, for unknown reason. 3155 ;; Emacs) that emit the ti termcap string twice, for unknown reason.
2444 (term-handle-deferred-scroll) 3156 (term-handle-deferred-scroll)
2445 (if (eq set (not (term-using-alternate-sub-buffer))) 3157 (if (eq set (not (term-using-alternate-sub-buffer)))
2446 (let ((row (term-current-row)) 3158 (let ((row (term-current-row))
2447 (col (term-horizontal-column))) 3159 (col (term-horizontal-column)))
2448 (cond (set 3160 (cond (set
2477 (fileline (string-to-int 3189 (fileline (string-to-int
2478 (substring string (1+ first-colon) second-colon)))) 3190 (substring string (1+ first-colon) second-colon))))
2479 (setq term-pending-frame (cons filename fileline)))) 3191 (setq term-pending-frame (cons filename fileline))))
2480 ((= (aref string 0) ?/) 3192 ((= (aref string 0) ?/)
2481 (cd (substring string 1))) 3193 (cd (substring string 1)))
2482 ;; Allowing the inferior to call functions in emacs is 3194 ;; Allowing the inferior to call functions in Emacs is
2483 ;; probably too big a security hole. 3195 ;; probably too big a security hole.
2484 ;; ((= (aref string 0) ?!) 3196 ;; ((= (aref string 0) ?!)
2485 ;; (eval (car (read-from-string string 1)))) 3197 ;; (eval (car (read-from-string string 1))))
2486 (t)));; Otherwise ignore it 3198 (t)));; Otherwise ignore it
2487 3199
2580 (define-key map [menu-bar page] (cons "More pages?" tmp)) 3292 (define-key map [menu-bar page] (cons "More pages?" tmp))
2581 )) 3293 ))
2582 3294
2583 (setq term-pager-break-map map))) 3295 (setq term-pager-break-map map)))
2584 ; (let ((process (get-buffer-process (current-buffer)))) 3296 ; (let ((process (get-buffer-process (current-buffer))))
2585 ; (stop-process process)) 3297 ; (stop-process process))
2586 (setq term-pager-old-local-map (current-local-map)) 3298 (setq term-pager-old-local-map (current-local-map))
2587 (use-local-map term-pager-break-map) 3299 (use-local-map term-pager-break-map)
2588 (make-local-variable 'term-old-mode-line-format) 3300 (make-local-variable 'term-old-mode-line-format)
2589 (setq term-old-mode-line-format mode-line-format) 3301 (setq term-old-mode-line-format mode-line-format)
2590 (setq mode-line-format 3302 (setq mode-line-format
2651 (interactive) 3363 (interactive)
2652 (if (term-handling-pager) 3364 (if (term-handling-pager)
2653 (term-pager-continue nil) 3365 (term-pager-continue nil)
2654 (setq term-pager-count nil)) 3366 (setq term-pager-count nil))
2655 (term-update-mode-line)) 3367 (term-update-mode-line))
2656 3368
2657 ; Enable pager processing. 3369 ; Enable pager processing.
2658 (defun term-pager-enable () 3370 (defun term-pager-enable ()
2659 (interactive) 3371 (interactive)
2660 (or (term-pager-enabled) 3372 (or (term-pager-enabled)
2661 (setq term-pager-count 0)) ;; Or maybe set to (term-current-row) ?? 3373 (setq term-pager-count 0)) ;; Or maybe set to (term-current-row) ??
2782 (term-vertical-motion 1) 3494 (term-vertical-motion 1)
2783 (delete-region saved-point (point)) 3495 (delete-region saved-point (point))
2784 ;; wrapped is true if we're at the beginning of screen line, 3496 ;; wrapped is true if we're at the beginning of screen line,
2785 ;; but not a buffer line. If we delete the current screen line 3497 ;; but not a buffer line. If we delete the current screen line
2786 ;; that will make the previous line no longer wrap, and (because 3498 ;; that will make the previous line no longer wrap, and (because
2787 ;; of the way emacs display works) point will be at the end of 3499 ;; of the way Emacs display works) point will be at the end of
2788 ;; the previous screen line rather then the beginning of the 3500 ;; the previous screen line rather then the beginning of the
2789 ;; current one. To avoid that, we make sure that current line 3501 ;; current one. To avoid that, we make sure that current line
2790 ;; contain a space, to force the previous line to continue to wrap. 3502 ;; contain a space, to force the previous line to continue to wrap.
2791 ;; We could do this always, but it seems preferable to not add the 3503 ;; We could do this always, but it seems preferable to not add the
2792 ;; extra space when wrapped is false. 3504 ;; extra space when wrapped is false.
2793 (if wrapped 3505 (if wrapped
2794 (insert ? )) 3506 (insert ? ))
2909 ;;; Do the user's customisation... 3621 ;;; Do the user's customisation...
2910 3622
2911 (defvar term-load-hook nil 3623 (defvar term-load-hook nil
2912 "This hook is run when term is loaded in. 3624 "This hook is run when term is loaded in.
2913 This is a good place to put keybindings.") 3625 This is a good place to put keybindings.")
2914 3626
2915 (run-hooks 'term-load-hook) 3627 (run-hooks 'term-load-hook)
2916 3628
2917 3629
2918 ;;; Filename/command/history completion in a buffer 3630 ;;; Filename/command/history completion in a buffer
2919 ;;; =========================================================================== 3631 ;;; ===========================================================================
2926 ;;; term-dynamic-list-filename-completions List completions in help buffer. 3638 ;;; term-dynamic-list-filename-completions List completions in help buffer.
2927 ;;; term-replace-by-expanded-filename Expand and complete filename at point; 3639 ;;; term-replace-by-expanded-filename Expand and complete filename at point;
2928 ;;; replace with expanded/completed name. 3640 ;;; replace with expanded/completed name.
2929 ;;; term-dynamic-simple-complete Complete stub given candidates. 3641 ;;; term-dynamic-simple-complete Complete stub given candidates.
2930 3642
2931 ;;; These are not installed in the term-mode keymap. But they are 3643 ;;; These are not installed in the term-mode keymap. But they are
2932 ;;; available for people who want them. Shell-mode installs them: 3644 ;;; available for people who want them. Shell-mode installs them:
2933 ;;; (define-key shell-mode-map "\t" 'term-dynamic-complete) 3645 ;;; (define-key shell-mode-map "\t" 'term-dynamic-complete)
2934 ;;; (define-key shell-mode-map "\M-?" 3646 ;;; (define-key shell-mode-map "\M-?"
2935 ;;; 'term-dynamic-list-filename-completions))) 3647 ;;; 'term-dynamic-list-filename-completions)))
2936 ;;; 3648 ;;;
2937 ;;; Commands like this are fine things to put in load hooks if you 3649 ;;; Commands like this are fine things to put in load hooks if you
3173 (mouse-choose-completion first) 3885 (mouse-choose-completion first)
3174 (set-window-configuration conf)) 3886 (set-window-configuration conf))
3175 (if (eq first ?\ ) 3887 (if (eq first ?\ )
3176 (set-window-configuration conf) 3888 (set-window-configuration conf)
3177 (setq unread-command-events (listify-key-sequence key))))))) 3889 (setq unread-command-events (listify-key-sequence key)))))))
3890
3891 ;;; I need a make-term that doesn't surround with *s -mm
3892 (defun term-ansi-make-term (name program &optional startfile &rest switches)
3893 "Make a term process NAME in a buffer, running PROGRAM.
3894 The name of the buffer is NAME.
3895 If there is already a running process in that buffer, it is not restarted.
3896 Optional third arg STARTFILE is the name of a file to send the contents of to
3897 the process. Any more args are arguments to PROGRAM."
3898 (let ((buffer (get-buffer-create name )))
3899 ;; If no process, or nuked process, crank up a new one and put buffer in
3900 ;; term mode. Otherwise, leave buffer and existing process alone.
3901 (cond ((not (term-check-proc buffer))
3902 (save-excursion
3903 (set-buffer buffer)
3904 (term-mode)) ; Install local vars, mode, keymap, ...
3905 (term-exec buffer name program startfile switches)))
3906 buffer))
3907
3908 (defvar term-ansi-buffer-name nil)
3909 (defvar term-ansi-default-program nil)
3910 (defvar term-ansi-buffer-base-name nil)
3911
3912 ;;;###autoload
3913 (defun ansi-term (program &optional new-buffer-name)
3914 "Start a terminal-emulator in a new buffer."
3915 (interactive (list (read-from-minibuffer "Run program: "
3916 (or explicit-shell-file-name
3917 (getenv "ESHELL")
3918 (getenv "SHELL")
3919 "/bin/sh"))))
3920
3921 ;; Pick the name of the new buffer.
3922 (setq term-ansi-buffer-name
3923 (if new-buffer-name
3924 new-buffer-name
3925 (if term-ansi-buffer-base-name
3926 (if (eq term-ansi-buffer-base-name t)
3927 (file-name-nondirectory program)
3928 term-ansi-buffer-base-name)
3929 "ansi-term")))
3930
3931 (setq term-ansi-buffer-name (concat "*" term-ansi-buffer-name "*"))
3932
3933 ;; In order to have more than one term active at a time
3934 ;; I'd like to have the term names have the *term-ansi-term<?>* form,
3935 ;; for now they have the *term-ansi-term*<?> form but we'll see...
3936
3937 (setq term-ansi-buffer-name (generate-new-buffer-name term-ansi-buffer-name))
3938 (setq term-ansi-buffer-name (term-ansi-make-term term-ansi-buffer-name program))
3939
3940 (set-buffer term-ansi-buffer-name)
3941 (term-mode)
3942 (term-char-mode)
3943
3944 ;; I wanna have find-file on C-x C-f -mm
3945 ;; your mileage may definitely vary, maybe it's better to put this in your
3946 ;; .emacs ...
3947
3948 (term-set-escape-char ?\C-x)
3949
3950 (switch-to-buffer term-ansi-buffer-name))
3951
3178 3952
3179 ;;; Converting process modes to use term mode 3953 ;;; Converting process modes to use term mode
3180 ;;; =========================================================================== 3954 ;;; ===========================================================================
3181 ;;; Renaming variables 3955 ;;; Renaming variables
3182 ;;; Most of the work is renaming variables and functions. These are the common 3956 ;;; Most of the work is renaming variables and functions. These are the common
3183 ;;; ones: 3957 ;;; ones:
3184 ;;; Local variables: 3958 ;;; Local variables:
3185 ;;; last-input-start term-last-input-start 3959 ;;; last-input-start term-last-input-start
3186 ;;; last-input-end term-last-input-end 3960 ;;; last-input-end term-last-input-end
3187 ;;; shell-prompt-pattern term-prompt-regexp 3961 ;;; shell-prompt-pattern term-prompt-regexp
3210 ;;; the buffer after input is sent, perhaps because the inferior 3984 ;;; the buffer after input is sent, perhaps because the inferior
3211 ;;; insists on echoing the input. The LAST-INPUT-START variable in 3985 ;;; insists on echoing the input. The LAST-INPUT-START variable in
3212 ;;; the old shell package was used to implement a history mechanism, 3986 ;;; the old shell package was used to implement a history mechanism,
3213 ;;; but you should think twice before using term-last-input-start 3987 ;;; but you should think twice before using term-last-input-start
3214 ;;; for this; the input history ring often does the job better. 3988 ;;; for this; the input history ring often does the job better.
3215 ;;; 3989 ;;;
3216 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do 3990 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
3217 ;;; *not* create the term-mode local variables in your foo-mode function. 3991 ;;; *not* create the term-mode local variables in your foo-mode function.
3218 ;;; This is not modular. Instead, call term-mode, and let *it* create the 3992 ;;; This is not modular. Instead, call term-mode, and let *it* create the
3219 ;;; necessary term-specific local variables. Then create the 3993 ;;; necessary term-specific local variables. Then create the
3220 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to 3994 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
3221 ;;; be foo-mode-map, and its mode to be foo-mode. Set the term-mode hooks 3995 ;;; be foo-mode-map, and its mode to be foo-mode. Set the term-mode hooks
3222 ;;; (term-{prompt-regexp, input-filter, input-filter-functions, 3996 ;;; (term-{prompt-regexp, input-filter, input-filter-functions,
3223 ;;; get-old-input) that need to be different from the defaults. Call 3997 ;;; get-old-input) that need to be different from the defaults. Call
3224 ;;; foo-mode-hook, and you're done. Don't run the term-mode hook yourself; 3998 ;;; foo-mode-hook, and you're done. Don't run the term-mode hook yourself;
3225 ;;; term-mode will take care of it. The following example, from shell.el, 3999 ;;; term-mode will take care of it. The following example, from shell.el,
3226 ;;; is typical: 4000 ;;; is typical:
3227 ;;; 4001 ;;;
3228 ;;; (defvar shell-mode-map '()) 4002 ;;; (defvar shell-mode-map '())
3229 ;;; (cond ((not shell-mode-map) 4003 ;;; (cond ((not shell-mode-map)
3230 ;;; (setq shell-mode-map (copy-keymap term-mode-map)) 4004 ;;; (setq shell-mode-map (copy-keymap term-mode-map))
3231 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command) 4005 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
3232 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command) 4006 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
3246 ;;; (add-hook 'term-input-filter-functions 'shell-directory-tracker) 4020 ;;; (add-hook 'term-input-filter-functions 'shell-directory-tracker)
3247 ;;; (run-hooks 'shell-mode-hook)) 4021 ;;; (run-hooks 'shell-mode-hook))
3248 ;;; 4022 ;;;
3249 ;;; 4023 ;;;
3250 ;;; Completion for term-mode users 4024 ;;; Completion for term-mode users
3251 ;;; 4025 ;;;
3252 ;;; For modes that use term-mode, term-dynamic-complete-functions is the 4026 ;;; For modes that use term-mode, term-dynamic-complete-functions is the
3253 ;;; hook to add completion functions to. Functions on this list should return 4027 ;;; hook to add completion functions to. Functions on this list should return
3254 ;;; non-nil if completion occurs (i.e., further completion should not occur). 4028 ;;; non-nil if completion occurs (i.e., further completion should not occur).
3255 ;;; You could use term-dynamic-simple-complete to do the bulk of the 4029 ;;; You could use term-dynamic-simple-complete to do the bulk of the
3256 ;;; completion job. 4030 ;;; completion job.