Commit | Line | Data |
---|---|---|
6bf7aab6 | 1 | @c This is part of the Emacs manual. |
73b0cd50 | 2 | @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011 |
42e96065 | 3 | @c Free Software Foundation, Inc. |
6bf7aab6 DL |
4 | @c See file emacs.texi for copying conditions. |
5 | @iftex | |
6 | @chapter Miscellaneous Commands | |
7 | ||
8 | This chapter contains several brief topics that do not fit anywhere | |
d14202c2 CY |
9 | else: viewing ``document files'', reading netnews, running shell |
10 | commands and shell subprocesses, using a single shared Emacs for | |
11 | utilities that expect to run an editor as a subprocess, printing | |
12 | hardcopy, sorting text, narrowing display to part of the buffer, | |
f404f8bc CY |
13 | editing binary files, saving an Emacs session for later resumption, |
14 | following hyperlinks, browsing images, emulating other editors, and | |
15 | various diversions and amusements. | |
6bf7aab6 DL |
16 | |
17 | @end iftex | |
2e7cfad6 LT |
18 | |
19 | @ifnottex | |
20 | @raisesections | |
21 | @end ifnottex | |
22 | ||
856ce114 | 23 | @node Gnus |
6bf7aab6 DL |
24 | @section Gnus |
25 | @cindex Gnus | |
26 | @cindex reading netnews | |
27 | ||
28 | Gnus is an Emacs package primarily designed for reading and posting | |
29 | Usenet news. It can also be used to read and respond to messages from a | |
30 | number of other sources---mail, remote directories, digests, and so on. | |
6bf7aab6 | 31 | Here we introduce Gnus and describe several basic features. |
d3ea5f55 | 32 | @ifnottex |
6bf7aab6 | 33 | For full details, see @ref{Top, Gnus,, gnus, The Gnus Manual}. |
d3ea5f55 | 34 | @end ifnottex |
6bf7aab6 | 35 | @iftex |
a42dbee1 | 36 | For full details on Gnus, type @kbd{C-h i} and then select the Gnus |
6bf7aab6 DL |
37 | manual. |
38 | @end iftex | |
39 | ||
40 | @findex gnus | |
41 | To start Gnus, type @kbd{M-x gnus @key{RET}}. | |
42 | ||
43 | @menu | |
8838673e GM |
44 | * Buffers of Gnus:: The group, summary, and article buffers. |
45 | * Gnus Startup:: What you should know about starting Gnus. | |
46 | * Summary of Gnus:: A short description of the basic Gnus commands. | |
6bf7aab6 DL |
47 | @end menu |
48 | ||
49 | @node Buffers of Gnus | |
50 | @subsection Gnus Buffers | |
51 | ||
ab192107 RS |
52 | Unlike most Emacs packages, Gnus uses several buffers to display |
53 | information and to receive commands. The three Gnus buffers users use | |
54 | most are the @dfn{group buffer}, the @dfn{summary buffer} and the | |
55 | @dfn{article buffer}. | |
6bf7aab6 | 56 | |
ab192107 RS |
57 | The @dfn{group buffer} contains a list of newsgroups. This is the |
58 | first buffer Gnus displays when it starts up. It normally displays | |
59 | only the groups to which you subscribe and that contain unread | |
60 | articles. Use this buffer to select a specific group. | |
6bf7aab6 DL |
61 | |
62 | The @dfn{summary buffer} lists one line for each article in a single | |
63 | group. By default, the author, the subject and the line number are | |
64 | displayed for each article, but this is customizable, like most aspects | |
65 | of Gnus display. The summary buffer is created when you select a group | |
66 | in the group buffer, and is killed when you exit the group. Use this | |
67 | buffer to select an article. | |
68 | ||
69 | The @dfn{article buffer} displays the article. In normal Gnus usage, | |
ab192107 RS |
70 | you see this buffer but you don't select it---all useful |
71 | article-oriented commands work in the summary buffer. But you can | |
72 | select the article buffer, and execute all Gnus commands from that | |
73 | buffer, if you want to. | |
6bf7aab6 DL |
74 | |
75 | @node Gnus Startup | |
76 | @subsection When Gnus Starts Up | |
77 | ||
78 | At startup, Gnus reads your @file{.newsrc} news initialization file | |
79 | and attempts to communicate with the local news server, which is a | |
80 | repository of news articles. The news server need not be the same | |
81 | computer you are logged in on. | |
82 | ||
83 | If you start Gnus and connect to the server, but do not see any | |
84 | newsgroups listed in the group buffer, type @kbd{L} or @kbd{A k} to get | |
85 | a listing of all the groups. Then type @kbd{u} to toggle | |
86 | subscription to groups. | |
87 | ||
88 | The first time you start Gnus, Gnus subscribes you to a few selected | |
89 | groups. All other groups start out as @dfn{killed groups} for you; you | |
90 | can list them with @kbd{A k}. All new groups that subsequently come to | |
91 | exist at the news server become @dfn{zombie groups} for you; type @kbd{A | |
92 | z} to list them. You can subscribe to a group shown in these lists | |
93 | using the @kbd{u} command. | |
94 | ||
95 | When you quit Gnus with @kbd{q}, it automatically records in your | |
96 | @file{.newsrc} and @file{.newsrc.eld} initialization files the | |
97 | subscribed or unsubscribed status of all groups. You should normally | |
98 | not edit these files manually, but you may if you know how. | |
99 | ||
100 | @node Summary of Gnus | |
101 | @subsection Summary of Gnus Commands | |
102 | ||
021037cb | 103 | Reading news is a two-step process: |
6bf7aab6 DL |
104 | |
105 | @enumerate | |
106 | @item | |
107 | Choose a group in the group buffer. | |
108 | ||
109 | @item | |
110 | Select articles from the summary buffer. Each article selected is | |
111 | displayed in the article buffer in a large window, below the summary | |
112 | buffer in its small window. | |
113 | @end enumerate | |
114 | ||
ab192107 RS |
115 | Each Gnus buffer has its own special commands; the meanings of any |
116 | given key in the various Gnus buffers are usually analogous, even if | |
117 | not identical. Here are commands for the group and summary buffers: | |
6bf7aab6 DL |
118 | |
119 | @table @kbd | |
120 | @kindex q @r{(Gnus Group mode)} | |
121 | @findex gnus-group-exit | |
122 | @item q | |
123 | In the group buffer, update your @file{.newsrc} initialization file | |
124 | and quit Gnus. | |
125 | ||
126 | In the summary buffer, exit the current group and return to the | |
127 | group buffer. Thus, typing @kbd{q} twice quits Gnus. | |
128 | ||
129 | @kindex L @r{(Gnus Group mode)} | |
130 | @findex gnus-group-list-all-groups | |
131 | @item L | |
132 | In the group buffer, list all the groups available on your news | |
133 | server (except those you have killed). This may be a long list! | |
134 | ||
135 | @kindex l @r{(Gnus Group mode)} | |
136 | @findex gnus-group-list-groups | |
137 | @item l | |
138 | In the group buffer, list only the groups to which you subscribe and | |
139 | which contain unread articles. | |
140 | ||
141 | @kindex u @r{(Gnus Group mode)} | |
142 | @findex gnus-group-unsubscribe-current-group | |
143 | @cindex subscribe groups | |
144 | @cindex unsubscribe groups | |
145 | @item u | |
146 | In the group buffer, unsubscribe from (or subscribe to) the group listed | |
147 | in the line that point is on. When you quit Gnus by typing @kbd{q}, | |
148 | Gnus lists in your @file{.newsrc} file which groups you have subscribed | |
149 | to. The next time you start Gnus, you won't see this group, | |
150 | because Gnus normally displays only subscribed-to groups. | |
151 | ||
152 | @kindex C-k @r{(Gnus)} | |
153 | @findex gnus-group-kill-group | |
154 | @item C-k | |
155 | In the group buffer, ``kill'' the current line's group---don't | |
156 | even list it in @file{.newsrc} from now on. This affects future | |
157 | Gnus sessions as well as the present session. | |
158 | ||
159 | When you quit Gnus by typing @kbd{q}, Gnus writes information | |
160 | in the file @file{.newsrc} describing all newsgroups except those you | |
161 | have ``killed.'' | |
162 | ||
163 | @kindex SPC @r{(Gnus)} | |
164 | @findex gnus-group-read-group | |
165 | @item @key{SPC} | |
166 | In the group buffer, select the group on the line under the cursor | |
167 | and display the first unread article in that group. | |
168 | ||
169 | @need 1000 | |
177c0ea7 | 170 | In the summary buffer, |
6bf7aab6 DL |
171 | |
172 | @itemize @bullet | |
173 | @item | |
174 | Select the article on the line under the cursor if none is selected. | |
175 | ||
176 | @item | |
177 | Scroll the text of the selected article (if there is one). | |
178 | ||
179 | @item | |
180 | Select the next unread article if at the end of the current article. | |
181 | @end itemize | |
182 | ||
183 | Thus, you can move through all the articles by repeatedly typing @key{SPC}. | |
184 | ||
185 | @kindex DEL @r{(Gnus)} | |
186 | @item @key{DEL} | |
187 | In the group buffer, move point to the previous group containing | |
188 | unread articles. | |
189 | ||
190 | @findex gnus-summary-prev-page | |
191 | In the summary buffer, scroll the text of the article backwards. | |
192 | ||
193 | @kindex n @r{(Gnus)} | |
194 | @findex gnus-group-next-unread-group | |
195 | @findex gnus-summary-next-unread-article | |
196 | @item n | |
197 | Move point to the next unread group, or select the next unread article. | |
198 | ||
199 | @kindex p @r{(Gnus)} | |
200 | @findex gnus-group-prev-unread-group | |
201 | @findex gnus-summary-prev-unread-article | |
202 | @item p | |
203 | Move point to the previous unread group, or select the previous | |
204 | unread article. | |
205 | ||
206 | @kindex C-n @r{(Gnus Group mode)} | |
207 | @findex gnus-group-next-group | |
208 | @kindex C-p @r{(Gnus Group mode)} | |
209 | @findex gnus-group-prev-group | |
210 | @kindex C-n @r{(Gnus Summary mode)} | |
211 | @findex gnus-summary-next-subject | |
212 | @kindex C-p @r{(Gnus Summary mode)} | |
213 | @findex gnus-summary-prev-subject | |
214 | @item C-n | |
215 | @itemx C-p | |
216 | Move point to the next or previous item, even if it is marked as read. | |
217 | This does not select the article or group on that line. | |
218 | ||
219 | @kindex s @r{(Gnus Summary mode)} | |
220 | @findex gnus-summary-isearch-article | |
221 | @item s | |
222 | In the summary buffer, do an incremental search of the current text in | |
223 | the article buffer, just as if you switched to the article buffer and | |
224 | typed @kbd{C-s}. | |
225 | ||
226 | @kindex M-s @r{(Gnus Summary mode)} | |
227 | @findex gnus-summary-search-article-forward | |
228 | @item M-s @var{regexp} @key{RET} | |
229 | In the summary buffer, search forward for articles containing a match | |
230 | for @var{regexp}. | |
231 | ||
232 | @end table | |
233 | ||
856ce114 CY |
234 | @node Document View |
235 | @section Document Viewing | |
236 | @cindex DVI file | |
237 | @cindex PDF file | |
238 | @cindex PS file | |
7877f373 | 239 | @cindex PostScript file |
856ce114 CY |
240 | @cindex OpenDocument file |
241 | @cindex Microsoft Office file | |
242 | @cindex DocView mode | |
243 | @cindex mode, DocView | |
244 | @cindex document viewer (DocView) | |
245 | @findex doc-view-mode | |
6bf7aab6 | 246 | |
7877f373 | 247 | DocView mode (@code{doc-view-mode}) is a viewer for DVI, PostScript |
856ce114 CY |
248 | (PS), PDF, OpenDocument, and Microsoft Office documents. It provides |
249 | features such as slicing, zooming, and searching inside documents. It | |
250 | works by converting the document to a set of images using the | |
251 | @command{gs} (GhostScript) command and other external tools | |
252 | @footnote{@code{gs} is a hard requirement. For DVI files, | |
253 | @code{dvipdf} or @code{dvipdfm} is needed. For OpenDocument and | |
254 | Microsoft Office documents, the @code{unoconv} tool is needed.}, and | |
255 | displaying those images. | |
6bf7aab6 | 256 | |
856ce114 CY |
257 | @findex doc-view-toggle-display |
258 | @findex doc-view-toggle-display | |
259 | @cindex doc-view-minor-mode | |
7877f373 | 260 | When you visit a document file with the exception of PostScript |
856ce114 CY |
261 | files, Emacs automatically switches to DocView mode if possible |
262 | @footnote{The needed external tools for this document type have to be | |
263 | available, emacs needs to run in a graphical frame, and PNG image | |
264 | support has to be compiled into emacs. If any of these requirements | |
265 | is not fulfilled, DocView falls back to an appropriate mode.}. When | |
7877f373 JB |
266 | you visit a PostScript file, Emacs switches to PS mode, a major mode |
267 | for editing PostScript files as text; however, it also enables DocView | |
856ce114 | 268 | minor mode, so you can type @kbd{C-c C-c} to view the document with |
7877f373 | 269 | DocView. (PDF and DVI files, unlike PostScript files, are not usually |
856ce114 CY |
270 | human-editable.) In either case, repeating @kbd{C-c C-c} |
271 | (@code{doc-view-toggle-display}) toggles between DocView and the file | |
272 | text. | |
6bf7aab6 | 273 | |
856ce114 CY |
274 | You can explicitly toggle DocView mode with the command @code{M-x |
275 | doc-view-mode}, and DocView minor mode with the command @code{M-x | |
276 | doc-view-minor-mode}. | |
6bf7aab6 | 277 | |
856ce114 CY |
278 | When DocView mode starts, it displays a welcome screen and begins |
279 | formatting the file, page by page. It displays the first page once | |
280 | that has been formatted. | |
6bf7aab6 | 281 | |
856ce114 CY |
282 | @findex doc-view-enlarge |
283 | @findex doc-view-shrink | |
284 | @vindex doc-view-resolution | |
285 | When in DocView mode, you can enlarge or shrink the document with | |
286 | @kbd{+} (@code{doc-view-enlarge}) and @kbd{-} | |
287 | (@code{doc-view-shrink}). To specify the default size for DocView, | |
288 | set or customize the variable @code{doc-view-resolution}. | |
6bf7aab6 | 289 | |
856ce114 CY |
290 | To kill the DocView buffer, type @kbd{k} |
291 | (@code{doc-view-kill-proc-and-buffer}). To bury it, type @kbd{q} | |
292 | (@code{quit-window}). | |
6bf7aab6 | 293 | |
856ce114 CY |
294 | @menu |
295 | * Navigation:: Navigation inside DocView buffers. | |
296 | * Searching:: Searching inside documents. | |
297 | * Slicing:: Specifying which part of pages should be displayed. | |
298 | * Conversion:: Influencing and triggering conversion. | |
299 | @end menu | |
6bf7aab6 | 300 | |
856ce114 CY |
301 | @node Navigation |
302 | @subsection Navigation | |
6bf7aab6 | 303 | |
856ce114 CY |
304 | When in DocView mode, you can scroll the current page using the usual |
305 | Emacs movement keys: @kbd{C-p}, @kbd{C-n}, @kbd{C-b}, @kbd{C-f}, and | |
306 | the arrow keys. | |
6bf7aab6 | 307 | |
856ce114 CY |
308 | @vindex doc-view-continuous |
309 | By default, the line-motion keys @kbd{C-p} and @kbd{C-n} stop | |
310 | scrolling at the beginning and end of the current page, respectively. | |
311 | However, if you change the variable @code{doc-view-continuous} to a | |
312 | non-@code{nil} value, then @kbd{C-p} displays the previous page if you | |
313 | are already at the beginning of the current page, and @kbd{C-n} | |
314 | displays the next page if you are at the end of the current page. | |
6bf7aab6 | 315 | |
856ce114 CY |
316 | @findex doc-view-next-page |
317 | @findex doc-view-previous-page | |
318 | You can also display the next page by typing @kbd{n}, @key{next} or | |
319 | @kbd{C-x ]} (@code{doc-view-next-page}). To display the previous | |
320 | page, type @kbd{p}, @key{prior} or @kbd{C-x [} | |
321 | (@code{doc-view-previous-page}). | |
6bf7aab6 | 322 | |
856ce114 CY |
323 | @findex doc-view-scroll-up-or-next-page |
324 | @findex doc-view-scroll-down-or-previous-page | |
325 | The @key{SPC} (@code{doc-view-scroll-up-or-next-page}) key is a | |
326 | convenient way to advance through the document. It scrolls within the | |
327 | current page or advances to the next. @key{DEL} moves backwards in a | |
328 | similar way (@code{doc-view-scroll-down-or-previous-page}). | |
6bf7aab6 | 329 | |
856ce114 CY |
330 | @findex doc-view-first-page |
331 | @findex doc-view-last-page | |
332 | @findex doc-view-goto-page | |
333 | To go to the first page, type @kbd{M-<} | |
334 | (@code{doc-view-first-page}); to go to the last one, type @kbd{M->} | |
335 | (@code{doc-view-last-page}). To jump to a page by its number, type | |
336 | @kbd{M-g M-g} or @kbd{M-g g} (@code{doc-view-goto-page}). | |
6bf7aab6 | 337 | |
856ce114 CY |
338 | @node Searching |
339 | @subsection Searching | |
6bf7aab6 | 340 | |
856ce114 CY |
341 | While in DocView mode, you can search the file's text for a regular |
342 | expression (@pxref{Regexps}). The interface for searching is inspired | |
343 | by @code{isearch} (@pxref{Incremental Search}). | |
344 | ||
345 | @findex doc-view-search | |
346 | @findex doc-view-search-backward | |
347 | @findex doc-view-show-tooltip | |
348 | To begin a search, type @kbd{C-s} (@code{doc-view-search}) or | |
349 | @kbd{C-r} (@code{doc-view-search-backward}). This reads a regular | |
350 | expression using a minibuffer, then echoes the number of matches found | |
351 | within the document. You can move forward and back among the matches | |
352 | by typing @kbd{C-s} and @kbd{C-r}. DocView mode has no way to show | |
353 | the match inside the page image; instead, it displays a tooltip (at | |
354 | the mouse position) listing all matching lines in the current page. | |
355 | To force display of this tooltip, type @kbd{C-t} | |
356 | (@code{doc-view-show-tooltip}). | |
357 | ||
358 | To start a new search, use the search command with a prefix | |
359 | argument; i.e., @kbd{C-u C-s} for a forward search or @kbd{C-u C-r} | |
360 | for a backward search. | |
361 | ||
362 | @node Slicing | |
363 | @subsection Slicing | |
364 | ||
365 | Documents often have wide margins for printing. They are annoying | |
366 | when reading the document on the screen, because they use up screen | |
367 | space and can cause inconvenient scrolling. | |
368 | ||
369 | @findex doc-view-set-slice | |
370 | @findex doc-view-set-slice-using-mouse | |
371 | With DocView you can hide these margins by selecting a @dfn{slice} | |
372 | of pages to display. A slice is a rectangle within the page area; | |
373 | once you specify a slice in DocView, it applies to whichever page you | |
374 | look at. | |
375 | ||
376 | To specify the slice numerically, type @kbd{s s} | |
377 | (@code{doc-view-set-slice}); then enter the top left pixel position | |
378 | and the slice's width and height. | |
379 | @c ??? how does this work? | |
380 | ||
381 | A more convenient graphical way to specify the slice is with @kbd{s | |
382 | m} (@code{doc-view-set-slice-using-mouse}), where you use the mouse to | |
383 | select the slice. | |
384 | @c ??? How does this work? | |
385 | ||
386 | @findex doc-view-reset-slice | |
387 | To cancel the selected slice, type @kbd{s r} | |
388 | (@code{doc-view-reset-slice}). Then DocView shows the entire page | |
389 | including its entire margins. | |
390 | ||
391 | @node Conversion | |
392 | @subsection Conversion | |
393 | ||
394 | @vindex doc-view-cache-directory | |
395 | @findex doc-view-clear-cache | |
396 | For efficiency, DocView caches the images produced by @command{gs}. | |
397 | The name of this directory is given by the variable | |
398 | @code{doc-view-cache-directory}. You can clear the cache directory by | |
399 | typing @code{M-x doc-view-clear-cache}. | |
400 | ||
401 | @findex doc-view-kill-proc | |
402 | @findex doc-view-kill-proc-and-buffer | |
403 | To force a reconversion of the currently viewed document, type | |
404 | @kbd{r} or @kbd{g} (@code{revert-buffer}). To kill the converter | |
405 | process associated with the current buffer, type @kbd{K} | |
406 | (@code{doc-view-kill-proc}). The command @kbd{k} | |
407 | (@code{doc-view-kill-proc-and-buffer}) kills the converter process and | |
408 | the DocView buffer. | |
409 | ||
410 | The zoom commands @kbd{+} (@code{doc-view-enlarge}) and @kbd{-} | |
411 | (@code{doc-view-shrink}) need to reconvert the document at the new | |
412 | size. The current page is converted first. | |
6bf7aab6 | 413 | |
856ce114 | 414 | @node Shell |
6bf7aab6 DL |
415 | @section Running Shell Commands from Emacs |
416 | @cindex subshell | |
417 | @cindex shell commands | |
418 | ||
419 | Emacs has commands for passing single command lines to inferior shell | |
bd4af791 | 420 | processes; it can also run a shell interactively with input and output |
df9d7630 | 421 | to an Emacs buffer named @samp{*shell*} or run a shell inside a terminal |
bd4af791 DL |
422 | emulator window. |
423 | ||
6bf7aab6 DL |
424 | @table @kbd |
425 | @item M-! @var{cmd} @key{RET} | |
426 | Run the shell command line @var{cmd} and display the output | |
427 | (@code{shell-command}). | |
428 | @item M-| @var{cmd} @key{RET} | |
429 | Run the shell command line @var{cmd} with region contents as input; | |
430 | optionally replace the region with the output | |
431 | (@code{shell-command-on-region}). | |
26e533e2 CY |
432 | @item M-& @var{cmd} @key{RET} |
433 | Run the shell command line @var{cmd} asynchronously, and display the | |
434 | output (@code{async-shell-command}). | |
6bf7aab6 DL |
435 | @item M-x shell |
436 | Run a subshell with input and output through an Emacs buffer. | |
437 | You can then give commands interactively. | |
3b65ce47 DL |
438 | @item M-x term |
439 | Run a subshell with input and output through an Emacs buffer. | |
440 | You can then give commands interactively. | |
441 | Full terminal emulation is available. | |
6bf7aab6 DL |
442 | @end table |
443 | ||
ab192107 RS |
444 | @kbd{M-x eshell} invokes a shell implemented entirely in Emacs. It |
445 | is documented in a separate manual. @xref{Top,Eshell,Eshell, eshell, | |
446 | Eshell: The Emacs Shell}. | |
447 | ||
6bf7aab6 DL |
448 | @menu |
449 | * Single Shell:: How to run one shell command and return. | |
450 | * Interactive Shell:: Permanent shell taking input via Emacs. | |
451 | * Shell Mode:: Special Emacs commands used with permanent shell. | |
e51d6b23 | 452 | * Shell Prompts:: Two ways to recognize shell prompts. |
6bf7aab6 | 453 | * History: Shell History. Repeating previous commands in a shell buffer. |
df9d7630 | 454 | * Directory Tracking:: Keeping track when the subshell changes directory. |
6bf7aab6 | 455 | * Options: Shell Options. Options for customizing Shell mode. |
3b65ce47 DL |
456 | * Terminal emulator:: An Emacs window as a terminal emulator. |
457 | * Term Mode:: Special Emacs commands used in Term mode. | |
458 | * Paging in Term:: Paging in the terminal emulator. | |
6bf7aab6 | 459 | * Remote Host:: Connecting to another computer. |
37e5d54a | 460 | * Serial Terminal:: Connecting to a serial port. |
6bf7aab6 DL |
461 | @end menu |
462 | ||
463 | @node Single Shell | |
464 | @subsection Single Shell Commands | |
465 | ||
466 | @kindex M-! | |
467 | @findex shell-command | |
468 | @kbd{M-!} (@code{shell-command}) reads a line of text using the | |
469 | minibuffer and executes it as a shell command in a subshell made just | |
470 | for that command. Standard input for the command comes from the null | |
fc98b4ba RS |
471 | device. If the shell command produces any output, the output appears |
472 | either in the echo area (if it is short), or in an Emacs buffer named | |
473 | @samp{*Shell Command Output*}, which is displayed in another window | |
d408f8d0 RS |
474 | but not selected (if the output is long). |
475 | ||
476 | For instance, one way to decompress a file @file{foo.gz} from Emacs | |
477 | is to type @kbd{M-! gunzip foo.gz @key{RET}}. That shell command | |
478 | normally creates the file @file{foo} and produces no terminal output. | |
479 | ||
480 | A numeric argument, as in @kbd{M-1 M-!}, says to insert terminal | |
481 | output into the current buffer instead of a separate buffer. It puts | |
482 | point before the output, and sets the mark after the output. For | |
a9749dab | 483 | instance, @kbd{M-1 M-! gunzip < foo.gz @key{RET}} would insert the |
d408f8d0 | 484 | uncompressed equivalent of @file{foo.gz} into the current buffer. |
6bf7aab6 DL |
485 | |
486 | If the shell command line ends in @samp{&}, it runs asynchronously. | |
487 | For a synchronous shell command, @code{shell-command} returns the | |
488 | command's exit status (0 means success), when it is called from a Lisp | |
d408f8d0 | 489 | program. You do not get any status information for an asynchronous |
ab192107 | 490 | command, since it hasn't finished yet when @code{shell-command} returns. |
6bf7aab6 | 491 | |
26e533e2 CY |
492 | You can also type @kbd{M-&} (@code{async-shell-command}) to execute |
493 | a shell command asynchronously. This behaves exactly like calling | |
494 | @code{shell-command} with @samp{&}, except that you do not need to add | |
495 | the @samp{&} to the shell command line. | |
496 | ||
6bf7aab6 DL |
497 | @kindex M-| |
498 | @findex shell-command-on-region | |
499 | @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!} but | |
500 | passes the contents of the region as the standard input to the shell | |
ab192107 RS |
501 | command, instead of no input. With a numeric argument, meaning insert |
502 | the output in the current buffer, it deletes the old region and the | |
503 | output replaces it as the contents of the region. It returns the | |
504 | command's exit status, like @kbd{M-!}. | |
6bf7aab6 | 505 | |
982dcb1b RS |
506 | One use for @kbd{M-|} is to run @code{gpg} to see what keys are in |
507 | the buffer. For instance, if the buffer contains a GPG key, type | |
ab192107 RS |
508 | @kbd{C-x h M-| gpg @key{RET}} to feed the entire buffer contents to |
509 | the @code{gpg} program. That program will ignore everything except | |
510 | the encoded keys, and will output a list of the keys the buffer | |
511 | contains. | |
d408f8d0 | 512 | |
6bf7aab6 | 513 | @vindex shell-file-name |
ab192107 RS |
514 | Both @kbd{M-!} and @kbd{M-|} use @code{shell-file-name} to specify |
515 | the shell to use. This variable is initialized based on your | |
516 | @env{SHELL} environment variable when Emacs is started. If the file | |
517 | name is relative, Emacs searches the directories in the list | |
518 | @code{exec-path}; this list is initialized based on the environment | |
932fd020 CY |
519 | variable @env{PATH} when Emacs is started. Your init file can |
520 | override either or both of these default initializations (@pxref{Init | |
521 | File}). | |
6bf7aab6 | 522 | |
982dcb1b | 523 | Both @kbd{M-!} and @kbd{M-|} wait for the shell command to complete, |
e51d6b23 | 524 | unless you end the command with @samp{&} to make it asynchronous. To |
982dcb1b | 525 | stop waiting, type @kbd{C-g} to quit; that terminates the shell |
6bf7aab6 | 526 | command with the signal @code{SIGINT}---the same signal that @kbd{C-c} |
ab192107 | 527 | normally generates in the shell. Emacs then waits until the command |
982dcb1b RS |
528 | actually terminates. If the shell command doesn't stop (because it |
529 | ignores the @code{SIGINT} signal), type @kbd{C-g} again; this sends | |
530 | the command a @code{SIGKILL} signal which is impossible to ignore. | |
531 | ||
532 | Asynchronous commands ending in @samp{&} feed their output into | |
533 | the buffer @samp{*Async Shell Command*}. Output arrives in that | |
534 | buffer regardless of whether it is visible in a window. | |
6bf7aab6 DL |
535 | |
536 | To specify a coding system for @kbd{M-!} or @kbd{M-|}, use the command | |
54b6e2d1 | 537 | @kbd{C-x @key{RET} c} immediately beforehand. @xref{Communication Coding}. |
6bf7aab6 DL |
538 | |
539 | @vindex shell-command-default-error-buffer | |
ab192107 RS |
540 | Error output from these commands is normally intermixed with the |
541 | regular output. But if the variable | |
542 | @code{shell-command-default-error-buffer} has a string as value, and | |
543 | it's the name of a buffer, @kbd{M-!} and @kbd{M-|} insert error output | |
544 | before point in that buffer. | |
6bf7aab6 DL |
545 | |
546 | @node Interactive Shell | |
547 | @subsection Interactive Inferior Shell | |
548 | ||
549 | @findex shell | |
932fd020 CY |
550 | To run a subshell interactively, use @kbd{M-x shell}. This creates |
551 | (or reuses) a buffer named @samp{*shell*} and runs a subshell with | |
552 | input coming from and output going to that buffer. That is to say, | |
553 | any ``terminal output'' from the subshell goes into the buffer, | |
554 | advancing point, and any ``terminal input'' for the subshell comes | |
555 | from text in the buffer. To give input to the subshell, go to the end | |
556 | of the buffer and type the input, terminated by @key{RET}. | |
6bf7aab6 DL |
557 | |
558 | Emacs does not wait for the subshell to do anything. You can switch | |
559 | windows or buffers and edit them while the shell is waiting, or while it is | |
560 | running a command. Output from the subshell waits until Emacs has time to | |
561 | process it; this happens whenever Emacs is waiting for keyboard input or | |
562 | for time to elapse. | |
563 | ||
df9d7630 RS |
564 | @cindex @code{comint-highlight-input} face |
565 | @cindex @code{comint-highlight-prompt} face | |
566 | Input lines, once you submit them, are displayed using the face | |
567 | @code{comint-highlight-input}, and prompts are displayed using the | |
568 | face @code{comint-highlight-prompt}. This makes it easier to see | |
569 | previous input lines in the buffer. @xref{Faces}. | |
570 | ||
a9749dab RS |
571 | To make multiple subshells, you can invoke @kbd{M-x shell} with a |
572 | prefix argument (e.g. @kbd{C-u M-x shell}), which will read a buffer | |
573 | name and create (or reuse) a subshell in that buffer. You can also | |
574 | rename the @samp{*shell*} buffer using @kbd{M-x rename-uniquely}, then | |
ab192107 RS |
575 | create a new @samp{*shell*} buffer using plain @kbd{M-x shell}. |
576 | Subshells in different buffers run independently and in parallel. | |
6bf7aab6 DL |
577 | |
578 | @vindex explicit-shell-file-name | |
b2c8319e | 579 | @cindex environment variables for subshells |
60a96371 GM |
580 | @cindex @env{ESHELL} environment variable |
581 | @cindex @env{SHELL} environment variable | |
6bf7aab6 | 582 | The file name used to load the subshell is the value of the variable |
932fd020 CY |
583 | @code{explicit-shell-file-name}, if that is non-@code{nil}. |
584 | Otherwise, the environment variable @env{ESHELL} is used, or the | |
585 | environment variable @env{SHELL} if there is no @env{ESHELL}. If the | |
586 | file name specified is relative, the directories in the list | |
587 | @code{exec-path} are searched; this list is initialized based on the | |
588 | environment variable @env{PATH} when Emacs is started. Your init file | |
589 | can override either or both of these default initializations. | |
590 | (@pxref{Init File}). | |
6bf7aab6 | 591 | |
df9d7630 RS |
592 | Emacs sends the new shell the contents of the file |
593 | @file{~/.emacs_@var{shellname}} as input, if it exists, where | |
594 | @var{shellname} is the name of the file that the shell was loaded | |
595 | from. For example, if you use bash, the file sent to it is | |
36ff5b10 JB |
596 | @file{~/.emacs_bash}. If this file is not found, Emacs tries to fallback |
597 | on @file{~/.emacs.d/init_@var{shellname}.sh}. | |
df9d7630 | 598 | |
6bf7aab6 | 599 | To specify a coding system for the shell, you can use the command |
ab192107 RS |
600 | @kbd{C-x @key{RET} c} immediately before @kbd{M-x shell}. You can |
601 | also change the coding system for a running subshell by typing | |
602 | @kbd{C-x @key{RET} p} in the shell buffer. @xref{Communication | |
603 | Coding}. | |
6bf7aab6 | 604 | |
ed91b7ed | 605 | @cindex @env{INSIDE_EMACS} environment variable |
b6c764ef RS |
606 | Emacs sets the environment variable @env{INSIDE_EMACS} in the |
607 | subshell to a comma-separated list including the Emacs version. | |
fe6dcbf6 GM |
608 | Programs can check this variable to determine whether they are running |
609 | inside an Emacs subshell. | |
ed91b7ed | 610 | |
b2c8319e | 611 | @cindex @env{EMACS} environment variable |
fe6dcbf6 | 612 | Emacs also sets the @env{EMACS} environment variable (to @code{t}) if |
ed91b7ed CY |
613 | it is not already defined. @strong{Warning:} This environment |
614 | variable is deprecated. Programs that check this variable should be | |
615 | changed to check @env{INSIDE_EMACS} instead. | |
6bf7aab6 DL |
616 | |
617 | @node Shell Mode | |
618 | @subsection Shell Mode | |
619 | @cindex Shell mode | |
620 | @cindex mode, Shell | |
621 | ||
622 | Shell buffers use Shell mode, which defines several special keys | |
623 | attached to the @kbd{C-c} prefix. They are chosen to resemble the usual | |
624 | editing and job control characters present in shells that are not under | |
625 | Emacs, except that you must type @kbd{C-c} first. Here is a complete list | |
626 | of the special key bindings of Shell mode: | |
627 | ||
628 | @table @kbd | |
629 | @item @key{RET} | |
630 | @kindex RET @r{(Shell mode)} | |
631 | @findex comint-send-input | |
df9d7630 | 632 | At end of buffer send line as input; otherwise, copy current line to |
ab192107 RS |
633 | end of buffer and send it (@code{comint-send-input}). Copying a line |
634 | in this way omits any prompt at the beginning of the line (text output | |
635 | by programs preceding your input). @xref{Shell Prompts}, for how | |
636 | Shell mode recognizes prompts. | |
6bf7aab6 DL |
637 | |
638 | @item @key{TAB} | |
639 | @kindex TAB @r{(Shell mode)} | |
640 | @findex comint-dynamic-complete | |
641 | Complete the command name or file name before point in the shell buffer | |
642 | (@code{comint-dynamic-complete}). @key{TAB} also completes history | |
643 | references (@pxref{History References}) and environment variable names. | |
644 | ||
645 | @vindex shell-completion-fignore | |
646 | @vindex comint-completion-fignore | |
647 | The variable @code{shell-completion-fignore} specifies a list of file | |
fc98b4ba RS |
648 | name extensions to ignore in Shell mode completion. The default |
649 | setting is @code{nil}, but some users prefer @code{("~" "#" "%")} to | |
650 | ignore file names ending in @samp{~}, @samp{#} or @samp{%}. Other | |
6bf7aab6 DL |
651 | related Comint modes use the variable @code{comint-completion-fignore} |
652 | instead. | |
653 | ||
654 | @item M-? | |
655 | @kindex M-? @r{(Shell mode)} | |
656 | @findex comint-dynamic-list-filename@dots{} | |
657 | Display temporarily a list of the possible completions of the file name | |
658 | before point in the shell buffer | |
659 | (@code{comint-dynamic-list-filename-completions}). | |
660 | ||
661 | @item C-d | |
662 | @kindex C-d @r{(Shell mode)} | |
663 | @findex comint-delchar-or-maybe-eof | |
76dd3692 | 664 | Either delete a character or send @acronym{EOF} |
6bf7aab6 | 665 | (@code{comint-delchar-or-maybe-eof}). Typed at the end of the shell |
76dd3692 | 666 | buffer, @kbd{C-d} sends @acronym{EOF} to the subshell. Typed at any other |
6bf7aab6 DL |
667 | position in the buffer, @kbd{C-d} deletes a character as usual. |
668 | ||
669 | @item C-c C-a | |
670 | @kindex C-c C-a @r{(Shell mode)} | |
fc98b4ba | 671 | @findex comint-bol-or-process-mark |
6bf7aab6 | 672 | Move to the beginning of the line, but after the prompt if any |
fc98b4ba RS |
673 | (@code{comint-bol-or-process-mark}). If you repeat this command twice |
674 | in a row, the second time it moves back to the process mark, which is | |
675 | the beginning of the input that you have not yet sent to the subshell. | |
676 | (Normally that is the same place---the end of the prompt on this | |
677 | line---but after @kbd{C-c @key{SPC}} the process mark may be in a | |
678 | previous line.) | |
6bf7aab6 DL |
679 | |
680 | @item C-c @key{SPC} | |
681 | Accumulate multiple lines of input, then send them together. This | |
682 | command inserts a newline before point, but does not send the preceding | |
683 | text as input to the subshell---at least, not yet. Both lines, the one | |
684 | before this newline and the one after, will be sent together (along with | |
685 | the newline that separates them), when you type @key{RET}. | |
686 | ||
687 | @item C-c C-u | |
688 | @kindex C-c C-u @r{(Shell mode)} | |
689 | @findex comint-kill-input | |
690 | Kill all text pending at end of buffer to be sent as input | |
e51d6b23 LT |
691 | (@code{comint-kill-input}). If point is not at end of buffer, |
692 | this only kills the part of this text that precedes point. | |
6bf7aab6 DL |
693 | |
694 | @item C-c C-w | |
695 | @kindex C-c C-w @r{(Shell mode)} | |
696 | Kill a word before point (@code{backward-kill-word}). | |
697 | ||
698 | @item C-c C-c | |
699 | @kindex C-c C-c @r{(Shell mode)} | |
700 | @findex comint-interrupt-subjob | |
701 | Interrupt the shell or its current subjob if any | |
702 | (@code{comint-interrupt-subjob}). This command also kills | |
703 | any shell input pending in the shell buffer and not yet sent. | |
704 | ||
705 | @item C-c C-z | |
706 | @kindex C-c C-z @r{(Shell mode)} | |
707 | @findex comint-stop-subjob | |
708 | Stop the shell or its current subjob if any (@code{comint-stop-subjob}). | |
709 | This command also kills any shell input pending in the shell buffer and | |
710 | not yet sent. | |
711 | ||
712 | @item C-c C-\ | |
713 | @findex comint-quit-subjob | |
714 | @kindex C-c C-\ @r{(Shell mode)} | |
715 | Send quit signal to the shell or its current subjob if any | |
716 | (@code{comint-quit-subjob}). This command also kills any shell input | |
717 | pending in the shell buffer and not yet sent. | |
718 | ||
719 | @item C-c C-o | |
720 | @kindex C-c C-o @r{(Shell mode)} | |
97f59309 MB |
721 | @findex comint-delete-output |
722 | Delete the last batch of output from a shell command | |
723 | (@code{comint-delete-output}). This is useful if a shell command spews | |
3226d6ca | 724 | out lots of output that just gets in the way. |
97f59309 MB |
725 | |
726 | @item C-c C-s | |
727 | @kindex C-c C-s @r{(Shell mode)} | |
728 | @findex comint-write-output | |
729 | Write the last batch of output from a shell command to a file | |
730 | (@code{comint-write-output}). With a prefix argument, the file is | |
731 | appended to instead. Any prompt at the end of the output is not | |
732 | written. | |
6bf7aab6 DL |
733 | |
734 | @item C-c C-r | |
735 | @itemx C-M-l | |
736 | @kindex C-c C-r @r{(Shell mode)} | |
737 | @kindex C-M-l @r{(Shell mode)} | |
738 | @findex comint-show-output | |
739 | Scroll to display the beginning of the last batch of output at the top | |
740 | of the window; also move the cursor there (@code{comint-show-output}). | |
741 | ||
742 | @item C-c C-e | |
743 | @kindex C-c C-e @r{(Shell mode)} | |
744 | @findex comint-show-maximum-output | |
745 | Scroll to put the end of the buffer at the bottom of the window | |
746 | (@code{comint-show-maximum-output}). | |
747 | ||
748 | @item C-c C-f | |
749 | @kindex C-c C-f @r{(Shell mode)} | |
750 | @findex shell-forward-command | |
751 | @vindex shell-command-regexp | |
752 | Move forward across one shell command, but not beyond the current line | |
753 | (@code{shell-forward-command}). The variable @code{shell-command-regexp} | |
754 | specifies how to recognize the end of a command. | |
755 | ||
756 | @item C-c C-b | |
757 | @kindex C-c C-b @r{(Shell mode)} | |
758 | @findex shell-backward-command | |
759 | Move backward across one shell command, but not beyond the current line | |
760 | (@code{shell-backward-command}). | |
761 | ||
6bf7aab6 DL |
762 | @item M-x dirs |
763 | Ask the shell what its current directory is, so that Emacs can agree | |
764 | with the shell. | |
765 | ||
766 | @item M-x send-invisible @key{RET} @var{text} @key{RET} | |
767 | @findex send-invisible | |
768 | Send @var{text} as input to the shell, after reading it without | |
769 | echoing. This is useful when a shell command runs a program that asks | |
770 | for a password. | |
771 | ||
e5b7fee6 EZ |
772 | Please note that Emacs will not echo passwords by default. If you |
773 | really want them to be echoed, evaluate the following Lisp | |
774 | expression: | |
6bf7aab6 DL |
775 | |
776 | @example | |
e5b7fee6 EZ |
777 | (remove-hook 'comint-output-filter-functions |
778 | 'comint-watch-for-password-prompt) | |
6bf7aab6 DL |
779 | @end example |
780 | ||
781 | @item M-x comint-continue-subjob | |
782 | @findex comint-continue-subjob | |
783 | Continue the shell process. This is useful if you accidentally suspend | |
784 | the shell process.@footnote{You should not suspend the shell process. | |
785 | Suspending a subjob of the shell is a completely different matter---that | |
786 | is normal practice, but you must use the shell to continue the subjob; | |
787 | this command won't do it.} | |
788 | ||
789 | @item M-x comint-strip-ctrl-m | |
790 | @findex comint-strip-ctrl-m | |
791 | Discard all control-M characters from the current group of shell output. | |
792 | The most convenient way to use this command is to make it run | |
793 | automatically when you get output from the subshell. To do that, | |
794 | evaluate this Lisp expression: | |
795 | ||
796 | @example | |
797 | (add-hook 'comint-output-filter-functions | |
798 | 'comint-strip-ctrl-m) | |
799 | @end example | |
800 | ||
801 | @item M-x comint-truncate-buffer | |
802 | @findex comint-truncate-buffer | |
803 | This command truncates the shell buffer to a certain maximum number of | |
804 | lines, specified by the variable @code{comint-buffer-maximum-size}. | |
805 | Here's how to do this automatically each time you get output from the | |
806 | subshell: | |
807 | ||
808 | @example | |
809 | (add-hook 'comint-output-filter-functions | |
810 | 'comint-truncate-buffer) | |
811 | @end example | |
812 | @end table | |
813 | ||
6bf7aab6 DL |
814 | @cindex Comint mode |
815 | @cindex mode, Comint | |
816 | Shell mode is a derivative of Comint mode, a general-purpose mode for | |
817 | communicating with interactive subprocesses. Most of the features of | |
818 | Shell mode actually come from Comint mode, as you can see from the | |
bd9e9287 MB |
819 | command names listed above. The special features of Shell mode include |
820 | the directory tracking feature, and a few user commands. | |
6bf7aab6 DL |
821 | |
822 | Other Emacs features that use variants of Comint mode include GUD | |
823 | (@pxref{Debuggers}) and @kbd{M-x run-lisp} (@pxref{External Lisp}). | |
824 | ||
825 | @findex comint-run | |
826 | You can use @kbd{M-x comint-run} to execute any program of your choice | |
827 | in a subprocess using unmodified Comint mode---without the | |
828 | specializations of Shell mode. | |
829 | ||
e51d6b23 LT |
830 | @node Shell Prompts |
831 | @subsection Shell Prompts | |
832 | ||
833 | @vindex shell-prompt-pattern | |
834 | @vindex comint-prompt-regexp | |
835 | @vindex comint-use-prompt-regexp | |
836 | @cindex prompt, shell | |
837 | A prompt is text output by a program to show that it is ready to | |
838 | accept new user input. Normally, Comint mode (and thus Shell mode) | |
839 | considers the prompt to be any text output by a program at the | |
840 | beginning of an input line. However, if the variable | |
841 | @code{comint-use-prompt-regexp} is non-@code{nil}, then Comint mode | |
842 | uses a regular expression to recognize prompts. In Shell mode, | |
843 | @code{shell-prompt-pattern} specifies the regular expression. | |
844 | ||
845 | The value of @code{comint-use-prompt-regexp} also affects many | |
846 | motion and paragraph commands. If the value is non-@code{nil}, the | |
847 | general Emacs motion commands behave as they normally do in buffers | |
848 | without special text properties. However, if the value is @code{nil}, | |
849 | the default, then Comint mode divides the buffer into two types of | |
850 | ``fields'' (ranges of consecutive characters having the same | |
851 | @code{field} text property): input and output. Prompts are part of | |
852 | the output. Most Emacs motion commands do not cross field boundaries, | |
853 | unless they move over multiple lines. For instance, when point is in | |
854 | input on the same line as a prompt, @kbd{C-a} puts point at the | |
855 | beginning of the input if @code{comint-use-prompt-regexp} is | |
856 | @code{nil} and at the beginning of the line otherwise. | |
857 | ||
858 | In Shell mode, only shell prompts start new paragraphs. Thus, a | |
859 | paragraph consists of a prompt and the input and output that follow | |
860 | it. However, if @code{comint-use-prompt-regexp} is @code{nil}, the | |
861 | default, most paragraph commands do not cross field boundaries. This | |
862 | means that prompts, ranges of input, and ranges of non-prompt output | |
863 | behave mostly like separate paragraphs; with this setting, numeric | |
864 | arguments to most paragraph commands yield essentially undefined | |
865 | behavior. For the purpose of finding paragraph boundaries, Shell mode | |
866 | uses @code{shell-prompt-pattern}, regardless of | |
867 | @code{comint-use-prompt-regexp}. | |
868 | ||
6bf7aab6 DL |
869 | @node Shell History |
870 | @subsection Shell Command History | |
871 | ||
872 | Shell buffers support three ways of repeating earlier commands. You | |
982dcb1b RS |
873 | can use keys like those used for the minibuffer history; these work |
874 | much as they do in the minibuffer, inserting text from prior commands | |
875 | while point remains always at the end of the buffer. You can move | |
876 | through the buffer to previous inputs in their original place, then | |
877 | resubmit them or copy them to the end. Or you can use a | |
878 | @samp{!}-style history reference. | |
6bf7aab6 DL |
879 | |
880 | @menu | |
881 | * Ring: Shell Ring. Fetching commands from the history list. | |
882 | * Copy: Shell History Copying. Moving to a command and then copying it. | |
883 | * History References:: Expanding @samp{!}-style history references. | |
884 | @end menu | |
885 | ||
886 | @node Shell Ring | |
887 | @subsubsection Shell History Ring | |
888 | ||
889 | @table @kbd | |
890 | @findex comint-previous-input | |
891 | @kindex M-p @r{(Shell mode)} | |
892 | @item M-p | |
982dcb1b | 893 | @itemx C-@key{UP} |
6bf7aab6 DL |
894 | Fetch the next earlier old shell command. |
895 | ||
896 | @kindex M-n @r{(Shell mode)} | |
897 | @findex comint-next-input | |
898 | @item M-n | |
982dcb1b | 899 | @itemx C-@key{DOWN} |
6bf7aab6 DL |
900 | Fetch the next later old shell command. |
901 | ||
902 | @kindex M-r @r{(Shell mode)} | |
f2608df3 CY |
903 | @findex comint-history-isearch-backward-regexp |
904 | @item M-r | |
905 | Begin an incremental regexp search of old shell commands. | |
6bf7aab6 | 906 | |
2a4a9af9 NR |
907 | @item C-c C-x |
908 | @kindex C-c C-x @r{(Shell mode)} | |
6bf7aab6 DL |
909 | @findex comint-get-next-from-history |
910 | Fetch the next subsequent command from the history. | |
91179e97 | 911 | |
2a4a9af9 NR |
912 | @item C-c . |
913 | @kindex C-c . @r{(Shell mode)} | |
91179e97 RS |
914 | @findex comint-input-previous-argument |
915 | Fetch one argument from an old shell command. | |
2a4a9af9 NR |
916 | |
917 | @item C-c C-l | |
918 | @kindex C-c C-l @r{(Shell mode)} | |
919 | @findex comint-dynamic-list-input-ring | |
920 | Display the buffer's history of shell commands in another window | |
921 | (@code{comint-dynamic-list-input-ring}). | |
6bf7aab6 DL |
922 | @end table |
923 | ||
924 | Shell buffers provide a history of previously entered shell commands. To | |
925 | reuse shell commands from the history, use the editing commands @kbd{M-p}, | |
926 | @kbd{M-n}, @kbd{M-r} and @kbd{M-s}. These work just like the minibuffer | |
927 | history commands except that they operate on the text at the end of the | |
928 | shell buffer, where you would normally insert text to send to the shell. | |
929 | ||
982dcb1b RS |
930 | @kbd{M-p} fetches an earlier shell command to the end of the shell |
931 | buffer. Successive use of @kbd{M-p} fetches successively earlier | |
932 | shell commands, each replacing any text that was already present as | |
933 | potential shell input. @kbd{M-n} does likewise except that it finds | |
934 | successively more recent shell commands from the buffer. | |
935 | @kbd{C-@key{UP}} works like @kbd{M-p}, and @kbd{C-@key{DOWN}} like | |
936 | @kbd{M-n}. | |
6bf7aab6 | 937 | |
f2608df3 CY |
938 | The history search command @kbd{M-r} begins an incremental regular |
939 | expression search of previous shell commands. After typing @kbd{M-r}, | |
940 | start typing the desired string or regular expression; the last | |
941 | matching shell command will be displayed in the current line. | |
942 | Incremental search commands have their usual effects---for instance, | |
943 | @kbd{C-s} and @kbd{C-r} search forward and backward for the next match | |
944 | (@pxref{Incremental Search}). When you find the desired input, type | |
945 | @key{RET} to terminate the search. This puts the input in the command | |
946 | line. Any partial input you were composing before navigating the | |
74600a6f S |
947 | history list is restored when you go to the beginning or end of the |
948 | history ring. | |
6bf7aab6 DL |
949 | |
950 | Often it is useful to reexecute several successive shell commands that | |
951 | were previously executed in sequence. To do this, first find and | |
952 | reexecute the first command of the sequence. Then type @kbd{C-c C-x}; | |
953 | that will fetch the following command---the one that follows the command | |
954 | you just repeated. Then type @key{RET} to reexecute this command. You | |
955 | can reexecute several successive commands by typing @kbd{C-c C-x | |
956 | @key{RET}} over and over. | |
957 | ||
91179e97 RS |
958 | The command @kbd{C-c .}@: (@code{comint-input-previous-argument}) |
959 | copies an individual argument from a previous command, like @kbd{ESC | |
960 | .} in Bash. The simplest use copies the last argument from the | |
961 | previous shell command. With a prefix argument @var{n}, it copies the | |
962 | @var{n}th argument instead. Repeating @kbd{C-c .} copies from an | |
963 | earlier shell command instead, always using the same value of @var{n} | |
964 | (don't give a prefix argument when you repeat the @kbd{C-c .} | |
965 | command). | |
966 | ||
6bf7aab6 DL |
967 | These commands get the text of previous shell commands from a special |
968 | history list, not from the shell buffer itself. Thus, editing the shell | |
969 | buffer, or even killing large parts of it, does not affect the history | |
970 | that these commands access. | |
971 | ||
972 | @vindex shell-input-ring-file-name | |
973 | Some shells store their command histories in files so that you can | |
e51d6b23 | 974 | refer to commands from previous shell sessions. Emacs reads |
6bf7aab6 DL |
975 | the command history file for your chosen shell, to initialize its own |
976 | command history. The file name is @file{~/.bash_history} for bash, | |
977 | @file{~/.sh_history} for ksh, and @file{~/.history} for other shells. | |
978 | ||
979 | @node Shell History Copying | |
980 | @subsubsection Shell History Copying | |
981 | ||
982 | @table @kbd | |
983 | @kindex C-c C-p @r{(Shell mode)} | |
984 | @findex comint-previous-prompt | |
985 | @item C-c C-p | |
986 | Move point to the previous prompt (@code{comint-previous-prompt}). | |
987 | ||
988 | @kindex C-c C-n @r{(Shell mode)} | |
989 | @findex comint-next-prompt | |
990 | @item C-c C-n | |
991 | Move point to the following prompt (@code{comint-next-prompt}). | |
992 | ||
993 | @kindex C-c RET @r{(Shell mode)} | |
55f62691 | 994 | @findex comint-copy-old-input |
6bf7aab6 | 995 | @item C-c @key{RET} |
932fd020 CY |
996 | Copy the input command at point, inserting the copy at the end of the |
997 | buffer (@code{comint-copy-old-input}). This is useful if you move | |
998 | point back to a previous command. After you copy the command, you can | |
999 | submit the copy as input with @key{RET}. If you wish, you can edit | |
1000 | the copy before resubmitting it. If you use this command on an output | |
1001 | line, it copies that line to the end of the buffer. | |
2a4a9af9 NR |
1002 | |
1003 | @item Mouse-2 | |
55f62691 LT |
1004 | If @code{comint-use-prompt-regexp} is @code{nil} (the default), copy |
1005 | the old input command that you click on, inserting the copy at the end | |
1006 | of the buffer (@code{comint-insert-input}). If | |
1007 | @code{comint-use-prompt-regexp} is non-@code{nil}, or if the click is | |
1008 | not over old input, just yank as usual. | |
6bf7aab6 DL |
1009 | @end table |
1010 | ||
1011 | Moving to a previous input and then copying it with @kbd{C-c | |
2a4a9af9 NR |
1012 | @key{RET}} or @kbd{Mouse-2} produces the same results---the same |
1013 | buffer contents---that you would get by using @kbd{M-p} enough times | |
1014 | to fetch that previous input from the history list. However, @kbd{C-c | |
1015 | @key{RET}} copies the text from the buffer, which can be different | |
1016 | from what is in the history list if you edit the input text in the | |
1017 | buffer after it has been sent. | |
6bf7aab6 DL |
1018 | |
1019 | @node History References | |
1020 | @subsubsection Shell History References | |
1021 | @cindex history reference | |
1022 | ||
df9d7630 RS |
1023 | Various shells including csh and bash support @dfn{history |
1024 | references} that begin with @samp{!} and @samp{^}. Shell mode | |
1025 | recognizes these constructs, and can perform the history substitution | |
1026 | for you. | |
1027 | ||
1028 | If you insert a history reference and type @key{TAB}, this searches | |
1029 | the input history for a matching command, performs substitution if | |
1030 | necessary, and places the result in the buffer in place of the history | |
1031 | reference. For example, you can fetch the most recent command | |
1032 | beginning with @samp{mv} with @kbd{! m v @key{TAB}}. You can edit the | |
1033 | command if you wish, and then resubmit the command to the shell by | |
1034 | typing @key{RET}. | |
1035 | ||
1036 | @vindex comint-input-autoexpand | |
1037 | @findex comint-magic-space | |
1038 | Shell mode can optionally expand history references in the buffer | |
1039 | when you send them to the shell. To request this, set the variable | |
1040 | @code{comint-input-autoexpand} to @code{input}. You can make | |
1041 | @key{SPC} perform history expansion by binding @key{SPC} to the | |
1042 | command @code{comint-magic-space}. | |
6bf7aab6 | 1043 | |
df9d7630 | 1044 | Shell mode recognizes history references when they follow a prompt. |
e51d6b23 | 1045 | @xref{Shell Prompts}, for how Shell mode recognizes prompts. |
df9d7630 RS |
1046 | |
1047 | @node Directory Tracking | |
1048 | @subsection Directory Tracking | |
1049 | @cindex directory tracking | |
6bf7aab6 | 1050 | |
df9d7630 RS |
1051 | @vindex shell-pushd-regexp |
1052 | @vindex shell-popd-regexp | |
1053 | @vindex shell-cd-regexp | |
1054 | Shell mode keeps track of @samp{cd}, @samp{pushd} and @samp{popd} | |
1055 | commands given to the inferior shell, so it can keep the | |
1056 | @samp{*shell*} buffer's default directory the same as the shell's | |
1057 | working directory. It recognizes these commands syntactically, by | |
1058 | examining lines of input that are sent. | |
6bf7aab6 | 1059 | |
df9d7630 RS |
1060 | If you use aliases for these commands, you can tell Emacs to |
1061 | recognize them also. For example, if the value of the variable | |
1062 | @code{shell-pushd-regexp} matches the beginning of a shell command | |
1063 | line, that line is regarded as a @code{pushd} command. Change this | |
1064 | variable when you add aliases for @samp{pushd}. Likewise, | |
1065 | @code{shell-popd-regexp} and @code{shell-cd-regexp} are used to | |
1066 | recognize commands with the meaning of @samp{popd} and @samp{cd}. | |
1067 | These commands are recognized only at the beginning of a shell command | |
1068 | line. | |
1069 | ||
fc98b4ba | 1070 | @ignore @c This seems to have been deleted long ago. |
df9d7630 RS |
1071 | @vindex shell-set-directory-error-hook |
1072 | If Emacs gets an error while trying to handle what it believes is a | |
1073 | @samp{cd}, @samp{pushd} or @samp{popd} command, it runs the hook | |
1074 | @code{shell-set-directory-error-hook} (@pxref{Hooks}). | |
fc98b4ba | 1075 | @end ignore |
df9d7630 RS |
1076 | |
1077 | @findex dirs | |
1078 | If Emacs gets confused about changes in the current directory of the | |
1079 | subshell, use the command @kbd{M-x dirs} to ask the shell what its | |
1080 | current directory is. This command works for shells that support the | |
1081 | most common command syntax; it may not work for unusual shells. | |
1082 | ||
1083 | @findex dirtrack-mode | |
1084 | You can also use @kbd{M-x dirtrack-mode} to enable (or disable) an | |
db8446b8 GM |
1085 | alternative method of tracking changes in the current directory. This |
1086 | method relies on your shell prompt containing the full current working | |
1087 | directory at all times. | |
6bf7aab6 DL |
1088 | |
1089 | @node Shell Options | |
1090 | @subsection Shell Mode Options | |
1091 | ||
1092 | @vindex comint-scroll-to-bottom-on-input | |
1093 | If the variable @code{comint-scroll-to-bottom-on-input} is | |
1094 | non-@code{nil}, insertion and yank commands scroll the selected window | |
67cf9997 | 1095 | to the bottom before inserting. The default is @code{nil}. |
6bf7aab6 DL |
1096 | |
1097 | @vindex comint-scroll-show-maximum-output | |
1098 | If @code{comint-scroll-show-maximum-output} is non-@code{nil}, then | |
e59d2bef RS |
1099 | arrival of output when point is at the end tries to scroll the last |
1100 | line of text to the bottom line of the window, showing as much useful | |
67cf9997 CY |
1101 | text as possible. (This mimics the scrolling behavior of most |
1102 | terminals.) The default is @code{t}. | |
6bf7aab6 | 1103 | |
fcc91da6 RS |
1104 | @vindex comint-move-point-for-output |
1105 | By setting @code{comint-move-point-for-output}, you can opt for | |
6bf7aab6 DL |
1106 | having point jump to the end of the buffer whenever output arrives---no |
1107 | matter where in the buffer point was before. If the value is | |
1108 | @code{this}, point jumps in the selected window. If the value is | |
021037cb | 1109 | @code{all}, point jumps in each window that shows the Comint buffer. If |
6bf7aab6 DL |
1110 | the value is @code{other}, point jumps in all nonselected windows that |
1111 | show the current buffer. The default value is @code{nil}, which means | |
1112 | point does not jump to the end. | |
1113 | ||
982dcb1b RS |
1114 | @vindex comint-prompt-read-only |
1115 | If you set @code{comint-prompt-read-only}, the prompts in the Comint | |
66dd6a00 | 1116 | buffer are read-only. |
982dcb1b | 1117 | |
6bf7aab6 DL |
1118 | @vindex comint-input-ignoredups |
1119 | The variable @code{comint-input-ignoredups} controls whether successive | |
1120 | identical inputs are stored in the input history. A non-@code{nil} | |
1121 | value means to omit an input that is the same as the previous input. | |
1122 | The default is @code{nil}, which means to store each input even if it is | |
1123 | equal to the previous input. | |
1124 | ||
1125 | @vindex comint-completion-addsuffix | |
1126 | @vindex comint-completion-recexact | |
1127 | @vindex comint-completion-autolist | |
1128 | Three variables customize file name completion. The variable | |
1129 | @code{comint-completion-addsuffix} controls whether completion inserts a | |
1130 | space or a slash to indicate a fully completed file or directory name | |
1131 | (non-@code{nil} means do insert a space or slash). | |
1132 | @code{comint-completion-recexact}, if non-@code{nil}, directs @key{TAB} | |
1133 | to choose the shortest possible completion if the usual Emacs completion | |
1134 | algorithm cannot add even a single character. | |
1135 | @code{comint-completion-autolist}, if non-@code{nil}, says to list all | |
1136 | the possible completions whenever completion is not exact. | |
1137 | ||
fc98b4ba | 1138 | @vindex shell-completion-execonly |
6bf7aab6 | 1139 | Command completion normally considers only executable files. |
fc98b4ba | 1140 | If you set @code{shell-completion-execonly} to @code{nil}, |
6bf7aab6 DL |
1141 | it considers nonexecutable files as well. |
1142 | ||
1143 | @findex shell-pushd-tohome | |
1144 | @findex shell-pushd-dextract | |
1145 | @findex shell-pushd-dunique | |
1146 | You can configure the behavior of @samp{pushd}. Variables control | |
1147 | whether @samp{pushd} behaves like @samp{cd} if no argument is given | |
1148 | (@code{shell-pushd-tohome}), pop rather than rotate with a numeric | |
1149 | argument (@code{shell-pushd-dextract}), and only add directories to the | |
1150 | directory stack if they are not already on it | |
1151 | (@code{shell-pushd-dunique}). The values you choose should match the | |
1152 | underlying shell, of course. | |
1153 | ||
3b65ce47 | 1154 | @node Terminal emulator |
df9d7630 | 1155 | @subsection Emacs Terminal Emulator |
3b65ce47 DL |
1156 | @findex term |
1157 | ||
932fd020 CY |
1158 | To run a subshell in a terminal emulator, use @kbd{M-x term}. This |
1159 | creates (or reuses) a buffer named @samp{*terminal*}, and runs a | |
1160 | subshell with input coming from your keyboard, and output going to | |
1161 | that buffer. | |
df9d7630 RS |
1162 | |
1163 | The terminal emulator uses Term mode, which has two input modes. In | |
1164 | line mode, Term basically acts like Shell mode; see @ref{Shell Mode}. | |
3b65ce47 | 1165 | |
df9d7630 RS |
1166 | In char mode, each character is sent directly to the inferior |
1167 | subshell, as ``terminal input.'' Any ``echoing'' of your input is the | |
1168 | responsibility of the subshell. The sole exception is the terminal | |
1169 | escape character, which by default is @kbd{C-c} (@pxref{Term Mode}). | |
3b65ce47 DL |
1170 | Any ``terminal output'' from the subshell goes into the buffer, |
1171 | advancing point. | |
1172 | ||
df9d7630 RS |
1173 | Some programs (such as Emacs itself) need to control the appearance |
1174 | on the terminal screen in detail. They do this by sending special | |
1175 | control codes. The exact control codes needed vary from terminal to | |
1176 | terminal, but nowadays most terminals and terminal emulators | |
1177 | (including @code{xterm}) understand the ANSI-standard (VT100-style) | |
1178 | escape sequences. Term mode recognizes these escape sequences, and | |
1179 | handles each one appropriately, changing the buffer so that the | |
1180 | appearance of the window matches what it would be on a real terminal. | |
1181 | You can actually run Emacs inside an Emacs Term window. | |
1182 | ||
37e5d54a | 1183 | You can use Term mode to communicate with a device connected to a |
932fd020 | 1184 | serial port of your computer. @xref{Serial Terminal}. |
37e5d54a GM |
1185 | |
1186 | The file name used to load the subshell is determined the same way | |
df9d7630 | 1187 | as for Shell mode. To make multiple terminal emulators, rename the |
fc98b4ba | 1188 | buffer @samp{*terminal*} to something different using @kbd{M-x |
df9d7630 RS |
1189 | rename-uniquely}, just as with Shell mode. |
1190 | ||
1191 | Unlike Shell mode, Term mode does not track the current directory by | |
1192 | examining your input. But some shells can tell Term what the current | |
1193 | directory is. This is done automatically by @code{bash} version 1.15 | |
1194 | and later. | |
3b65ce47 DL |
1195 | |
1196 | @node Term Mode | |
1197 | @subsection Term Mode | |
1198 | @cindex Term mode | |
1199 | @cindex mode, Term | |
1200 | ||
df9d7630 RS |
1201 | The terminal emulator uses Term mode, which has two input modes. In |
1202 | line mode, Term basically acts like Shell mode; see @ref{Shell Mode}. | |
1203 | In char mode, each character is sent directly to the inferior | |
1204 | subshell, except for the Term escape character, normally @kbd{C-c}. | |
1205 | ||
1206 | To switch between line and char mode, use these commands: | |
3b65ce47 | 1207 | |
3b65ce47 | 1208 | @table @kbd |
91179e97 | 1209 | @kindex C-c C-j @r{(Term mode)} |
3b65ce47 | 1210 | @findex term-char-mode |
91179e97 | 1211 | @item C-c C-j |
3b65ce47 DL |
1212 | Switch to line mode. Do nothing if already in line mode. |
1213 | ||
91179e97 | 1214 | @kindex C-c C-k @r{(Term mode)} |
3b65ce47 | 1215 | @findex term-line-mode |
91179e97 | 1216 | @item C-c C-k |
3b65ce47 DL |
1217 | Switch to char mode. Do nothing if already in char mode. |
1218 | @end table | |
1219 | ||
df9d7630 RS |
1220 | The following commands are only available in char mode: |
1221 | ||
3b65ce47 DL |
1222 | @table @kbd |
1223 | @item C-c C-c | |
1224 | Send a literal @key{C-c} to the sub-shell. | |
1225 | ||
6f8ca5e4 RS |
1226 | @item C-c @var{char} |
1227 | This is equivalent to @kbd{C-x @var{char}} in normal Emacs. For | |
1228 | example, @kbd{C-c o} invokes the global binding of @kbd{C-x o}, which | |
1229 | is normally @samp{other-window}. | |
3b65ce47 DL |
1230 | @end table |
1231 | ||
1232 | @node Paging in Term | |
df9d7630 RS |
1233 | @subsection Page-At-A-Time Output |
1234 | @cindex page-at-a-time | |
3b65ce47 | 1235 | |
df9d7630 RS |
1236 | Term mode has a page-at-a-time feature. When enabled it makes |
1237 | output pause at the end of each screenful. | |
3b65ce47 DL |
1238 | |
1239 | @table @kbd | |
1240 | @kindex C-c C-q @r{(Term mode)} | |
1241 | @findex term-pager-toggle | |
1242 | @item C-c C-q | |
df9d7630 RS |
1243 | Toggle the page-at-a-time feature. This command works in both line |
1244 | and char modes. When page-at-a-time is enabled, the mode-line | |
1245 | displays the word @samp{page}. | |
3b65ce47 DL |
1246 | @end table |
1247 | ||
df9d7630 RS |
1248 | With page-at-a-time enabled, whenever Term receives more than a |
1249 | screenful of output since your last input, it pauses, displaying | |
1250 | @samp{**MORE**} in the mode-line. Type @key{SPC} to display the next | |
1251 | screenful of output. Type @kbd{?} to see your other options. The | |
892c6176 | 1252 | interface is similar to the @code{more} program. |
3b65ce47 | 1253 | |
6bf7aab6 DL |
1254 | @node Remote Host |
1255 | @subsection Remote Host Shell | |
1256 | @cindex remote host | |
1257 | @cindex connecting to remote host | |
1258 | @cindex Telnet | |
1259 | @cindex Rlogin | |
1260 | ||
3b65ce47 DL |
1261 | You can login to a remote computer, using whatever commands you |
1262 | would from a regular terminal (e.g.@: using the @code{telnet} or | |
1263 | @code{rlogin} commands), from a Term window. | |
1264 | ||
df9d7630 RS |
1265 | A program that asks you for a password will normally suppress |
1266 | echoing of the password, so the password will not show up in the | |
1267 | buffer. This will happen just as if you were using a real terminal, | |
1268 | if the buffer is in char mode. If it is in line mode, the password is | |
1269 | temporarily visible, but will be erased when you hit return. (This | |
1270 | happens automatically; there is no special password processing.) | |
3b65ce47 | 1271 | |
df9d7630 | 1272 | When you log in to a different machine, you need to specify the type |
e51d6b23 LT |
1273 | of terminal you're using, by setting the @env{TERM} environment |
1274 | variable in the environment for the remote login command. (If you use | |
1275 | bash, you do that by writing the variable assignment before the remote | |
1276 | login command, without separating comma.) Terminal types @samp{ansi} | |
1277 | or @samp{vt100} will work on most systems. | |
3b65ce47 DL |
1278 | |
1279 | @c If you are talking to a Bourne-compatible | |
60a96371 | 1280 | @c shell, and your system understands the @env{TERMCAP} variable, |
3b65ce47 DL |
1281 | @c you can use the command @kbd{M-x shell-send-termcap}, which |
1282 | @c sends a string specifying the terminal type and size. | |
1283 | @c (This command is also useful after the window has changed size.) | |
1284 | ||
1285 | @c You can of course run @samp{gdb} on that remote computer. One useful | |
1286 | @c trick: If you invoke gdb with the @code{--fullname} option, | |
1287 | @c it will send special commands to Emacs that will cause Emacs to | |
1288 | @c pop up the source files you're debugging. This will work | |
1289 | @c whether or not gdb is running on a different computer than Emacs, | |
1290 | @c as long as Emacs can access the source files specified by gdb. | |
1291 | ||
df9d7630 | 1292 | @ignore |
021037cb | 1293 | You cannot log in to a remote computer using the Shell mode. |
3b65ce47 DL |
1294 | @c (This will change when Shell is re-written to use Term.) |
1295 | Instead, Emacs provides two commands for logging in to another computer | |
df9d7630 | 1296 | and communicating with it through an Emacs buffer using Comint mode: |
6bf7aab6 DL |
1297 | |
1298 | @table @kbd | |
1299 | @item M-x telnet @key{RET} @var{hostname} @key{RET} | |
1300 | Set up a Telnet connection to the computer named @var{hostname}. | |
1301 | @item M-x rlogin @key{RET} @var{hostname} @key{RET} | |
1302 | Set up an Rlogin connection to the computer named @var{hostname}. | |
1303 | @end table | |
1304 | ||
1305 | @findex telnet | |
1306 | Use @kbd{M-x telnet} to set up a Telnet connection to another | |
1307 | computer. (Telnet is the standard Internet protocol for remote login.) | |
1308 | It reads the host name of the other computer as an argument with the | |
1309 | minibuffer. Once the connection is established, talking to the other | |
1310 | computer works like talking to a subshell: you can edit input with the | |
1311 | usual Emacs commands, and send it a line at a time by typing @key{RET}. | |
1312 | The output is inserted in the Telnet buffer interspersed with the input. | |
1313 | ||
1314 | @findex rlogin | |
1315 | @vindex rlogin-explicit-args | |
1316 | Use @kbd{M-x rlogin} to set up an Rlogin connection. Rlogin is | |
1317 | another remote login communication protocol, essentially much like the | |
1318 | Telnet protocol but incompatible with it, and supported only by certain | |
1319 | systems. Rlogin's advantages are that you can arrange not to have to | |
1320 | give your user name and password when communicating between two machines | |
1321 | you frequently use, and that you can make an 8-bit-clean connection. | |
1322 | (To do that in Emacs, set @code{rlogin-explicit-args} to @code{("-8")} | |
1323 | before you run Rlogin.) | |
1324 | ||
1325 | @kbd{M-x rlogin} sets up the default file directory of the Emacs | |
1326 | buffer to access the remote host via FTP (@pxref{File Names}), and it | |
1327 | tracks the shell commands that change the current directory, just like | |
1328 | Shell mode. | |
1329 | ||
1330 | @findex rlogin-directory-tracking-mode | |
1331 | There are two ways of doing directory tracking in an Rlogin | |
1332 | buffer---either with remote directory names | |
1333 | @file{/@var{host}:@var{dir}/} or with local names (that works if the | |
1334 | ``remote'' machine shares file systems with your machine of origin). | |
1335 | You can use the command @code{rlogin-directory-tracking-mode} to switch | |
1336 | modes. No argument means use remote directory names, a positive | |
1337 | argument means use local names, and a negative argument means turn | |
1338 | off directory tracking. | |
1339 | ||
df9d7630 RS |
1340 | @end ignore |
1341 | ||
37e5d54a GM |
1342 | @node Serial Terminal |
1343 | @subsection Serial Terminal | |
1344 | @cindex terminal, serial | |
1345 | @findex serial-term | |
1346 | ||
1347 | If you have a device connected to a serial port of your computer, | |
1348 | you can use Emacs to communicate with it. @kbd{M-x serial-term} will | |
1349 | ask you for a serial port name and speed and will then open a new | |
1350 | window in @ref{Term Mode}. | |
1351 | ||
1352 | The speed of the serial port is measured in bits per second. The | |
1353 | most common speed is 9600 bits per second. You can change the speed | |
1354 | interactively by clicking on the mode line. | |
1355 | ||
1356 | A serial port can be configured even more by clicking on ``8N1'' in | |
1357 | the mode line. By default, a serial port is configured as ``8N1'', | |
1358 | which means that each byte consists of 8 data bits, No parity check | |
1359 | bit, and 1 stopbit. | |
1360 | ||
1361 | When you have opened the serial port connection, you will see output | |
1362 | from the device in the window. Also, what you type in the window is | |
1363 | sent to the device. | |
1364 | ||
1365 | If the speed or the configuration is wrong, you cannot communicate | |
1366 | with your device and will probably only see garbage output in the | |
1367 | window. | |
1368 | ||
66bb4d9a | 1369 | @node Emacs Server, Printing, Shell, Top |
6bf7aab6 DL |
1370 | @section Using Emacs as a Server |
1371 | @pindex emacsclient | |
1372 | @cindex Emacs as a server | |
1373 | @cindex server, using Emacs as | |
60a96371 | 1374 | @cindex @env{EDITOR} environment variable |
6bf7aab6 | 1375 | |
8cec98c0 CY |
1376 | Various programs such as @command{mail} can invoke your choice of |
1377 | editor to edit a particular piece of text, such as a message that you | |
1378 | are sending. By convention, most of these programs use the | |
1379 | environment variable @env{EDITOR} to specify which editor to run. If | |
1380 | you set @env{EDITOR} to @samp{emacs}, they invoke Emacs---but in an | |
1381 | inconvenient way, by starting a new Emacs process. This is | |
1382 | inconvenient because the new Emacs process doesn't share buffers, a | |
1383 | command history, or other kinds of information with any existing Emacs | |
1384 | process. | |
1385 | ||
1386 | You can solve this problem by setting up Emacs as an @dfn{edit | |
1387 | server}, so that it ``listens'' for external edit requests and acts | |
1388 | accordingly. There are two ways to start an Emacs server: | |
6bf7aab6 | 1389 | |
d9d81805 | 1390 | @findex server-start |
8cec98c0 CY |
1391 | The first is to run the command @code{server-start} in an existing |
1392 | Emacs process: either type @kbd{M-x server-start}, or put the | |
1393 | expression @code{(server-start)} in your initialization file | |
1394 | (@pxref{Init File}). The existing Emacs process is the server; when | |
1395 | you exit Emacs, the server dies with the Emacs process. | |
1396 | ||
1397 | @cindex daemon, Emacs | |
1398 | The second way to start an Emacs server is to run Emacs as a | |
1399 | @dfn{daemon}, using the @samp{--daemon} command-line option. | |
1400 | @xref{Initial Options}. When Emacs is started this way, it calls | |
1401 | @code{server-start} after initialization, and returns control to the | |
1402 | calling terminal instead of opening an initial frame; it then waits in | |
1403 | the background, listening for edit requests. | |
df9d7630 | 1404 | |
8cec98c0 CY |
1405 | @cindex @env{TEXEDIT} environment variable |
1406 | Once an Emacs server is set up, you can use a shell command called | |
1407 | @command{emacsclient} to connect to the existing Emacs process and | |
1408 | tell it to visit a file. If you set the @env{EDITOR} environment | |
1409 | variable to @samp{emacsclient}, programs such as @command{mail} will | |
1410 | use the existing Emacs process for editing.@footnote{Some programs use | |
1411 | a different environment variable; for example, to make @TeX{} use | |
1412 | @samp{emacsclient}, set the @env{TEXEDIT} environment variable to | |
1413 | @samp{emacsclient +%d %s}.} | |
6bf7aab6 | 1414 | |
82b9073d RS |
1415 | @vindex server-name |
1416 | You can run multiple Emacs servers on the same machine by giving | |
1417 | each one a unique ``server name'', using the variable | |
4f256c8e RS |
1418 | @code{server-name}. For example, @kbd{M-x set-variable @key{RET} |
1419 | server-name @key{RET} foo @key{RET}} sets the server name to | |
d9d81805 | 1420 | @samp{foo}. The @code{emacsclient} program can specify a server by |
8cec98c0 | 1421 | name, using the @samp{-s} option (@pxref{emacsclient Options}). |
82b9073d | 1422 | |
e793a940 LMI |
1423 | @findex server-eval-at |
1424 | If you have defined a server by a unique server name, you can | |
1425 | connect to this server from other Emacs instances and evaluate forms | |
1426 | on it by using the @code{server-eval-at} function. | |
1427 | ||
1428 | @code{(server-eval-at "foo" '(+ 1 2))} gives the result @code{3}, if | |
1429 | there's a server with that name that is listening. If not, an error | |
1430 | will be signaled. | |
1431 | ||
8cec98c0 CY |
1432 | @menu |
1433 | * Invoking emacsclient:: Connecting to the Emacs server. | |
1434 | * emacsclient Options:: Emacs client startup options. | |
1435 | @end menu | |
6bf7aab6 | 1436 | |
8cec98c0 CY |
1437 | @node Invoking emacsclient |
1438 | @subsection Invoking @code{emacsclient} | |
1439 | @cindex @code{emacsclient} invocation | |
1440 | ||
1441 | The simplest way to use the @command{emacsclient} program is to run | |
1442 | the shell command @samp{emacsclient @var{file}}, where @var{file} is a | |
1443 | file name. This connects to an Emacs server, and tells that Emacs | |
1444 | process to visit @var{file} in one of its existing frames---either a | |
1445 | graphical frame, or one in a text-only terminal (@pxref{Frames}). You | |
a568b1f9 | 1446 | can then select that frame to begin editing. |
8cec98c0 CY |
1447 | |
1448 | If there is no Emacs server, the @command{emacsclient} program halts | |
1449 | with an error message. If the Emacs process has no existing | |
1450 | frame---which can happen if it was started as a daemon (@pxref{Emacs | |
8b72835c | 1451 | Server})---then Emacs opens a frame on the terminal in which you |
6a5ca7c8 CY |
1452 | called @command{emacsclient}. |
1453 | ||
1454 | You can also force @command{emacsclient} to open a new frame on a | |
1455 | graphical display, or on a text-only terminal, using the @samp{-c} and | |
1456 | @samp{-t} options. @xref{emacsclient Options}. | |
1457 | ||
1458 | If you are running on a single text-only terminal, you can switch | |
1459 | between @command{emacsclient}'s shell and the Emacs server using one | |
1460 | of two methods: (i) run the Emacs server and @command{emacsclient} on | |
1461 | different virtual terminals, and switch to the Emacs server's virtual | |
1462 | terminal after calling @command{emacsclient}; or (ii) call | |
1463 | @command{emacsclient} from within the Emacs server itself, using Shell | |
1464 | mode (@pxref{Interactive Shell}) or Term mode (@pxref{Term Mode}); | |
1465 | @code{emacsclient} blocks only the subshell under Emacs, and you can | |
1466 | still use Emacs to edit the file. | |
a568b1f9 | 1467 | |
8cec98c0 CY |
1468 | @kindex C-x # |
1469 | @findex server-edit | |
a568b1f9 CY |
1470 | When you finish editing @var{file} in the Emacs server, type |
1471 | @kbd{C-x #} (@code{server-edit}) in its buffer. This saves the file | |
1472 | and sends a message back to the @command{emacsclient} program, telling | |
1473 | it to exit. Programs that use @env{EDITOR} usually wait for the | |
da0bbbc4 | 1474 | ``editor''---in this case @command{emacsclient}---to exit before doing |
a568b1f9 | 1475 | something else. |
8cec98c0 CY |
1476 | |
1477 | You can also call @command{emacsclient} with multiple file name | |
1478 | arguments: @samp{emacsclient @var{file1} @var{file2} ...} tells the | |
1479 | Emacs server to visit @var{file1}, @var{file2}, and so forth. Emacs | |
1480 | selects the buffer visiting @var{file1}, and buries the other buffers | |
1481 | at the bottom of the buffer list (@pxref{Buffers}). The | |
1482 | @command{emacsclient} program exits once all the specified files are | |
1483 | finished (i.e., once you have typed @kbd{C-x #} in each server | |
1484 | buffer). | |
6bf7aab6 | 1485 | |
8cec98c0 CY |
1486 | @vindex server-kill-new-buffers |
1487 | @vindex server-temp-file-regexp | |
1488 | Finishing with a server buffer also kills the buffer, unless it | |
1489 | already existed in the Emacs session before the server was asked to | |
1490 | create it. However, if you set @code{server-kill-new-buffers} to | |
1491 | @code{nil}, then a different criterion is used: finishing with a | |
1492 | server buffer kills it if the file name matches the regular expression | |
1493 | @code{server-temp-file-regexp}. This is set up to distinguish certain | |
1494 | ``temporary'' files. | |
7448f7a2 | 1495 | |
8cec98c0 CY |
1496 | Each @kbd{C-x #} checks for other pending external requests to edit |
1497 | various files, and selects the next such file. You can switch to a | |
1498 | server buffer manually if you wish; you don't have to arrive at it | |
1499 | with @kbd{C-x #}. But @kbd{C-x #} is the way to tell | |
1500 | @command{emacsclient} that you are finished. | |
b1a92ebf | 1501 | |
8cec98c0 | 1502 | @vindex server-window |
6a5ca7c8 CY |
1503 | If you set the value of the variable @code{server-window} to a |
1504 | window or a frame, @kbd{C-x #} always displays the next server buffer | |
1505 | in that window or in that frame. | |
6bf7aab6 | 1506 | |
8cec98c0 CY |
1507 | @node emacsclient Options |
1508 | @subsection @code{emacsclient} Options | |
1509 | @cindex @code{emacsclient} options | |
6bf7aab6 | 1510 | |
8cec98c0 CY |
1511 | You can pass some optional arguments to the @command{emacsclient} |
1512 | program, such as: | |
6bf7aab6 DL |
1513 | |
1514 | @example | |
8cec98c0 | 1515 | emacsclient -c +12 @var{file1} +4:3 @var{file2} |
6bf7aab6 DL |
1516 | @end example |
1517 | ||
df9d7630 | 1518 | @noindent |
78b6d6d2 CY |
1519 | The @samp{+@var{line}} or @samp{+@var{line}:@var{column}} arguments |
1520 | specify line numbers, or line and column numbers, for the next file | |
1521 | argument. These behave like the command line arguments for Emacs | |
1522 | itself. @xref{Action Arguments}. | |
8cec98c0 CY |
1523 | |
1524 | The other optional arguments recognized by @command{emacsclient} are | |
1525 | listed below: | |
1526 | ||
1527 | @table @samp | |
1528 | @item -a @var{command} | |
1529 | @itemx --alternate-editor=@var{command} | |
1530 | Specify a command to run if @code{emacsclient} fails to contact Emacs. | |
ae742cb5 | 1531 | This is useful when running @code{emacsclient} in a script. |
6bf7aab6 | 1532 | |
932fd020 | 1533 | As a special exception, if @var{command} is the empty string, then |
453e4522 CY |
1534 | @code{emacsclient} starts Emacs in daemon mode (as @command{emacs |
1535 | --daemon}) and then tries connecting again. | |
932fd020 | 1536 | |
d9d81805 | 1537 | @cindex @env{ALTERNATE_EDITOR} environment variable |
932fd020 CY |
1538 | The environment variable @env{ALTERNATE_EDITOR} has the same effect as |
1539 | the @samp{-a} option. If both are present, the latter takes | |
8cec98c0 CY |
1540 | precedence. |
1541 | ||
1542 | @item -c | |
1543 | Create a new graphical frame, instead of using an existing Emacs | |
78b6d6d2 CY |
1544 | frame. Emacs 23 can create a graphical frame even if it was started |
1545 | in a text-only terminal, provided it is able to connect to a graphical | |
1546 | display. If no graphical display is available, Emacs creates a new | |
1547 | text-only terminal frame (@pxref{Frames}). If you omit a filename | |
1548 | argument while supplying the @samp{-c} option, the new frame displays | |
1549 | the @samp{*scratch*} buffer (@pxref{Buffers}). | |
8cec98c0 | 1550 | |
18a4ce5e AR |
1551 | @item -F |
1552 | @itemx --frame-parameters=@var{alist} | |
1553 | Set the parameters for a newly-created graphical frame | |
1554 | (@pxref{Frame Parameters}). | |
1555 | ||
8cec98c0 CY |
1556 | @item -d @var{display} |
1557 | @itemx --display=@var{display} | |
1558 | Tell Emacs to open the given files on the X display @var{display} | |
1559 | (assuming there is more than one X display available). | |
1560 | ||
1561 | @item -e | |
1562 | @itemx --eval | |
1563 | Tell Emacs to evaluate some Emacs Lisp code, instead of visiting some | |
1564 | files. When this option is given, the arguments to | |
1565 | @command{emacsclient} are interpreted as a list of expressions to | |
1566 | evaluate, @emph{not} as a list of files to visit. | |
1567 | ||
1568 | @item -f @var{server-file} | |
1569 | @itemx --server-file=@var{server-file} | |
d9d81805 | 1570 | @cindex @env{EMACS_SERVER_FILE} environment variable |
8cec98c0 | 1571 | @cindex server file |
01bfa900 CY |
1572 | @vindex server-use-tcp |
1573 | @vindex server-host | |
8cec98c0 CY |
1574 | Specify a @dfn{server file} for connecting to an Emacs server via TCP. |
1575 | ||
01bfa900 | 1576 | An Emacs server usually uses an operating system feature called a |
8cec98c0 CY |
1577 | ``local socket'' to listen for connections. Some operating systems, |
1578 | such as Microsoft Windows, do not support local sockets; in that case, | |
01bfa900 CY |
1579 | Emacs uses TCP instead. When you start the Emacs server, Emacs |
1580 | creates a server file containing some TCP information that | |
1581 | @command{emacsclient} needs for making the connection. By default, | |
1582 | the server file is in @file{~/.emacs.d/server/}. On Microsoft | |
1583 | Windows, if @command{emacsclient} does not find the server file there, | |
1584 | it looks in the @file{.emacs.d/server/} subdirectory of the directory | |
1585 | pointed to by the @env{APPDATA} environment variable. You can tell | |
1586 | @command{emacsclient} to use a specific server file with the @samp{-f} | |
1587 | or @samp{--server-file} option, or by setting the | |
1588 | @env{EMACS_SERVER_FILE} environment variable. | |
1589 | ||
1590 | Even if local sockets are available, you can tell Emacs to use TCP by | |
1591 | setting the variable @code{server-use-tcp} to @code{t}. One advantage | |
1592 | of TCP is that the server can accept connections from remote machines. | |
1593 | For this to work, you must (i) set the variable @code{server-host} to | |
1594 | the hostname or IP address of the machine on which the Emacs server | |
1595 | runs, and (ii) provide @command{emacsclient} with the server file. | |
1596 | (One convenient way to do the latter is to put the server file on a | |
1597 | networked file system such as NFS.) | |
5b8b9fa7 | 1598 | |
ddb54206 CY |
1599 | @vindex server-port |
1600 | When the Emacs server is using TCP, the variable @code{server-port} | |
1601 | determines the port number to listen on; the default value, | |
1602 | @code{nil}, means to choose a random port when the server starts. | |
1603 | ||
8cec98c0 CY |
1604 | @item -n |
1605 | @itemx --no-wait | |
1606 | Let @command{emacsclient} exit immediately, instead of waiting until | |
1607 | all server buffers are finished. You can take as long as you like to | |
1608 | edit the server buffers within Emacs, and they are @emph{not} killed | |
1609 | when you type @kbd{C-x #} in them. | |
1610 | ||
fdeb32ec CY |
1611 | @item --parent-id @var{ID} |
1612 | Open an @command{emacsclient} frame as a client frame in the parent X | |
1613 | window with id @var{ID}, via the XEmbed protocol. Currently, this | |
1614 | option is mainly useful for developers. | |
1615 | ||
0b973fc5 DW |
1616 | @item -q |
1617 | @itemx --quiet | |
1618 | Do not let @command{emacsclient} display messages about waiting for | |
1619 | Emacs or connecting to remote server sockets. | |
1620 | ||
8cec98c0 CY |
1621 | @item -s @var{server-name} |
1622 | @itemx --socket-name=@var{server-name} | |
1623 | Connect to the Emacs server named @var{server-name}. The server name | |
1624 | is given by the variable @code{server-name} on the Emacs server. If | |
1625 | this option is omitted, @command{emacsclient} connects to the first | |
1626 | server it finds. (This option is not supported on MS-Windows.) | |
1627 | ||
1628 | @item -t | |
1629 | @itemx --tty | |
1630 | @itemx -nw | |
1631 | Create a new Emacs frame on the current text-only terminal, instead of | |
78b6d6d2 CY |
1632 | using an existing Emacs frame. Emacs 23 can open a text-only terminal |
1633 | even if it was started in another text-only terminal, or on a | |
1634 | graphical display. If you omit a filename argument while supplying | |
1635 | this option, the new frame displays the @samp{*scratch*} buffer. | |
1636 | @xref{Buffers}. | |
8cec98c0 CY |
1637 | @end table |
1638 | ||
1639 | If you type @kbd{C-x C-c} (@code{save-buffers-kill-terminal}) in an | |
1640 | Emacs frame created with @command{emacsclient}, via the @samp{-c} or | |
1641 | @samp{-t} options, Emacs deletes the frame instead of killing the | |
1642 | Emacs process itself. On a text-only terminal frame created with the | |
1643 | @samp{-t} option, this returns control to the terminal. Emacs also | |
1644 | marks all the server buffers for the client as finished, as though you | |
1645 | had typed @kbd{C-x #} in all of them. | |
1646 | ||
1647 | When Emacs is started as a daemon, all frames are considered client | |
1648 | frames, so @kbd{C-x C-c} will never kill Emacs. To kill the Emacs | |
1649 | process, type @kbd{M-x kill-emacs}. | |
1650 | ||
66bb4d9a EZ |
1651 | @node Printing, Sorting, Emacs Server, Top |
1652 | @section Printing Hard Copies | |
6bf7aab6 | 1653 | @cindex hardcopy |
66bb4d9a | 1654 | @cindex printing |
6bf7aab6 | 1655 | |
66bb4d9a EZ |
1656 | Emacs provides commands for printing hard copies of either an entire |
1657 | buffer or just part of one, with or without page headers. You can | |
1658 | invoke the printing commands directly, as detailed in the following | |
eb5ed549 CY |
1659 | section, or using the @samp{File} menu on the menu bar. |
1660 | ||
1661 | @findex htmlfontify-buffer | |
1662 | Aside from the commands described in this section, you can also | |
1663 | ``print'' an Emacs buffer to HTML with @kbd{M-x htmlfontify-buffer}. | |
1664 | This command converts the current buffer to a HTML file, replacing | |
1665 | Emacs faces with CSS-based markup. In addition, see the hardcopy | |
1666 | commands of Dired (@pxref{Misc File Ops}) and the diary | |
66bb4d9a | 1667 | (@pxref{Displaying the Diary}). |
6bf7aab6 DL |
1668 | |
1669 | @table @kbd | |
1670 | @item M-x print-buffer | |
1671 | Print hardcopy of current buffer with page headings containing the file | |
1672 | name and page number. | |
1673 | @item M-x lpr-buffer | |
1674 | Print hardcopy of current buffer without page headings. | |
1675 | @item M-x print-region | |
1676 | Like @code{print-buffer} but print only the current region. | |
1677 | @item M-x lpr-region | |
1678 | Like @code{lpr-buffer} but print only the current region. | |
1679 | @end table | |
1680 | ||
1681 | @findex print-buffer | |
1682 | @findex print-region | |
1683 | @findex lpr-buffer | |
1684 | @findex lpr-region | |
1685 | @vindex lpr-switches | |
891c0674 | 1686 | The hardcopy commands (aside from the PostScript commands) pass extra |
6bf7aab6 DL |
1687 | switches to the @code{lpr} program based on the value of the variable |
1688 | @code{lpr-switches}. Its value should be a list of strings, each string | |
1689 | an option starting with @samp{-}. For example, to specify a line width | |
1690 | of 80 columns for all the printing you do in Emacs, set | |
1691 | @code{lpr-switches} like this: | |
1692 | ||
1693 | @example | |
1694 | (setq lpr-switches '("-w80")) | |
1695 | @end example | |
1696 | ||
1697 | @vindex printer-name | |
1698 | You can specify the printer to use by setting the variable | |
1699 | @code{printer-name}. | |
1700 | ||
1701 | @vindex lpr-headers-switches | |
1702 | @vindex lpr-commands | |
1703 | @vindex lpr-add-switches | |
1704 | The variable @code{lpr-command} specifies the name of the printer | |
1705 | program to run; the default value depends on your operating system type. | |
1706 | On most systems, the default is @code{"lpr"}. The variable | |
1707 | @code{lpr-headers-switches} similarly specifies the extra switches to | |
1708 | use to make page headers. The variable @code{lpr-add-switches} controls | |
1709 | whether to supply @samp{-T} and @samp{-J} options (suitable for | |
1710 | @code{lpr}) to the printer program: @code{nil} means don't add them. | |
1711 | @code{lpr-add-switches} should be @code{nil} if your printer program is | |
1712 | not compatible with @code{lpr}. | |
1713 | ||
66bb4d9a | 1714 | @menu |
8838673e | 1715 | * PostScript:: Printing buffers or regions as PostScript. |
66bb4d9a EZ |
1716 | * PostScript Variables:: Customizing the PostScript printing commands. |
1717 | * Printing Package:: An optional advanced printing interface. | |
1718 | @end menu | |
1719 | ||
1720 | @node PostScript, PostScript Variables,, Printing | |
856ce114 | 1721 | @subsection PostScript Hardcopy |
6bf7aab6 | 1722 | |
3b65ce47 | 1723 | These commands convert buffer contents to PostScript, |
6bf7aab6 DL |
1724 | either printing it or leaving it in another Emacs buffer. |
1725 | ||
1726 | @table @kbd | |
1727 | @item M-x ps-print-buffer | |
3b65ce47 | 1728 | Print hardcopy of the current buffer in PostScript form. |
6bf7aab6 | 1729 | @item M-x ps-print-region |
3b65ce47 | 1730 | Print hardcopy of the current region in PostScript form. |
6bf7aab6 | 1731 | @item M-x ps-print-buffer-with-faces |
3b65ce47 DL |
1732 | Print hardcopy of the current buffer in PostScript form, showing the |
1733 | faces used in the text by means of PostScript features. | |
6bf7aab6 | 1734 | @item M-x ps-print-region-with-faces |
3b65ce47 | 1735 | Print hardcopy of the current region in PostScript form, showing the |
6bf7aab6 DL |
1736 | faces used in the text. |
1737 | @item M-x ps-spool-buffer | |
2f298da2 | 1738 | Generate and spool a PostScript image for the current buffer text. |
6bf7aab6 | 1739 | @item M-x ps-spool-region |
2f298da2 | 1740 | Generate and spool a PostScript image for the current region. |
6bf7aab6 | 1741 | @item M-x ps-spool-buffer-with-faces |
2f298da2 | 1742 | Generate and spool a PostScript image for the current buffer, showing the faces used. |
6bf7aab6 | 1743 | @item M-x ps-spool-region-with-faces |
2f298da2 VJL |
1744 | Generate and spool a PostScript image for the current region, showing the faces used. |
1745 | @item M-x ps-despool | |
1746 | Send the spooled PostScript to the printer. | |
3b65ce47 | 1747 | @item M-x handwrite |
2f298da2 | 1748 | Generate/print PostScript for the current buffer as if handwritten. |
6bf7aab6 DL |
1749 | @end table |
1750 | ||
1751 | @findex ps-print-region | |
1752 | @findex ps-print-buffer | |
1753 | @findex ps-print-region-with-faces | |
1754 | @findex ps-print-buffer-with-faces | |
3b65ce47 DL |
1755 | The PostScript commands, @code{ps-print-buffer} and |
1756 | @code{ps-print-region}, print buffer contents in PostScript form. One | |
6bf7aab6 DL |
1757 | command prints the entire buffer; the other, just the region. The |
1758 | corresponding @samp{-with-faces} commands, | |
1759 | @code{ps-print-buffer-with-faces} and @code{ps-print-region-with-faces}, | |
3b65ce47 | 1760 | use PostScript features to show the faces (fonts and colors) in the text |
2f298da2 VJL |
1761 | properties of the text being printed. The @samp{-with-faces} commands only |
1762 | work if they are used in a window system, so it has a way to determine color | |
1763 | values. | |
1764 | ||
1765 | Interactively, when you use a prefix argument (@kbd{C-u}), the command | |
1766 | prompts the user for a file name, and saves the PostScript image in that file | |
1767 | instead of sending it to the printer. | |
1768 | ||
1769 | Noninteractively, the argument @var{filename} is treated as follows: if it is | |
1770 | @code{nil}, send the image to the printer. If @var{filename} is a string, save | |
1771 | the PostScript image in a file with that name. | |
6bf7aab6 DL |
1772 | |
1773 | If you are using a color display, you can print a buffer of program | |
1774 | code with color highlighting by turning on Font-Lock mode in that | |
1775 | buffer, and using @code{ps-print-buffer-with-faces}. | |
1776 | ||
1777 | @findex ps-spool-region | |
1778 | @findex ps-spool-buffer | |
1779 | @findex ps-spool-region-with-faces | |
1780 | @findex ps-spool-buffer-with-faces | |
2f298da2 | 1781 | The commands whose names have @samp{spool} instead of @samp{print}, |
3b65ce47 | 1782 | generate the PostScript output in an Emacs buffer instead of sending |
6bf7aab6 DL |
1783 | it to the printer. |
1784 | ||
2f298da2 VJL |
1785 | Use the command @code{ps-despool} to send the spooled images to the printer. |
1786 | ||
1787 | @findex ps-despool | |
1788 | This command sends the PostScript generated by @samp{-spool-} commands (see | |
1789 | commands above) to the printer. | |
1790 | ||
1791 | Interactively, when you use a prefix argument (@kbd{C-u}), the command | |
1792 | prompts the user for a file name, and saves the spooled PostScript image in | |
1793 | that file instead of sending it to the printer. | |
1794 | ||
1795 | Noninteractively, the argument @var{filename} is treated as follows: if it is | |
1796 | @code{nil}, send the image to the printer. If @var{filename} is a string, save | |
1797 | the PostScript image in a file with that name. | |
1798 | ||
3b65ce47 DL |
1799 | @findex handwrite |
1800 | @cindex handwriting | |
1801 | @kbd{M-x handwrite} is more frivolous. It generates a PostScript | |
1802 | rendition of the current buffer as a cursive handwritten document. It | |
fc98b4ba RS |
1803 | can be customized in group @code{handwrite}. This function only |
1804 | supports ISO 8859-1 characters. | |
3b65ce47 | 1805 | |
d3ea5f55 | 1806 | @ifnottex |
6bf7aab6 | 1807 | The following section describes variables for customizing these commands. |
d3ea5f55 | 1808 | @end ifnottex |
6bf7aab6 | 1809 | |
66bb4d9a | 1810 | @node PostScript Variables, Printing Package, PostScript, Printing |
856ce114 | 1811 | @subsection Variables for PostScript Hardcopy |
6bf7aab6 DL |
1812 | |
1813 | @vindex ps-lpr-command | |
1814 | @vindex ps-lpr-switches | |
1815 | @vindex ps-printer-name | |
3b65ce47 | 1816 | All the PostScript hardcopy commands use the variables |
6bf7aab6 DL |
1817 | @code{ps-lpr-command} and @code{ps-lpr-switches} to specify how to print |
1818 | the output. @code{ps-lpr-command} specifies the command name to run, | |
1819 | @code{ps-lpr-switches} specifies command line options to use, and | |
1820 | @code{ps-printer-name} specifies the printer. If you don't set the | |
1821 | first two variables yourself, they take their initial values from | |
1822 | @code{lpr-command} and @code{lpr-switches}. If @code{ps-printer-name} | |
1823 | is @code{nil}, @code{printer-name} is used. | |
1824 | ||
1825 | @vindex ps-print-header | |
6bf7aab6 DL |
1826 | The variable @code{ps-print-header} controls whether these commands |
1827 | add header lines to each page---set it to @code{nil} to turn headers | |
550135d1 EZ |
1828 | off. |
1829 | ||
1830 | @cindex color emulation on black-and-white printers | |
1831 | @vindex ps-print-color-p | |
1832 | If your printer doesn't support colors, you should turn off color | |
1833 | processing by setting @code{ps-print-color-p} to @code{nil}. By | |
1834 | default, if the display supports colors, Emacs produces hardcopy output | |
1835 | with color information; on black-and-white printers, colors are emulated | |
1836 | with shades of gray. This might produce illegible output, even if your | |
1837 | screen colors only use shades of gray. | |
1838 | ||
2f298da2 VJL |
1839 | Alternatively, you can set @code{ps-print-color-p} to @code{black-white} to |
1840 | print colors on black/white printers. | |
1841 | ||
550135d1 | 1842 | @vindex ps-use-face-background |
df9d7630 RS |
1843 | By default, PostScript printing ignores the background colors of the |
1844 | faces, unless the variable @code{ps-use-face-background} is | |
1845 | non-@code{nil}. This is to avoid unwanted interference with the zebra | |
1846 | stripes and background image/text. | |
6bf7aab6 DL |
1847 | |
1848 | @vindex ps-paper-type | |
1849 | @vindex ps-page-dimensions-database | |
1850 | The variable @code{ps-paper-type} specifies which size of paper to | |
1851 | format for; legitimate values include @code{a4}, @code{a3}, | |
1852 | @code{a4small}, @code{b4}, @code{b5}, @code{executive}, @code{ledger}, | |
1853 | @code{legal}, @code{letter}, @code{letter-small}, @code{statement}, | |
1854 | @code{tabloid}. The default is @code{letter}. You can define | |
1855 | additional paper sizes by changing the variable | |
1856 | @code{ps-page-dimensions-database}. | |
1857 | ||
1858 | @vindex ps-landscape-mode | |
1859 | The variable @code{ps-landscape-mode} specifies the orientation of | |
1860 | printing on the page. The default is @code{nil}, which stands for | |
1861 | ``portrait'' mode. Any non-@code{nil} value specifies ``landscape'' | |
1862 | mode. | |
1863 | ||
1864 | @vindex ps-number-of-columns | |
1865 | The variable @code{ps-number-of-columns} specifies the number of | |
1866 | columns; it takes effect in both landscape and portrait mode. The | |
1867 | default is 1. | |
1868 | ||
1869 | @vindex ps-font-family | |
1870 | @vindex ps-font-size | |
1871 | @vindex ps-font-info-database | |
1872 | The variable @code{ps-font-family} specifies which font family to use | |
1873 | for printing ordinary text. Legitimate values include @code{Courier}, | |
1874 | @code{Helvetica}, @code{NewCenturySchlbk}, @code{Palatino} and | |
1875 | @code{Times}. The variable @code{ps-font-size} specifies the size of | |
1876 | the font for ordinary text. It defaults to 8.5 points. | |
1877 | ||
adee28ff EZ |
1878 | @vindex ps-multibyte-buffer |
1879 | @cindex Intlfonts for PostScript printing | |
1880 | @cindex fonts for PostScript printing | |
1881 | Emacs supports more scripts and characters than a typical PostScript | |
1882 | printer. Thus, some of the characters in your buffer might not be | |
1883 | printable using the fonts built into your printer. You can augment | |
1884 | the fonts supplied with the printer with those from the GNU Intlfonts | |
1885 | package, or you can instruct Emacs to use Intlfonts exclusively. The | |
1886 | variable @code{ps-multibyte-buffer} controls this: the default value, | |
76dd3692 | 1887 | @code{nil}, is appropriate for printing @acronym{ASCII} and Latin-1 |
adee28ff | 1888 | characters; a value of @code{non-latin-printer} is for printers which |
76dd3692 | 1889 | have the fonts for @acronym{ASCII}, Latin-1, Japanese, and Korean |
adee28ff EZ |
1890 | characters built into them. A value of @code{bdf-font} arranges for |
1891 | the BDF fonts from the Intlfonts package to be used for @emph{all} | |
1892 | characters. Finally, a value of @code{bdf-font-except-latin} | |
76dd3692 | 1893 | instructs the printer to use built-in fonts for @acronym{ASCII} and Latin-1 |
adee28ff EZ |
1894 | characters, and Intlfonts BDF fonts for the rest. |
1895 | ||
1896 | @vindex bdf-directory-list | |
021037cb | 1897 | To be able to use the BDF fonts, Emacs needs to know where to find |
adee28ff EZ |
1898 | them. The variable @code{bdf-directory-list} holds the list of |
1899 | directories where Emacs should look for the fonts; the default value | |
1900 | includes a single directory @file{/usr/local/share/emacs/fonts/bdf}. | |
1901 | ||
6bf7aab6 | 1902 | Many other customization variables for these commands are defined and |
adee28ff | 1903 | described in the Lisp files @file{ps-print.el} and @file{ps-mule.el}. |
6bf7aab6 | 1904 | |
66bb4d9a | 1905 | @node Printing Package,, PostScript Variables, Printing |
856ce114 | 1906 | @subsection Printing Package |
66bb4d9a EZ |
1907 | @cindex Printing package |
1908 | ||
1909 | The basic Emacs facilities for printing hardcopy can be extended | |
1910 | using the Printing package. This provides an easy-to-use interface | |
1911 | for choosing what to print, previewing PostScript files before | |
1912 | printing, and setting various printing options such as print headers, | |
1913 | landscape or portrait modes, duplex modes, and so forth. On GNU/Linux | |
1914 | or Unix systems, the Printing package relies on the @file{gs} and | |
1915 | @file{gv} utilities, which are distributed as part of the GhostScript | |
1916 | program. On MS-Windows, the @file{gstools} port of Ghostscript can be | |
1917 | used. | |
1918 | ||
1919 | @findex pr-interface | |
1920 | To use the Printing package, add @code{(require 'printing)} to your | |
aada47fc RS |
1921 | init file (@pxref{Init File}), followed by @code{(pr-update-menus)}. |
1922 | This function replaces the usual printing commands in the menu bar | |
1923 | with a @samp{Printing} submenu that contains various printing options. | |
1924 | You can also type @kbd{M-x pr-interface RET}; this creates a | |
1925 | @samp{*Printing Interface*} buffer, similar to a customization buffer, | |
1926 | where you can set the printing options. After selecting what and how | |
1927 | to print, you start the print job using the @samp{Print} button (click | |
1928 | @kbd{mouse-2} on it, or move point over it and type @kbd{RET}). For | |
1929 | further information on the various options, use the @samp{Interface | |
1930 | Help} button. | |
66bb4d9a | 1931 | |
f404f8bc | 1932 | @node Sorting |
6bf7aab6 DL |
1933 | @section Sorting Text |
1934 | @cindex sorting | |
1935 | ||
1936 | Emacs provides several commands for sorting text in the buffer. All | |
982dcb1b RS |
1937 | operate on the contents of the region. |
1938 | They divide the text of the region into many @dfn{sort records}, | |
6bf7aab6 DL |
1939 | identify a @dfn{sort key} for each record, and then reorder the records |
1940 | into the order determined by the sort keys. The records are ordered so | |
1941 | that their keys are in alphabetical order, or, for numeric sorting, in | |
1942 | numeric order. In alphabetic sorting, all upper-case letters `A' through | |
76dd3692 | 1943 | `Z' come before lower-case `a', in accord with the @acronym{ASCII} character |
6bf7aab6 DL |
1944 | sequence. |
1945 | ||
1946 | The various sort commands differ in how they divide the text into sort | |
1947 | records and in which part of each record is used as the sort key. Most of | |
1948 | the commands make each line a separate sort record, but some commands use | |
1949 | paragraphs or pages as sort records. Most of the sort commands use each | |
1950 | entire sort record as its own sort key, but some use only a portion of the | |
1951 | record as the sort key. | |
1952 | ||
1953 | @findex sort-lines | |
1954 | @findex sort-paragraphs | |
1955 | @findex sort-pages | |
1956 | @findex sort-fields | |
1957 | @findex sort-numeric-fields | |
efd68b8a | 1958 | @vindex sort-numeric-base |
6bf7aab6 DL |
1959 | @table @kbd |
1960 | @item M-x sort-lines | |
1961 | Divide the region into lines, and sort by comparing the entire | |
1962 | text of a line. A numeric argument means sort into descending order. | |
1963 | ||
1964 | @item M-x sort-paragraphs | |
1965 | Divide the region into paragraphs, and sort by comparing the entire | |
1966 | text of a paragraph (except for leading blank lines). A numeric | |
1967 | argument means sort into descending order. | |
1968 | ||
1969 | @item M-x sort-pages | |
1970 | Divide the region into pages, and sort by comparing the entire | |
1971 | text of a page (except for leading blank lines). A numeric | |
1972 | argument means sort into descending order. | |
1973 | ||
1974 | @item M-x sort-fields | |
1975 | Divide the region into lines, and sort by comparing the contents of | |
1976 | one field in each line. Fields are defined as separated by | |
1977 | whitespace, so the first run of consecutive non-whitespace characters | |
1978 | in a line constitutes field 1, the second such run constitutes field | |
1979 | 2, etc. | |
1980 | ||
1981 | Specify which field to sort by with a numeric argument: 1 to sort by | |
1982 | field 1, etc. A negative argument means count fields from the right | |
1983 | instead of from the left; thus, minus 1 means sort by the last field. | |
1984 | If several lines have identical contents in the field being sorted, they | |
021037cb | 1985 | keep the same relative order that they had in the original buffer. |
6bf7aab6 DL |
1986 | |
1987 | @item M-x sort-numeric-fields | |
1988 | Like @kbd{M-x sort-fields} except the specified field is converted | |
1989 | to an integer for each line, and the numbers are compared. @samp{10} | |
1990 | comes before @samp{2} when considered as text, but after it when | |
efd68b8a GM |
1991 | considered as a number. By default, numbers are interpreted according |
1992 | to @code{sort-numeric-base}, but numbers beginning with @samp{0x} or | |
1993 | @samp{0} are interpreted as hexadecimal and octal, respectively. | |
6bf7aab6 DL |
1994 | |
1995 | @item M-x sort-columns | |
1996 | Like @kbd{M-x sort-fields} except that the text within each line | |
1997 | used for comparison comes from a fixed range of columns. See below | |
1998 | for an explanation. | |
1999 | ||
2000 | @item M-x reverse-region | |
2001 | Reverse the order of the lines in the region. This is useful for | |
2002 | sorting into descending order by fields or columns, since those sort | |
2003 | commands do not have a feature for doing that. | |
2004 | @end table | |
2005 | ||
2006 | For example, if the buffer contains this: | |
2007 | ||
2008 | @smallexample | |
2009 | On systems where clash detection (locking of files being edited) is | |
2010 | implemented, Emacs also checks the first time you modify a buffer | |
2011 | whether the file has changed on disk since it was last visited or | |
2012 | saved. If it has, you are asked to confirm that you want to change | |
2013 | the buffer. | |
2014 | @end smallexample | |
2015 | ||
2016 | @noindent | |
2017 | applying @kbd{M-x sort-lines} to the entire buffer produces this: | |
2018 | ||
2019 | @smallexample | |
2020 | On systems where clash detection (locking of files being edited) is | |
2021 | implemented, Emacs also checks the first time you modify a buffer | |
2022 | saved. If it has, you are asked to confirm that you want to change | |
2023 | the buffer. | |
2024 | whether the file has changed on disk since it was last visited or | |
2025 | @end smallexample | |
2026 | ||
2027 | @noindent | |
2028 | where the upper-case @samp{O} sorts before all lower-case letters. If | |
2029 | you use @kbd{C-u 2 M-x sort-fields} instead, you get this: | |
2030 | ||
2031 | @smallexample | |
2032 | implemented, Emacs also checks the first time you modify a buffer | |
2033 | saved. If it has, you are asked to confirm that you want to change | |
2034 | the buffer. | |
2035 | On systems where clash detection (locking of files being edited) is | |
2036 | whether the file has changed on disk since it was last visited or | |
2037 | @end smallexample | |
2038 | ||
2039 | @noindent | |
2040 | where the sort keys were @samp{Emacs}, @samp{If}, @samp{buffer}, | |
2041 | @samp{systems} and @samp{the}. | |
2042 | ||
2043 | @findex sort-columns | |
2044 | @kbd{M-x sort-columns} requires more explanation. You specify the | |
2045 | columns by putting point at one of the columns and the mark at the other | |
2046 | column. Because this means you cannot put point or the mark at the | |
2047 | beginning of the first line of the text you want to sort, this command | |
2684ed46 | 2048 | uses an unusual definition of ``region'': all of the line point is in is |
6bf7aab6 DL |
2049 | considered part of the region, and so is all of the line the mark is in, |
2050 | as well as all the lines in between. | |
2051 | ||
2052 | For example, to sort a table by information found in columns 10 to 15, | |
2053 | you could put the mark on column 10 in the first line of the table, and | |
2054 | point on column 15 in the last line of the table, and then run | |
2055 | @code{sort-columns}. Equivalently, you could run it with the mark on | |
2056 | column 15 in the first line and point on column 10 in the last line. | |
2057 | ||
2058 | This can be thought of as sorting the rectangle specified by point and | |
2059 | the mark, except that the text on each line to the left or right of the | |
2060 | rectangle moves along with the text inside the rectangle. | |
2061 | @xref{Rectangles}. | |
2062 | ||
2063 | @vindex sort-fold-case | |
2064 | Many of the sort commands ignore case differences when comparing, if | |
2065 | @code{sort-fold-case} is non-@code{nil}. | |
2066 | ||
f404f8bc CY |
2067 | @c Picture Mode documentation |
2068 | @ifnottex | |
2069 | @include picture-xtra.texi | |
2070 | @end ifnottex | |
6bf7aab6 | 2071 | |
6bf7aab6 | 2072 | |
f404f8bc | 2073 | @node Editing Binary Files |
6bf7aab6 DL |
2074 | @section Editing Binary Files |
2075 | ||
2076 | @cindex Hexl mode | |
2077 | @cindex mode, Hexl | |
2078 | @cindex editing binary files | |
c965d0ac | 2079 | @cindex hex editing |
6bf7aab6 DL |
2080 | There is a special major mode for editing binary files: Hexl mode. To |
2081 | use it, use @kbd{M-x hexl-find-file} instead of @kbd{C-x C-f} to visit | |
2082 | the file. This command converts the file's contents to hexadecimal and | |
2083 | lets you edit the translation. When you save the file, it is converted | |
2084 | automatically back to binary. | |
2085 | ||
2086 | You can also use @kbd{M-x hexl-mode} to translate an existing buffer | |
2087 | into hex. This is useful if you visit a file normally and then discover | |
2088 | it is a binary file. | |
2089 | ||
2090 | Ordinary text characters overwrite in Hexl mode. This is to reduce | |
2091 | the risk of accidentally spoiling the alignment of data in the file. | |
2092 | There are special commands for insertion. Here is a list of the | |
2093 | commands of Hexl mode: | |
2094 | ||
2095 | @c I don't think individual index entries for these commands are useful--RMS. | |
2096 | @table @kbd | |
2097 | @item C-M-d | |
2098 | Insert a byte with a code typed in decimal. | |
2099 | ||
2100 | @item C-M-o | |
2101 | Insert a byte with a code typed in octal. | |
2102 | ||
2103 | @item C-M-x | |
2104 | Insert a byte with a code typed in hex. | |
2105 | ||
2106 | @item C-x [ | |
2107 | Move to the beginning of a 1k-byte ``page.'' | |
2108 | ||
2109 | @item C-x ] | |
2110 | Move to the end of a 1k-byte ``page.'' | |
2111 | ||
2112 | @item M-g | |
2113 | Move to an address specified in hex. | |
2114 | ||
2115 | @item M-j | |
2116 | Move to an address specified in decimal. | |
2117 | ||
2118 | @item C-c C-c | |
2119 | Leave Hexl mode, going back to the major mode this buffer had before you | |
2120 | invoked @code{hexl-mode}. | |
2121 | @end table | |
2122 | ||
c965d0ac | 2123 | @noindent |
fc98b4ba | 2124 | Other Hexl commands let you insert strings (sequences) of binary |
021037cb EZ |
2125 | bytes, move by @code{short}s or @code{int}s, etc.; type @kbd{C-h a |
2126 | hexl-@key{RET}} for details. | |
c965d0ac EZ |
2127 | |
2128 | ||
6bf7aab6 DL |
2129 | @node Saving Emacs Sessions, Recursive Edit, Editing Binary Files, Top |
2130 | @section Saving Emacs Sessions | |
2131 | @cindex saving sessions | |
24cd2514 EZ |
2132 | @cindex restore session |
2133 | @cindex remember editing session | |
2134 | @cindex reload files | |
6bf7aab6 DL |
2135 | @cindex desktop |
2136 | ||
6a51fedc RS |
2137 | Use the desktop library to save the state of Emacs from one session |
2138 | to another. Once you save the Emacs @dfn{desktop}---the buffers, | |
2139 | their file names, major modes, buffer positions, and so on---then | |
2140 | subsequent Emacs sessions reload the saved desktop. | |
6bf7aab6 | 2141 | |
6a51fedc | 2142 | @findex desktop-save |
080e83d1 | 2143 | @vindex desktop-save-mode |
6a51fedc | 2144 | You can save the desktop manually with the command @kbd{M-x |
1096b4a0 RS |
2145 | desktop-save}. You can also enable automatic saving of the desktop |
2146 | when you exit Emacs, and automatic restoration of the last saved | |
2147 | desktop when Emacs starts: use the Customization buffer (@pxref{Easy | |
2148 | Customization}) to set @code{desktop-save-mode} to @code{t} for future | |
932fd020 | 2149 | sessions, or add this line in your init file (@pxref{Init File}): |
6bf7aab6 DL |
2150 | |
2151 | @example | |
080e83d1 | 2152 | (desktop-save-mode 1) |
6bf7aab6 DL |
2153 | @end example |
2154 | ||
080e83d1 LH |
2155 | @findex desktop-change-dir |
2156 | @findex desktop-revert | |
e4a0188a | 2157 | @vindex desktop-path |
932fd020 CY |
2158 | If you turn on @code{desktop-save-mode} in your init file, then when |
2159 | Emacs starts, it looks for a saved desktop in the current directory. | |
e4a0188a GM |
2160 | (More precisely, it looks in the directories specified by |
2161 | @var{desktop-path}, and uses the first desktop it finds.) | |
932fd020 CY |
2162 | Thus, you can have separate saved desktops in different directories, |
2163 | and the starting directory determines which one Emacs reloads. You | |
2164 | can save the current desktop and reload one saved in another directory | |
2165 | by typing @kbd{M-x desktop-change-dir}. Typing @kbd{M-x | |
2166 | desktop-revert} reverts to the desktop previously reloaded. | |
080e83d1 | 2167 | |
6a51fedc | 2168 | Specify the option @samp{--no-desktop} on the command line when you |
b9ed2fa6 | 2169 | don't want it to reload any saved desktop. This turns off |
5bfef96c EZ |
2170 | @code{desktop-save-mode} for the current session. Starting Emacs with |
2171 | the @samp{--no-init-file} option also disables desktop reloading, | |
932fd020 CY |
2172 | since it bypasses the init file, where @code{desktop-save-mode} is |
2173 | usually turned on. | |
6bf7aab6 | 2174 | |
a3f7375f RS |
2175 | @vindex desktop-restore-eager |
2176 | By default, all the buffers in the desktop are restored at one go. | |
2177 | However, this may be slow if there are a lot of buffers in the | |
2178 | desktop. You can specify the maximum number of buffers to restore | |
2179 | immediately with the variable @code{desktop-restore-eager}; the | |
2180 | remaining buffers are restored ``lazily,'' when Emacs is idle. | |
2181 | ||
080e83d1 | 2182 | @findex desktop-clear |
080e83d1 LH |
2183 | @vindex desktop-globals-to-clear |
2184 | @vindex desktop-clear-preserve-buffers-regexp | |
6a51fedc RS |
2185 | Type @kbd{M-x desktop-clear} to empty the Emacs desktop. This kills |
2186 | all buffers except for internal ones, and clears the global variables | |
2187 | listed in @code{desktop-globals-to-clear}. If you want this to | |
080e83d1 | 2188 | preserve certain buffers, customize the variable |
6a51fedc RS |
2189 | @code{desktop-clear-preserve-buffers-regexp}, whose value is a regular |
2190 | expression matching the names of buffers not to kill. | |
17a4f5ec | 2191 | |
89b5d9ab RS |
2192 | If you want to save minibuffer history from one session to |
2193 | another, use the @code{savehist} library. | |
2194 | ||
6bf7aab6 DL |
2195 | @node Recursive Edit, Emulation, Saving Emacs Sessions, Top |
2196 | @section Recursive Editing Levels | |
2197 | @cindex recursive editing level | |
2198 | @cindex editing level, recursive | |
2199 | ||
2200 | A @dfn{recursive edit} is a situation in which you are using Emacs | |
2201 | commands to perform arbitrary editing while in the middle of another | |
2202 | Emacs command. For example, when you type @kbd{C-r} inside of a | |
2203 | @code{query-replace}, you enter a recursive edit in which you can change | |
2204 | the current buffer. On exiting from the recursive edit, you go back to | |
2205 | the @code{query-replace}. | |
2206 | ||
2207 | @kindex C-M-c | |
2208 | @findex exit-recursive-edit | |
2209 | @cindex exiting recursive edit | |
2210 | @dfn{Exiting} the recursive edit means returning to the unfinished | |
2211 | command, which continues execution. The command to exit is @kbd{C-M-c} | |
2212 | (@code{exit-recursive-edit}). | |
2213 | ||
2214 | You can also @dfn{abort} the recursive edit. This is like exiting, | |
2215 | but also quits the unfinished command immediately. Use the command | |
2216 | @kbd{C-]} (@code{abort-recursive-edit}) to do this. @xref{Quitting}. | |
2217 | ||
2218 | The mode line shows you when you are in a recursive edit by displaying | |
2219 | square brackets around the parentheses that always surround the major and | |
021037cb | 2220 | minor mode names. Every window's mode line shows this in the same way, |
6bf7aab6 DL |
2221 | since being in a recursive edit is true of Emacs as a whole rather than |
2222 | any particular window or buffer. | |
2223 | ||
2224 | It is possible to be in recursive edits within recursive edits. For | |
2225 | example, after typing @kbd{C-r} in a @code{query-replace}, you may type a | |
2226 | command that enters the debugger. This begins a recursive editing level | |
2227 | for the debugger, within the recursive editing level for @kbd{C-r}. | |
2228 | Mode lines display a pair of square brackets for each recursive editing | |
2229 | level currently in progress. | |
2230 | ||
982dcb1b | 2231 | Exiting the inner recursive edit (such as with the debugger @kbd{c} |
6bf7aab6 DL |
2232 | command) resumes the command running in the next level up. When that |
2233 | command finishes, you can then use @kbd{C-M-c} to exit another recursive | |
2234 | editing level, and so on. Exiting applies to the innermost level only. | |
2235 | Aborting also gets out of only one level of recursive edit; it returns | |
2236 | immediately to the command level of the previous recursive edit. If you | |
2237 | wish, you can then abort the next recursive editing level. | |
2238 | ||
2239 | Alternatively, the command @kbd{M-x top-level} aborts all levels of | |
25ed034e CY |
2240 | recursive edits, returning immediately to the top-level command |
2241 | reader. It also exits the minibuffer, if it is active. | |
6bf7aab6 DL |
2242 | |
2243 | The text being edited inside the recursive edit need not be the same text | |
2244 | that you were editing at top level. It depends on what the recursive edit | |
2245 | is for. If the command that invokes the recursive edit selects a different | |
2246 | buffer first, that is the buffer you will edit recursively. In any case, | |
2247 | you can switch buffers within the recursive edit in the normal manner (as | |
2248 | long as the buffer-switching keys have not been rebound). You could | |
2249 | probably do all the rest of your editing inside the recursive edit, | |
2250 | visiting files and all. But this could have surprising effects (such as | |
2251 | stack overflow) from time to time. So remember to exit or abort the | |
2252 | recursive edit when you no longer need it. | |
2253 | ||
2254 | In general, we try to minimize the use of recursive editing levels in | |
2255 | GNU Emacs. This is because they constrain you to ``go back'' in a | |
2256 | particular order---from the innermost level toward the top level. When | |
2257 | possible, we present different activities in separate buffers so that | |
2258 | you can switch between them as you please. Some commands switch to a | |
2259 | new major mode which provides a command to switch back. These | |
2260 | approaches give you more flexibility to go back to unfinished tasks in | |
2261 | the order you choose. | |
2262 | ||
3f724e9a | 2263 | @node Emulation, Hyperlinking, Recursive Edit, Top |
6bf7aab6 DL |
2264 | @section Emulation |
2265 | @cindex emulating other editors | |
2266 | @cindex other editors | |
2267 | @cindex EDT | |
2268 | @cindex vi | |
d0960fb3 | 2269 | @cindex PC key bindings |
3b65ce47 | 2270 | @cindex scrolling all windows |
d0960fb3 RS |
2271 | @cindex PC selection |
2272 | @cindex Motif key bindings | |
2273 | @cindex Macintosh key bindings | |
3b65ce47 | 2274 | @cindex WordStar |
6bf7aab6 DL |
2275 | |
2276 | GNU Emacs can be programmed to emulate (more or less) most other | |
2277 | editors. Standard facilities can emulate these: | |
2278 | ||
2279 | @table @asis | |
3b65ce47 DL |
2280 | @item CRiSP/Brief (PC editor) |
2281 | @findex crisp-mode | |
2282 | @vindex crisp-override-meta-x | |
2283 | @findex scroll-all-mode | |
b1a92ebf DL |
2284 | @cindex CRiSP mode |
2285 | @cindex Brief emulation | |
4946337d | 2286 | @cindex emulation of Brief |
b1a92ebf | 2287 | @cindex mode, CRiSP |
d0960fb3 | 2288 | You can turn on key bindings to emulate the CRiSP/Brief editor with |
b1a92ebf | 2289 | @kbd{M-x crisp-mode}. Note that this rebinds @kbd{M-x} to exit Emacs |
19b2c4ca RS |
2290 | unless you set the variable @code{crisp-override-meta-x}. You can |
2291 | also use the command @kbd{M-x scroll-all-mode} or set the variable | |
b1a92ebf DL |
2292 | @code{crisp-load-scroll-all} to emulate CRiSP's scroll-all feature |
2293 | (scrolling all windows together). | |
3b65ce47 | 2294 | |
6bf7aab6 DL |
2295 | @item EDT (DEC VMS editor) |
2296 | @findex edt-emulation-on | |
2297 | @findex edt-emulation-off | |
ae742cb5 CY |
2298 | Turn on EDT emulation @kbd{M-x edt-emulation-on}; use @kbd{M-x |
2299 | edt-emulation-off} to restore normal Emacs command bindings. | |
6bf7aab6 DL |
2300 | |
2301 | Most of the EDT emulation commands are keypad keys, and most standard | |
2302 | Emacs key bindings are still available. The EDT emulation rebindings | |
2303 | are done in the global keymap, so there is no problem switching | |
2304 | buffers or major modes while in EDT emulation. | |
2305 | ||
3f724e9a DL |
2306 | @item TPU (DEC VMS editor) |
2307 | @findex tpu-edt-on | |
2308 | @cindex TPU | |
2309 | @kbd{M-x tpu-edt-on} turns on emulation of the TPU editor emulating EDT. | |
2310 | ||
6bf7aab6 DL |
2311 | @item vi (Berkeley editor) |
2312 | @findex viper-mode | |
2313 | Viper is the newest emulator for vi. It implements several levels of | |
2314 | emulation; level 1 is closest to vi itself, while level 5 departs | |
2315 | somewhat from strict emulation to take advantage of the capabilities of | |
2316 | Emacs. To invoke Viper, type @kbd{M-x viper-mode}; it will guide you | |
2317 | the rest of the way and ask for the emulation level. @inforef{Top, | |
2318 | Viper, viper}. | |
2319 | ||
2320 | @item vi (another emulator) | |
2321 | @findex vi-mode | |
2322 | @kbd{M-x vi-mode} enters a major mode that replaces the previously | |
2323 | established major mode. All of the vi commands that, in real vi, enter | |
2324 | ``input'' mode are programmed instead to return to the previous major | |
2325 | mode. Thus, ordinary Emacs serves as vi's ``input'' mode. | |
2326 | ||
2327 | Because vi emulation works through major modes, it does not work | |
2328 | to switch buffers during emulation. Return to normal Emacs first. | |
2329 | ||
2330 | If you plan to use vi emulation much, you probably want to bind a key | |
2331 | to the @code{vi-mode} command. | |
2332 | ||
2333 | @item vi (alternate emulator) | |
2334 | @findex vip-mode | |
2335 | @kbd{M-x vip-mode} invokes another vi emulator, said to resemble real vi | |
2336 | more thoroughly than @kbd{M-x vi-mode}. ``Input'' mode in this emulator | |
2337 | is changed from ordinary Emacs so you can use @key{ESC} to go back to | |
2338 | emulated vi command mode. To get from emulated vi command mode back to | |
2339 | ordinary Emacs, type @kbd{C-z}. | |
2340 | ||
2341 | This emulation does not work through major modes, and it is possible | |
2342 | to switch buffers in various ways within the emulator. It is not | |
2343 | so necessary to assign a key to the command @code{vip-mode} as | |
2344 | it is with @code{vi-mode} because terminating insert mode does | |
2345 | not use it. | |
2346 | ||
2347 | @inforef{Top, VIP, vip}, for full information. | |
3b65ce47 DL |
2348 | |
2349 | @item WordStar (old wordprocessor) | |
2350 | @findex wordstar-mode | |
2351 | @kbd{M-x wordstar-mode} provides a major mode with WordStar-like | |
d0960fb3 | 2352 | key bindings. |
6bf7aab6 DL |
2353 | @end table |
2354 | ||
ecd0b990 | 2355 | @node Hyperlinking, Amusements, Emulation, Top |
3f724e9a DL |
2356 | @section Hyperlinking and Navigation Features |
2357 | ||
2358 | @cindex hyperlinking | |
3f724e9a | 2359 | @cindex navigation |
df9d7630 RS |
2360 | Various modes documented elsewhere have hypertext features so that |
2361 | you can follow links, usually by clicking @kbd{Mouse-2} on the link or | |
982dcb1b RS |
2362 | typing @key{RET} while point is on the link. Clicking @kbd{Mouse-1} |
2363 | quickly on the link also follows it. (Hold @kbd{Mouse-1} for longer | |
2364 | if you want to set point instead.) | |
2365 | ||
2366 | Info mode, Help mode and the Dired-like modes are examples of modes | |
2367 | that have links in the buffer. The Tags facility links between uses | |
2368 | and definitions in source files, see @ref{Tags}. Imenu provides | |
df9d7630 RS |
2369 | navigation amongst items indexed in the current buffer, see |
2370 | @ref{Imenu}. Info-lookup provides mode-specific lookup of definitions | |
2371 | in Info indexes, see @ref{Documentation}. Speedbar maintains a frame | |
2372 | in which links to files, and locations in files are displayed, see | |
2373 | @ref{Speedbar}. | |
2374 | ||
2375 | Other non-mode-specific facilities described in this section enable | |
2376 | following links from the current buffer in a context-sensitive | |
2377 | fashion. | |
3f724e9a | 2378 | |
b1a92ebf DL |
2379 | @menu |
2380 | * Browse-URL:: Following URLs. | |
39791e03 | 2381 | * Goto Address mode:: Activating URLs. |
b1a92ebf | 2382 | * FFAP:: Finding files etc. at point. |
b1a92ebf DL |
2383 | @end menu |
2384 | ||
2385 | @node Browse-URL | |
2386 | @subsection Following URLs | |
3f724e9a | 2387 | @cindex World Wide Web |
b1a92ebf | 2388 | @cindex Web |
3f724e9a DL |
2389 | @findex browse-url |
2390 | @findex browse-url-at-point | |
2391 | @findex browse-url-at-mouse | |
3f724e9a DL |
2392 | @cindex Browse-URL |
2393 | @cindex URLs | |
b1a92ebf DL |
2394 | |
2395 | @table @kbd | |
fc98b4ba | 2396 | @item M-x browse-url @key{RET} @var{url} @key{RET} |
b1a92ebf DL |
2397 | Load a URL into a Web browser. |
2398 | @end table | |
2399 | ||
3f724e9a DL |
2400 | The Browse-URL package provides facilities for following URLs specifying |
2401 | links on the World Wide Web. Usually this works by invoking a web | |
df9d7630 RS |
2402 | browser, but you can, for instance, arrange to invoke @code{compose-mail} |
2403 | from @samp{mailto:} URLs. | |
2404 | ||
2405 | The general way to use this feature is to type @kbd{M-x browse-url}, | |
2406 | which displays a specified URL. If point is located near a plausible | |
2407 | URL, that URL is used as the default. Other commands are available | |
2408 | which you might like to bind to keys, such as | |
b1a92ebf | 2409 | @code{browse-url-at-point} and @code{browse-url-at-mouse}. |
3f724e9a | 2410 | |
b1a92ebf | 2411 | @vindex browse-url-browser-function |
39cf6a8d | 2412 | You can customize Browse-URL's behavior via various options in the |
b1a92ebf | 2413 | @code{browse-url} Customize group, particularly |
df9d7630 RS |
2414 | @code{browse-url-browser-function}. You can invoke actions dependent |
2415 | on the type of URL by defining @code{browse-url-browser-function} as | |
2416 | an association list. The package's commentary available via @kbd{C-h | |
23c9ed48 JL |
2417 | p} under the @samp{hypermedia} keyword provides more information. |
2418 | Packages with facilities for following URLs should always go through | |
2419 | Browse-URL, so that the customization options for Browse-URL will | |
2420 | affect all browsing in Emacs. | |
3f724e9a | 2421 | |
39791e03 | 2422 | @node Goto Address mode |
b1a92ebf | 2423 | @subsection Activating URLs |
39791e03 CY |
2424 | @findex goto-address-mode |
2425 | @cindex Goto Address mode | |
3f724e9a | 2426 | @cindex URLs, activating |
b1a92ebf DL |
2427 | |
2428 | @table @kbd | |
39791e03 | 2429 | @item M-x goto-address-mode |
b1a92ebf DL |
2430 | Activate URLs and e-mail addresses in the current buffer. |
2431 | @end table | |
2432 | ||
df9d7630 | 2433 | You can make URLs in the current buffer active with @kbd{M-x |
39791e03 CY |
2434 | goto-address-mode}. This minor mode finds all the URLs in the buffer, |
2435 | highlights them, and turns them into @dfn{buttons}: if you click on a | |
2436 | URL with @kbd{Mouse-1} or @kbd{Mouse-2} (@pxref{Mouse References}), or | |
2437 | move to the URL and type @kbd{C-c @key{RET}}, that displays the web | |
2438 | page that the URL specifies. For a @samp{mailto} URL, it sends mail | |
2439 | instead, using your selected mail-composition method (@pxref{Mail | |
2440 | Methods}). | |
2441 | ||
2442 | It can be useful to add @code{goto-address-mode} to mode hooks and | |
2443 | the hooks used to display an incoming message (e.g., | |
2444 | @code{rmail-show-message-hook} for Rmail, and @code{mh-show-mode-hook} | |
2445 | for MH-E). This is not needed for Gnus, which has a similar feature | |
2446 | of its own. | |
3f724e9a | 2447 | |
b1a92ebf DL |
2448 | @node FFAP |
2449 | @subsection Finding Files and URLs at Point | |
3f724e9a DL |
2450 | @findex find-file-at-point |
2451 | @findex ffap | |
37ed0ee5 | 2452 | @findex dired-at-point |
b1a92ebf DL |
2453 | @findex ffap-next |
2454 | @findex ffap-menu | |
b1a92ebf DL |
2455 | @cindex finding file at point |
2456 | ||
df9d7630 RS |
2457 | FFAP mode replaces certain key bindings for finding files, including |
2458 | @kbd{C-x C-f}, with commands that provide more sensitive defaults. | |
2459 | These commands behave like the ordinary ones when given a prefix | |
2460 | argument. Otherwise, they get the default file name or URL from the | |
2461 | text around point. If what is found in the buffer has the form of a | |
2462 | URL rather than a file name, the commands use @code{browse-url} to | |
2463 | view it. | |
b1a92ebf | 2464 | |
df9d7630 RS |
2465 | This feature is useful for following references in mail or news |
2466 | buffers, @file{README} files, @file{MANIFEST} files, and so on. The | |
23c9ed48 JL |
2467 | @samp{ffap} package's commentary available via @kbd{C-h p} under the |
2468 | @samp{files} keyword and the @code{ffap} Custom group provide details. | |
b1a92ebf DL |
2469 | |
2470 | @cindex FFAP minor mode | |
2471 | @findex ffap-mode | |
23c9ed48 JL |
2472 | You can turn on FFAP minor mode by calling @code{ffap-bindings} to |
2473 | make the following key bindings and to install hooks for using | |
2474 | @code{ffap} in Rmail, Gnus and VM article buffers. | |
b1a92ebf DL |
2475 | |
2476 | @table @kbd | |
df9d7630 | 2477 | @item C-x C-f @var{filename} @key{RET} |
b1a92ebf | 2478 | @kindex C-x C-f @r{(FFAP)} |
df9d7630 RS |
2479 | Find @var{filename}, guessing a default from text around point |
2480 | (@code{find-file-at-point}). | |
b79529b7 JL |
2481 | @item C-x C-r |
2482 | @kindex C-x C-r @r{(FFAP)} | |
2483 | @code{ffap-read-only}, analogous to @code{find-file-read-only}. | |
2484 | @item C-x C-v | |
2485 | @kindex C-x C-v @r{(FFAP)} | |
2486 | @code{ffap-alternate-file}, analogous to @code{find-alternate-file}. | |
2487 | @item C-x d @var{directory} @key{RET} | |
2488 | @kindex C-x d @r{(FFAP)} | |
2489 | Start Dired on @var{directory}, defaulting to the directory name at | |
37ed0ee5 | 2490 | point (@code{dired-at-point}). |
b79529b7 JL |
2491 | @item C-x C-d |
2492 | @code{ffap-list-directory}, analogous to @code{list-directory}. | |
b1a92ebf DL |
2493 | @item C-x 4 f |
2494 | @kindex C-x 4 f @r{(FFAP)} | |
df9d7630 | 2495 | @code{ffap-other-window}, analogous to @code{find-file-other-window}. |
b79529b7 JL |
2496 | @item C-x 4 r |
2497 | @code{ffap-read-only-other-window}, analogous to | |
2498 | @code{find-file-read-only-other-window}. | |
2499 | @item C-x 4 d | |
2500 | @code{ffap-dired-other-window}, analogous to @code{dired-other-window}. | |
b1a92ebf DL |
2501 | @item C-x 5 f |
2502 | @kindex C-x 5 f @r{(FFAP)} | |
df9d7630 | 2503 | @code{ffap-other-frame}, analogous to @code{find-file-other-frame}. |
b79529b7 JL |
2504 | @item C-x 5 r |
2505 | @code{ffap-read-only-other-frame}, analogous to | |
2506 | @code{find-file-read-only-other-frame}. | |
2507 | @item C-x 5 d | |
2508 | @code{ffap-dired-other-frame}, analogous to @code{dired-other-frame}. | |
df9d7630 RS |
2509 | @item M-x ffap-next |
2510 | Search buffer for next file name or URL, then find that file or URL. | |
df9d7630 RS |
2511 | @item S-Mouse-3 |
2512 | @kindex S-Mouse-3 @r{(FFAP)} | |
b1a92ebf | 2513 | @code{ffap-at-mouse} finds the file guessed from text around the position |
df9d7630 RS |
2514 | of a mouse click. |
2515 | @item C-S-Mouse-3 | |
2516 | @kindex C-S-Mouse-3 @r{(FFAP)} | |
2517 | Display a menu of files and URLs mentioned in current buffer, then | |
2518 | find the one you select (@code{ffap-menu}). | |
b1a92ebf DL |
2519 | @end table |
2520 | ||
d43f5a42 | 2521 | @node Amusements, Packages, Hyperlinking, Top |
6bf7aab6 DL |
2522 | @section Other Amusements |
2523 | @cindex boredom | |
6bf7aab6 | 2524 | |
ecd0b990 CY |
2525 | @findex animate-birthday-present |
2526 | @cindex animate | |
2527 | The @code{animate} package makes text dance. For an example, try | |
2528 | @kbd{M-x animate-birthday-present}. | |
50dd7bc6 | 2529 | |
6bf7aab6 DL |
2530 | @findex blackbox |
2531 | @findex mpuz | |
3b65ce47 | 2532 | @findex 5x5 |
6bf7aab6 | 2533 | @cindex puzzles |
ab192107 | 2534 | @kbd{M-x blackbox}, @kbd{M-x mpuz} and @kbd{M-x 5x5} are puzzles. |
6bf7aab6 DL |
2535 | @code{blackbox} challenges you to determine the location of objects |
2536 | inside a box by tomography. @code{mpuz} displays a multiplication | |
2537 | puzzle with letters standing for digits in a code that you must | |
2538 | guess---to guess a value, type a letter and then the digit you think it | |
3b65ce47 | 2539 | stands for. The aim of @code{5x5} is to fill in all the squares. |
6bf7aab6 | 2540 | |
ecd0b990 CY |
2541 | @findex bubbles |
2542 | @kbd{M-x bubbles} is a game in which the object is to remove as many | |
2543 | bubbles as you can in the smallest number of moves. | |
2544 | ||
b1a92ebf DL |
2545 | @findex decipher |
2546 | @cindex ciphers | |
2547 | @cindex cryptanalysis | |
ecd0b990 CY |
2548 | @kbd{M-x decipher} helps you to cryptanalyze a buffer which is |
2549 | encrypted in a simple monoalphabetic substitution cipher. | |
2550 | ||
2551 | @findex dissociated-press | |
2552 | @kbd{M-x dissociated-press} scrambles the text in the current Emacs | |
2553 | buffer, word by word or character by character, writing its output to | |
2554 | a buffer named @samp{*Dissociation*}. A positive argument tells it to | |
2555 | operate character by character, and specifies the number of overlap | |
2556 | characters. A negative argument tells it to operate word by word, and | |
2557 | specifies the number of overlap words. Dissociated Press produces | |
2558 | results fairly like those of a Markov chain, but is however, an | |
2559 | independent, ignoriginal invention; it techniquitously copies several | |
2560 | consecutive characters from the sample text between random jumps, | |
2561 | unlike a Markov chain which would jump randomly after each word or | |
2562 | character. Keep dissociwords out of your documentation, if you want | |
2563 | it to be well userenced and properbose. | |
b1a92ebf | 2564 | |
6bf7aab6 | 2565 | @findex dunnet |
ecd0b990 | 2566 | @kbd{M-x dunnet} runs an text-based adventure game. |
6bf7aab6 | 2567 | |
ecd0b990 CY |
2568 | @findex gomoku |
2569 | @cindex Go Moku | |
2570 | If you want a little more personal involvement, try @kbd{M-x gomoku}, | |
2571 | which plays the game Go Moku with you. | |
2572 | ||
2573 | @cindex tower of Hanoi | |
2574 | @findex hanoi | |
2575 | If you are a little bit bored, you can try @kbd{M-x hanoi}. If you are | |
2576 | considerably bored, give it a numeric argument. If you are very, very | |
2577 | bored, try an argument of 9. Sit back and watch. | |
3b65ce47 DL |
2578 | |
2579 | @findex life | |
2580 | @cindex Life | |
ecd0b990 CY |
2581 | @kbd{M-x life} runs Conway's ``Life'' cellular automaton. |
2582 | ||
2583 | @findex lm | |
2584 | @cindex landmark game | |
2585 | @kbd{M-x lm} runs a relatively non-participatory game in which a | |
2586 | robot attempts to maneuver towards a tree at the center of the window | |
2587 | based on unique olfactory cues from each of the four directions. | |
3b65ce47 | 2588 | |
b1a92ebf DL |
2589 | @findex morse-region |
2590 | @findex unmorse-region | |
2591 | @cindex Morse code | |
2592 | @cindex --/---/.-./.../. | |
ecd0b990 | 2593 | @kbd{M-x morse-region} converts text in a region to Morse code and |
b1a92ebf DL |
2594 | @kbd{M-x unmorse-region} converts it back. No cause for remorse. |
2595 | ||
2596 | @findex pong | |
2597 | @cindex Pong game | |
3b65ce47 DL |
2598 | @findex tetris |
2599 | @cindex Tetris | |
3b65ce47 DL |
2600 | @findex snake |
2601 | @cindex Snake | |
ecd0b990 CY |
2602 | @kbd{M-x pong}, @kbd{M-x snake} and @kbd{M-x tetris} are |
2603 | implementations of the well-known Pong, Snake and Tetris games. | |
3b65ce47 | 2604 | |
ecd0b990 CY |
2605 | @findex solitaire |
2606 | @cindex solitaire | |
2607 | @kbd{M-x solitaire} plays a game of solitaire in which you jump pegs | |
2608 | across other pegs. | |
6bf7aab6 | 2609 | |
834d56ed | 2610 | @findex zone |
ecd0b990 CY |
2611 | The command @kbd{M-x zone} plays games with the display when Emacs |
2612 | is idle. | |
2613 | ||
2614 | Finally, if you find yourself frustrated, try the famous Eliza | |
2615 | program. Just do @kbd{M-x doctor}. End each input by typing | |
2616 | @key{RET} twice. | |
ab5796a9 | 2617 | |
2e7cfad6 LT |
2618 | @ifnottex |
2619 | @lowersections | |
2620 | @end ifnottex |