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