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