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