SXEmacs v22.1.16 is released!
[sxemacs] / info / sxemacs / misc.texi
1 @iftex
2 @chapter Miscellaneous Commands
3
4   This chapter contains several brief topics that do not fit anywhere else.
5
6 @end iftex
7
8 @node Sorting, Shell, Calendar/Diary, Top
9 @section Sorting Text
10 @cindex sorting
11
12   SXEmacs provides several commands for sorting text in a buffer.  All
13 operate on the contents of the region (the text between point and the
14 mark).  They divide the text of the region into many @dfn{sort records},
15 identify a @dfn{sort key} for each record, and then reorder the records
16 using the order determined by the sort keys.  The records are ordered so
17 that their keys are in alphabetical order, or, for numerical sorting, in
18 numerical order.  In alphabetical sorting, all upper-case letters `A'
19 through `Z' come before lower-case `a', in accordance with the ASCII
20 character sequence.
21
22   The sort commands differ in how they divide the text into sort
23 records and in which part of each record they use as the sort key.  Most of
24 the commands make each line a separate sort record, but some commands use
25 paragraphs or pages as sort records.  Most of the sort commands use each
26 entire sort record as its own sort key, but some use only a portion of the
27 record as the sort key.
28
29 @findex sort-lines
30 @findex sort-paragraphs
31 @findex sort-pages
32 @findex sort-fields
33 @findex sort-numeric-fields
34 @table @kbd
35 @item M-x sort-lines
36 Divide the region into lines and sort by comparing the entire
37 text of a line.  A prefix argument means sort in descending order.
38
39 @item M-x sort-paragraphs
40 Divide the region into paragraphs and sort by comparing the entire
41 text of a paragraph (except for leading blank lines).  A prefix
42 argument means sort in descending order.
43
44 @item M-x sort-pages
45 Divide the region into pages and sort by comparing the entire
46 text of a page (except for leading blank lines).  A prefix
47 argument means sort in descending order.
48
49 @item M-x sort-fields
50 Divide the region into lines and sort by comparing the contents of
51 one field in each line.  Fields are defined as separated by
52 whitespace, so the first run of consecutive non-whitespace characters
53 in a line constitutes field 1, the second such run constitutes field
54 2, etc.
55
56 You specify which field to sort by with a numeric argument: 1 to sort
57 by field 1, etc.  A negative argument means sort in descending
58 order.  Thus, minus 2 means sort by field 2 in reverse-alphabetical
59 order.
60
61 @item M-x sort-numeric-fields
62 Like @kbd{M-x sort-fields}, except the specified field is converted
63 to a number for each line and the numbers are compared.  @samp{10}
64 comes before @samp{2} when considered as text, but after it when
65 considered as a number.
66
67 @item M-x sort-columns
68 Like @kbd{M-x sort-fields}, except that the text within each line
69 used for comparison comes from a fixed range of columns.  An explanation
70 is given below.
71 @end table
72
73 For example, if the buffer contains:
74
75 @smallexample
76 On systems where clash detection (locking of files being edited) is
77 implemented, SXEmacs also checks the first time you modify a buffer
78 whether the file has changed on disk since it was last visited or
79 saved.  If it has, you are asked to confirm that you want to change
80 the buffer.
81 @end smallexample
82
83 @noindent
84 then if you apply @kbd{M-x sort-lines} to the entire buffer you get:
85
86 @smallexample
87 On systems where clash detection (locking of files being edited) is
88 implemented, SXEmacs also checks the first time you modify a buffer
89 saved.  If it has, you are asked to confirm that you want to change
90 the buffer.
91 whether the file has changed on disk since it was last visited or
92 @end smallexample
93
94 @noindent
95 where the upper case `O' comes before all lower case letters.  If you apply
96 instead @kbd{C-u 2 M-x sort-fields} you get:
97
98 @smallexample
99 saved.  If it has, you are asked to confirm that you want to change
100 implemented, SXEmacs also checks the first time you modify a buffer
101 the buffer.
102 On systems where clash detection (locking of files being edited) is
103 whether the file has changed on disk since it was last visited or
104 @end smallexample
105
106 @noindent
107 where the sort keys were @samp{If}, @samp{SXEmacs}, @samp{buffer},
108 @samp{systems}, and @samp{the}.@refill
109
110 @findex sort-columns
111   @kbd{M-x sort-columns} requires more explanation.  You specify the
112 columns by putting point at one of the columns and the mark at the other
113 column.  Because this means you cannot put point or the mark at the
114 beginning of the first line to sort, this command uses an unusual
115 definition of `region': all of the line point is in is considered part of
116 the region, and so is all of the line the mark is in.
117
118   For example, to sort a table by information found in columns 10 to 15,
119 you could put the mark on column 10 in the first line of the table, and
120 point on column 15 in the last line of the table, and then use this command.
121 Or you could put the mark on column 15 in the first line and point on
122 column 10 in the last line.
123
124   This can be thought of as sorting the rectangle specified by point and
125 the mark, except that the text on each line to the left or right of the
126 rectangle moves along with the text inside the rectangle.
127 @xref{Rectangles}.
128
129 @node Shell, Narrowing, Sorting, Top
130 @section Running Shell Commands from SXEmacs
131 @cindex subshell
132 @cindex shell commands
133
134   SXEmacs has commands for passing single command lines to inferior shell
135 processes; it can also run a shell interactively with input and output to
136 an SXEmacs buffer @samp{*shell*}.
137
138 @table @kbd
139 @item M-!
140 Run a specified shell command line and display the output
141 (@code{shell-command}).
142 @item M-|
143 Run a specified shell command line with region contents as input;
144 optionally replace the region with the output
145 (@code{shell-command-on-region}).
146 @item M-x shell
147 Run a subshell with input and output through an SXEmacs buffer.
148 You can then give commands interactively.
149 @item M-x term
150 Run a subshell with input and output through an SXEmacs buffer.
151 You can then give commands interactively.
152 Full terminal emulation is available.
153 @end table
154
155 @menu
156 * Single Shell::         How to run one shell command and return.
157 * Interactive Shell::    Permanent shell taking input via SXEmacs.
158 * Shell Mode::           Special SXEmacs commands used with permanent shell.
159 * Terminal emulator::    An SXEmacs window as a terminal emulator.
160 * Term Mode::            Special SXEmacs commands used in Term mode.
161 * Paging in Term::       Paging in the terminal emulator.
162 @end menu
163
164 @node Single Shell, Interactive Shell, Shell, Shell
165 @subsection Single Shell Commands
166
167 @kindex M-!
168 @findex shell-command
169   @kbd{M-!} (@code{shell-command}) reads a line of text using the
170 minibuffer and creates an inferior shell to execute the line as a command.
171 Standard input from the command comes from the null device.  If the shell
172 command produces any output, the output goes to an SXEmacs buffer named
173 @samp{*Shell Command Output*}, which is displayed in another window but not
174 selected.  A numeric argument, as in @kbd{M-1 M-!}, directs this command to
175 insert any output into the current buffer.  In that case, point is left
176 before the output and the mark is set after the output.
177
178 @kindex M-|
179 @findex shell-command-on-region
180   @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!} but passes
181 the contents of the region as input to the shell command, instead of no
182 input.  If a numeric argument is used to direct  output to the current
183 buffer, then the old region is deleted first and the output replaces it as
184 the contents of the region.@refill
185
186 @vindex shell-file-name
187 @cindex environment
188   Both @kbd{M-!} and @kbd{M-|} use @code{shell-file-name} to specify the
189 shell to use.  This variable is initialized based on your @code{SHELL}
190 environment variable when you start SXEmacs.  If the file name does not
191 specify a directory, the directories in the list @code{exec-path} are
192 searched; this list is initialized based on the @code{PATH} environment
193 variable when you start SXEmacs.  You can override either or both of these
194 default initializations in your init file. @xref{Init File}.@refill
195
196   When you use @kbd{M-!} and @kbd{M-|}, SXEmacs has to wait until the
197 shell command completes.  You can quit with @kbd{C-g}; that terminates
198 the shell command.
199
200 @node Interactive Shell, Shell Mode, Single Shell, Shell
201 @subsection Interactive Inferior Shell
202
203 @findex shell
204   To run a subshell interactively with its typescript in an SXEmacs
205 buffer, use @kbd{M-x shell}.  This creates (or reuses) a buffer named
206 @samp{*shell*} and runs a subshell with input coming from and output going
207 to that buffer.  That is to say, any ``terminal output'' from the subshell
208 will go into the buffer, advancing point, and any ``terminal input'' for
209 the subshell comes from text in the buffer.  To give input to the subshell,
210 go to the end of the buffer and type the input, terminated by @key{RET}.
211
212   SXEmacs does not wait for the subshell to do anything.  You can switch
213 windows or buffers and edit them while the shell is waiting, or while it is
214 running a command.  Output from the subshell waits until SXEmacs has time to
215 process it; this happens whenever SXEmacs is waiting for keyboard input or
216 for time to elapse.
217
218  To get multiple subshells, change the name of buffer
219 @samp{*shell*} to something different by using @kbd{M-x rename-buffer}.  The
220 next use of @kbd{M-x shell} creates a new buffer @samp{*shell*} with
221 its own subshell.  By renaming this buffer as well you can create a third
222 one, and so on.  All the subshells run independently and in parallel.
223
224 @vindex explicit-shell-file-name
225   The file name used to load the subshell is the value of the variable
226 @code{explicit-shell-file-name}, if that is non-@code{nil}.  Otherwise, the
227 environment variable @code{ESHELL} is used, or the environment variable
228 @code{SHELL} if there is no @code{ESHELL}.  If the file name specified
229 is relative, the directories in the list @code{exec-path} are searched
230 (@pxref{Single Shell,Single Shell Commands}).@refill
231
232   As soon as the subshell is started, it is sent as input the contents of
233 the file @file{~/.emacs_@var{shellname}}, if that file exists, where
234 @var{shellname} is the name of the file that the shell was loaded from.
235 For example, if you use @code{csh}, the file sent to it is
236 @file{~/.emacs_csh}.@refill
237
238 @vindex shell-pushd-regexp
239 @vindex shell-popd-regexp
240 @vindex shell-cd-regexp
241   @code{cd}, @code{pushd}, and @code{popd} commands given to the inferior
242 shell are watched by SXEmacs so it can keep the @samp{*shell*} buffer's
243 default directory the same as the shell's working directory.  These
244 commands are recognized syntactically by examining lines of input that are
245 sent.  If you use aliases for these commands, you can tell SXEmacs to
246 recognize them also.  For example, if the value of the variable
247 @code{shell-pushd-regexp} matches the beginning of a shell command line,
248 that line is regarded as a @code{pushd} command.  Change this variable when
249 you add aliases for @samp{pushd}.  Likewise, @code{shell-popd-regexp} and
250 @code{shell-cd-regexp} are used to recognize commands with the meaning of
251 @samp{popd} and @samp{cd}.@refill
252
253 @kbd{M-x shell-resync-dirs} queries the shell and resynchronizes SXEmacs'
254 idea of what the current directory stack is.  @kbd{M-x
255 shell-dirtrack-toggle} turns directory tracking on and off.
256
257 @vindex input-ring-size
258 SXEmacs keeps a history of the most recent commands you have typed in the
259 @samp{*shell*} buffer.  If you are at the beginning of a shell command
260 line and type @key{M-p}, the previous shell input is inserted into the
261 buffer before point.  Immediately typing @key{M-p} again deletes that
262 input and inserts the one before it.  By repeating @key{M-p} you can
263 move backward through your commands until you find one you want to
264 repeat.  You may then edit the command before typing @key{RET} if you
265 wish. @key{M-n} moves forward through the command history, in case you
266 moved backward past the one you wanted while using @key{M-p}.  If you
267 type the first few characters of a previous command and then type
268 @key{M-p}, the most recent shell input starting with those characters is
269 inserted.  This can be very convenient when you are repeating a sequence
270 of shell commands.  The variable @code{input-ring-size} controls how
271 many commands are saved in your input history.  The default is 30.
272
273
274 @node Shell Mode, Terminal emulator, Interactive Shell, Shell
275 @subsection Shell Mode
276
277 @cindex Shell mode
278   The shell buffer uses Shell mode, which defines several special keys
279 attached to the @kbd{C-c} prefix.  They are chosen to resemble the usual
280 editing and job control characters present in shells that are not under
281 SXEmacs, except that you must type @kbd{C-c} first.  Here is a list
282 of the special key bindings of Shell mode:
283
284 @kindex RET (Shell mode)
285 @kindex C-c C-d (Shell mode)
286 @kindex C-d (Shell mode)
287 @kindex C-c C-u (Shell mode)
288 @kindex C-c C-w (Shell mode)
289 @kindex C-c C-c (Shell mode)
290 @kindex C-c C-z (Shell mode)
291 @kindex C-c C-\ (Shell mode)
292 @kindex C-c C-o (Shell mode)
293 @kindex C-c C-r (Shell mode)
294 @kindex C-c C-y (Shell mode)
295 @kindex M-p (Shell mode)
296 @kindex M-n (Shell mode)
297 @kindex TAB (Shell mode)
298 @findex send-shell-input
299 @findex shell-send-eof
300 @findex comint-delchar-or-maybe-eof
301 @findex interrupt-shell-subjob
302 @findex stop-shell-subjob
303 @findex quit-shell-subjob
304 @findex kill-output-from-shell
305 @findex show-output-from-shell
306 @findex copy-last-shell-input
307 @findex comint-previous-input
308 @findex comint-next-input
309 @findex comint-dynamic-complete
310 @vindex shell-prompt-pattern
311 @table @kbd
312 @item @key{RET}
313 At end of buffer send line as input; otherwise, copy current line to end of
314 buffer and send it (@code{send-shell-input}).  When a line is copied, any
315 text at the beginning of the line that matches the variable
316 @code{shell-prompt-pattern} is left out; this variable's value should be a
317 regexp string that matches the prompts that you use in your subshell.
318 @item C-c C-d
319 Send end-of-file as input, probably causing the shell or its current
320 subjob to finish (@code{shell-send-eof}).
321 @item C-d
322 If point is not at the end of the buffer, delete the next character just
323 like most other modes.  If point is at the end of the buffer, send
324 end-of-file as input, instead of generating an error as in other modes
325 (@code{comint-delchar-or-maybe-eof}).
326 @item C-c C-u
327 Kill all text that has yet to be sent as input (@code{kill-shell-input}).
328 @item C-c C-w
329 Kill a word before point (@code{backward-kill-word}).
330 @item C-c C-c
331 Interrupt the shell or its current subjob if any
332 (@code{interrupt-shell-subjob}).
333 @item C-c C-z
334 Stop the shell or its current subjob if any (@code{stop-shell-subjob}).
335 @item C-c C-\
336 Send quit signal to the shell or its current subjob if any
337 (@code{quit-shell-subjob}).
338 @item C-c C-o
339 Delete last batch of output from shell (@code{kill-output-from-shell}).
340 @item C-c C-r
341 Scroll top of last batch of output to top of window
342 (@code{show-output-from-shell}).
343 @item C-c C-y
344 Copy the previous bunch of shell input and insert it into the
345 buffer before point (@code{copy-last-shell-input}).  No final newline
346 is inserted, and the input copied is not resubmitted until you type
347 @key{RET}.
348 @item M-p
349 Move backward through the input history.  Search for a matching command
350 if you have typed the beginning of a command (@code{comint-previous-input}).
351 @item M-n
352 Move forward through the input history.  Useful when you are
353 using @key{M-p} quickly and go past the desired command
354 (@code{comint-next-input}).
355 @item @key{TAB}
356 Complete the file name preceding point (@code{comint-dynamic-complete}).
357 @end table
358
359 @node Terminal emulator, Term Mode, Shell Mode, Shell
360 @subsection Interactive Inferior Shell with Terminal Emulator
361 @findex term
362
363   To run a subshell in a terminal emulator, putting its typescript in an SXEmacs
364 buffer, use @kbd{M-x term}.  This creates (or reuses) a buffer named
365 @samp{*term*} and runs a subshell with input coming from your keyboard and
366 output going to that buffer.
367
368 All the normal keys that you type are sent without any interpretation
369 by SXEmacs directly to the subshell, as ``terminal input.''
370 Any ``echo'' of your input is the responsibility of the subshell.
371 (The exception is the terminal escape character,
372 which by default is @kbd{C-c}. @pxref{Term Mode}.)
373 Any ``terminal output'' from the subshell goes into the buffer,
374 advancing point.
375
376   Some programs (such as SXEmacs itself) need to control the
377 appearance on the terminal screen in detail.  They do this by
378 sending special control codes.  The exact control
379 codes needed vary from terminal to terminal, but nowadays
380 most terminals and terminal emulators (including xterm)
381 understand the so-called "ANSI escape sequences" (first
382 popularized by the Digital's VT100 family of terminal).
383 The term mode also understands these escape sequences,
384 and for each control code does the appropriate thing
385 to change the buffer so that the appearance of the window
386 will match what it would be on a real terminal.
387 Thus you can actually run SXEmacs inside an SXEmacs Term window!
388
389    SXEmacs does not wait for the subshell to do anything.  You can switch
390 windows or buffers and edit them while the shell is waiting, or while
391 it is running a command.  Output from the subshell waits until SXEmacs
392 has time to process it; this happens whenever SXEmacs is waiting for
393 keyboard input or for time to elapse.
394
395    To make multiple terminal emulators, rename the buffer @samp{*term*}
396 to something different using @kbd{M-x rename-uniquely},
397 just as with Shell mode.
398
399    The file name used to load the subshell is determined
400 the same way as for Shell mode.
401
402 Unlike Shell mode, Term mode does not track the current directory
403 by examining your input.  Instead, if you use a programmable
404 shell, you can have it tell Term what the current directory is.
405 This is done automatically by bash for version 1.15 and later.
406
407 @node Term Mode, Paging in Term, Terminal emulator, Shell
408 @subsection Term Mode
409 @cindex Term mode
410 @cindex mode, Term
411
412   Term uses Term mode, which has two input modes:
413 In line mode, Term basically acts like Shell mode.  @xref{Shell Mode}.
414 In Char mode, each character is sent directly to the inferior subshell,
415 except for the Term escape character, normally @kbd{C-c}.
416
417 To switch between line and char mode, use these commands:
418 @table @kbd
419 @kindex C-c C-j @r{(Term mode)}
420 findex term-char-mode
421 @item C-c C-j
422 Switch to line mode.  Do nothing if already in line mode.
423
424 @kindex C-c C-k @r{(Term mode)}
425 @findex term-line-mode
426 @item C-c C-k
427 Switch to char mode.  Do nothing if already in char mode.
428 @end table
429
430 The following commands are only available in Char mode:
431 @table @kbd
432 @item C-c C-c
433 Send a literal @key{C-c} to the sub-shell.
434
435 @item C-c C-x
436 A prefix command to conveniently access the global @key{C-x} commands.
437 For example, @kbd{C-c C-x o} invokes the global binding of
438 @kbd{C-x o}, which is normally @samp{other-window}.
439 @end table
440
441 @node Paging in Term,, Term Mode, Shell
442 @subsection Paging in the terminal emulator
443
444 Term mode has a pager feature.  When the pager is enabled,
445 term mode will pause at the end of each screenful.
446
447 @table @kbd
448 @kindex C-c C-q @r{(Term mode)}
449 @findex term-pager-toggle
450 @item C-c C-q
451 Toggles the pager feature:  Disables the pager if it is enabled,
452 and vice versa.  This works in both line and char modes.
453 If the pager enabled, the mode-line contains the word @samp{page}.
454 @end table
455
456 If the pager is enabled, and Term receives more than a screenful
457 of output since your last input, Term will enter More break mode.
458 This is indicated by @samp{**MORE**} in the mode-line.
459 Type a @kbd{Space} to display the next screenful of output.
460 Type @kbd{?} to see your other options.  The interface is similar
461 to the Unix @samp{more} program.
462
463 @node Narrowing, Hardcopy, Shell, Top
464 @section Narrowing
465 @cindex widening
466 @cindex restriction
467 @cindex narrowing
468
469   @dfn{Narrowing} means focusing in on some portion of the buffer, making
470 the rest temporarily invisible and inaccessible.  Cancelling the narrowing
471 and making the entire buffer once again visible is called @dfn{widening}.
472 The amount of narrowing in effect in a buffer at any time is called the
473 buffer's @dfn{restriction}.
474
475 @c WideCommands
476 @table @kbd
477 @item C-x n n
478 Narrow down to between point and mark (@code{narrow-to-region}).
479 @item C-x n w
480 Widen to make the entire buffer visible again (@code{widen}).
481 @end table
482
483   Narrowing sometimes makes it easier to concentrate on a single
484 subroutine or paragraph by eliminating clutter.  It can also be used to
485 restrict the range of operation of a replace command or repeating
486 keyboard macro.  The word @samp{Narrow} appears in the mode line
487 whenever narrowing is in effect.  When you have narrowed to a part of the
488 buffer, that part appears to be all there is.  You can't see the rest,
489 can't move into it (motion commands won't go outside the visible part),
490 and can't change it in any way.  However, the invisible text is not
491 gone; if you save the file, it will be saved.
492
493 @kindex C-x n n
494 @findex narrow-to-region
495   The primary narrowing command is @kbd{C-x n n} (@code{narrow-to-region}).
496 It sets the current buffer's restrictions so that the text in the current
497 region remains visible but all text before the region or after the region
498 is invisible.  Point and mark do not change.
499
500   Because narrowing can easily confuse users who do not understand it,
501 @code{narrow-to-region} is normally a disabled command.  Attempting to use
502 this command asks for confirmation and gives you the option of enabling it;
503 once you enable the command, confirmation will no longer be required.  @xref{Disabling}.
504
505 @kindex C-x n w
506 @findex widen
507    To undo narrowing, use @kbd{C-x n w} (@code{widen}).  This makes all
508 text in the buffer accessible again.
509
510    Use the @kbd{C-x =} command to get information on what part of the
511 buffer you narrowed down.  @xref{Position Info}.
512
513 @node Hardcopy, Recursive Edit, Narrowing, Top
514 @section Hardcopy Output
515 @cindex hardcopy
516
517   The SXEmacs commands for making hardcopy derive their names from the
518 Unix commands @samp{print} and @samp{lpr}.
519
520 @table @kbd
521 @item M-x print-buffer
522 Print hardcopy of current buffer using Unix command @samp{print}
523 @*(@samp{lpr -p}).  This command adds page headings containing the file name
524 and page number.
525 @item M-x lpr-buffer
526 Print hardcopy of current buffer using Unix command @samp{lpr}.
527 This command does not add page headings.
528 @item M-x print-region
529 Like @code{print-buffer}, but prints only the current region.
530 @item M-x lpr-region
531 Like @code{lpr-buffer}, but prints only the current region.
532 @end table
533
534 @findex print-buffer
535 @findex print-region
536 @findex lpr-buffer
537 @findex lpr-region
538 @vindex lpr-switches
539   All the hardcopy commands pass extra switches to the @code{lpr} program
540 based on the value of the variable @code{lpr-switches}.  Its value should
541 be a list of strings, each string a switch starting with @samp{-}.  For
542 example, the value could be @code{("-Pfoo")} to print on printer
543 @samp{foo}.
544
545 @node Recursive Edit, Dissociated Press, Hardcopy, Top
546 @section Recursive Editing Levels
547 @cindex recursive editing level
548 @cindex editing level, recursive
549
550   A @dfn{recursive edit} is a situation in which you are using SXEmacs
551 commands to perform arbitrary editing while in the middle of another
552 SXEmacs command.  For example, when you type @kbd{C-r} inside a
553 @code{query-replace}, you enter a recursive edit in which you can change
554 the current buffer.  When you exit from the recursive edit, you go back to
555 the @code{query-replace}.
556
557 @kindex C-M-c
558 @findex exit-recursive-edit
559 @cindex exiting
560   @dfn{Exiting} a recursive edit means returning to the unfinished
561 command, which continues execution.  For example, exiting the recursive
562 edit requested by @kbd{C-r} in @code{query-replace} causes query replacing
563 to resume.  Exiting is done with @kbd{C-M-c} (@code{exit-recursive-edit}).
564
565 @kindex C-]
566 @findex abort-recursive-edit
567   You can also @dfn{abort} a recursive edit.  This is like exiting, but
568 also quits the unfinished command immediately.  Use the command @kbd{C-]}
569 (@code{abort-recursive-edit}) for this.  @xref{Quitting}.
570
571   The mode line shows you when you are in a recursive edit by displaying
572 square brackets around the parentheses that always surround the major
573 and minor mode names.  Every window's mode line shows the square
574 brackets, since SXEmacs as a whole, rather than any particular buffer, is
575 in a recursive edit.
576
577 @findex top-level
578   It is possible to be in recursive edits within recursive edits.  For
579 example, after typing @kbd{C-r} in a @code{query-replace}, you might
580 type a command that entered the debugger.  In such a case, two or
581 more sets of square brackets appear in the mode line(s).  Exiting the
582 inner recursive edit (here with the debugger @kbd{c} command)
583 resumes the query-replace command where it called the debugger.  After
584 the end of the query-replace command, you would be able to exit the
585 first recursive edit.  Aborting exits only one level of recursive edit;
586 it returns to the command level of the previous recursive edit.  You can
587 then abort that one as well.
588
589   The command @kbd{M-x top-level} aborts all levels of
590 recursive edits, returning immediately to the top level command reader.
591
592   The text you edit inside the recursive edit need not be the same text
593 that you were editing at top level.  If the command that invokes the
594 recursive edit selects a different buffer first, that is the buffer you
595 will edit recursively.  You can switch buffers within the recursive edit
596 in the normal manner (as long as the buffer-switching keys have not been
597 rebound).  While you could theoretically do the rest of your editing
598 inside the recursive edit, including visiting files, this could have
599 surprising effects (such as stack overflow) from time to time.  It is
600 best if you always exit or abort a recursive edit when you no longer
601 need it.
602
603   In general, SXEmacs tries to avoid using recursive edits.  It is
604 usually preferable to allow users to switch among the possible editing
605 modes in any order they like.  With recursive edits, the only way to get
606 to another state is to go ``back'' to the state that the recursive edit
607 was invoked from.
608
609 @node Dissociated Press, CONX, Recursive Edit, Top
610 @section Dissociated Press
611
612 @findex dissociated-press
613   @kbd{M-x dissociated-press} is a command for scrambling a file of text
614 either word by word or character by character.  Starting from a buffer of
615 straight English, it produces extremely amusing output.  The input comes
616 from the current SXEmacs buffer.  Dissociated Press writes its output in a
617 buffer named @samp{*Dissociation*}, and redisplays that buffer after every
618 couple of lines (approximately) to facilitate reading it.
619
620   @code{dissociated-press} asks every so often whether to continue
621 operating.  Answer @kbd{n} to stop it.  You can also stop at any time by
622 typing @kbd{C-g}.  The dissociation output remains in the @samp{*Dissociation*}
623 buffer for you to copy elsewhere if you wish.
624
625 @cindex presidentagon
626   Dissociated Press operates by jumping at random from one point in the
627 buffer to another.  In order to produce plausible output rather than
628 gibberish, it insists on a certain amount of overlap between the end of one
629 run of consecutive words or characters and the start of the next.  That is,
630 if it has just printed out `president' and then decides to jump to a
631 different point in the file, it might spot the `ent' in `pentagon' and
632 continue from there, producing `presidentagon'.  Long sample texts produce
633 the best results.
634
635 @cindex againformation
636   A positive argument to @kbd{M-x dissociated-press} tells it to operate
637 character by character, and specifies the number of overlap characters.  A
638 negative argument tells it to operate word by word and specifies the number
639 of overlap words.  In this mode, whole words are treated as the elements to
640 be permuted, rather than characters.  No argument is equivalent to an
641 argument of two.  For your againformation, the output goes only into the
642 buffer @samp{*Dissociation*}.  The buffer you start with is not changed.
643
644 @cindex Markov chain
645 @cindex ignoriginal
646 @cindex techniquitous
647   Dissociated Press produces nearly the same results as a Markov chain
648 based on a frequency table constructed from the sample text.  It is,
649 however, an independent, ignoriginal invention.  Dissociated Press
650 techniquitously copies several consecutive characters from the sample
651 between random choices, whereas a Markov chain would choose randomly for
652 each word or character.  This makes for more plausible sounding results
653 and runs faster.
654
655 @cindex outragedy
656 @cindex buggestion
657 @cindex properbose
658   It is a mustatement that too much use of Dissociated Press can be a
659 developediment to your real work.  Sometimes to the point of outragedy.
660 And keep dissociwords out of your documentation, if you want it to be well
661 userenced and properbose.  Have fun.  Your buggestions are welcome.
662
663 @node CONX, Amusements, Dissociated Press, Top
664 @section CONX
665 @cindex random sentences
666
667 Besides producing a file of scrambled text with Dissociated Press, you
668 can generate random sentences by using CONX.
669
670 @table @kbd
671 @item M-x conx
672 Generate random sentences in the @code{*conx*} buffer.
673 @item M-x conx-buffer
674 Absorb the text in the current buffer into the @code{conx} database.
675 @item M-x conx-init
676 Forget the current word-frequency tree.
677 @item M-x conx-load
678 Load a @code{conx} database that has been previously saved with
679 @code{M-x conx-save}.
680 @item M-x conx-region
681 Absorb the text in the current buffer into the @code{conx} database.
682 @item M-x conx-save
683 Save the current @code{conx} database to a file for future retrieval.
684 @end table
685
686 @findex conx
687 @findex conx-buffer
688 @findex conx-load
689 @findex conx-region
690 @findex conx-init
691 @findex conx-save
692
693 Copy text from a buffer using @kbd{M-x conx-buffer} or @kbd{M-x conx-region}
694 and then type @kbd{M-x conx}.  Output is continuously generated until you
695 type @key{^G}. You can save the @code{conx} database to a file with
696 @kbd{M-x conx-save}, which you can retrieve with @code{M-x conx-load}.
697 To clear the database, use @code{M-x conx-init}.
698
699 @node Amusements, Emulation, CONX, Top
700 @section Other Amusements
701 @cindex boredom
702 @findex hanoi
703 @findex yow
704
705   If you are a little bit bored, you can try @kbd{M-x hanoi}.  If you are
706 considerably bored, give it a numeric argument.  If you are very, very
707 bored, try an argument of 9.  Sit back and watch.
708
709   When you are frustrated, try the famous Eliza program.  Just do
710 @kbd{M-x doctor}.  End each input by typing @kbd{RET} twice.
711
712   When you are feeling strange, type @kbd{M-x yow}.
713
714 @node Emulation, Customization, Amusements, Top
715 @comment  node-name,  next,  previous,  up
716 @section Emulation
717 @cindex other editors
718 @cindex vi
719 @cindex EDT
720
721   SXEmacs can be programmed to emulate (more or less) most other
722 editors.  Standard facilities can emulate these:
723
724 @table @asis
725 @item Viper (a vi emulator)
726 @cindex Viper
727 In SXEmacs, Viper is the preferred emulation of vi within SXEmacs.
728 Viper is designed to allow you to take advantage of the best
729 features of SXEmacs while still doing your basic editing in a
730 familiar, vi-like fashion.  Viper provides various different
731 levels of vi emulation, from a quite complete emulation that
732 allows almost no access to native SXEmacs commands, to an
733 ``expert'' mode that combines the most useful vi commands with
734 the most useful SXEmacs commands.
735
736 To start Viper, put the command
737
738 @example
739 (viper-mode)
740 @end example
741
742 in your init file.  @xref{Init File}.
743
744 Viper comes with a separate manual that is provided standard
745 with the SXEmacs distribution.
746
747 @ignore
748 @item evi (alternative vi emulator)
749 @cindex evi
750 evi is an alternative vi emulator that also provides a nearly complete
751 emulation of vi.
752
753 evi comes with a separate manual that is provided standard
754 with the SXEmacs distribution.
755
756 Warning: loading more than one vi emulator at once may cause name
757 conflicts; no one has checked.
758 @end ignore
759
760 @item EDT (DEC VMS editor)
761 @findex edt-emulation-on
762 @findex edt-emulation-off
763 Turn on EDT emulation with @kbd{M-x edt-emulation-on}.  @kbd{M-x
764 @*edt-emulation-off} restores normal Emacs command bindings.
765
766 Most of the EDT emulation commands are keypad keys, and most standard
767 Emacs key bindings are still available.  The EDT emulation rebindings
768 are done in the global keymap, so there is no problem switching
769 buffers or major modes while in EDT emulation.
770
771 @item Gosling Emacs
772 @findex set-gosmacs-bindings
773 @findex set-gnu-bindings
774 Turn on emulation of Gosling Emacs (aka Unipress Emacs) with @kbd{M-x
775 set-gosmacs-bindings}.  This redefines many keys, mostly on the
776 @kbd{C-x} and @kbd{ESC} prefixes, to work as they do in Gosmacs.
777 @kbd{M-x set-gnu-bindings} returns to normal SXEmacs by rebinding
778 the same keys to the definitions they had at the time @kbd{M-x
779 set-gosmacs-bindings} was done.
780
781 It is also possible to run Mocklisp code written for Gosling Emacs.
782 @xref{Mocklisp}.
783 @end table