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