1 @\input texinfo @c -*-texinfo-*-
2 settitle Notes about emacs Term mode
7 @center @titlefont(Notes about Emacs TERM Mode)
11 @dircategory SXEmacs Editor
13 * Term mode: (term). Emacs terminal emulator mode.
19 @top Terminal emulator mode
22 This is some notes about the term Emacs mode.
33 * Connecting to remote computers::
38 The @code{term} package includes the major modes @code{term},
39 @code{shell}, and @code{gud} (for running gbd or another debugger).
40 It is a replacement for the comint mode of Emacs 19,
41 as well as shell, gdb, terminal, and telnet modes.
42 The package works best with recent releases of Emacs 19,
43 but will also work reasonably well with Emacs 18 as well as Lucid Emacs 19.
45 The file @code{nshell.el} is a wrapper to use unless term mode
46 is built into Emacs. If works around some of the missing
47 in older Emacs versions.
48 To use it, edit the paths in @code{nshell.el}, appropriately,
49 and then @code{M-x load-file nshell.el RET}.
50 This will also load in replacement shell and gud modes.
55 The @code{term} mode is used to control a program (an "inferior process").
56 It sends most keyboard input characters to the program,
57 and displays output from the program in the buffer.
58 This is similar to the traditional comint mode, and
59 modes derived from it (such as shell and gdb modes).
60 You can do with the new term-based shell the same sort
61 of things you could do with the old shell mode,
62 using more or less the same interface. However, the
63 new mode is more flexible, and works somewhat differently.
66 * Output from the inferior::
67 * subbuffer:: The sub-buffer
68 * altsubbuffer:: The alternate sub-buffer
69 * Input to the inferior::
72 @node Output from the inferior
73 @subsection Output from the inferior
75 In typical usage, output from the inferior is
76 added to the end of the buffer. If needed, the window
77 will be scrolled, just like a regular terminal.
78 (Only one line at a time will be scrolled, just like
79 regular terminals, and in contrast to the old shell mode.)
80 Thus the buffer becomes a log of your interaction with the
81 inferior, just like the old shell mode.
83 Like a real terminal, term maintains a "cursor position."
84 This is the @code{process-mark} of the inferior process.
85 If the process-mark is not at the end of the buffer, output from
86 the inferior will overwrite existing text in the buffer.
87 This is like a real terminal, but unlike the old shell mode
88 (which inserts the output, instead of overwriting).
90 Some programs (such as Emacs itself) need to control the
91 appearance on the screen in detail. They do this by
92 sending special control codes. The exact control
93 codes needed from terminal to terminal, but nowadays
94 most terminals and terminal emulators (including xterm)
95 understand the so-called "ANSI escape sequences" (first
96 popularized by the Digital's VT100 family of terminal).
97 The term mode also understands these escape sequences,
98 and for each control code does the appropriate thing
99 to change the buffer so that the appearance of the window
100 will match what it would be on a real terminal.
101 (In contrast, the old shell mode doesn't handle
102 terminal control codes at all.)
104 See <...> for the specific control codes.
107 @subsection The sub-buffer
109 A program that talks to terminal expects the terminal to have a fixed size.
110 If the program is talking a terminal emulator program such as @code{xterm},
111 that size can be changed (if the xterm window is re-sized), but programs
112 still assume a logical terminal that has a fixed size independent
113 of the amount of output transmitted by the programs.
115 To programs that use it, the Emacs terminal emulator acts as if it
116 too has a fixed size. The @dfn{sub-buffer} is the part of a @code{term}-mode
117 buffer that corresponds to a "normal" terminal. Most of the time
118 (unless you explicitly scroll the window displaying the buffer),
119 the sub-buffer is the part of the buffer that is displayed in a window.
121 The sub-buffer is defined in terms of three buffer-local-variable:
124 The height of the sub-buffer, in screen lines.
128 The width of the sub-buffer, in screen columns.
131 @defvar term-home-marker
132 The "home" position, that is the top left corner of the sub-buffer.
135 The sub-buffer is assumed to be the end part of the buffer;
136 the @code{term-home-marker} should never be more than
137 @code{term-height} screen lines from the end of the buffer.
140 @subsection The alternate sub-buffer
142 When a "graphical" program finishes, it is nice to
143 restore the screen state to what it was before the program started.
144 Many people are used to this behavior from @code{xterm}, and
145 its also offered by the @code{term} emulator.
147 @defun term-switch-to-alternate-sub-buffer set
148 If @var{set} is true, and we're not already using the alternate sub-buffer,
149 switch to it. What this means is that the @code{term-home-marker}
150 is saved (in the variable @code{term-saved-home-marker}), and the
151 @code{term-home-marker} is set to the end of the buffer.
153 If @var{set} is false and we're using the alternate sub-buffer,
154 switch back to the saved sub-buffer. What this means is that the
155 (current, alternate) sub-buffer is deleted (using
156 @code{(delete-region term-home-marker (point-max))}), and then the
157 @code{term-home-marker} is restored (from @code{term-saved-home-marker}).
160 @node Input to the inferior
161 @subsection Input to the inferior
163 Characters typed by the user are sent to the inferior.
164 How this is done depends on whether the @code{term} buffer
165 is in "character" mode or "line" mode.
166 (A @code{term} buffer can also be in "pager" mode.
167 This is discussed <later>.)
168 Which of these is currently active is specified in the mode line.
169 The difference between them is the key-bindings available.
171 In character mode, one character (by default @key{C-c}) is special,
172 and is a prefix for various commands. All other characters are
173 sent directly to the inferior process, with no interpretation by Emacs.
174 Character mode looks and feels like a real terminal, or a conventional
175 terminal emulator such as xterm.
177 In line mode, key commands mostly have standard Emacs actions.
178 Regulars characters insert themselves into the buffer.
179 When return is typed, the entire current line of the buffer
180 (except possibly the prompt) is sent to the inferior process.
181 Line mode is basically the original shell mode from earlier Emacs versions.
183 To switch from line mode to character mode type @kbd{C-c C-k}.
184 To switch from character mode to line mode type @kbd{C-c C-j}.