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