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