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