21.4.14 "Reasonable Discussion".
[chise/xemacs-chise.git.1] / man / lispref / display.texi
1 @c -*-texinfo-*-
2 @c This is part of the XEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998 Free Software Foundation, Inc.
4 @c See the file lispref.texi for copying conditions.
5 @setfilename ../../info/display.info
6 @node Display, Hash Tables, Annotations, Top
7 @chapter Emacs Display
8
9   This chapter describes a number of other features related to the display
10 that XEmacs presents to the user.
11
12 @menu
13 * Refresh Screen::      Clearing the screen and redrawing everything on it.
14 * Truncation::          Folding or wrapping long text lines.
15 * The Echo Area::       Where messages are displayed.
16 * Warnings::            Display of Warnings.
17 * Invisible Text::      Hiding part of the buffer text.
18 * Selective Display::   Hiding part of the buffer text (the old way).
19 * Overlay Arrow::       Display of an arrow to indicate position.
20 * Temporary Displays::  Displays that go away automatically.
21 * Blinking::            How XEmacs shows the matching open parenthesis.
22 * Usual Display::       The usual conventions for displaying nonprinting chars.
23 * Display Tables::      How to specify other conventions.
24 * Beeping::             Audible signal to the user.
25 @end menu
26
27 @node Refresh Screen
28 @section Refreshing the Screen
29
30 The function @code{redraw-frame} redisplays the entire contents of a
31 given frame.  @xref{Frames}.
32
33 @defun redraw-frame &optional frame no-preempt
34 This function clears and redisplays frame @var{frame}.
35
36 @var{frame} defaults to the selected frame if omitted.
37
38 Normally, redisplay is preempted as normal if input arrives.  However,
39 if optional second arg @var{no-preempt} is non-@code{nil}, redisplay
40 will not stop for input and is guaranteed to proceed to completion.
41 @end defun
42
43 Even more powerful is @code{redraw-display}:
44
45 @deffn Command redraw-display &optional device
46 This function redraws all frames on @var{device} marked as having their
47 image garbled.  @var{device} defaults to the selected device.  If
48 @var{device} is @code{t}, all devices will have their frames checked.
49 @end deffn
50
51   Processing user input takes absolute priority over redisplay.  If you
52 call these functions when input is available, they do nothing
53 immediately, but a full redisplay does happen eventually---after all the
54 input has been processed.
55
56   Normally, suspending and resuming XEmacs also refreshes the screen.
57 Some terminal emulators record separate contents for display-oriented
58 programs such as XEmacs and for ordinary sequential display.  If you are
59 using such a terminal, you might want to inhibit the redisplay on
60 resumption.  @xref{Suspending XEmacs}.
61
62 @defvar no-redraw-on-reenter
63 @cindex suspend (cf. @code{no-redraw-on-reenter})
64 @cindex resume (cf. @code{no-redraw-on-reenter})
65 This variable controls whether XEmacs redraws the entire screen after it
66 has been suspended and resumed.  Non-@code{nil} means yes, @code{nil}
67 means no.
68 @end defvar
69
70 @cindex display update
71 @cindex update display
72 @cindex refresh display
73   The above functions do not actually cause the display to be updated;
74 rather, they clear out the internal display records that XEmacs
75 maintains, so that the next time the display is updated it will be
76 redrawn from scratch.  Normally this occurs the next time that
77 @code{next-event} or @code{sit-for} is called; however, a display update
78 will not occur if there is input pending.  @xref{Command Loop}.
79
80 @defun force-cursor-redisplay &optional frame
81 This function causes an immediate update of the cursor on @var{frame},
82 which defaults to the selected frame.
83 @end defun
84
85 @node Truncation
86 @section Truncation
87 @cindex line wrapping
88 @cindex continuation lines
89 @cindex @samp{$} in display
90 @cindex @samp{\} in display
91
92   When a line of text extends beyond the right edge of a window, the
93 line can either be truncated or continued on the next line.  When a line
94 is truncated, this is normally shown with a @samp{\} in the rightmost
95 column of the window on X displays, and with a @samp{$} on TTY devices.
96 When a line is continued or ``wrapped'' onto the next line, this is
97 shown with a curved arrow in the rightmost column of the window (or with
98 a @samp{\} on TTY devices).  The additional screen lines used to display
99 a long text line are called @dfn{continuation} lines.
100
101   Normally, whenever line truncation is in effect for a particular
102 window, a horizontal scrollbar is displayed in that window if the
103 device supports scrollbars.  @xref{Scrollbars}.
104
105   Note that continuation is different from filling; continuation happens
106 on the screen only, not in the buffer contents, and it breaks a line
107 precisely at the right margin, not at a word boundary.  @xref{Filling}.
108
109 @defopt truncate-lines
110 This buffer-local variable controls how XEmacs displays lines that
111 extend beyond the right edge of the window.  If it is non-@code{nil},
112 then XEmacs does not display continuation lines; rather each line of
113 text occupies exactly one screen line, and a backslash appears at the
114 edge of any line that extends to or beyond the edge of the window.  The
115 default is @code{nil}.
116
117 If the variable @code{truncate-partial-width-windows} is non-@code{nil},
118 then truncation is always used for side-by-side windows (within one
119 frame) regardless of the value of @code{truncate-lines}.
120 @end defopt
121
122 @defopt default-truncate-lines
123 This variable is the default value for @code{truncate-lines}, for
124 buffers that do not have local values for it.
125 @end defopt
126
127 @defopt truncate-partial-width-windows
128 This variable controls display of lines that extend beyond the right
129 edge of the window, in side-by-side windows (@pxref{Splitting Windows}).
130 If it is non-@code{nil}, these lines are truncated; otherwise,
131 @code{truncate-lines} says what to do with them.
132 @end defopt
133
134   The backslash and curved arrow used to indicate truncated or continued
135 lines are only defaults, and can be changed.  These images are actually
136 glyphs (@pxref{Glyphs}).  XEmacs provides a great deal of flexibility
137 in how glyphs can be controlled. (This differs from FSF Emacs, which
138 uses display tables to control these images.)
139
140   For details, @ref{Redisplay Glyphs}.
141
142 @ignore Not yet in XEmacs
143   If your buffer contains @strong{very} long lines, and you use
144 continuation to display them, just thinking about them can make Emacs
145 redisplay slow.  The column computation and indentation functions also
146 become slow.  Then you might find it advisable to set
147 @code{cache-long-line-scans} to @code{t}.
148
149 @defvar cache-long-line-scans
150 If this variable is non-@code{nil}, various indentation and motion
151 functions, and Emacs redisplay, cache the results of scanning the
152 buffer, and consult the cache to avoid rescanning regions of the buffer
153 unless they are modified.
154
155 Turning on the cache slows down processing of short lines somewhat.
156
157 This variable is automatically local in every buffer.
158 @end defvar
159 @end ignore
160
161 @node The Echo Area
162 @section The Echo Area
163 @cindex error display
164 @cindex echo area
165
166 The @dfn{echo area} is used for displaying messages made with the
167 @code{message} primitive, and for echoing keystrokes.  It is not the
168 same as the minibuffer, despite the fact that the minibuffer appears
169 (when active) in the same place on the screen as the echo area.  The
170 @cite{XEmacs Lisp Reference Manual} specifies the rules for resolving conflicts
171 between the echo area and the minibuffer for use of that screen space
172 (@pxref{Minibuffer,, The Minibuffer, xemacs, The XEmacs Lisp Reference Manual}).
173 Error messages appear in the echo area; see @ref{Errors}.
174
175 You can write output in the echo area by using the Lisp printing
176 functions with @code{t} as the stream (@pxref{Output Functions}), or as
177 follows:
178
179 @defun message string &rest arguments
180 This function displays a one-line message in the echo area.  The
181 argument @var{string} is similar to a C language @code{printf} control
182 string.  See @code{format} in @ref{String Conversion}, for the details
183 on the conversion specifications.  @code{message} returns the
184 constructed string.
185
186 In batch mode, @code{message} prints the message text on the standard
187 error stream, followed by a newline.
188
189 @c Emacs 19 feature
190 If @var{string} is @code{nil}, @code{message} clears the echo area.  If
191 the minibuffer is active, this brings the minibuffer contents back onto
192 the screen immediately.
193
194 @example
195 @group
196 (message "Minibuffer depth is %d."
197          (minibuffer-depth))
198  @print{} Minibuffer depth is 0.
199 @result{} "Minibuffer depth is 0."
200 @end group
201
202 @group
203 ---------- Echo Area ----------
204 Minibuffer depth is 0.
205 ---------- Echo Area ----------
206 @end group
207 @end example
208 @end defun
209
210 In addition to only displaying a message, XEmacs allows you to
211 @dfn{label} your messages, giving you fine-grained control of their
212 display.  Message label is a symbol denoting the message type.  Some
213 standard labels are:
214
215 @itemize @bullet
216 @item @code{message}---default label used by the @code{message}
217 function;
218
219 @item @code{error}---default label used for reporting errors;
220
221 @item @code{progress}---progress indicators like
222 @samp{Converting... 45%} (not logged by default);
223
224 @item @code{prompt}---prompt-like messages like @samp{Isearch: foo} (not
225 logged by default);
226
227 @item @code{command}---helper command messages like @samp{Mark set} (not
228 logged by default);
229
230 @item @code{no-log}---messages that should never be logged
231 @end itemize
232
233 Several messages may be stacked in the echo area at once.  Lisp programs
234 may access these messages, or remove them as appropriate, via the
235 message stack.
236
237 @defun display-message label message &optional frame stdout-p
238 This function displays @var{message} (a string) labeled as @var{label},
239 as described above.
240
241 The @var{frame} argument specifies the frame to whose minibuffer the
242 message should be printed.  This is currently unimplemented.  The
243 @var{stdout-p} argument is used internally.
244
245 @example
246 (display-message 'command "Mark set")
247 @end example
248 @end defun
249
250 @defun lmessage label string &rest arguments
251 This function displays a message @var{string} with label @var{label}.
252 It is similar to @code{message} in that it accepts a @code{printf}-like
253 strings and any number of arguments.
254
255 @example
256 @group
257 ;; @r{Display a command message.}
258 (lmessage 'command "Comment column set to %d" comment-column)
259 @end group
260
261 @group
262 ;; @r{Display a progress message.}
263 (lmessage 'progress "Fontifying %s... (%d)" buffer percentage)
264 @end group
265
266 @group
267 ;; @r{Display a message that should not be logged.}
268 (lmessage 'no-log "Done")
269 @end group
270 @end example
271 @end defun
272
273 @defun clear-message &optional label frame stdout-p no-restore
274 This function remove any message with the given @var{label}
275 from the message-stack, erasing it from the echo area if it's currently
276 displayed there.
277
278 If a message remains at the head of the message-stack and
279 @var{no-restore} is @code{nil}, it will be displayed.  The string which
280 remains in the echo area will be returned, or @code{nil} if the
281 message-stack is now empty.  If @var{label} is @code{nil}, the entire
282 message-stack is cleared.
283
284 @example
285 ;; @r{Show a message, wait for 2 seconds, and restore old minibuffer}
286 ;; @r{contents.}
287 (message "A message")
288  @print{} A message
289 @result{} "A Message"
290 (lmessage 'my-label "Newsflash!  Newsflash!")
291  @print{} Newsflash!  Newsflash!
292 @result{} "Newsflash!  Newsflash!"
293 (sit-for 2)
294 (clear-message 'my-label)
295  @print{} A message
296 @result{} "A message"
297 @end example
298
299 Unless you need the return value or you need to specify a label,
300 you should just use @code{(message nil)}.
301 @end defun
302
303 @defun current-message &optional frame
304 This function returns the current message in the echo area, or
305 @code{nil}.  The @var{frame} argument is currently unused.
306 @end defun
307
308 Some of the messages displayed in the echo area are also recorded in the
309 @samp{ *Message-Log*} buffer.  Exactly which messages will be recorded
310 can be tuned using the following variables.
311
312 @defopt log-message-max-size
313 This variable specifies the maximum size of the @samp{ *Message-log*}
314 buffer.
315 @end defopt
316
317 @defvar log-message-ignore-labels
318 This variable specifies the labels whose messages will not be logged.
319 It should be a list of symbols.
320 @end defvar
321
322 @defvar log-message-ignore-regexps
323 This variable specifies the regular expressions matching messages that
324 will not be logged.  It should be a list of regular expressions.
325
326 Normally, packages that generate messages that might need to be ignored
327 should label them with @code{progress}, @code{prompt}, or @code{no-log},
328 so they can be filtered by @code{log-message-ignore-labels}.
329 @end defvar
330
331 @defvar echo-keystrokes
332 This variable determines how much time should elapse before command
333 characters echo.  Its value must be a number, which specifies the number
334 of seconds to wait before echoing.  If the user types a prefix key (such
335 as @kbd{C-x}) and then delays this many seconds before continuing, the
336 prefix key is echoed in the echo area.  Any subsequent characters in the
337 same command will be echoed as well.
338
339 If the value is zero, then command input is not echoed.
340 @end defvar
341
342 @defvar cursor-in-echo-area
343 This variable controls where the cursor appears when a message is
344 displayed in the echo area.  If it is non-@code{nil}, then the cursor
345 appears at the end of the message.  Otherwise, the cursor appears at
346 point---not in the echo area at all.
347
348 The value is normally @code{nil}; Lisp programs bind it to @code{t}
349 for brief periods of time.
350 @end defvar
351
352 @node Warnings
353 @section Warnings
354
355 XEmacs contains a facility for unified display of various warnings.
356 Unlike errors, warnings are displayed in the situations when XEmacs
357 encounters a problem that is recoverable, but which should be fixed for
358 safe future operation.
359
360 For example, warnings are printed by the startup code when it encounters
361 problems with X keysyms, when there is an error in @file{.emacs}, and in
362 other problematic situations.  Unlike messages, warnings are displayed
363 in a separate buffer, and include an explanatory message that may span
364 across several lines.  Here is an example of how a warning is displayed:
365
366 @example
367 (1) (initialization/error) An error has occurred while loading ~/.emacs:
368
369 Symbol's value as variable is void: bogus-variable
370
371 To ensure normal operation, you should investigate the cause of the error
372 in your initialization file and remove it.  Use the `-debug-init' option
373 to XEmacs to view a complete error backtrace.
374 @end example
375
376 Each warning has a @dfn{class} and a @dfn{priority level}.  The class is
377 a symbol describing what sort of warning this is, such as
378 @code{initialization}, @code{resource} or @code{key-mapping}.
379
380 The warning priority level specifies how important the warning is.  The
381 recognized warning levels, in increased order of priority, are:
382 @code{debug}, @code{info}, @code{notice}, @code{warning}, @code{error},
383 @code{critical}, @code{alert} and @code{emergency}.
384
385 @defun display-warning class message &optional level
386 This function displays a warning message @var{message} (a string).
387 @var{class} should be a warning class symbol, as described above, or a
388 list of such symbols.  @var{level} describes the warning priority level.
389 If unspecified, it default to @code{warning}.
390
391 @example
392 @group
393 (display-warning 'resource
394   "Bad resource specification encountered:
395 something like
396
397     Emacs*foo: bar
398
399 You should replace the * with a . in order to get proper behavior when
400 you use the specifier and/or `set-face-*' functions.")
401 @end group
402
403 @group
404 ---------- Warning buffer ----------
405 (1) (resource/warning) Bad resource specification encountered:
406 something like
407
408     Emacs*foo: bar
409
410 You should replace the * with a . in order to get proper behavior when
411 you use the specifier and/or `set-face-*' functions.
412 ---------- Warning buffer ----------
413 @end group
414 @end example
415 @end defun
416
417 @defun lwarn class level message &rest args
418 This function displays a formatted labeled warning message.  As above,
419 @var{class} should be the warning class symbol, or a list of such
420 symbols, and @var{level} should specify the warning priority level
421 (@code{warning} by default).
422
423 Unlike in @code{display-warning}, @var{message} may be a formatted
424 message, which will be, together with the rest of the arguments, passed
425 to @code{format}.
426
427 @example
428 (lwarn 'message-log 'warning
429   "Error caught in `remove-message-hook': %s"
430   (error-message-string e))
431 @end example
432 @end defun
433
434 @defvar log-warning-minimum-level
435 This variable specifies the minimum level of warnings that should be
436 generated.  Warnings with level lower than defined by this variable are
437 completely ignored, as if they never happened.
438 @end defvar
439
440 @defvar display-warning-minimum-level
441 This variable specifies the minimum level of warnings that should be
442 displayed.  Unlike @code{log-warning-minimum-level}, setting this
443 function does not suppress warnings entirely---they are still generated
444 in the @samp{*Warnings*} buffer, only they are not displayed by default.
445 @end defvar
446
447 @defvar log-warning-suppressed-classes
448 This variable specifies a list of classes that should not be logged or
449 displayed.  If any of the class symbols associated with a warning is the
450 same as any of the symbols listed here, the warning will be completely
451 ignored, as it they never happened.
452 @end defvar
453
454 @defvar display-warning-suppressed-classes
455 This variable specifies a list of classes that should not be logged or
456 displayed.  If any of the class symbols associated with a warning is the
457 same as any of the symbols listed here, the warning will not be
458 displayed.  The warning will still logged in the *Warnings* buffer
459 (unless also contained in `log-warning-suppressed-classes'), but the
460 buffer will not be automatically popped up.
461 @end defvar
462
463 @node Invisible Text
464 @section Invisible Text
465
466 @cindex invisible text
467 You can make characters @dfn{invisible}, so that they do not appear on
468 the screen, with the @code{invisible} property.  This can be either a
469 text property or a property of an overlay.
470
471 In the simplest case, any non-@code{nil} @code{invisible} property makes
472 a character invisible.  This is the default case---if you don't alter
473 the default value of @code{buffer-invisibility-spec}, this is how the
474 @code{invisibility} property works.  This feature is much like selective
475 display (@pxref{Selective Display}), but more general and cleaner.
476
477 More generally, you can use the variable @code{buffer-invisibility-spec}
478 to control which values of the @code{invisible} property make text
479 invisible.  This permits you to classify the text into different subsets
480 in advance, by giving them different @code{invisible} values, and
481 subsequently make various subsets visible or invisible by changing the
482 value of @code{buffer-invisibility-spec}.
483
484 Controlling visibility with @code{buffer-invisibility-spec} is
485 especially useful in a program to display the list of entries in a data
486 base.  It permits the implementation of convenient filtering commands to
487 view just a part of the entries in the data base.  Setting this variable
488 is very fast, much faster than scanning all the text in the buffer
489 looking for properties to change.
490
491 @defvar buffer-invisibility-spec
492 This variable specifies which kinds of @code{invisible} properties
493 actually make a character invisible.
494
495 @table @asis
496 @item @code{t}
497 A character is invisible if its @code{invisible} property is
498 non-@code{nil}.  This is the default.
499
500 @item a list
501 Each element of the list makes certain characters invisible.
502 Ultimately, a character is invisible if any of the elements of this list
503 applies to it.  The list can have two kinds of elements:
504
505 @table @code
506 @item @var{atom}
507 A character is invisible if its @code{invisible} property value
508 is @var{atom} or if it is a list with @var{atom} as a member.
509
510 @item (@var{atom} . t)
511 A character is invisible if its @code{invisible} property value
512 is @var{atom} or if it is a list with @var{atom} as a member.
513 Moreover, if this character is at the end of a line and is followed
514 by a visible newline, it displays an ellipsis.
515 @end table
516 @end table
517 @end defvar
518
519   Ordinarily, commands that operate on text or move point do not care
520 whether the text is invisible.  However, the user-level line motion
521 commands explicitly ignore invisible newlines.  Since this causes a
522 slow-down of these commands it is turned off by default, controlled by
523 the variable @code{line-move-ignore-invisible}.
524
525 @node Selective Display
526 @section Selective Display
527 @cindex selective display
528
529   @dfn{Selective display} is a pair of features that hide certain
530 lines on the screen.
531
532   The first variant, explicit selective display, is designed for use in
533 a Lisp program.  The program controls which lines are hidden by altering
534 the text.  Outline mode has traditionally used this variant.  It has
535 been partially replaced by the invisible text feature (@pxref{Invisible
536 Text}); there is a new version of Outline mode which uses that instead.
537
538   In the second variant, the choice of lines to hide is made
539 automatically based on indentation.  This variant is designed to be a
540 user-level feature.
541
542   The way you control explicit selective display is by replacing a
543 newline (control-j) with a carriage return (control-m).  The text that
544 was formerly a line following that newline is now invisible.  Strictly
545 speaking, it is temporarily no longer a line at all, since only newlines
546 can separate lines; it is now part of the previous line.
547
548   Selective display does not directly affect editing commands.  For
549 example, @kbd{C-f} (@code{forward-char}) moves point unhesitatingly into
550 invisible text.  However, the replacement of newline characters with
551 carriage return characters affects some editing commands.  For example,
552 @code{next-line} skips invisible lines, since it searches only for
553 newlines.  Modes that use selective display can also define commands
554 that take account of the newlines, or that make parts of the text
555 visible or invisible.
556
557   When you write a selectively displayed buffer into a file, all the
558 control-m's are output as newlines.  This means that when you next read
559 in the file, it looks OK, with nothing invisible.  The selective display
560 effect is seen only within XEmacs.
561
562 @defvar selective-display
563 This buffer-local variable enables selective display.  This means that
564 lines, or portions of lines, may be made invisible.
565
566 @itemize @bullet
567 @item
568 If the value of @code{selective-display} is @code{t}, then any portion
569 of a line that follows a control-m is not displayed.
570
571 @item
572 If the value of @code{selective-display} is a positive integer, then
573 lines that start with more than that many columns of indentation are not
574 displayed.
575 @end itemize
576
577 When some portion of a buffer is invisible, the vertical movement
578 commands operate as if that portion did not exist, allowing a single
579 @code{next-line} command to skip any number of invisible lines.
580 However, character movement commands (such as @code{forward-char}) do
581 not skip the invisible portion, and it is possible (if tricky) to insert
582 or delete text in an invisible portion.
583
584 In the examples below, we show the @emph{display appearance} of the
585 buffer @code{foo}, which changes with the value of
586 @code{selective-display}.  The @emph{contents} of the buffer do not
587 change.
588
589 @example
590 @group
591 (setq selective-display nil)
592      @result{} nil
593
594 ---------- Buffer: foo ----------
595 1 on this column
596  2on this column
597   3n this column
598   3n this column
599  2on this column
600 1 on this column
601 ---------- Buffer: foo ----------
602 @end group
603
604 @group
605 (setq selective-display 2)
606      @result{} 2
607
608 ---------- Buffer: foo ----------
609 1 on this column
610  2on this column
611  2on this column
612 1 on this column
613 ---------- Buffer: foo ----------
614 @end group
615 @end example
616 @end defvar
617
618 @defvar selective-display-ellipses
619 If this buffer-local variable is non-@code{nil}, then XEmacs displays
620 @samp{@dots{}} at the end of a line that is followed by invisible text.
621 This example is a continuation of the previous one.
622
623 @example
624 @group
625 (setq selective-display-ellipses t)
626      @result{} t
627
628 ---------- Buffer: foo ----------
629 1 on this column
630  2on this column ...
631  2on this column
632 1 on this column
633 ---------- Buffer: foo ----------
634 @end group
635 @end example
636
637 You can use a display table to substitute other text for the ellipsis
638 (@samp{@dots{}}).  @xref{Display Tables}.
639 @end defvar
640
641 @node Overlay Arrow
642 @section The Overlay Arrow
643 @cindex overlay arrow
644
645   The @dfn{overlay arrow} is useful for directing the user's attention
646 to a particular line in a buffer.  For example, in the modes used for
647 interface to debuggers, the overlay arrow indicates the line of code
648 about to be executed.
649
650 @defvar overlay-arrow-string
651 This variable holds the string to display to call attention to a
652 particular line, or @code{nil} if the arrow feature is not in use.
653 Despite its name, the value of this variable can be either a string
654 or a glyph (@pxref{Glyphs}).
655 @end defvar
656
657 @defvar overlay-arrow-position
658 This variable holds a marker that indicates where to display the overlay
659 arrow.  It should point at the beginning of a line.  The arrow text
660 appears at the beginning of that line, overlaying any text that would
661 otherwise appear.  Since the arrow is usually short, and the line
662 usually begins with indentation, normally nothing significant is
663 overwritten.
664
665 The overlay string is displayed only in the buffer that this marker
666 points into.  Thus, only one buffer can have an overlay arrow at any
667 given time.
668 @c !!! overlay-arrow-position: but the overlay string may remain in the display
669 @c of some other buffer until an update is required.  This should be fixed
670 @c now.  Is it?
671 @end defvar
672
673   You can do the same job by creating an extent with a
674 @code{begin-glyph} property.  @xref{Extent Properties}.
675
676 @node Temporary Displays
677 @section Temporary Displays
678
679   Temporary displays are used by commands to put output into a buffer
680 and then present it to the user for perusal rather than for editing.
681 Many of the help commands use this feature.
682
683 @defspec with-output-to-temp-buffer buffer-name forms@dots{}
684 This function executes @var{forms} while arranging to insert any
685 output they print into the buffer named @var{buffer-name}.  The buffer
686 is then shown in some window for viewing, displayed but not selected.
687
688 The string @var{buffer-name} specifies the temporary buffer, which
689 need not already exist.  The argument must be a string, not a buffer.
690 The buffer is erased initially (with no questions asked), and it is
691 marked as unmodified after @code{with-output-to-temp-buffer} exits.
692
693 @code{with-output-to-temp-buffer} binds @code{standard-output} to the
694 temporary buffer, then it evaluates the forms in @var{forms}.  Output
695 using the Lisp output functions within @var{forms} goes by default to
696 that buffer (but screen display and messages in the echo area, although
697 they are ``output'' in the general sense of the word, are not affected).
698 @xref{Output Functions}.
699
700 The value of the last form in @var{forms} is returned.
701
702 @example
703 @group
704 ---------- Buffer: foo ----------
705  This is the contents of foo.
706 ---------- Buffer: foo ----------
707 @end group
708
709 @group
710 (with-output-to-temp-buffer "foo"
711     (print 20)
712     (print standard-output))
713 @result{} #<buffer foo>
714
715 ---------- Buffer: foo ----------
716 20
717
718 #<buffer foo>
719
720 ---------- Buffer: foo ----------
721 @end group
722 @end example
723 @end defspec
724
725 @defvar temp-buffer-show-function
726 If this variable is non-@code{nil}, @code{with-output-to-temp-buffer}
727 calls it as a function to do the job of displaying a help buffer.  The
728 function gets one argument, which is the buffer it should display.
729
730 In Emacs versions 18 and earlier, this variable was called
731 @code{temp-buffer-show-hook}.
732 @end defvar
733
734 @defun momentary-string-display string position &optional char message
735 This function momentarily displays @var{string} in the current buffer at
736 @var{position}.  It has no effect on the undo list or on the buffer's
737 modification status.
738
739 The momentary display remains until the next input event.  If the next
740 input event is @var{char}, @code{momentary-string-display} ignores it
741 and returns.  Otherwise, that event remains buffered for subsequent use
742 as input.  Thus, typing @var{char} will simply remove the string from
743 the display, while typing (say) @kbd{C-f} will remove the string from
744 the display and later (presumably) move point forward.  The argument
745 @var{char} is a space by default.
746
747 The return value of @code{momentary-string-display} is not meaningful.
748
749 You can do the same job in a more general way by creating an extent
750 with a begin-glyph property.  @xref{Extent Properties}.
751
752 If @var{message} is non-@code{nil}, it is displayed in the echo area
753 while @var{string} is displayed in the buffer.  If it is @code{nil}, a
754 default message says to type @var{char} to continue.
755
756 In this example, point is initially located at the beginning of the
757 second line:
758
759 @example
760 @group
761 ---------- Buffer: foo ----------
762 This is the contents of foo.
763 @point{}Second line.
764 ---------- Buffer: foo ----------
765 @end group
766
767 @group
768 (momentary-string-display
769   "**** Important Message! ****"
770   (point) ?\r
771   "Type RET when done reading")
772 @result{} t
773 @end group
774
775 @group
776 ---------- Buffer: foo ----------
777 This is the contents of foo.
778 **** Important Message! ****Second line.
779 ---------- Buffer: foo ----------
780
781 ---------- Echo Area ----------
782 Type RET when done reading
783 ---------- Echo Area ----------
784 @end group
785 @end example
786
787   This function works by actually changing the text in the buffer.  As a
788 result, if you later undo in this buffer, you will see the message come
789 and go.
790 @end defun
791
792 @node Blinking
793 @section Blinking Parentheses
794 @cindex parenthesis matching
795 @cindex blinking
796 @cindex balancing parentheses
797 @cindex close parenthesis
798
799   This section describes the mechanism by which XEmacs shows a matching
800 open parenthesis when the user inserts a close parenthesis.
801
802 @vindex blink-paren-hook
803 @defvar blink-paren-function
804 The value of this variable should be a function (of no arguments) to
805 be called whenever a character with close parenthesis syntax is inserted.
806 The value of @code{blink-paren-function} may be @code{nil}, in which
807 case nothing is done.
808
809 @quotation
810 @strong{Please note:} This variable was named @code{blink-paren-hook} in
811 older Emacs versions, but since it is not called with the standard
812 convention for hooks, it was renamed to @code{blink-paren-function} in
813 version 19.
814 @end quotation
815 @end defvar
816
817 @defvar blink-matching-paren
818 If this variable is @code{nil}, then @code{blink-matching-open} does
819 nothing.
820 @end defvar
821
822 @defvar blink-matching-paren-distance
823 This variable specifies the maximum distance to scan for a matching
824 parenthesis before giving up.
825 @end defvar
826
827 @defvar blink-matching-paren-delay
828 This variable specifies the number of seconds for the cursor to remain
829 at the matching parenthesis.  A fraction of a second often gives
830 good results, but the default is 1, which works on all systems.
831 @end defvar
832
833 @deffn Command blink-matching-open
834 This function is the default value of @code{blink-paren-function}.  It
835 assumes that point follows a character with close parenthesis syntax and
836 moves the cursor momentarily to the matching opening character.  If that
837 character is not already on the screen, it displays the character's
838 context in the echo area.  To avoid long delays, this function does not
839 search farther than @code{blink-matching-paren-distance} characters.
840
841 Here is an example of calling this function explicitly.
842
843 @smallexample
844 @group
845 (defun interactive-blink-matching-open ()
846   "Indicate momentarily the start of sexp before point."
847   (interactive)
848 @end group
849 @group
850   (let ((blink-matching-paren-distance
851          (buffer-size))
852         (blink-matching-paren t))
853     (blink-matching-open)))
854 @end group
855 @end smallexample
856 @end deffn
857
858 @node Usual Display
859 @section Usual Display Conventions
860
861   The usual display conventions define how to display each character
862 code.  You can override these conventions by setting up a display table
863 (@pxref{Display Tables}).  Here are the usual display conventions:
864
865 @itemize @bullet
866 @item
867 Character codes 32 through 126 map to glyph codes 32 through 126.
868 Normally this means they display as themselves.
869
870 @item
871 Character code 9 is a horizontal tab.  It displays as whitespace
872 up to a position determined by @code{tab-width}.
873
874 @item
875 Character code 10 is a newline.
876
877 @item
878 All other codes in the range 0 through 31, and code 127, display in one
879 of two ways according to the value of @code{ctl-arrow}.  If it is
880 non-@code{nil}, these codes map to sequences of two glyphs, where the
881 first glyph is the @sc{ascii} code for @samp{^}.  (A display table can
882 specify a glyph to use instead of @samp{^}.)  Otherwise, these codes map
883 just like the codes in the range 128 to 255.
884
885 @item
886 Character codes 128 through 255 map to sequences of four glyphs, where
887 the first glyph is the @sc{ascii} code for @samp{\}, and the others are
888 digit characters representing the code in octal.  (A display table can
889 specify a glyph to use instead of @samp{\}.)
890 @end itemize
891
892   The usual display conventions apply even when there is a display
893 table, for any character whose entry in the active display table is
894 @code{nil}.  Thus, when you set up a display table, you need only
895 specify the characters for which you want unusual behavior.
896
897   These variables affect the way certain characters are displayed on the
898 screen.  Since they change the number of columns the characters occupy,
899 they also affect the indentation functions.
900
901 @defopt ctl-arrow
902 @cindex control characters in display
903 This buffer-local variable controls how control characters are
904 displayed.  If it is non-@code{nil}, they are displayed as a caret
905 followed by the character: @samp{^A}.  If it is @code{nil}, they are
906 displayed as a backslash followed by three octal digits: @samp{\001}.
907 @end defopt
908
909 @c Following may have overfull hbox.
910 @defvar default-ctl-arrow
911 The value of this variable is the default value for @code{ctl-arrow} in
912 buffers that do not override it.  @xref{Default Value}.
913 @end defvar
914
915 @defopt tab-width
916 The value of this variable is the spacing between tab stops used for
917 displaying tab characters in Emacs buffers.  The default is 8.  Note
918 that this feature is completely independent from the user-settable tab
919 stops used by the command @code{tab-to-tab-stop}.  @xref{Indent Tabs}.
920 @end defopt
921
922 @node Display Tables
923 @section Display Tables
924
925 @cindex display table
926 You can use the @dfn{display table} feature to control how all 256
927 possible character codes display on the screen.  This is useful for
928 displaying European languages that have letters not in the @sc{ascii}
929 character set.
930
931 The display table maps each character code into a sequence of
932 @dfn{runes}, each rune being an image that takes up one character
933 position on the screen.  You can also define how to display each rune
934 on your terminal, using the @dfn{rune table}.
935
936 @menu
937 * Display Table Format::        What a display table consists of.
938 * Active Display Table::        How XEmacs selects a display table to use.
939 * Character Descriptors::       Format of an individual element of a
940                                   display table.
941 @end menu
942
943 @ignore Not yet working in XEmacs?
944 * ISO Latin 1::                 How to use display tables
945                                   to support the ISO Latin 1 character set.
946 @end ignore
947
948 @node Display Table Format
949 @subsection Display Table Format
950
951   A display table is an array of 256 elements. (In FSF Emacs, a display
952 table is 262 elements.  The six extra elements specify the truncation
953 and continuation glyphs, etc.  This method is very kludgey, and in
954 XEmacs the variables @code{truncation-glyph}, @code{continuation-glyph},
955 etc. are used.  @xref{Truncation}.)
956
957 @defun make-display-table
958 This creates and returns a display table.  The table initially has
959 @code{nil} in all elements.
960 @end defun
961
962   The 256 elements correspond to character codes; the @var{n}th
963 element says how to display the character code @var{n}.  The value
964 should be @code{nil}, a string, a glyph, or a vector of strings and
965 glyphs (@pxref{Character Descriptors}).  If an element is @code{nil},
966 it says to display that character according to the usual display
967 conventions (@pxref{Usual Display}).
968
969   If you use the display table to change the display of newline
970 characters, the whole buffer will be displayed as one long ``line.''
971
972   For example, here is how to construct a display table that mimics the
973 effect of setting @code{ctl-arrow} to a non-@code{nil} value:
974
975 @example
976 (setq disptab (make-display-table))
977 (let ((i 0))
978   (while (< i 32)
979     (or (= i ?\t) (= i ?\n)
980         (aset disptab i (concat "^" (char-to-string (+ i 64)))))
981     (setq i (1+ i)))
982   (aset disptab 127 "^?"))
983 @end example
984
985 @node Active Display Table
986 @subsection Active Display Table
987 @cindex active display table
988
989   The active display table is controlled by the variable
990 @code{current-display-table}.  This is a specifier, which means
991 that you can specify separate values for it in individual buffers,
992 windows, frames, and devices, as well as a global value.  It also
993 means that you cannot set this variable using @code{setq}; use
994 @code{set-specifier} instead.  @xref{Specifiers}. (FSF Emacs
995 uses @code{window-display-table}, @code{buffer-display-table},
996 @code{standard-display-table}, etc. to control the display table.
997 However, specifiers are a cleaner and more powerful way of doing
998 the same thing.  FSF Emacs also uses a different format for
999 the contents of a display table, using additional indirection
1000 to a ``glyph table'' and such.  Note that ``glyph'' has a different
1001 meaning in XEmacs.)
1002
1003 @defvar current-display-table
1004
1005 The display table currently in use.  This is a specifier.
1006
1007 Display tables are used to control how characters are displayed.  Each
1008 time that redisplay processes a character, it is looked up in all the
1009 display tables that apply (obtained by calling @code{specifier-instance}
1010 on @code{current-display-table} and any overriding display tables
1011 specified in currently active faces).  The first entry found that
1012 matches the character determines how the character is displayed.  If
1013 there is no matching entry, the default display method is
1014 used. (Non-control characters are displayed as themselves and control
1015 characters are displayed according to the buffer-local variable
1016 @code{ctl-arrow}.  Control characters are further affected by
1017 @code{control-arrow-glyph} and @code{octal-escape-glyph}.)
1018
1019 Each instantiator in this specifier and the display-table specifiers
1020 in faces is a display table or a list of such tables.  If a list, each
1021 table will be searched in turn for an entry matching a particular
1022 character.  Each display table is one of
1023
1024 @itemize @bullet
1025 @item
1026 A vector, specifying values for characters starting at 0.
1027 @item
1028 A char table, either of type @code{char} or @code{generic}.
1029 @item
1030 A range table.
1031 @end itemize
1032
1033 Each entry in a display table should be one of
1034
1035 @itemize @bullet
1036 @item
1037 nil (this entry is ignored and the search continues).
1038 @item
1039 A character (use this character; if it happens to be the same as
1040 the original character, default processing happens, otherwise
1041 redisplay attempts to display this character directly;
1042 #### At some point recursive display-table lookup will be
1043 implemented).
1044 @item
1045 A string (display each character in the string directly;
1046 #### At some point recursive display-table lookup will be
1047 implemented).
1048 @item
1049 A glyph (display the glyph;
1050 #### At some point recursive display-table lookup will be
1051 implemented when a string glyph is being processed).
1052 @item
1053 A cons of the form (format "@var{string}") where @var{string} is a
1054 printf-like spec used to process the character. #### Unfortunately no
1055 formatting directives other than %% are implemented.
1056 @item
1057 A vector (each element of the vector is processed recursively;
1058 in such a case, nil elements in the vector are simply ignored).
1059
1060 #### At some point in the near future, display tables are likely to
1061 be expanded to include other features, such as referencing characters
1062 in particular fonts and allowing the character search to continue
1063 all the way up the chain of specifier instantiators.  These features
1064 are necessary to properly display Unicode characters.
1065 @end itemize
1066 @end defvar
1067
1068   Individual faces can also specify an overriding display table;
1069 this is set using @code{set-face-display-table}.  @xref{Faces}.
1070
1071   If no display table can be determined for a particular window,
1072 then XEmacs uses the usual display conventions.  @xref{Usual Display}.
1073
1074 @node Character Descriptors
1075 @subsection Character Descriptors
1076
1077 @cindex character descriptor
1078   Each element of the display-table vector describes how to display
1079 a particular character and is called a @dfn{character descriptor}.
1080 A character descriptor can be:
1081
1082 @table @asis
1083 @item a string
1084 Display this particular string wherever the character is to be displayed.
1085
1086 @item a glyph
1087 Display this particular glyph wherever the character is to be displayed.
1088
1089 @item a vector
1090 The vector may contain strings and/or glyphs.  Display the elements of
1091 the vector one after another wherever the character is to be displayed.
1092
1093 @item @code{nil}
1094 Display according to the standard interpretation (@pxref{Usual Display}).
1095 @end table
1096
1097 @ignore Not yet working in XEmacs?
1098 @node ISO Latin 1
1099 @subsection ISO Latin 1
1100
1101 If you have a terminal that can handle the entire ISO Latin 1 character
1102 set, you can arrange to use that character set as follows:
1103
1104 @example
1105 (require 'disp-table)
1106 ;; @r{Set char codes 160--255 to display as themselves.}
1107 ;; @r{(Codes 128--159 are the additional control characters.)}
1108 (standard-display-8bit 160 255)
1109 @end example
1110
1111 If you are editing buffers written in the ISO Latin 1 character set and
1112 your terminal doesn't handle anything but @sc{ascii}, you can load the
1113 file @file{iso-ascii} to set up a display table that displays the other
1114 ISO characters as explanatory sequences of @sc{ascii} characters.  For
1115 example, the character ``o with umlaut'' displays as @samp{@{"o@}}.
1116
1117 Some European countries have terminals that don't support ISO Latin 1
1118 but do support the special characters for that country's language.  You
1119 can define a display table to work one language using such terminals.
1120 For an example, see @file{lisp/iso-swed.el}, which handles certain
1121 Swedish terminals.
1122
1123 You can load the appropriate display table for your terminal
1124 automatically by writing a terminal-specific Lisp file for the terminal
1125 type.
1126 @end ignore
1127
1128 @node Beeping
1129 @section Beeping
1130 @cindex beeping
1131 @cindex bell
1132 @cindex sound
1133
1134   You can make XEmacs ring a bell, play a sound, or blink the screen to
1135 attract the user's attention.  Be conservative about how often you do
1136 this; frequent bells can become irritating.  Also be careful not to use
1137 beeping alone when signaling an error is appropriate.  (@xref{Errors}.)
1138
1139 @defun ding &optional dont-terminate sound device
1140 @cindex keyboard macro termination
1141 This function beeps, or flashes the screen (see @code{visible-bell}
1142 below).  It also terminates any keyboard macro currently executing
1143 unless @var{dont-terminate} is non-@code{nil}.  If @var{sound} is
1144 specified, it should be a symbol specifying which sound to make.  This
1145 sound will be played if @code{visible-bell} is @code{nil}. (This only
1146 works if sound support was compiled into the executable and you are
1147 running on the console of a Sun SparcStation, SGI, HP9000s700, or Linux
1148 PC. Otherwise you just get a beep.) The optional third argument
1149 specifies what device to make the sound on, and defaults to the selected
1150 device.
1151 @end defun
1152
1153 @defun beep &optional dont-terminate sound device
1154 This is a synonym for @code{ding}.
1155 @end defun
1156
1157 @defopt visible-bell
1158 This variable determines whether XEmacs should flash the screen to
1159 represent a bell.  Non-@code{nil} means yes, @code{nil} means no.  On
1160 TTY devices, this is effective only if the Termcap entry for the
1161 terminal type has the visible bell flag (@samp{vb}) set.
1162 @end defopt
1163
1164 @defvar sound-alist
1165   This variable holds an alist associating names with sounds.  When
1166 @code{beep} or @code{ding} is called with one of the name symbols, the
1167 associated sound will be generated instead of the standard beep.
1168
1169   Each element of @code{sound-alist} is a list describing a sound.  The
1170 first element of the list is the name of the sound being defined.
1171 Subsequent elements of the list are alternating keyword/value pairs:
1172
1173 @table @code
1174 @item sound
1175 A string of raw sound data, or the name of another sound to play.  The
1176 symbol @code{t} here means use the default X beep.
1177 @item volume
1178 An integer from 0-100, defaulting to @code{bell-volume}.
1179 @item pitch
1180 If using the default X beep, the pitch (Hz) to generate.
1181 @item duration
1182 If using the default X beep, the duration (milliseconds).
1183 @end table
1184
1185 For compatibility, elements of `sound-alist' may also be:
1186
1187 @itemize @bullet
1188 @item
1189 @code{( sound-name . <sound> )}
1190 @item
1191 @code{( sound-name <volume> <sound> )}
1192 @end itemize
1193
1194 You should probably add things to this list by calling the function
1195 @code{load-sound-file}.
1196
1197 Caveats:
1198
1199 @itemize @minus
1200 @item
1201 You can only play audio data if running on the console screen of a Sun
1202 SparcStation, SGI, or HP9000s700.
1203
1204 @item
1205 The pitch, duration, and volume options are available everywhere, but
1206 many X servers ignore the `pitch' option.
1207 @end itemize
1208
1209 The following beep-types are used by XEmacs itself:
1210
1211 @table @code
1212 @item auto-save-error
1213 when an auto-save does not succeed
1214 @item command-error
1215 when the XEmacs command loop catches an error
1216 @item undefined-key
1217 when you type a key that is undefined
1218 @item undefined-click
1219 when you use an undefined mouse-click combination
1220 @item no-completion
1221 during completing-read
1222 @item y-or-n-p
1223 when you type something other than 'y' or 'n'
1224 @item yes-or-no-p
1225 when you type something other than 'yes' or 'no'
1226 @item default
1227 used when nothing else is appropriate.
1228 @end table
1229
1230 Other lisp packages may use other beep types, but these are the ones that
1231 the C kernel of XEmacs uses.
1232 @end defvar
1233
1234 @defopt bell-volume
1235 This variable specifies the default volume for sounds, from 0 to 100.
1236 @end defopt
1237
1238 @deffn Command load-default-sounds
1239 This function loads and installs some sound files as beep-types.
1240 @end deffn
1241
1242 @deffn Command load-sound-file filename sound-name &optional volume
1243 This function reads in an audio file and adds it to @code{sound-alist}.
1244 The sound file must be in the Sun/NeXT U-LAW format.  @var{sound-name}
1245 should be a symbol, specifying the name of the sound.  If @var{volume}
1246 is specified, the sound will be played at that volume; otherwise, the
1247 value of @var{bell-volume} will be used.
1248 @end deffn
1249
1250 @defun play-sound sound &optional volume device
1251 This function plays sound @var{sound}, which should be a symbol
1252 mentioned in @code{sound-alist}.  If @var{volume} is specified, it
1253 overrides the value (if any) specified in @code{sound-alist}.
1254 @var{device} specifies the device to play the sound on, and defaults
1255 to the selected device.
1256 @end defun
1257
1258 @deffn Command play-sound-file file &optional volume device
1259 This function plays the named sound file at volume @var{volume}, which
1260 defaults to @code{bell-volume}.  @var{device} specifies the device to
1261 play the sound on, and defaults to the selected device.
1262 @end deffn