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