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