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