Spelling fixes.
[emacs.git] / doc / lispref / display.texi
bloba9921d7443d9b792c763aaea7b675739918812b8
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-2011  Free Software Foundation, Inc.
4 @c See the file elisp.texi for copying conditions.
5 @setfilename ../../info/display
6 @node Display, System Interface, Processes, Top
7 @chapter Emacs Display
9   This chapter describes a number of features related to the display
10 that Emacs presents to the user.
12 @menu
13 * Refresh Screen::      Clearing the screen and redrawing everything on it.
14 * Forcing Redisplay::   Forcing redisplay.
15 * Truncation::          Folding or wrapping long text lines.
16 * The Echo Area::       Displaying messages at the bottom of the screen.
17 * Warnings::            Displaying warning messages for the user.
18 * Invisible Text::      Hiding part of the buffer text.
19 * Selective Display::   Hiding part of the buffer text (the old way).
20 * Temporary Displays::  Displays that go away automatically.
21 * Overlays::            Use overlays to highlight parts of the buffer.
22 * Width::               How wide a character or string is on the screen.
23 * Line Height::         Controlling the height of lines.
24 * Faces::               A face defines a graphics style for text characters:
25                           font, colors, etc.
26 * Fringes::             Controlling window fringes.
27 * Scroll Bars::         Controlling vertical scroll bars.
28 * Display Property::    Enabling special display features.
29 * Images::              Displaying images in Emacs buffers.
30 * Buttons::             Adding clickable buttons to Emacs buffers.
31 * Abstract Display::    Emacs' Widget for Object Collections.
32 * Blinking::            How Emacs shows the matching open parenthesis.
33 * Usual Display::       The usual conventions for displaying nonprinting chars.
34 * Display Tables::      How to specify other conventions.
35 * Beeping::             Audible signal to the user.
36 * Window Systems::      Which window system is being used.
37 * Bidirectional Display:: Display of bidirectional scripts, such as
38                              Arabic and Farsi.
39 * Glyphless Chars::     How glyphless characters are drawn.
40 @end menu
42 @node Refresh Screen
43 @section Refreshing the Screen
45   The function @code{redraw-frame} clears and redisplays the entire
46 contents of a given frame (@pxref{Frames}).  This is useful if the
47 screen is corrupted.
49 @c Emacs 19 feature
50 @defun redraw-frame frame
51 This function clears and redisplays frame @var{frame}.
52 @end defun
54   Even more powerful is @code{redraw-display}:
56 @deffn Command redraw-display
57 This function clears and redisplays all visible frames.
58 @end deffn
60   In Emacs, processing user input takes priority over redisplay.  If
61 you call these functions when input is available, they don't redisplay
62 immediately, but the requested redisplay does happen
63 eventually---after all the input has been processed.
65   On text-only terminals, suspending and resuming Emacs normally also
66 refreshes the screen.  Some terminal emulators record separate
67 contents for display-oriented programs such as Emacs and for ordinary
68 sequential display.  If you are using such a terminal, you might want
69 to inhibit the redisplay on resumption.
71 @defopt no-redraw-on-reenter
72 @cindex suspend (cf. @code{no-redraw-on-reenter})
73 @cindex resume (cf. @code{no-redraw-on-reenter})
74 This variable controls whether Emacs redraws the entire screen after it
75 has been suspended and resumed.  Non-@code{nil} means there is no need
76 to redraw, @code{nil} means redrawing is needed.  The default is @code{nil}.
77 @end defopt
79 @node Forcing Redisplay
80 @section Forcing Redisplay
81 @cindex forcing redisplay
83   Emacs normally tries to redisplay the screen whenever it waits for
84 input.  With the following function, you can request an immediate
85 attempt to redisplay, in the middle of Lisp code, without actually
86 waiting for input.
88 @defun redisplay &optional force
89 This function tries immediately to redisplay, provided there are no
90 pending input events.
92 If the optional argument @var{force} is non-@code{nil}, it does all
93 pending redisplay work even if input is available, with no
94 pre-emption.
96 The function returns @code{t} if it actually tried to redisplay, and
97 @code{nil} otherwise.  A value of @code{t} does not mean that
98 redisplay proceeded to completion; it could have been pre-empted by
99 newly arriving terminal input.
100 @end defun
102   @code{redisplay} with no argument tries immediately to redisplay,
103 but has no effect on the usual rules for what parts of the screen to
104 redisplay.  By contrast, the following function adds certain windows
105 to the pending redisplay work (as if their contents had completely
106 changed), but doesn't immediately try to do any redisplay work.
108 @defun force-window-update &optional object
109 This function forces some or all windows to be updated on next
110 redisplay.  If @var{object} is a window, it requires eventual
111 redisplay of that window.  If @var{object} is a buffer or buffer name,
112 it requires eventual redisplay of all windows displaying that buffer.
113 If @var{object} is @code{nil} (or omitted), it requires eventual
114 redisplay of all windows.
115 @end defun
117   @code{force-window-update} does not do a redisplay immediately.
118 (Emacs will do that when it waits for input.)  Rather, its effect is
119 to put more work on the queue to be done by redisplay whenever there
120 is a chance.
122 @defvar redisplay-dont-pause
123 If this variable is non-@code{nil}, pending input does not prevent or
124 halt redisplay; redisplay occurs, and finishes, regardless of whether
125 input is available.  If it is @code{nil}, Emacs redisplay stops if
126 input arrives, and does not happen at all if input is available before
127 it starts.  The default is @code{t}.
128 @end defvar
130 @defvar redisplay-preemption-period
131 This variable specifies how many seconds Emacs waits between checks
132 for new input during redisplay.  (The default is 0.1 seconds.)  If
133 input has arrived when Emacs checks, it pre-empts redisplay and
134 processes the available input before trying again to redisplay.
136 If this variable is @code{nil}, Emacs does not check for input during
137 redisplay, and redisplay cannot be preempted by input.
139 This variable is only obeyed on graphical terminals.  For
140 text terminals, see @ref{Terminal Output}.
141 @end defvar
143 @node Truncation
144 @section Truncation
145 @cindex line wrapping
146 @cindex line truncation
147 @cindex continuation lines
148 @cindex @samp{$} in display
149 @cindex @samp{\} in display
151   When a line of text extends beyond the right edge of a window, Emacs
152 can @dfn{continue} the line (make it ``wrap'' to the next screen
153 line), or @dfn{truncate} the line (limit it to one screen line).  The
154 additional screen lines used to display a long text line are called
155 @dfn{continuation} lines.  Continuation is not the same as filling;
156 continuation happens on the screen only, not in the buffer contents,
157 and it breaks a line precisely at the right margin, not at a word
158 boundary.  @xref{Filling}.
160    On a graphical display, tiny arrow images in the window fringes
161 indicate truncated and continued lines (@pxref{Fringes}).  On a text
162 terminal, a @samp{$} in the rightmost column of the window indicates
163 truncation; a @samp{\} on the rightmost column indicates a line that
164 ``wraps.''  (The display table can specify alternate characters to use
165 for this; @pxref{Display Tables}).
167 @defopt truncate-lines
168 If this buffer-local variable is non-@code{nil}, lines that extend
169 beyond the right edge of the window are truncated; otherwise, they are
170 continued.  As a special exception, the variable
171 @code{truncate-partial-width-windows} takes precedence in
172 @dfn{partial-width} windows (i.e., windows that do not occupy the
173 entire frame width).
174 @end defopt
176 @defopt truncate-partial-width-windows
177 This variable controls line truncation in @dfn{partial-width} windows.
178 A partial-width window is one that does not occupy the entire frame
179 width (@pxref{Splitting Windows}).  If the value is @code{nil}, line
180 truncation is determined by the variable @code{truncate-lines} (see
181 above).  If the value is an integer @var{n}, lines are truncated if
182 the partial-width window has fewer than @var{n} columns, regardless of
183 the value of @code{truncate-lines}; if the partial-width window has
184 @var{n} or more columns, line truncation is determined by
185 @code{truncate-lines}.  For any other non-@code{nil} value, lines are
186 truncated in every partial-width window, regardless of the value of
187 @code{truncate-lines}.
188 @end defopt
190   When horizontal scrolling (@pxref{Horizontal Scrolling}) is in use in
191 a window, that forces truncation.
193 @defvar wrap-prefix
194 If this buffer-local variable is non-@code{nil}, it defines a
195 ``prefix'' that is prepended to every continuation line at
196 display time.  (If lines are truncated, the wrap-prefix is never
197 used.)  It may be a string or an image (@pxref{Other Display Specs}),
198 or a stretch of whitespace such as specified by the @code{:width} or
199 @code{:align-to} display properties (@pxref{Specified Space}).  The
200 value is interpreted in the same way as a @code{display} text
201 property.  @xref{Display Property}.
203 A wrap-prefix may also be specified for regions of text, using the
204 @code{wrap-prefix} text or overlay property.  This takes precedence
205 over the @code{wrap-prefix} variable.  @xref{Special Properties}.
206 @end defvar
208 @defvar line-prefix
209 If this buffer-local variable is non-@code{nil}, it defines a
210 ``prefix'' that is prepended to every non-continuation line at
211 display time.  It may be a string or an image (@pxref{Other Display
212 Specs}), or a stretch of whitespace such as specified by the
213 @code{:width} or @code{:align-to} display properties (@pxref{Specified
214 Space}).  The value is interpreted in the same way as a @code{display}
215 text property.  @xref{Display Property}.
217 A line-prefix may also be specified for regions of text using the
218 @code{line-prefix} text or overlay property.  This takes precedence
219 over the @code{line-prefix} variable.  @xref{Special Properties}.
220 @end defvar
222   If your buffer contains @emph{very} long lines, and you use
223 continuation to display them, computing the continuation lines can
224 make Emacs redisplay slow.  The column computation and indentation
225 functions also become slow.  Then you might find it advisable to set
226 @code{cache-long-line-scans} to @code{t}.
228 @defvar cache-long-line-scans
229 If this variable is non-@code{nil}, various indentation and motion
230 functions, and Emacs redisplay, cache the results of scanning the
231 buffer, and consult the cache to avoid rescanning regions of the buffer
232 unless they are modified.
234 Turning on the cache slows down processing of short lines somewhat.
236 This variable is automatically buffer-local in every buffer.
237 @end defvar
239 @node The Echo Area
240 @section The Echo Area
241 @cindex error display
242 @cindex echo area
244   The @dfn{echo area} is used for displaying error messages
245 (@pxref{Errors}), for messages made with the @code{message} primitive,
246 and for echoing keystrokes.  It is not the same as the minibuffer,
247 despite the fact that the minibuffer appears (when active) in the same
248 place on the screen as the echo area.  The @cite{GNU Emacs Manual}
249 specifies the rules for resolving conflicts between the echo area and
250 the minibuffer for use of that screen space (@pxref{Minibuffer,, The
251 Minibuffer, emacs, The GNU Emacs Manual}).
253   You can write output in the echo area by using the Lisp printing
254 functions with @code{t} as the stream (@pxref{Output Functions}), or
255 explicitly.
257 @menu
258 * Displaying Messages:: Explicitly displaying text in the echo area.
259 * Progress::            Informing user about progress of a long operation.
260 * Logging Messages::    Echo area messages are logged for the user.
261 * Echo Area Customization:: Controlling the echo area.
262 @end menu
264 @node Displaying Messages
265 @subsection Displaying Messages in the Echo Area
266 @cindex display message in echo area
268   This section describes the functions for explicitly producing echo
269 area messages.  Many other Emacs features display messages there, too.
271 @defun message format-string &rest arguments
272 This function displays a message in the echo area.  The argument
273 @var{format-string} is similar to a C language @code{printf} format
274 string.  See @code{format} in @ref{Formatting Strings}, for the details
275 on the conversion specifications.  @code{message} returns the
276 constructed string.
278 In batch mode, @code{message} prints the message text on the standard
279 error stream, followed by a newline.
281 If @var{format-string}, or strings among the @var{arguments}, have
282 @code{face} text properties, these affect the way the message is displayed.
284 @c Emacs 19 feature
285 If @var{format-string} is @code{nil} or the empty string,
286 @code{message} clears the echo area; if the echo area has been
287 expanded automatically, this brings it back to its normal size.
288 If the minibuffer is active, this brings the minibuffer contents back
289 onto the screen immediately.
291 @example
292 @group
293 (message "Minibuffer depth is %d."
294          (minibuffer-depth))
295  @print{} Minibuffer depth is 0.
296 @result{} "Minibuffer depth is 0."
297 @end group
299 @group
300 ---------- Echo Area ----------
301 Minibuffer depth is 0.
302 ---------- Echo Area ----------
303 @end group
304 @end example
306 To automatically display a message in the echo area or in a pop-buffer,
307 depending on its size, use @code{display-message-or-buffer} (see below).
308 @end defun
310 @defmac with-temp-message message &rest body
311 This construct displays a message in the echo area temporarily, during
312 the execution of @var{body}.  It displays @var{message}, executes
313 @var{body}, then returns the value of the last body form while restoring
314 the previous echo area contents.
315 @end defmac
317 @defun message-or-box format-string &rest arguments
318 This function displays a message like @code{message}, but may display it
319 in a dialog box instead of the echo area.  If this function is called in
320 a command that was invoked using the mouse---more precisely, if
321 @code{last-nonmenu-event} (@pxref{Command Loop Info}) is either
322 @code{nil} or a list---then it uses a dialog box or pop-up menu to
323 display the message.  Otherwise, it uses the echo area.  (This is the
324 same criterion that @code{y-or-n-p} uses to make a similar decision; see
325 @ref{Yes-or-No Queries}.)
327 You can force use of the mouse or of the echo area by binding
328 @code{last-nonmenu-event} to a suitable value around the call.
329 @end defun
331 @defun message-box format-string &rest arguments
332 @anchor{message-box}
333 This function displays a message like @code{message}, but uses a dialog
334 box (or a pop-up menu) whenever that is possible.  If it is impossible
335 to use a dialog box or pop-up menu, because the terminal does not
336 support them, then @code{message-box} uses the echo area, like
337 @code{message}.
338 @end defun
340 @defun display-message-or-buffer message &optional buffer-name not-this-window frame
341 This function displays the message @var{message}, which may be either a
342 string or a buffer.  If it is shorter than the maximum height of the
343 echo area, as defined by @code{max-mini-window-height}, it is displayed
344 in the echo area, using @code{message}.  Otherwise,
345 @code{display-buffer} is used to show it in a pop-up buffer.
347 Returns either the string shown in the echo area, or when a pop-up
348 buffer is used, the window used to display it.
350 If @var{message} is a string, then the optional argument
351 @var{buffer-name} is the name of the buffer used to display it when a
352 pop-up buffer is used, defaulting to @samp{*Message*}.  In the case
353 where @var{message} is a string and displayed in the echo area, it is
354 not specified whether the contents are inserted into the buffer anyway.
356 The optional arguments @var{not-this-window} and @var{frame} are as for
357 @code{display-buffer}, and only used if a buffer is displayed.
358 @end defun
360 @defun current-message
361 This function returns the message currently being displayed in the
362 echo area, or @code{nil} if there is none.
363 @end defun
365 @node Progress
366 @subsection Reporting Operation Progress
367 @cindex progress reporting
369   When an operation can take a while to finish, you should inform the
370 user about the progress it makes.  This way the user can estimate
371 remaining time and clearly see that Emacs is busy working, not hung.
372 A convenient way to do this is to use a @dfn{progress reporter}.
374   Here is a working example that does nothing useful:
376 @smallexample
377 (let ((progress-reporter
378        (make-progress-reporter "Collecting mana for Emacs..."
379                                0  500)))
380   (dotimes (k 500)
381     (sit-for 0.01)
382     (progress-reporter-update progress-reporter k))
383   (progress-reporter-done progress-reporter))
384 @end smallexample
386 @defun make-progress-reporter message &optional min-value max-value current-value min-change min-time
387 This function creates and returns a progress reporter object, which
388 you will use as an argument for the other functions listed below.  The
389 idea is to precompute as much data as possible to make progress
390 reporting very fast.
392 When this progress reporter is subsequently used, it will display
393 @var{message} in the echo area, followed by progress percentage.
394 @var{message} is treated as a simple string.  If you need it to depend
395 on a filename, for instance, use @code{format} before calling this
396 function.
398 The arguments @var{min-value} and @var{max-value} should be numbers
399 standing for the starting and final states of the operation.  For
400 instance, an operation that ``scans'' a buffer should set these to the
401 results of @code{point-min} and @code{point-max} correspondingly.
402 @var{max-value} should be greater than @var{min-value}.
404 Alternatively, you can set @var{min-value} and @var{max-value} to
405 @code{nil}.  In that case, the progress reporter does not report
406 process percentages; it instead displays a ``spinner'' that rotates a
407 notch each time you update the progress reporter.
409 If @var{min-value} and @var{max-value} are numbers, you can give the
410 argument @var{current-value} a numerical value specifying the initial
411 progress; if omitted, this defaults to @var{min-value}.
413 The remaining arguments control the rate of echo area updates.  The
414 progress reporter will wait for at least @var{min-change} more
415 percents of the operation to be completed before printing next
416 message; the default is one percent.  @var{min-time} specifies the
417 minimum time in seconds to pass between successive prints; the default
418 is 0.2 seconds.  (On some operating systems, the progress reporter may
419 handle fractions of seconds with varying precision).
421 This function calls @code{progress-reporter-update}, so the first
422 message is printed immediately.
423 @end defun
425 @defun progress-reporter-update reporter value
426 This function does the main work of reporting progress of your
427 operation.  It displays the message of @var{reporter}, followed by
428 progress percentage determined by @var{value}.  If percentage is zero,
429 or close enough according to the @var{min-change} and @var{min-time}
430 arguments, then it is omitted from the output.
432 @var{reporter} must be the result of a call to
433 @code{make-progress-reporter}.  @var{value} specifies the current
434 state of your operation and must be between @var{min-value} and
435 @var{max-value} (inclusive) as passed to
436 @code{make-progress-reporter}.  For instance, if you scan a buffer,
437 then @var{value} should be the result of a call to @code{point}.
439 This function respects @var{min-change} and @var{min-time} as passed
440 to @code{make-progress-reporter} and so does not output new messages
441 on every invocation.  It is thus very fast and normally you should not
442 try to reduce the number of calls to it: resulting overhead will most
443 likely negate your effort.
444 @end defun
446 @defun progress-reporter-force-update reporter value &optional new-message
447 This function is similar to @code{progress-reporter-update} except
448 that it prints a message in the echo area unconditionally.
450 The first two arguments have the same meaning as for
451 @code{progress-reporter-update}.  Optional @var{new-message} allows
452 you to change the message of the @var{reporter}.  Since this functions
453 always updates the echo area, such a change will be immediately
454 presented to the user.
455 @end defun
457 @defun progress-reporter-done reporter
458 This function should be called when the operation is finished.  It
459 prints the message of @var{reporter} followed by word ``done'' in the
460 echo area.
462 You should always call this function and not hope for
463 @code{progress-reporter-update} to print ``100%.''  Firstly, it may
464 never print it, there are many good reasons for this not to happen.
465 Secondly, ``done'' is more explicit.
466 @end defun
468 @defmac dotimes-with-progress-reporter (var count [result]) message body@dots{}
469 This is a convenience macro that works the same way as @code{dotimes}
470 does, but also reports loop progress using the functions described
471 above.  It allows you to save some typing.
473 You can rewrite the example in the beginning of this node using
474 this macro this way:
476 @example
477 (dotimes-with-progress-reporter
478     (k 500)
479     "Collecting some mana for Emacs..."
480   (sit-for 0.01))
481 @end example
482 @end defmac
484 @node Logging Messages
485 @subsection Logging Messages in @samp{*Messages*}
486 @cindex logging echo-area messages
488   Almost all the messages displayed in the echo area are also recorded
489 in the @samp{*Messages*} buffer so that the user can refer back to
490 them.  This includes all the messages that are output with
491 @code{message}.
493 @defopt message-log-max
494 This variable specifies how many lines to keep in the @samp{*Messages*}
495 buffer.  The value @code{t} means there is no limit on how many lines to
496 keep.  The value @code{nil} disables message logging entirely.  Here's
497 how to display a message and prevent it from being logged:
499 @example
500 (let (message-log-max)
501   (message @dots{}))
502 @end example
503 @end defopt
505   To make @samp{*Messages*} more convenient for the user, the logging
506 facility combines successive identical messages.  It also combines
507 successive related messages for the sake of two cases: question
508 followed by answer, and a series of progress messages.
510   A ``question followed by an answer'' means two messages like the
511 ones produced by @code{y-or-n-p}: the first is @samp{@var{question}},
512 and the second is @samp{@var{question}...@var{answer}}.  The first
513 message conveys no additional information beyond what's in the second,
514 so logging the second message discards the first from the log.
516   A ``series of progress messages'' means successive messages like
517 those produced by @code{make-progress-reporter}.  They have the form
518 @samp{@var{base}...@var{how-far}}, where @var{base} is the same each
519 time, while @var{how-far} varies.  Logging each message in the series
520 discards the previous one, provided they are consecutive.
522   The functions @code{make-progress-reporter} and @code{y-or-n-p}
523 don't have to do anything special to activate the message log
524 combination feature.  It operates whenever two consecutive messages
525 are logged that share a common prefix ending in @samp{...}.
527 @node Echo Area Customization
528 @subsection Echo Area Customization
530   These variables control details of how the echo area works.
532 @defvar cursor-in-echo-area
533 This variable controls where the cursor appears when a message is
534 displayed in the echo area.  If it is non-@code{nil}, then the cursor
535 appears at the end of the message.  Otherwise, the cursor appears at
536 point---not in the echo area at all.
538 The value is normally @code{nil}; Lisp programs bind it to @code{t}
539 for brief periods of time.
540 @end defvar
542 @defvar echo-area-clear-hook
543 This normal hook is run whenever the echo area is cleared---either by
544 @code{(message nil)} or for any other reason.
545 @end defvar
547 @defopt echo-keystrokes
548 This variable determines how much time should elapse before command
549 characters echo.  Its value must be an integer or floating point number,
550 which specifies the
551 number of seconds to wait before echoing.  If the user types a prefix
552 key (such as @kbd{C-x}) and then delays this many seconds before
553 continuing, the prefix key is echoed in the echo area.  (Once echoing
554 begins in a key sequence, all subsequent characters in the same key
555 sequence are echoed immediately.)
557 If the value is zero, then command input is not echoed.
558 @end defopt
560 @defvar message-truncate-lines
561 Normally, displaying a long message resizes the echo area to display
562 the entire message.  But if the variable @code{message-truncate-lines}
563 is non-@code{nil}, the echo area does not resize, and the message is
564 truncated to fit it, as in Emacs 20 and before.
565 @end defvar
567   The variable @code{max-mini-window-height}, which specifies the
568 maximum height for resizing minibuffer windows, also applies to the
569 echo area (which is really a special use of the minibuffer window.
570 @xref{Minibuffer Misc}.).
572 @node Warnings
573 @section Reporting Warnings
574 @cindex warnings
576   @dfn{Warnings} are a facility for a program to inform the user of a
577 possible problem, but continue running.
579 @menu
580 * Warning Basics::      Warnings concepts and functions to report them.
581 * Warning Variables::   Variables programs bind to customize their warnings.
582 * Warning Options::     Variables users set to control display of warnings.
583 @end menu
585 @node Warning Basics
586 @subsection Warning Basics
587 @cindex severity level
589   Every warning has a textual message, which explains the problem for
590 the user, and a @dfn{severity level} which is a symbol.  Here are the
591 possible severity levels, in order of decreasing severity, and their
592 meanings:
594 @table @code
595 @item :emergency
596 A problem that will seriously impair Emacs operation soon
597 if you do not attend to it promptly.
598 @item :error
599 A report of data or circumstances that are inherently wrong.
600 @item :warning
601 A report of data or circumstances that are not inherently wrong, but
602 raise suspicion of a possible problem.
603 @item :debug
604 A report of information that may be useful if you are debugging.
605 @end table
607   When your program encounters invalid input data, it can either
608 signal a Lisp error by calling @code{error} or @code{signal} or report
609 a warning with severity @code{:error}.  Signaling a Lisp error is the
610 easiest thing to do, but it means the program cannot continue
611 processing.  If you want to take the trouble to implement a way to
612 continue processing despite the bad data, then reporting a warning of
613 severity @code{:error} is the right way to inform the user of the
614 problem.  For instance, the Emacs Lisp byte compiler can report an
615 error that way and continue compiling other functions.  (If the
616 program signals a Lisp error and then handles it with
617 @code{condition-case}, the user won't see the error message; it could
618 show the message to the user by reporting it as a warning.)
620 @cindex warning type
621   Each warning has a @dfn{warning type} to classify it.  The type is a
622 list of symbols.  The first symbol should be the custom group that you
623 use for the program's user options.  For example, byte compiler
624 warnings use the warning type @code{(bytecomp)}.  You can also
625 subcategorize the warnings, if you wish, by using more symbols in the
626 list.
628 @defun display-warning type message &optional level buffer-name
629 This function reports a warning, using @var{message} as the message
630 and @var{type} as the warning type.  @var{level} should be the
631 severity level, with @code{:warning} being the default.
633 @var{buffer-name}, if non-@code{nil}, specifies the name of the buffer
634 for logging the warning.  By default, it is @samp{*Warnings*}.
635 @end defun
637 @defun lwarn type level message &rest args
638 This function reports a warning using the value of @code{(format
639 @var{message} @var{args}...)} as the message.  In other respects it is
640 equivalent to @code{display-warning}.
641 @end defun
643 @defun warn message &rest args
644 This function reports a warning using the value of @code{(format
645 @var{message} @var{args}...)} as the message, @code{(emacs)} as the
646 type, and @code{:warning} as the severity level.  It exists for
647 compatibility only; we recommend not using it, because you should
648 specify a specific warning type.
649 @end defun
651 @node Warning Variables
652 @subsection Warning Variables
654   Programs can customize how their warnings appear by binding
655 the variables described in this section.
657 @defvar warning-levels
658 This list defines the meaning and severity order of the warning
659 severity levels.  Each element defines one severity level,
660 and they are arranged in order of decreasing severity.
662 Each element has the form @code{(@var{level} @var{string}
663 @var{function})}, where @var{level} is the severity level it defines.
664 @var{string} specifies the textual description of this level.
665 @var{string} should use @samp{%s} to specify where to put the warning
666 type information, or it can omit the @samp{%s} so as not to include
667 that information.
669 The optional @var{function}, if non-@code{nil}, is a function to call
670 with no arguments, to get the user's attention.
672 Normally you should not change the value of this variable.
673 @end defvar
675 @defvar warning-prefix-function
676 If non-@code{nil}, the value is a function to generate prefix text for
677 warnings.  Programs can bind the variable to a suitable function.
678 @code{display-warning} calls this function with the warnings buffer
679 current, and the function can insert text in it.  That text becomes
680 the beginning of the warning message.
682 The function is called with two arguments, the severity level and its
683 entry in @code{warning-levels}.  It should return a list to use as the
684 entry (this value need not be an actual member of
685 @code{warning-levels}).  By constructing this value, the function can
686 change the severity of the warning, or specify different handling for
687 a given severity level.
689 If the variable's value is @code{nil} then there is no function
690 to call.
691 @end defvar
693 @defvar warning-series
694 Programs can bind this variable to @code{t} to say that the next
695 warning should begin a series.  When several warnings form a series,
696 that means to leave point on the first warning of the series, rather
697 than keep moving it for each warning so that it appears on the last one.
698 The series ends when the local binding is unbound and
699 @code{warning-series} becomes @code{nil} again.
701 The value can also be a symbol with a function definition.  That is
702 equivalent to @code{t}, except that the next warning will also call
703 the function with no arguments with the warnings buffer current.  The
704 function can insert text which will serve as a header for the series
705 of warnings.
707 Once a series has begun, the value is a marker which points to the
708 buffer position in the warnings buffer of the start of the series.
710 The variable's normal value is @code{nil}, which means to handle
711 each warning separately.
712 @end defvar
714 @defvar warning-fill-prefix
715 When this variable is non-@code{nil}, it specifies a fill prefix to
716 use for filling each warning's text.
717 @end defvar
719 @defvar warning-type-format
720 This variable specifies the format for displaying the warning type
721 in the warning message.  The result of formatting the type this way
722 gets included in the message under the control of the string in the
723 entry in @code{warning-levels}.  The default value is @code{" (%s)"}.
724 If you bind it to @code{""} then the warning type won't appear at
725 all.
726 @end defvar
728 @node Warning Options
729 @subsection Warning Options
731   These variables are used by users to control what happens
732 when a Lisp program reports a warning.
734 @defopt warning-minimum-level
735 This user option specifies the minimum severity level that should be
736 shown immediately to the user.  The default is @code{:warning}, which
737 means to immediately display all warnings except @code{:debug}
738 warnings.
739 @end defopt
741 @defopt warning-minimum-log-level
742 This user option specifies the minimum severity level that should be
743 logged in the warnings buffer.  The default is @code{:warning}, which
744 means to log all warnings except @code{:debug} warnings.
745 @end defopt
747 @defopt warning-suppress-types
748 This list specifies which warning types should not be displayed
749 immediately for the user.  Each element of the list should be a list
750 of symbols.  If its elements match the first elements in a warning
751 type, then that warning is not displayed immediately.
752 @end defopt
754 @defopt warning-suppress-log-types
755 This list specifies which warning types should not be logged in the
756 warnings buffer.  Each element of the list should be a list of
757 symbols.  If it matches the first few elements in a warning type, then
758 that warning is not logged.
759 @end defopt
761 @node Invisible Text
762 @section Invisible Text
764 @cindex invisible text
765 You can make characters @dfn{invisible}, so that they do not appear on
766 the screen, with the @code{invisible} property.  This can be either a
767 text property (@pxref{Text Properties}) or a property of an overlay
768 (@pxref{Overlays}).  Cursor motion also partly ignores these
769 characters; if the command loop finds point within them, it moves
770 point to the other side of them.
772 In the simplest case, any non-@code{nil} @code{invisible} property makes
773 a character invisible.  This is the default case---if you don't alter
774 the default value of @code{buffer-invisibility-spec}, this is how the
775 @code{invisible} property works.  You should normally use @code{t}
776 as the value of the @code{invisible} property if you don't plan
777 to set @code{buffer-invisibility-spec} yourself.
779 More generally, you can use the variable @code{buffer-invisibility-spec}
780 to control which values of the @code{invisible} property make text
781 invisible.  This permits you to classify the text into different subsets
782 in advance, by giving them different @code{invisible} values, and
783 subsequently make various subsets visible or invisible by changing the
784 value of @code{buffer-invisibility-spec}.
786 Controlling visibility with @code{buffer-invisibility-spec} is
787 especially useful in a program to display the list of entries in a
788 database.  It permits the implementation of convenient filtering
789 commands to view just a part of the entries in the database.  Setting
790 this variable is very fast, much faster than scanning all the text in
791 the buffer looking for properties to change.
793 @defvar buffer-invisibility-spec
794 This variable specifies which kinds of @code{invisible} properties
795 actually make a character invisible.  Setting this variable makes it
796 buffer-local.
798 @table @asis
799 @item @code{t}
800 A character is invisible if its @code{invisible} property is
801 non-@code{nil}.  This is the default.
803 @item a list
804 Each element of the list specifies a criterion for invisibility; if a
805 character's @code{invisible} property fits any one of these criteria,
806 the character is invisible.  The list can have two kinds of elements:
808 @table @code
809 @item @var{atom}
810 A character is invisible if its @code{invisible} property value
811 is @var{atom} or if it is a list with @var{atom} as a member.
813 @item (@var{atom} . t)
814 A character is invisible if its @code{invisible} property value is
815 @var{atom} or if it is a list with @var{atom} as a member.  Moreover,
816 a sequence of such characters displays as an ellipsis.
817 @end table
818 @end table
819 @end defvar
821   Two functions are specifically provided for adding elements to
822 @code{buffer-invisibility-spec} and removing elements from it.
824 @defun add-to-invisibility-spec element
825 This function adds the element @var{element} to
826 @code{buffer-invisibility-spec}.  If @code{buffer-invisibility-spec}
827 was @code{t}, it changes to a list, @code{(t)}, so that text whose
828 @code{invisible} property is @code{t} remains invisible.
829 @end defun
831 @defun remove-from-invisibility-spec element
832 This removes the element @var{element} from
833 @code{buffer-invisibility-spec}.  This does nothing if @var{element}
834 is not in the list.
835 @end defun
837   A convention for use of @code{buffer-invisibility-spec} is that a
838 major mode should use the mode's own name as an element of
839 @code{buffer-invisibility-spec} and as the value of the
840 @code{invisible} property:
842 @example
843 ;; @r{If you want to display an ellipsis:}
844 (add-to-invisibility-spec '(my-symbol . t))
845 ;; @r{If you don't want ellipsis:}
846 (add-to-invisibility-spec 'my-symbol)
848 (overlay-put (make-overlay beginning end)
849              'invisible 'my-symbol)
851 ;; @r{When done with the overlays:}
852 (remove-from-invisibility-spec '(my-symbol . t))
853 ;; @r{Or respectively:}
854 (remove-from-invisibility-spec 'my-symbol)
855 @end example
857   You can check for invisibility using the following function:
859 @defun invisible-p pos-or-prop
860 If @var{pos-or-prop} is a marker or number, this function returns a
861 non-@code{nil} value if the text at that position is invisible.
863 If @var{pos-or-prop} is any other kind of Lisp object, that is taken
864 to mean a possible value of the @code{invisible} text or overlay
865 property.  In that case, this function returns a non-@code{nil} value
866 if that value would cause text to become invisible, based on the
867 current value of @code{buffer-invisibility-spec}.
868 @end defun
870 @vindex line-move-ignore-invisible
871   Ordinarily, functions that operate on text or move point do not care
872 whether the text is invisible.  The user-level line motion commands
873 ignore invisible newlines if @code{line-move-ignore-invisible} is
874 non-@code{nil} (the default), but only because they are explicitly
875 programmed to do so.
877   However, if a command ends with point inside or at the boundary of invisible
878 text, the main editing loop moves point to one of the two ends of the invisible
879 text.  Which end to move to is chosen based on the following factors: make sure
880 that the overall movement of the command is still in the same direction, and
881 prefer a position where an inserted char would not inherit the @code{invisible}
882 property.  Additionally, if the text is not replaced by an ellipsis and the
883 command only moved within the invisible text, then point is moved one extra
884 character so as to try and reflect the command's movement by a visible movement
885 of the cursor.
887   Thus, if the command moved point back to an invisible range (with the usual
888 stickiness), Emacs moves point back to the beginning of that range.  If the
889 command moved point forward into an invisible range, Emacs moves point forward
890 to the first visible character that follows the invisible text and then forward
891 one more character.
893   Incremental search can make invisible overlays visible temporarily
894 and/or permanently when a match includes invisible text.  To enable
895 this, the overlay should have a non-@code{nil}
896 @code{isearch-open-invisible} property.  The property value should be a
897 function to be called with the overlay as an argument.  This function
898 should make the overlay visible permanently; it is used when the match
899 overlaps the overlay on exit from the search.
901   During the search, such overlays are made temporarily visible by
902 temporarily modifying their invisible and intangible properties.  If you
903 want this to be done differently for a certain overlay, give it an
904 @code{isearch-open-invisible-temporary} property which is a function.
905 The function is called with two arguments: the first is the overlay, and
906 the second is @code{nil} to make the overlay visible, or @code{t} to
907 make it invisible again.
909 @node Selective Display
910 @section Selective Display
911 @c @cindex selective display   Duplicates selective-display
913   @dfn{Selective display} refers to a pair of related features for
914 hiding certain lines on the screen.
916   The first variant, explicit selective display, is designed for use
917 in a Lisp program: it controls which lines are hidden by altering the
918 text.  This kind of hiding in some ways resembles the effect of the
919 @code{invisible} property (@pxref{Invisible Text}), but the two
920 features are different and do not work the same way.
922   In the second variant, the choice of lines to hide is made
923 automatically based on indentation.  This variant is designed to be a
924 user-level feature.
926   The way you control explicit selective display is by replacing a
927 newline (control-j) with a carriage return (control-m).  The text that
928 was formerly a line following that newline is now hidden.  Strictly
929 speaking, it is temporarily no longer a line at all, since only
930 newlines can separate lines; it is now part of the previous line.
932   Selective display does not directly affect editing commands.  For
933 example, @kbd{C-f} (@code{forward-char}) moves point unhesitatingly
934 into hidden text.  However, the replacement of newline characters with
935 carriage return characters affects some editing commands.  For
936 example, @code{next-line} skips hidden lines, since it searches only
937 for newlines.  Modes that use selective display can also define
938 commands that take account of the newlines, or that control which
939 parts of the text are hidden.
941   When you write a selectively displayed buffer into a file, all the
942 control-m's are output as newlines.  This means that when you next read
943 in the file, it looks OK, with nothing hidden.  The selective display
944 effect is seen only within Emacs.
946 @defvar selective-display
947 This buffer-local variable enables selective display.  This means that
948 lines, or portions of lines, may be made hidden.
950 @itemize @bullet
951 @item
952 If the value of @code{selective-display} is @code{t}, then the character
953 control-m marks the start of hidden text; the control-m, and the rest
954 of the line following it, are not displayed.  This is explicit selective
955 display.
957 @item
958 If the value of @code{selective-display} is a positive integer, then
959 lines that start with more than that many columns of indentation are not
960 displayed.
961 @end itemize
963 When some portion of a buffer is hidden, the vertical movement
964 commands operate as if that portion did not exist, allowing a single
965 @code{next-line} command to skip any number of hidden lines.
966 However, character movement commands (such as @code{forward-char}) do
967 not skip the hidden portion, and it is possible (if tricky) to insert
968 or delete text in an hidden portion.
970 In the examples below, we show the @emph{display appearance} of the
971 buffer @code{foo}, which changes with the value of
972 @code{selective-display}.  The @emph{contents} of the buffer do not
973 change.
975 @example
976 @group
977 (setq selective-display nil)
978      @result{} nil
980 ---------- Buffer: foo ----------
981 1 on this column
982  2on this column
983   3n this column
984   3n this column
985  2on this column
986 1 on this column
987 ---------- Buffer: foo ----------
988 @end group
990 @group
991 (setq selective-display 2)
992      @result{} 2
994 ---------- Buffer: foo ----------
995 1 on this column
996  2on this column
997  2on this column
998 1 on this column
999 ---------- Buffer: foo ----------
1000 @end group
1001 @end example
1002 @end defvar
1004 @defopt selective-display-ellipses
1005 If this buffer-local variable is non-@code{nil}, then Emacs displays
1006 @samp{@dots{}} at the end of a line that is followed by hidden text.
1007 This example is a continuation of the previous one.
1009 @example
1010 @group
1011 (setq selective-display-ellipses t)
1012      @result{} t
1014 ---------- Buffer: foo ----------
1015 1 on this column
1016  2on this column ...
1017  2on this column
1018 1 on this column
1019 ---------- Buffer: foo ----------
1020 @end group
1021 @end example
1023 You can use a display table to substitute other text for the ellipsis
1024 (@samp{@dots{}}).  @xref{Display Tables}.
1025 @end defopt
1027 @node Temporary Displays
1028 @section Temporary Displays
1030   Temporary displays are used by Lisp programs to put output into a
1031 buffer and then present it to the user for perusal rather than for
1032 editing.  Many help commands use this feature.
1034 @defspec with-output-to-temp-buffer buffer-name forms@dots{}
1035 This function executes @var{forms} while arranging to insert any output
1036 they print into the buffer named @var{buffer-name}, which is first
1037 created if necessary, and put into Help mode.  Finally, the buffer is
1038 displayed in some window, but not selected.
1040 If the @var{forms} do not change the major mode in the output buffer,
1041 so that it is still Help mode at the end of their execution, then
1042 @code{with-output-to-temp-buffer} makes this buffer read-only at the
1043 end, and also scans it for function and variable names to make them
1044 into clickable cross-references.  @xref{Docstring hyperlinks, , Tips
1045 for Documentation Strings}, in particular the item on hyperlinks in
1046 documentation strings, for more details.
1048 The string @var{buffer-name} specifies the temporary buffer, which
1049 need not already exist.  The argument must be a string, not a buffer.
1050 The buffer is erased initially (with no questions asked), and it is
1051 marked as unmodified after @code{with-output-to-temp-buffer} exits.
1053 @code{with-output-to-temp-buffer} binds @code{standard-output} to the
1054 temporary buffer, then it evaluates the forms in @var{forms}.  Output
1055 using the Lisp output functions within @var{forms} goes by default to
1056 that buffer (but screen display and messages in the echo area, although
1057 they are ``output'' in the general sense of the word, are not affected).
1058 @xref{Output Functions}.
1060 Several hooks are available for customizing the behavior
1061 of this construct; they are listed below.
1063 The value of the last form in @var{forms} is returned.
1065 @example
1066 @group
1067 ---------- Buffer: foo ----------
1068  This is the contents of foo.
1069 ---------- Buffer: foo ----------
1070 @end group
1072 @group
1073 (with-output-to-temp-buffer "foo"
1074     (print 20)
1075     (print standard-output))
1076 @result{} #<buffer foo>
1078 ---------- Buffer: foo ----------
1081 #<buffer foo>
1083 ---------- Buffer: foo ----------
1084 @end group
1085 @end example
1086 @end defspec
1088 @defopt temp-buffer-show-function
1089 If this variable is non-@code{nil}, @code{with-output-to-temp-buffer}
1090 calls it as a function to do the job of displaying a help buffer.  The
1091 function gets one argument, which is the buffer it should display.
1093 It is a good idea for this function to run @code{temp-buffer-show-hook}
1094 just as @code{with-output-to-temp-buffer} normally would, inside of
1095 @code{save-selected-window} and with the chosen window and buffer
1096 selected.
1097 @end defopt
1099 @defvar temp-buffer-setup-hook
1100 This normal hook is run by @code{with-output-to-temp-buffer} before
1101 evaluating @var{body}.  When the hook runs, the temporary buffer is
1102 current.  This hook is normally set up with a function to put the
1103 buffer in Help mode.
1104 @end defvar
1106 @defvar temp-buffer-show-hook
1107 This normal hook is run by @code{with-output-to-temp-buffer} after
1108 displaying the temporary buffer.  When the hook runs, the temporary buffer
1109 is current, and the window it was displayed in is selected.
1110 @end defvar
1112 @defun momentary-string-display string position &optional char message
1113 This function momentarily displays @var{string} in the current buffer at
1114 @var{position}.  It has no effect on the undo list or on the buffer's
1115 modification status.
1117 The momentary display remains until the next input event.  If the next
1118 input event is @var{char}, @code{momentary-string-display} ignores it
1119 and returns.  Otherwise, that event remains buffered for subsequent use
1120 as input.  Thus, typing @var{char} will simply remove the string from
1121 the display, while typing (say) @kbd{C-f} will remove the string from
1122 the display and later (presumably) move point forward.  The argument
1123 @var{char} is a space by default.
1125 The return value of @code{momentary-string-display} is not meaningful.
1127 If the string @var{string} does not contain control characters, you can
1128 do the same job in a more general way by creating (and then subsequently
1129 deleting) an overlay with a @code{before-string} property.
1130 @xref{Overlay Properties}.
1132 If @var{message} is non-@code{nil}, it is displayed in the echo area
1133 while @var{string} is displayed in the buffer.  If it is @code{nil}, a
1134 default message says to type @var{char} to continue.
1136 In this example, point is initially located at the beginning of the
1137 second line:
1139 @example
1140 @group
1141 ---------- Buffer: foo ----------
1142 This is the contents of foo.
1143 @point{}Second line.
1144 ---------- Buffer: foo ----------
1145 @end group
1147 @group
1148 (momentary-string-display
1149   "**** Important Message! ****"
1150   (point) ?\r
1151   "Type RET when done reading")
1152 @result{} t
1153 @end group
1155 @group
1156 ---------- Buffer: foo ----------
1157 This is the contents of foo.
1158 **** Important Message! ****Second line.
1159 ---------- Buffer: foo ----------
1161 ---------- Echo Area ----------
1162 Type RET when done reading
1163 ---------- Echo Area ----------
1164 @end group
1165 @end example
1166 @end defun
1168 @node Overlays
1169 @section Overlays
1170 @cindex overlays
1172 You can use @dfn{overlays} to alter the appearance of a buffer's text on
1173 the screen, for the sake of presentation features.  An overlay is an
1174 object that belongs to a particular buffer, and has a specified
1175 beginning and end.  It also has properties that you can examine and set;
1176 these affect the display of the text within the overlay.
1178 @cindex scalability of overlays
1179 The visual effect of an overlay is the same as of the corresponding
1180 text property (@pxref{Text Properties}).  However, due to a different
1181 implementation, overlays generally don't scale well (many operations
1182 take a time that is proportional to the number of overlays in the
1183 buffer).  If you need to affect the visual appearance of many portions
1184 in the buffer, we recommend using text properties.
1186 An overlay uses markers to record its beginning and end; thus,
1187 editing the text of the buffer adjusts the beginning and end of each
1188 overlay so that it stays with the text.  When you create the overlay,
1189 you can specify whether text inserted at the beginning should be
1190 inside the overlay or outside, and likewise for the end of the overlay.
1192 @menu
1193 * Managing Overlays::   Creating and moving overlays.
1194 * Overlay Properties::  How to read and set properties.
1195                           What properties do to the screen display.
1196 * Finding Overlays::    Searching for overlays.
1197 @end menu
1199 @node Managing Overlays
1200 @subsection Managing Overlays
1202   This section describes the functions to create, delete and move
1203 overlays, and to examine their contents.  Overlay changes are not
1204 recorded in the buffer's undo list, since the overlays are not
1205 part of the buffer's contents.
1207 @defun overlayp object
1208 This function returns @code{t} if @var{object} is an overlay.
1209 @end defun
1211 @defun make-overlay start end &optional buffer front-advance rear-advance
1212 This function creates and returns an overlay that belongs to
1213 @var{buffer} and ranges from @var{start} to @var{end}.  Both @var{start}
1214 and @var{end} must specify buffer positions; they may be integers or
1215 markers.  If @var{buffer} is omitted, the overlay is created in the
1216 current buffer.
1218 The arguments @var{front-advance} and @var{rear-advance} specify the
1219 marker insertion type for the start of the overlay and for the end of
1220 the overlay, respectively.  @xref{Marker Insertion Types}.  If they
1221 are both @code{nil}, the default, then the overlay extends to include
1222 any text inserted at the beginning, but not text inserted at the end.
1223 If @var{front-advance} is non-@code{nil}, text inserted at the
1224 beginning of the overlay is excluded from the overlay.  If
1225 @var{rear-advance} is non-@code{nil}, text inserted at the end of the
1226 overlay is included in the overlay.
1227 @end defun
1229 @defun overlay-start overlay
1230 This function returns the position at which @var{overlay} starts,
1231 as an integer.
1232 @end defun
1234 @defun overlay-end overlay
1235 This function returns the position at which @var{overlay} ends,
1236 as an integer.
1237 @end defun
1239 @defun overlay-buffer overlay
1240 This function returns the buffer that @var{overlay} belongs to.  It
1241 returns @code{nil} if @var{overlay} has been deleted.
1242 @end defun
1244 @defun delete-overlay overlay
1245 This function deletes @var{overlay}.  The overlay continues to exist as
1246 a Lisp object, and its property list is unchanged, but it ceases to be
1247 attached to the buffer it belonged to, and ceases to have any effect on
1248 display.
1250 A deleted overlay is not permanently disconnected.  You can give it a
1251 position in a buffer again by calling @code{move-overlay}.
1252 @end defun
1254 @defun move-overlay overlay start end &optional buffer
1255 This function moves @var{overlay} to @var{buffer}, and places its bounds
1256 at @var{start} and @var{end}.  Both arguments @var{start} and @var{end}
1257 must specify buffer positions; they may be integers or markers.
1259 If @var{buffer} is omitted, @var{overlay} stays in the same buffer it
1260 was already associated with; if @var{overlay} was deleted, it goes into
1261 the current buffer.
1263 The return value is @var{overlay}.
1265 This is the only valid way to change the endpoints of an overlay.  Do
1266 not try modifying the markers in the overlay by hand, as that fails to
1267 update other vital data structures and can cause some overlays to be
1268 ``lost.''
1269 @end defun
1271 @defun remove-overlays &optional start end name value
1272 This function removes all the overlays between @var{start} and
1273 @var{end} whose property @var{name} has the value @var{value}.  It can
1274 move the endpoints of the overlays in the region, or split them.
1276 If @var{name} is omitted or @code{nil}, it means to delete all overlays in
1277 the specified region.  If @var{start} and/or @var{end} are omitted or
1278 @code{nil}, that means the beginning and end of the buffer respectively.
1279 Therefore, @code{(remove-overlays)} removes all the overlays in the
1280 current buffer.
1281 @end defun
1283 @defun copy-overlay overlay
1284 This function returns a copy of @var{overlay}.  The copy has the same
1285 endpoints and properties as @var{overlay}.  However, the marker
1286 insertion type for the start of the overlay and for the end of the
1287 overlay are set to their default values (@pxref{Marker Insertion
1288 Types}).
1289 @end defun
1291   Here are some examples:
1293 @example
1294 ;; @r{Create an overlay.}
1295 (setq foo (make-overlay 1 10))
1296      @result{} #<overlay from 1 to 10 in display.texi>
1297 (overlay-start foo)
1298      @result{} 1
1299 (overlay-end foo)
1300      @result{} 10
1301 (overlay-buffer foo)
1302      @result{} #<buffer display.texi>
1303 ;; @r{Give it a property we can check later.}
1304 (overlay-put foo 'happy t)
1305      @result{} t
1306 ;; @r{Verify the property is present.}
1307 (overlay-get foo 'happy)
1308      @result{} t
1309 ;; @r{Move the overlay.}
1310 (move-overlay foo 5 20)
1311      @result{} #<overlay from 5 to 20 in display.texi>
1312 (overlay-start foo)
1313      @result{} 5
1314 (overlay-end foo)
1315      @result{} 20
1316 ;; @r{Delete the overlay.}
1317 (delete-overlay foo)
1318      @result{} nil
1319 ;; @r{Verify it is deleted.}
1321      @result{} #<overlay in no buffer>
1322 ;; @r{A deleted overlay has no position.}
1323 (overlay-start foo)
1324      @result{} nil
1325 (overlay-end foo)
1326      @result{} nil
1327 (overlay-buffer foo)
1328      @result{} nil
1329 ;; @r{Undelete the overlay.}
1330 (move-overlay foo 1 20)
1331      @result{} #<overlay from 1 to 20 in display.texi>
1332 ;; @r{Verify the results.}
1333 (overlay-start foo)
1334      @result{} 1
1335 (overlay-end foo)
1336      @result{} 20
1337 (overlay-buffer foo)
1338      @result{} #<buffer display.texi>
1339 ;; @r{Moving and deleting the overlay does not change its properties.}
1340 (overlay-get foo 'happy)
1341      @result{} t
1342 @end example
1344   Emacs stores the overlays of each buffer in two lists, divided
1345 around an arbitrary ``center position.''  One list extends backwards
1346 through the buffer from that center position, and the other extends
1347 forwards from that center position.  The center position can be anywhere
1348 in the buffer.
1350 @defun overlay-recenter pos
1351 This function recenters the overlays of the current buffer around
1352 position @var{pos}.  That makes overlay lookup faster for positions
1353 near @var{pos}, but slower for positions far away from @var{pos}.
1354 @end defun
1356   A loop that scans the buffer forwards, creating overlays, can run
1357 faster if you do @code{(overlay-recenter (point-max))} first.
1359 @node Overlay Properties
1360 @subsection Overlay Properties
1362   Overlay properties are like text properties in that the properties that
1363 alter how a character is displayed can come from either source.  But in
1364 most respects they are different.  @xref{Text Properties}, for comparison.
1366   Text properties are considered a part of the text; overlays and
1367 their properties are specifically considered not to be part of the
1368 text.  Thus, copying text between various buffers and strings
1369 preserves text properties, but does not try to preserve overlays.
1370 Changing a buffer's text properties marks the buffer as modified,
1371 while moving an overlay or changing its properties does not.  Unlike
1372 text property changes, overlay property changes are not recorded in
1373 the buffer's undo list.
1375   Since more than one overlay can specify a property value for the
1376 same character, Emacs lets you specify a priority value of each
1377 overlay.  You should not make assumptions about which overlay will
1378 prevail when there is a conflict and they have the same priority.
1380   These functions read and set the properties of an overlay:
1382 @defun overlay-get overlay prop
1383 This function returns the value of property @var{prop} recorded in
1384 @var{overlay}, if any.  If @var{overlay} does not record any value for
1385 that property, but it does have a @code{category} property which is a
1386 symbol, that symbol's @var{prop} property is used.  Otherwise, the value
1387 is @code{nil}.
1388 @end defun
1390 @defun overlay-put overlay prop value
1391 This function sets the value of property @var{prop} recorded in
1392 @var{overlay} to @var{value}.  It returns @var{value}.
1393 @end defun
1395 @defun overlay-properties overlay
1396 This returns a copy of the property list of @var{overlay}.
1397 @end defun
1399   See also the function @code{get-char-property} which checks both
1400 overlay properties and text properties for a given character.
1401 @xref{Examining Properties}.
1403   Many overlay properties have special meanings; here is a table
1404 of them:
1406 @table @code
1407 @item priority
1408 @kindex priority @r{(overlay property)}
1409 This property's value (which should be a nonnegative integer number)
1410 determines the priority of the overlay.  No priority, or @code{nil},
1411 means zero.
1413 The priority matters when two or more overlays cover the same
1414 character and both specify the same property; the one whose
1415 @code{priority} value is larger overrides the other.  For the
1416 @code{face} property, the higher priority overlay's value does not
1417 completely override the other value; instead, its face attributes
1418 override the face attributes of the lower priority @code{face}
1419 property.
1421 Currently, all overlays take priority over text properties.  Please
1422 avoid using negative priority values, as we have not yet decided just
1423 what they should mean.
1425 @item window
1426 @kindex window @r{(overlay property)}
1427 If the @code{window} property is non-@code{nil}, then the overlay
1428 applies only on that window.
1430 @item category
1431 @kindex category @r{(overlay property)}
1432 If an overlay has a @code{category} property, we call it the
1433 @dfn{category} of the overlay.  It should be a symbol.  The properties
1434 of the symbol serve as defaults for the properties of the overlay.
1436 @item face
1437 @kindex face @r{(overlay property)}
1438 This property controls the way text is displayed---for example, which
1439 font and which colors.  @xref{Faces}, for more information.
1441 In the simplest case, the value is a face name.  It can also be a list;
1442 then each element can be any of these possibilities:
1444 @itemize @bullet
1445 @item
1446 A face name (a symbol or string).
1448 @item
1449 A property list of face attributes.  This has the form (@var{keyword}
1450 @var{value} @dots{}), where each @var{keyword} is a face attribute
1451 name and @var{value} is a meaningful value for that attribute.  With
1452 this feature, you do not need to create a face each time you want to
1453 specify a particular attribute for certain text.  @xref{Face
1454 Attributes}.
1456 @item
1457 A cons cell, of the form @code{(foreground-color . @var{color-name})}
1458 or @code{(background-color . @var{color-name})}.  These elements
1459 specify just the foreground color or just the background color.
1461 @code{(foreground-color . @var{color-name})} has the same effect as
1462 @code{(:foreground @var{color-name})}; likewise for the background.
1463 @end itemize
1465 @item mouse-face
1466 @kindex mouse-face @r{(overlay property)}
1467 This property is used instead of @code{face} when the mouse is within
1468 the range of the overlay.  However, Emacs ignores all face attributes
1469 from this property that alter the text size (e.g.  @code{:height},
1470 @code{:weight}, and @code{:slant}).  Those attributes are always the
1471 same as in the unhighlighted text.
1473 @item display
1474 @kindex display @r{(overlay property)}
1475 This property activates various features that change the
1476 way text is displayed.  For example, it can make text appear taller
1477 or shorter, higher or lower, wider or narrower, or replaced with an image.
1478 @xref{Display Property}.
1480 @item help-echo
1481 @kindex help-echo @r{(overlay property)}
1482 If an overlay has a @code{help-echo} property, then when you move the
1483 mouse onto the text in the overlay, Emacs displays a help string in the
1484 echo area, or in the tooltip window.  For details see @ref{Text
1485 help-echo}.
1487 @item modification-hooks
1488 @kindex modification-hooks @r{(overlay property)}
1489 This property's value is a list of functions to be called if any
1490 character within the overlay is changed or if text is inserted strictly
1491 within the overlay.
1493 The hook functions are called both before and after each change.
1494 If the functions save the information they receive, and compare notes
1495 between calls, they can determine exactly what change has been made
1496 in the buffer text.
1498 When called before a change, each function receives four arguments: the
1499 overlay, @code{nil}, and the beginning and end of the text range to be
1500 modified.
1502 When called after a change, each function receives five arguments: the
1503 overlay, @code{t}, the beginning and end of the text range just
1504 modified, and the length of the pre-change text replaced by that range.
1505 (For an insertion, the pre-change length is zero; for a deletion, that
1506 length is the number of characters deleted, and the post-change
1507 beginning and end are equal.)
1509 If these functions modify the buffer, they should bind
1510 @code{inhibit-modification-hooks} to @code{t} around doing so, to
1511 avoid confusing the internal mechanism that calls these hooks.
1513 Text properties also support the @code{modification-hooks} property,
1514 but the details are somewhat different (@pxref{Special Properties}).
1516 @item insert-in-front-hooks
1517 @kindex insert-in-front-hooks @r{(overlay property)}
1518 This property's value is a list of functions to be called before and
1519 after inserting text right at the beginning of the overlay.  The calling
1520 conventions are the same as for the @code{modification-hooks} functions.
1522 @item insert-behind-hooks
1523 @kindex insert-behind-hooks @r{(overlay property)}
1524 This property's value is a list of functions to be called before and
1525 after inserting text right at the end of the overlay.  The calling
1526 conventions are the same as for the @code{modification-hooks} functions.
1528 @item invisible
1529 @kindex invisible @r{(overlay property)}
1530 The @code{invisible} property can make the text in the overlay
1531 invisible, which means that it does not appear on the screen.
1532 @xref{Invisible Text}, for details.
1534 @item intangible
1535 @kindex intangible @r{(overlay property)}
1536 The @code{intangible} property on an overlay works just like the
1537 @code{intangible} text property.  @xref{Special Properties}, for details.
1539 @item isearch-open-invisible
1540 This property tells incremental search how to make an invisible overlay
1541 visible, permanently, if the final match overlaps it.  @xref{Invisible
1542 Text}.
1544 @item isearch-open-invisible-temporary
1545 This property tells incremental search how to make an invisible overlay
1546 visible, temporarily, during the search.  @xref{Invisible Text}.
1548 @item before-string
1549 @kindex before-string @r{(overlay property)}
1550 This property's value is a string to add to the display at the beginning
1551 of the overlay.  The string does not appear in the buffer in any
1552 sense---only on the screen.
1554 @item after-string
1555 @kindex after-string @r{(overlay property)}
1556 This property's value is a string to add to the display at the end of
1557 the overlay.  The string does not appear in the buffer in any
1558 sense---only on the screen.
1560 @item line-prefix
1561 This property specifies a display spec to prepend to each
1562 non-continuation line at display-time.  @xref{Truncation}.
1564 @itemx wrap-prefix
1565 This property specifies a display spec to prepend to each continuation
1566 line at display-time.  @xref{Truncation}.
1568 @item evaporate
1569 @kindex evaporate @r{(overlay property)}
1570 If this property is non-@code{nil}, the overlay is deleted automatically
1571 if it becomes empty (i.e., if its length becomes zero).  If you give
1572 an empty overlay a non-@code{nil} @code{evaporate} property, that deletes
1573 it immediately.
1575 @item local-map
1576 @cindex keymap of character (and overlays)
1577 @kindex local-map @r{(overlay property)}
1578 If this property is non-@code{nil}, it specifies a keymap for a portion
1579 of the text.  The property's value replaces the buffer's local map, when
1580 the character after point is within the overlay.  @xref{Active Keymaps}.
1582 @item keymap
1583 @kindex keymap @r{(overlay property)}
1584 The @code{keymap} property is similar to @code{local-map} but overrides the
1585 buffer's local map (and the map specified by the @code{local-map}
1586 property) rather than replacing it.
1587 @end table
1589 The @code{local-map} and @code{keymap} properties do not affect a
1590 string displayed by the @code{before-string}, @code{after-string}, or
1591 @code{display} properties.  This is only relevant for mouse clicks and
1592 other mouse events that fall on the string, since point is never on
1593 the string.  To bind special mouse events for the string, assign it a
1594 @code{local-map} or @code{keymap} text property.  @xref{Special
1595 Properties}.
1597 @node Finding Overlays
1598 @subsection Searching for Overlays
1600 @defun overlays-at pos
1601 This function returns a list of all the overlays that cover the
1602 character at position @var{pos} in the current buffer.  The list is in
1603 no particular order.  An overlay contains position @var{pos} if it
1604 begins at or before @var{pos}, and ends after @var{pos}.
1606 To illustrate usage, here is a Lisp function that returns a list of the
1607 overlays that specify property @var{prop} for the character at point:
1609 @smallexample
1610 (defun find-overlays-specifying (prop)
1611   (let ((overlays (overlays-at (point)))
1612         found)
1613     (while overlays
1614       (let ((overlay (car overlays)))
1615         (if (overlay-get overlay prop)
1616             (setq found (cons overlay found))))
1617       (setq overlays (cdr overlays)))
1618     found))
1619 @end smallexample
1620 @end defun
1622 @defun overlays-in beg end
1623 This function returns a list of the overlays that overlap the region
1624 @var{beg} through @var{end}.  ``Overlap'' means that at least one
1625 character is contained within the overlay and also contained within the
1626 specified region; however, empty overlays are included in the result if
1627 they are located at @var{beg}, strictly between @var{beg} and @var{end},
1628 or at @var{end} when @var{end} denotes the position at the end of the
1629 buffer.
1630 @end defun
1632 @defun next-overlay-change pos
1633 This function returns the buffer position of the next beginning or end
1634 of an overlay, after @var{pos}.  If there is none, it returns
1635 @code{(point-max)}.
1636 @end defun
1638 @defun previous-overlay-change pos
1639 This function returns the buffer position of the previous beginning or
1640 end of an overlay, before @var{pos}.  If there is none, it returns
1641 @code{(point-min)}.
1642 @end defun
1644   As an example, here's a simplified (and inefficient) version of the
1645 primitive function @code{next-single-char-property-change}
1646 (@pxref{Property Search}).  It searches forward from position
1647 @var{pos} for the next position where the value of a given property
1648 @code{prop}, as obtained from either overlays or text properties,
1649 changes.
1651 @smallexample
1652 (defun next-single-char-property-change (position prop)
1653   (save-excursion
1654     (goto-char position)
1655     (let ((propval (get-char-property (point) prop)))
1656       (while (and (not (eobp))
1657                   (eq (get-char-property (point) prop) propval))
1658         (goto-char (min (next-overlay-change (point))
1659                         (next-single-property-change (point) prop)))))
1660     (point)))
1661 @end smallexample
1663 @node Width
1664 @section Width
1666 Since not all characters have the same width, these functions let you
1667 check the width of a character.  @xref{Primitive Indent}, and
1668 @ref{Screen Lines}, for related functions.
1670 @defun char-width char
1671 This function returns the width in columns of the character @var{char},
1672 if it were displayed in the current buffer and the selected window.
1673 @end defun
1675 @defun string-width string
1676 This function returns the width in columns of the string @var{string},
1677 if it were displayed in the current buffer and the selected window.
1678 @end defun
1680 @defun truncate-string-to-width string width &optional start-column padding ellipsis
1681 This function returns the part of @var{string} that fits within
1682 @var{width} columns, as a new string.
1684 If @var{string} does not reach @var{width}, then the result ends where
1685 @var{string} ends.  If one multi-column character in @var{string}
1686 extends across the column @var{width}, that character is not included in
1687 the result.  Thus, the result can fall short of @var{width} but cannot
1688 go beyond it.
1690 The optional argument @var{start-column} specifies the starting column.
1691 If this is non-@code{nil}, then the first @var{start-column} columns of
1692 the string are omitted from the value.  If one multi-column character in
1693 @var{string} extends across the column @var{start-column}, that
1694 character is not included.
1696 The optional argument @var{padding}, if non-@code{nil}, is a padding
1697 character added at the beginning and end of the result string, to extend
1698 it to exactly @var{width} columns.  The padding character is used at the
1699 end of the result if it falls short of @var{width}.  It is also used at
1700 the beginning of the result if one multi-column character in
1701 @var{string} extends across the column @var{start-column}.
1703 If @var{ellipsis} is non-@code{nil}, it should be a string which will
1704 replace the end of @var{str} (including any padding) if it extends
1705 beyond @var{end-column}, unless the display width of @var{str} is
1706 equal to or less than the display width of @var{ellipsis}.  If
1707 @var{ellipsis} is non-@code{nil} and not a string, it stands for
1708 @code{"..."}.
1710 @example
1711 (truncate-string-to-width "\tab\t" 12 4)
1712      @result{} "ab"
1713 (truncate-string-to-width "\tab\t" 12 4 ?\s)
1714      @result{} "    ab  "
1715 @end example
1716 @end defun
1718 @node Line Height
1719 @section Line Height
1720 @cindex line height
1722   The total height of each display line consists of the height of the
1723 contents of the line, plus optional additional vertical line spacing
1724 above or below the display line.
1726   The height of the line contents is the maximum height of any
1727 character or image on that display line, including the final newline
1728 if there is one.  (A display line that is continued doesn't include a
1729 final newline.)  That is the default line height, if you do nothing to
1730 specify a greater height.  (In the most common case, this equals the
1731 height of the default frame font.)
1733   There are several ways to explicitly specify a larger line height,
1734 either by specifying an absolute height for the display line, or by
1735 specifying vertical space.  However, no matter what you specify, the
1736 actual line height can never be less than the default.
1738 @kindex line-height @r{(text property)}
1739   A newline can have a @code{line-height} text or overlay property
1740 that controls the total height of the display line ending in that
1741 newline.
1743   If the property value is @code{t}, the newline character has no
1744 effect on the displayed height of the line---the visible contents
1745 alone determine the height.  This is useful for tiling small images
1746 (or image slices) without adding blank areas between the images.
1748   If the property value is a list of the form @code{(@var{height}
1749 @var{total})}, that adds extra space @emph{below} the display line.
1750 First Emacs uses @var{height} as a height spec to control extra space
1751 @emph{above} the line; then it adds enough space @emph{below} the line
1752 to bring the total line height up to @var{total}.  In this case, the
1753 other ways to specify the line spacing are ignored.
1755   Any other kind of property value is a height spec, which translates
1756 into a number---the specified line height.  There are several ways to
1757 write a height spec; here's how each of them translates into a number:
1759 @table @code
1760 @item @var{integer}
1761 If the height spec is a positive integer, the height value is that integer.
1762 @item @var{float}
1763 If the height spec is a float, @var{float}, the numeric height value
1764 is @var{float} times the frame's default line height.
1765 @item (@var{face} . @var{ratio})
1766 If the height spec is a cons of the format shown, the numeric height
1767 is @var{ratio} times the height of face @var{face}.  @var{ratio} can
1768 be any type of number, or @code{nil} which means a ratio of 1.
1769 If @var{face} is @code{t}, it refers to the current face.
1770 @item (nil . @var{ratio})
1771 If the height spec is a cons of the format shown, the numeric height
1772 is @var{ratio} times the height of the contents of the line.
1773 @end table
1775   Thus, any valid height spec determines the height in pixels, one way
1776 or another.  If the line contents' height is less than that, Emacs
1777 adds extra vertical space above the line to achieve the specified
1778 total height.
1780   If you don't specify the @code{line-height} property, the line's
1781 height consists of the contents' height plus the line spacing.
1782 There are several ways to specify the line spacing for different
1783 parts of Emacs text.
1785   On graphical terminals, you can specify the line spacing for all
1786 lines in a frame, using the @code{line-spacing} frame parameter
1787 (@pxref{Layout Parameters}).  However, if the default value of
1788 @code{line-spacing} is non-@code{nil}, it overrides the
1789 frame's @code{line-spacing} parameter.  An integer value specifies the
1790 number of pixels put below lines.  A floating point number specifies
1791 the spacing relative to the frame's default line height.
1793 @vindex line-spacing
1794   You can specify the line spacing for all lines in a buffer via the
1795 buffer-local @code{line-spacing} variable.  An integer value specifies
1796 the number of pixels put below lines.  A floating point number
1797 specifies the spacing relative to the default frame line height.  This
1798 overrides line spacings specified for the frame.
1800 @kindex line-spacing @r{(text property)}
1801   Finally, a newline can have a @code{line-spacing} text or overlay
1802 property that overrides the default frame line spacing and the buffer
1803 local @code{line-spacing} variable, for the display line ending in
1804 that newline.
1806   One way or another, these mechanisms specify a Lisp value for the
1807 spacing of each line.  The value is a height spec, and it translates
1808 into a Lisp value as described above.  However, in this case the
1809 numeric height value specifies the line spacing, rather than the line
1810 height.
1812   On text-only terminals, the line spacing cannot be altered.
1814 @node Faces
1815 @section Faces
1816 @cindex faces
1818   A @dfn{face} is a collection of graphical attributes for displaying
1819 text: font, foreground color, background color, optional underlining,
1820 and so on.  Faces control how buffer text is displayed, and how some
1821 parts of the frame, such as the mode-line, are displayed.
1822 @xref{Standard Faces,,, emacs, The GNU Emacs Manual}, for the list of
1823 faces Emacs normally comes with.
1825 @cindex face id
1826   For most purposes, you refer to a face in Lisp programs using its
1827 @dfn{face name}.  This is either a string or (equivalently) a Lisp
1828 symbol whose name is equal to that string.
1830 @defun facep object
1831 This function returns a non-@code{nil} value if @var{object} is a Lisp
1832 symbol or string that names a face.  Otherwise, it returns @code{nil}.
1833 @end defun
1835   Each face name is meaningful for all frames, and by default it has
1836 the same meaning in all frames.  But you can arrange to give a
1837 particular face name a special meaning in one frame if you wish.
1839 @menu
1840 * Defining Faces::      How to define a face with @code{defface}.
1841 * Face Attributes::     What is in a face?
1842 * Attribute Functions::  Functions to examine and set face attributes.
1843 * Displaying Faces::     How Emacs combines the faces specified for a character.
1844 * Face Remapping::      Remapping faces to alternative definitions.
1845 * Face Functions::      How to define and examine faces.
1846 * Auto Faces::          Hook for automatic face assignment.
1847 * Basic Faces::         Faces that are defined by default.
1848 * Font Selection::      Finding the best available font for a face.
1849 * Font Lookup::         Looking up the names of available fonts
1850                           and information about them.
1851 * Fontsets::            A fontset is a collection of fonts
1852                           that handle a range of character sets.
1853 * Low-Level Font::      Lisp representation for character display fonts.
1854 @end menu
1856 @node Defining Faces
1857 @subsection Defining Faces
1859   The way to define a new face is with @code{defface}.  This creates a
1860 kind of customization item (@pxref{Customization}) which the user can
1861 customize using the Customization buffer (@pxref{Easy Customization,,,
1862 emacs, The GNU Emacs Manual}).
1864   People are sometimes tempted to create variables whose values specify
1865 which faces to use (for example, Font-Lock does this).  In the vast
1866 majority of cases, this is not necessary, and simply using faces
1867 directly is preferable.
1869 @defmac defface face spec doc [keyword value]@dots{}
1870 This declares @var{face} as a customizable face whose default
1871 attributes are given by @var{spec}.  You should not quote the symbol
1872 @var{face}, and it should not end in @samp{-face} (that would be
1873 redundant).  The argument @var{doc} specifies the face documentation.
1874 The keywords you can use in @code{defface} are the same as in
1875 @code{defgroup} and @code{defcustom} (@pxref{Common Keywords}).
1877 When @code{defface} executes, it defines the face according to
1878 @var{spec}, then uses any customizations that were read from the
1879 init file (@pxref{Init File}) to override that specification.
1881 When you evaluate a @code{defface} form with @kbd{C-M-x} in Emacs
1882 Lisp mode (@code{eval-defun}), a special feature of @code{eval-defun}
1883 overrides any customizations of the face.  This way, the face reflects
1884 exactly what the @code{defface} says.
1886 The purpose of @var{spec} is to specify how the face should appear on
1887 different kinds of terminals.  It should be an alist whose elements
1888 have the form @code{(@var{display} @var{atts})}.  Each element's
1889 @sc{car}, @var{display}, specifies a class of terminals.  (The first
1890 element, if its @sc{car} is @code{default}, is special---it specifies
1891 defaults for the remaining elements).  The element's @sc{cadr},
1892 @var{atts}, is a list of face attributes and their values; it
1893 specifies what the face should look like on that kind of terminal.
1894 The possible attributes are defined in the value of
1895 @code{custom-face-attributes}.
1897 The @var{display} part of an element of @var{spec} determines which
1898 frames the element matches.  If more than one element of @var{spec}
1899 matches a given frame, the first element that matches is the one used
1900 for that frame.  There are three possibilities for @var{display}:
1902 @table @asis
1903 @item @code{default}
1904 This element of @var{spec} doesn't match any frames; instead, it
1905 specifies defaults that apply to all frames.  This kind of element, if
1906 used, must be the first element of @var{spec}.  Each of the following
1907 elements can override any or all of these defaults.
1909 @item @code{t}
1910 This element of @var{spec} matches all frames.  Therefore, any
1911 subsequent elements of @var{spec} are never used.  Normally
1912 @code{t} is used in the last (or only) element of @var{spec}.
1914 @item a list
1915 If @var{display} is a list, each element should have the form
1916 @code{(@var{characteristic} @var{value}@dots{})}.  Here
1917 @var{characteristic} specifies a way of classifying frames, and the
1918 @var{value}s are possible classifications which @var{display} should
1919 apply to.  Here are the possible values of @var{characteristic}:
1921 @table @code
1922 @item type
1923 The kind of window system the frame uses---either @code{graphic} (any
1924 graphics-capable display), @code{x}, @code{pc} (for the MS-DOS console),
1925 @code{w32} (for MS Windows 9X/NT/2K/XP), or @code{tty} 
1926 (a non-graphics-capable display).
1927 @xref{Window Systems, window-system}.
1929 @item class
1930 What kinds of colors the frame supports---either @code{color},
1931 @code{grayscale}, or @code{mono}.
1933 @item background
1934 The kind of background---either @code{light} or @code{dark}.
1936 @item min-colors
1937 An integer that represents the minimum number of colors the frame
1938 should support.  This matches a frame if its
1939 @code{display-color-cells} value is at least the specified integer.
1941 @item supports
1942 Whether or not the frame can display the face attributes given in
1943 @var{value}@dots{} (@pxref{Face Attributes}).  @xref{Display Face
1944 Attribute Testing}, for more information on exactly how this testing
1945 is done.
1946 @end table
1948 If an element of @var{display} specifies more than one @var{value} for a
1949 given @var{characteristic}, any of those values is acceptable.  If
1950 @var{display} has more than one element, each element should specify a
1951 different @var{characteristic}; then @emph{each} characteristic of the
1952 frame must match one of the @var{value}s specified for it in
1953 @var{display}.
1954 @end table
1955 @end defmac
1957   Here's how the standard face @code{region} is defined:
1959 @example
1960 @group
1961 (defface region
1962   '((((class color) (min-colors 88) (background dark))
1963      :background "blue3")
1964 @end group
1965     (((class color) (min-colors 88) (background light))
1966      :background "lightgoldenrod2")
1967     (((class color) (min-colors 16) (background dark))
1968      :background "blue3")
1969     (((class color) (min-colors 16) (background light))
1970      :background "lightgoldenrod2")
1971     (((class color) (min-colors 8))
1972      :background "blue" :foreground "white")
1973     (((type tty) (class mono))
1974      :inverse-video t)
1975     (t :background "gray"))
1976 @group
1977   "Basic face for highlighting the region."
1978   :group 'basic-faces)
1979 @end group
1980 @end example
1982   Internally, @code{defface} uses the symbol property
1983 @code{face-defface-spec} to record the specified face attributes.  The
1984 attributes saved by the user with the customization buffer are
1985 recorded in the symbol property @code{saved-face}; the attributes
1986 customized by the user for the current session, but not saved, are
1987 recorded in the symbol property @code{customized-face}.  The
1988 documentation string is recorded in the symbol property
1989 @code{face-documentation}.
1991 @defopt frame-background-mode
1992 This option, if non-@code{nil}, specifies the background type to use for
1993 interpreting face definitions.  If it is @code{dark}, then Emacs treats
1994 all frames as if they had a dark background, regardless of their actual
1995 background colors.  If it is @code{light}, then Emacs treats all frames
1996 as if they had a light background.
1997 @end defopt
1999 @node Face Attributes
2000 @subsection Face Attributes
2001 @cindex face attributes
2003   The effect of using a face is determined by a fixed set of @dfn{face
2004 attributes}.  This table lists all the face attributes, their possible
2005 values, and their effects.  You can specify more than one face for a
2006 given piece of text; Emacs merges the attributes of all the faces to
2007 determine how to display the text.  @xref{Displaying Faces}.
2009   In addition to the values given below, each face attribute can also
2010 have the value @code{unspecified}.  This special value means the face
2011 doesn't specify that attribute.  In face merging, when the first face
2012 fails to specify a particular attribute, the next face gets a chance.
2013 However, the @code{default} face must specify all attributes.
2015   Some of these font attributes are meaningful only on certain kinds
2016 of displays.  If your display cannot handle a certain attribute, the
2017 attribute is ignored.
2019 @table @code
2020 @item :family
2021 Font family or fontset (a string).  @xref{Fonts,,, emacs, The GNU
2022 Emacs Manual}.  If you specify a font family name, the wild-card
2023 characters @samp{*} and @samp{?} are allowed.  The function
2024 @code{font-family-list}, described below, returns a list of available
2025 family names.  @xref{Fontsets}, for information about fontsets.
2027 @item :foundry
2028 The name of the @dfn{font foundry} for the font family specified by
2029 the @code{:family} attribute (a string).  The wild-card characters
2030 @samp{*} and @samp{?} are allowed.  @xref{Fonts,,, emacs, The GNU
2031 Emacs Manual}.
2033 @item :width
2034 Relative proportionate character width, also known as the character
2035 set width.  This should be one of the symbols @code{ultra-condensed},
2036 @code{extra-condensed}, @code{condensed}, @code{semi-condensed},
2037 @code{normal}, @code{semi-expanded}, @code{expanded},
2038 @code{extra-expanded}, or @code{ultra-expanded}.
2040 @item :height
2041 The height of the font.  In the simplest case, this is an integer in
2042 units of 1/10 point.
2044 The value can also be a floating point number or a function, which
2045 specifies the height relative to an @dfn{underlying face} (i.e., a
2046 face that has a lower priority in the list described in
2047 @ref{Displaying Faces}).  If the value is a floating point number,
2048 that specifies the amount by which to scale the height of the
2049 underlying face.  If the value is a function, that function is called
2050 with one argument, the height of the underlying face, and returns the
2051 height of the new face.  If the function is passed an integer
2052 argument, it must return an integer.
2054 The height of the default face must be specified using an integer;
2055 floating point and function values are not allowed.
2057 @item :weight
2058 Font weight---one of the symbols (from densest to faintest)
2059 @code{ultra-bold}, @code{extra-bold}, @code{bold}, @code{semi-bold},
2060 @code{normal}, @code{semi-light}, @code{light}, @code{extra-light}, or
2061 @code{ultra-light}.  On text-only terminals that support
2062 variable-brightness text, any weight greater than normal is displayed
2063 as extra bright, and any weight less than normal is displayed as
2064 half-bright.
2066 @item :slant
2067 Font slant---one of the symbols @code{italic}, @code{oblique},
2068 @code{normal}, @code{reverse-italic}, or @code{reverse-oblique}.  On
2069 text-only terminals that support variable-brightness text, slanted
2070 text is displayed as half-bright.
2072 @item :foreground
2073 Foreground color, a string.  The value can be a system-defined color
2074 name, or a hexadecimal color specification.  @xref{Color Names}.  On
2075 black-and-white displays, certain shades of gray are implemented by
2076 stipple patterns.
2078 @item :background
2079 Background color, a string.  The value can be a system-defined color
2080 name, or a hexadecimal color specification.  @xref{Color Names}.
2082 @item :underline
2083 Whether or not characters should be underlined, and in what color.  If
2084 the value is @code{t}, underlining uses the foreground color of the
2085 face.  If the value is a string, underlining uses that color.  The
2086 value @code{nil} means do not underline.
2088 @item :overline
2089 Whether or not characters should be overlined, and in what color.
2090 The value is used like that of @code{:underline}.
2092 @item :strike-through
2093 Whether or not characters should be strike-through, and in what
2094 color.  The value is used like that of @code{:underline}.
2096 @item :box
2097 Whether or not a box should be drawn around characters, its color, the
2098 width of the box lines, and 3D appearance.  Here are the possible
2099 values of the @code{:box} attribute, and what they mean:
2101 @table @asis
2102 @item @code{nil}
2103 Don't draw a box.
2105 @item @code{t}
2106 Draw a box with lines of width 1, in the foreground color.
2108 @item @var{color}
2109 Draw a box with lines of width 1, in color @var{color}.
2111 @item @code{(:line-width @var{width} :color @var{color} :style @var{style})}
2112 This way you can explicitly specify all aspects of the box.  The value
2113 @var{width} specifies the width of the lines to draw; it defaults to
2114 1.  A negative width @var{-n} means to draw a line of width @var{n}
2115 that occupies the space of the underlying text, thus avoiding any
2116 increase in the character height or width.
2118 The value @var{color} specifies the color to draw with.  The default is
2119 the foreground color of the face for simple boxes, and the background
2120 color of the face for 3D boxes.
2122 The value @var{style} specifies whether to draw a 3D box.  If it is
2123 @code{released-button}, the box looks like a 3D button that is not being
2124 pressed.  If it is @code{pressed-button}, the box looks like a 3D button
2125 that is being pressed.  If it is @code{nil} or omitted, a plain 2D box
2126 is used.
2127 @end table
2129 @item :inverse-video
2130 Whether or not characters should be displayed in inverse video.  The
2131 value should be @code{t} (yes) or @code{nil} (no).
2133 @item :stipple
2134 The background stipple, a bitmap.
2136 The value can be a string; that should be the name of a file containing
2137 external-format X bitmap data.  The file is found in the directories
2138 listed in the variable @code{x-bitmap-file-path}.
2140 Alternatively, the value can specify the bitmap directly, with a list
2141 of the form @code{(@var{width} @var{height} @var{data})}.  Here,
2142 @var{width} and @var{height} specify the size in pixels, and
2143 @var{data} is a string containing the raw bits of the bitmap, row by
2144 row.  Each row occupies @math{(@var{width} + 7) / 8} consecutive bytes
2145 in the string (which should be a unibyte string for best results).
2146 This means that each row always occupies at least one whole byte.
2148 If the value is @code{nil}, that means use no stipple pattern.
2150 Normally you do not need to set the stipple attribute, because it is
2151 used automatically to handle certain shades of gray.
2153 @item :font
2154 The font used to display the face.  Its value should be a font object.
2155 @xref{Font Selection}, for information about font objects.
2157 When specifying this attribute using @code{set-face-attribute}
2158 (@pxref{Attribute Functions}), you may also supply a font spec, a font
2159 entity, or a string.  Emacs converts such values to an appropriate
2160 font object, and stores that font object as the actual attribute
2161 value.  If you specify a string, the contents of the string should be
2162 a font name (@pxref{Fonts,,, emacs, The GNU Emacs Manual}); if the
2163 font name is an XLFD containing wildcards, Emacs chooses the first
2164 font matching those wildcards.  Specifying this attribute also changes
2165 the values of the @code{:family}, @code{:foundry}, @code{:width},
2166 @code{:height}, @code{:weight}, and @code{:slant} attributes.
2168 @item :inherit
2169 The name of a face from which to inherit attributes, or a list of face
2170 names.  Attributes from inherited faces are merged into the face like
2171 an underlying face would be, with higher priority than underlying
2172 faces (@pxref{Displaying Faces}).  If a list of faces is used,
2173 attributes from faces earlier in the list override those from later
2174 faces.
2175 @end table
2177 For compatibility with Emacs 20, you can also specify values for two
2178 ``fake'' face attributes: @code{:bold} and @code{:italic}.  Their
2179 values must be either @code{t} or @code{nil}; a value of
2180 @code{unspecified} is not allowed.  Setting @code{:bold} to @code{t}
2181 is equivalent to setting the @code{:weight} attribute to @code{bold},
2182 and setting it to @code{nil} is equivalent to setting @code{:weight}
2183 to @code{normal}.  Setting @code{:italic} to @code{t} is equivalent to
2184 setting the @code{:slant} attribute to @code{italic}, and setting it
2185 to @code{nil} is equivalent to setting @code{:slant} to @code{normal}.
2187 @defun font-family-list &optional frame
2188 This function returns a list of available font family names.  The
2189 optional argument @var{frame} specifies the frame on which the text is
2190 to be displayed; if it is @code{nil}, the selected frame is used.
2191 @end defun
2193 @defopt underline-minimum-offset
2194 This variable specifies the minimum distance between the baseline and
2195 the underline, in pixels, when displaying underlined text.
2196 @end defopt
2198 @defopt x-bitmap-file-path
2199 This variable specifies a list of directories for searching
2200 for bitmap files, for the @code{:stipple} attribute.
2201 @end defopt
2203 @defun bitmap-spec-p object
2204 This returns @code{t} if @var{object} is a valid bitmap specification,
2205 suitable for use with @code{:stipple} (see above).  It returns
2206 @code{nil} otherwise.
2207 @end defun
2209 @node Attribute Functions
2210 @subsection Face Attribute Functions
2212   This section describes the functions for accessing and modifying the
2213 attributes of an existing face.
2215 @defun set-face-attribute face frame &rest arguments
2216 This function sets one or more attributes of @var{face} for
2217 @var{frame}.  The attributes you specify this way override whatever
2218 the @code{defface} says.
2220 The extra arguments @var{arguments} specify the attributes to set, and
2221 the values for them.  They should consist of alternating attribute names
2222 (such as @code{:family} or @code{:underline}) and corresponding values.
2223 Thus,
2225 @example
2226 (set-face-attribute 'foo nil
2227                     :width 'extended
2228                     :weight 'bold
2229                     :underline "red")
2230 @end example
2232 @noindent
2233 sets the attributes @code{:width}, @code{:weight} and @code{:underline}
2234 to the corresponding values.
2236 If @var{frame} is @code{t}, this function sets the default attributes
2237 for new frames.  Default attribute values specified this way override
2238 the @code{defface} for newly created frames.
2240 If @var{frame} is @code{nil}, this function sets the attributes for
2241 all existing frames, and the default for new frames.
2242 @end defun
2244 @defun face-attribute face attribute &optional frame inherit
2245 This returns the value of the @var{attribute} attribute of @var{face}
2246 on @var{frame}.  If @var{frame} is @code{nil}, that means the selected
2247 frame (@pxref{Input Focus}).
2249 If @var{frame} is @code{t}, this returns whatever new-frames default
2250 value you previously specified with @code{set-face-attribute} for the
2251 @var{attribute} attribute of @var{face}.  If you have not specified
2252 one, it returns @code{nil}.
2254 If @var{inherit} is @code{nil}, only attributes directly defined by
2255 @var{face} are considered, so the return value may be
2256 @code{unspecified}, or a relative value.  If @var{inherit} is
2257 non-@code{nil}, @var{face}'s definition of @var{attribute} is merged
2258 with the faces specified by its @code{:inherit} attribute; however the
2259 return value may still be @code{unspecified} or relative.  If
2260 @var{inherit} is a face or a list of faces, then the result is further
2261 merged with that face (or faces), until it becomes specified and
2262 absolute.
2264 To ensure that the return value is always specified and absolute, use
2265 a value of @code{default} for @var{inherit}; this will resolve any
2266 unspecified or relative values by merging with the @code{default} face
2267 (which is always completely specified).
2269 For example,
2271 @example
2272 (face-attribute 'bold :weight)
2273      @result{} bold
2274 @end example
2275 @end defun
2277 @defun face-attribute-relative-p attribute value
2278 This function returns non-@code{nil} if @var{value}, when used as the
2279 value of the face attribute @var{attribute}, is relative.  This means
2280 it would modify, rather than completely override, any value that comes
2281 from a subsequent face in the face list or that is inherited from
2282 another face.
2284 @code{unspecified} is a relative value for all attributes.  For
2285 @code{:height}, floating point and function values are also relative.
2287 For example:
2289 @example
2290 (face-attribute-relative-p :height 2.0)
2291      @result{} t
2292 @end example
2293 @end defun
2295 @defun face-all-attributes face &optional frame
2296 This function returns an alist of attributes of @var{face}.  The
2297 elements of the result are name-value pairs of the form
2298 @w{@code{(@var{attr-name} . @var{attr-value})}}.  Optional argument
2299 @var{frame} specifies the frame whose definition of @var{face} to
2300 return; if omitted or @code{nil}, the returned value describes the
2301 default attributes of @var{face} for newly created frames.
2302 @end defun
2304 @defun merge-face-attribute attribute value1 value2
2305 If @var{value1} is a relative value for the face attribute
2306 @var{attribute}, returns it merged with the underlying value
2307 @var{value2}; otherwise, if @var{value1} is an absolute value for the
2308 face attribute @var{attribute}, returns @var{value1} unchanged.
2309 @end defun
2311   The following functions provide compatibility with Emacs 20 and
2312 below.  They work by calling @code{set-face-attribute}.  Values of
2313 @code{t} and @code{nil} for their @var{frame} argument are handled
2314 just like @code{set-face-attribute} and @code{face-attribute}.
2316 @defun set-face-foreground face color &optional frame
2317 @defunx set-face-background face color &optional frame
2318 These functions set the @code{:foreground} attribute (or
2319 @code{:background} attribute, respectively) of @var{face} to
2320 @var{color}.
2321 @end defun
2323 @defun set-face-stipple face pattern &optional frame
2324 This function sets the @code{:stipple} attribute of @var{face} to
2325 @var{pattern}.
2326 @end defun
2328 @defun set-face-font face font &optional frame
2329 This function sets the @code{:font} attribute of @var{face} to
2330 @var{font}.
2331 @end defun
2333 @defun set-face-bold-p face bold-p &optional frame
2334 This function sets the @code{:weight} attribute of @var{face} to
2335 @var{normal} if @var{bold-p} is @code{nil}, and to @var{bold}
2336 otherwise.
2337 @end defun
2339 @defun set-face-italic-p face italic-p &optional frame
2340 This function sets the @code{:slant} attribute of @var{face} to
2341 @var{normal} if @var{italic-p} is @code{nil}, and to @var{italic}
2342 otherwise.
2343 @end defun
2345 @defun set-face-underline-p face underline &optional frame
2346 This function sets the @code{:underline} attribute of @var{face} to
2347 @var{underline}.
2348 @end defun
2350 @defun set-face-inverse-video-p face inverse-video-p &optional frame
2351 This function sets the @code{:inverse-video} attribute of @var{face}
2352 to @var{inverse-video-p}.
2353 @end defun
2355 @defun invert-face face &optional frame
2356 This function swaps the foreground and background colors of face
2357 @var{face}.
2358 @end defun
2360   The following functions examine the attributes of a face.  If you
2361 don't specify @var{frame}, they refer to the selected frame; @code{t}
2362 refers to the default data for new frames.  They return the symbol
2363 @code{unspecified} if the face doesn't define any value for that
2364 attribute.
2366 @defun face-foreground face &optional frame inherit
2367 @defunx face-background face &optional frame inherit
2368 These functions return the foreground color (or background color,
2369 respectively) of face @var{face}, as a string.
2371 If @var{inherit} is @code{nil}, only a color directly defined by the face is
2372 returned.  If @var{inherit} is non-@code{nil}, any faces specified by its
2373 @code{:inherit} attribute are considered as well, and if @var{inherit}
2374 is a face or a list of faces, then they are also considered, until a
2375 specified color is found.  To ensure that the return value is always
2376 specified, use a value of @code{default} for @var{inherit}.
2377 @end defun
2379 @defun face-stipple face &optional frame inherit
2380 This function returns the name of the background stipple pattern of face
2381 @var{face}, or @code{nil} if it doesn't have one.
2383 If @var{inherit} is @code{nil}, only a stipple directly defined by the
2384 face is returned.  If @var{inherit} is non-@code{nil}, any faces
2385 specified by its @code{:inherit} attribute are considered as well, and
2386 if @var{inherit} is a face or a list of faces, then they are also
2387 considered, until a specified stipple is found.  To ensure that the
2388 return value is always specified, use a value of @code{default} for
2389 @var{inherit}.
2390 @end defun
2392 @defun face-font face &optional frame
2393 This function returns the name of the font of face @var{face}.
2394 @end defun
2396 @defun face-bold-p face &optional frame
2397 This function returns a non-@code{nil} value if the @code{:weight}
2398 attribute of @var{face} is bolder than normal (i.e., one of
2399 @code{semi-bold}, @code{bold}, @code{extra-bold}, or
2400 @code{ultra-bold}).  Otherwise, it returns @code{nil}.
2401 @end defun
2403 @defun face-italic-p face &optional frame
2404 This function returns a non-@code{nil} value if the @code{:slant}
2405 attribute of @var{face} is @code{italic} or @code{oblique}, and
2406 @code{nil} otherwise.
2407 @end defun
2409 @defun face-underline-p face &optional frame
2410 This function returns the @code{:underline} attribute of face @var{face}.
2411 @end defun
2413 @defun face-inverse-video-p face &optional frame
2414 This function returns the @code{:inverse-video} attribute of face @var{face}.
2415 @end defun
2417 @node Displaying Faces
2418 @subsection Displaying Faces
2420   Here is how Emacs determines the face to use for displaying any
2421 given piece of text:
2423 @itemize @bullet
2424 @item
2425 If the text consists of a special glyph, the glyph can specify a
2426 particular face.  @xref{Glyphs}.
2428 @item
2429 If the text lies within an active region, Emacs highlights it using
2430 the @code{region} face.  @xref{Standard Faces,,, emacs, The GNU Emacs
2431 Manual}.
2433 @item
2434 If the text lies within an overlay with a non-@code{nil} @code{face}
2435 property, Emacs applies the face or face attributes specified by that
2436 property.  If the overlay has a @code{mouse-face} property and the
2437 mouse is ``near enough'' to the overlay, Emacs applies the face or
2438 face attributes specified by the @code{mouse-face} property instead.
2439 @xref{Overlay Properties}.
2441 When multiple overlays cover one character, an overlay with higher
2442 priority overrides those with lower priority.  @xref{Overlays}.
2444 @item
2445 If the text contains a @code{face} or @code{mouse-face} property,
2446 Emacs applies the specified faces and face attributes.  @xref{Special
2447 Properties}.  (This is how Font Lock mode faces are applied.
2448 @xref{Font Lock Mode}.)
2450 @item
2451 If the text lies within the mode line of the selected window, Emacs
2452 applies the @code{mode-line} face.  For the mode line of a
2453 non-selected window, Emacs applies the @code{mode-line-inactive} face.
2454 For a header line, Emacs applies the @code{header-line} face.
2456 @item
2457 If any given attribute has not been specified during the preceding
2458 steps, Emacs applies the attribute of the @code{default} face.
2459 @end itemize
2461   If these various sources together specify more than one face for a
2462 particular character, Emacs merges the attributes of the various faces
2463 specified.  For each attribute, Emacs tries using the above order
2464 (i.e., first the face of any special glyph; then the face for region
2465 highlighting, if appropriate; then faces specified by overlays, then
2466 faces specified by text properties, then the @code{mode-line} or
2467 @code{mode-line-inactive} or @code{header-line} face, if appropriate,
2468 and finally the @code{default} face).
2470 @node Face Remapping
2471 @subsection Face Remapping
2473   The variable @code{face-remapping-alist} is used for buffer-local or
2474 global changes in the appearance of a face.  For instance, it can be
2475 used to make the @code{default} face a variable-pitch face within a
2476 particular buffer.
2478 @defvar face-remapping-alist
2479 An alist whose elements have the form @code{(@var{face}
2480 @var{remapping...})}.  This causes Emacs to display text using the
2481 face @var{face} using @var{remapping...} instead of @var{face}'s
2482 ordinary definition.  @var{remapping...} may be any face specification
2483 suitable for a @code{face} text property: either a face name, or a
2484 property list of attribute/value pairs.  @xref{Special Properties}.
2486 If @code{face-remapping-alist} is buffer-local, its local value takes
2487 effect only within that buffer.
2489 Two points bear emphasizing:
2491 @enumerate
2492 @item
2493 The new definition @var{remapping...} is the complete
2494 specification of how to display @var{face}---it entirely replaces,
2495 rather than augmenting or modifying, the normal definition of that
2496 face.
2498 @item
2499 If @var{remapping...} recursively references the same face name
2500 @var{face}, either directly remapping entry, or via the
2501 @code{:inherit} attribute of some other face in @var{remapping...},
2502 then that reference uses the normal definition of @var{face} in the
2503 selected frame, instead of the ``remapped'' definition.
2505 For instance, if the @code{mode-line} face is remapped using this
2506 entry in @code{face-remapping-alist}:
2507 @example
2508 (mode-line italic mode-line)
2509 @end example
2510 @noindent
2511 then the new definition of the @code{mode-line} face inherits from the
2512 @code{italic} face, and the @emph{normal} (non-remapped) definition of
2513 @code{mode-line} face.
2514 @end enumerate
2515 @end defvar
2517   A typical use of the @code{face-remapping-alist} is to change a
2518 buffer's @code{default} face; for example, the following changes a
2519 buffer's @code{default} face to use the @code{variable-pitch} face,
2520 with the height doubled:
2522 @example
2523 (set (make-local-variable 'face-remapping-alist)
2524      '((default variable-pitch :height 2.0)))
2525 @end example
2527   The following functions implement a higher-level interface to
2528 @code{face-remapping-alist}, making it easier to use
2529 ``cooperatively''.  They are mainly intended for buffer-local use, and
2530 so all make @code{face-remapping-alist} variable buffer-local as a
2531 side-effect.  They use entries in @code{face-remapping-alist} which
2532 have the general form:
2534 @example
2535   (@var{face} @var{relative_specs_1} @var{relative_specs_2} @var{...} @var{base_specs})
2536 @end example
2538 Everything except @var{face} is a ``face spec'': a list of face names
2539 or face attribute-value pairs.  All face specs are merged together,
2540 with earlier values taking precedence.
2542 The @var{relative_specs_}n values are ``relative specs'', and are
2543 added by @code{face-remap-add-relative} (and removed by
2544 @code{face-remap-remove-relative}.  These are intended for face
2545 modifications (such as increasing the size).  Typical users of these
2546 relative specs would be minor modes.
2548 @var{base_specs} is the lowest-priority value, and by default is just the
2549 face name, which causes the global definition of that face to be used.
2551 A non-default value of @var{base_specs} may also be set using
2552 @code{face-remap-set-base}.  Because this @emph{overwrites} the
2553 default base-spec value (which inherits the global face definition),
2554 it is up to the caller of @code{face-remap-set-base} to add such
2555 inheritance if it is desired.  A typical use of
2556 @code{face-remap-set-base} would be a major mode adding a face
2557 remappings, e.g., of the default face.
2560 @defun face-remap-add-relative face &rest specs
2561 This functions adds a face remapping entry of @var{face} to @var{specs}
2562 in the current buffer.
2564 It returns a ``cookie'' which can be used to later delete the remapping with
2565 @code{face-remap-remove-relative}.
2567 @var{specs} can be any value suitable for the @code{face} text
2568 property, including a face name, a list of face names, or a
2569 face-attribute property list.  The attributes given by @var{specs}
2570 will be merged with any other currently active face remappings of
2571 @var{face}, and with the global definition of @var{face} (by default;
2572 this may be changed using @code{face-remap-set-base}), with the most
2573 recently added relative remapping taking precedence.
2574 @end defun
2576 @defun face-remap-remove-relative cookie
2577 This function removes a face remapping previously added by
2578 @code{face-remap-add-relative}.  @var{cookie} should be a return value
2579 from that function.
2580 @end defun
2582 @defun face-remap-set-base face &rest specs
2583 This function sets the ``base remapping'' of @var{face} in the current
2584 buffer to @var{specs}.  If @var{specs} is empty, the default base
2585 remapping is restored, which inherits from the global definition of
2586 @var{face}; note that this is different from @var{specs} containing a
2587 single value @code{nil}, which has the opposite result (the global
2588 definition of @var{face} is ignored).
2589 @end defun
2591 @defun face-remap-reset-base face
2592 This function sets the ``base remapping'' of @var{face} to its default
2593 value, which inherits from @var{face}'s global definition.
2594 @end defun
2596 @node Face Functions
2597 @subsection Functions for Working with Faces
2599   Here are additional functions for creating and working with faces.
2601 @defun make-face name
2602 This function defines a new face named @var{name}, initially with all
2603 attributes @code{nil}.  It does nothing if there is already a face named
2604 @var{name}.
2605 @end defun
2607 @defun face-list
2608 This function returns a list of all defined faces.
2609 @end defun
2611 @defun copy-face old-face new-name &optional frame new-frame
2612 This function defines a face named @var{new-name} as a copy of the existing
2613 face named @var{old-face}.  It creates the face @var{new-name} if that
2614 doesn't already exist.
2616 If the optional argument @var{frame} is given, this function applies
2617 only to that frame.  Otherwise it applies to each frame individually,
2618 copying attributes from @var{old-face} in each frame to @var{new-face}
2619 in the same frame.
2621 If the optional argument @var{new-frame} is given, then @code{copy-face}
2622 copies the attributes of @var{old-face} in @var{frame} to @var{new-name}
2623 in @var{new-frame}.
2624 @end defun
2626 @defun face-id face
2627 This function returns the @dfn{face number} of face @var{face}.  This
2628 is a number that uniquely identifies a face at low levels within
2629 Emacs.  It is seldom necessary to refer to a face by its face number.
2630 @end defun
2632 @defun face-documentation face
2633 This function returns the documentation string of face @var{face}, or
2634 @code{nil} if none was specified for it.
2635 @end defun
2637 @defun face-equal face1 face2 &optional frame
2638 This returns @code{t} if the faces @var{face1} and @var{face2} have the
2639 same attributes for display.
2640 @end defun
2642 @defun face-differs-from-default-p face &optional frame
2643 This returns non-@code{nil} if the face @var{face} displays
2644 differently from the default face.
2645 @end defun
2647 @cindex face alias
2648 A @dfn{face alias} provides an equivalent name for a face.  You can
2649 define a face alias by giving the alias symbol the @code{face-alias}
2650 property, with a value of the target face name.  The following example
2651 makes @code{modeline} an alias for the @code{mode-line} face.
2653 @example
2654 (put 'modeline 'face-alias 'mode-line)
2655 @end example
2657 @defun define-obsolete-face-alias obsolete-face current-face &optional when
2658 This function defines a face alias and marks it as obsolete, indicating
2659 that it may be removed in future.  The optional string @var{when}
2660 indicates when the face was made obsolete (for example, a release number).
2661 @end defun
2663 @node Auto Faces
2664 @subsection Automatic Face Assignment
2665 @cindex automatic face assignment
2666 @cindex faces, automatic choice
2668   This hook is used for automatically assigning faces to text in the
2669 buffer.  It is part of the implementation of Jit-Lock mode, used by
2670 Font-Lock.
2672 @defvar fontification-functions
2673 This variable holds a list of functions that are called by Emacs
2674 redisplay as needed, just before doing redisplay.  They are called even
2675 when Font Lock Mode isn't enabled.  When Font Lock Mode is enabled, this
2676 variable usually holds just one function, @code{jit-lock-function}.
2678 The functions are called in the order listed, with one argument, a
2679 buffer position @var{pos}.  Collectively they should attempt to assign
2680 faces to the text in the current buffer starting at @var{pos}.
2682 The functions should record the faces they assign by setting the
2683 @code{face} property.  They should also add a non-@code{nil}
2684 @code{fontified} property to all the text they have assigned faces to.
2685 That property tells redisplay that faces have been assigned to that text
2686 already.
2688 It is probably a good idea for the functions to do nothing if the
2689 character after @var{pos} already has a non-@code{nil} @code{fontified}
2690 property, but this is not required.  If one function overrides the
2691 assignments made by a previous one, the properties after the last
2692 function finishes are the ones that really matter.
2694 For efficiency, we recommend writing these functions so that they
2695 usually assign faces to around 400 to 600 characters at each call.
2696 @end defvar
2698 @node Basic Faces
2699 @subsection Basic Faces
2701 If your Emacs Lisp program needs to assign some faces to text, it is
2702 often a good idea to use certain existing faces or inherit from them,
2703 rather than defining entirely new faces.  This way, if other users
2704 have customized the basic faces to give Emacs a certain look, your
2705 program will ``fit in'' without additional customization.
2707   Some of the basic faces defined in Emacs are listed below.  In
2708 addition to these, you might want to make use of the Font Lock faces
2709 for syntactic highlighting, if highlighting is not already handled by
2710 Font Lock mode, or if some Font Lock faces are not in use.
2711 @xref{Faces for Font Lock}.
2713 @table @code
2714 @item default
2715 The default face, whose attributes are all specified.  All other faces
2716 implicitly inherit from it: any unspecified attribute defaults to the
2717 attribute on this face (@pxref{Face Attributes}).
2719 @item bold
2720 @itemx italic
2721 @itemx bold-italic
2722 @itemx underline
2723 @itemx fixed-pitch
2724 @itemx variable-pitch
2725 These have the attributes indicated by their names (e.g. @code{bold}
2726 has a bold @code{:weight} attribute), with all other attributes
2727 unspecified (and so given by @code{default}).
2729 @item shadow
2730 For ``dimmed out'' text.  For example, it is used for the ignored
2731 part of a filename in the minibuffer (@pxref{Minibuffer File,,
2732 Minibuffers for File Names, emacs, The GNU Emacs Manual}).
2734 @item link
2735 @itemx link-visited
2736 For clickable text buttons that send the user to a different
2737 buffer or ``location''.
2739 @item highlight
2740 For stretches of text that should temporarily stand out.  For example,
2741 it is commonly assigned to the @code{mouse-face} property for cursor
2742 highlighting (@pxref{Special Properties}).
2744 @item match
2745 For text matching a search command.
2747 @item error
2748 @itemx warning
2749 @itemx success
2750 For text concerning errors, warnings, or successes.  For example,
2751 these are used for messages in @samp{*Compilation*} buffers.
2752 @end table
2754 @node Font Selection
2755 @subsection Font Selection
2757   Before Emacs can draw a character on a particular display, it must
2758 select a @dfn{font} for that character@footnote{In this context, the
2759 term @dfn{font} has nothing to do with Font Lock (@pxref{Font Lock
2760 Mode}).}.  @xref{Fonts,,, emacs, The GNU Emacs Manual}.  Normally,
2761 Emacs automatically chooses a font based on the faces assigned to that
2762 character---specifically, the face attributes @code{:family},
2763 @code{:weight}, @code{:slant}, and @code{:width} (@pxref{Face
2764 Attributes}).  The choice of font also depends on the character to be
2765 displayed; some fonts can only display a limited set of characters.
2766 If no available font exactly fits the requirements, Emacs looks for
2767 the @dfn{closest matching font}.  The variables in this section
2768 control how Emacs makes this selection.
2770 @defopt face-font-family-alternatives
2771 If a given family is specified but does not exist, this variable
2772 specifies alternative font families to try.  Each element should have
2773 this form:
2775 @example
2776 (@var{family} @var{alternate-families}@dots{})
2777 @end example
2779 If @var{family} is specified but not available, Emacs will try the other
2780 families given in @var{alternate-families}, one by one, until it finds a
2781 family that does exist.
2782 @end defopt
2784 @defopt face-font-selection-order
2785 If there is no font that exactly matches all desired face attributes
2786 (@code{:width}, @code{:height}, @code{:weight}, and @code{:slant}),
2787 this variable specifies the order in which these attributes should be
2788 considered when selecting the closest matching font.  The value should
2789 be a list containing those four attribute symbols, in order of
2790 decreasing importance.  The default is @code{(:width :height :weight
2791 :slant)}.
2793 Font selection first finds the best available matches for the first
2794 attribute in the list; then, among the fonts which are best in that
2795 way, it searches for the best matches in the second attribute, and so
2798 The attributes @code{:weight} and @code{:width} have symbolic values in
2799 a range centered around @code{normal}.  Matches that are more extreme
2800 (farther from @code{normal}) are somewhat preferred to matches that are
2801 less extreme (closer to @code{normal}); this is designed to ensure that
2802 non-normal faces contrast with normal ones, whenever possible.
2804 One example of a case where this variable makes a difference is when the
2805 default font has no italic equivalent.  With the default ordering, the
2806 @code{italic} face will use a non-italic font that is similar to the
2807 default one.  But if you put @code{:slant} before @code{:height}, the
2808 @code{italic} face will use an italic font, even if its height is not
2809 quite right.
2810 @end defopt
2812 @defopt face-font-registry-alternatives
2813 This variable lets you specify alternative font registries to try, if a
2814 given registry is specified and doesn't exist.  Each element should have
2815 this form:
2817 @example
2818 (@var{registry} @var{alternate-registries}@dots{})
2819 @end example
2821 If @var{registry} is specified but not available, Emacs will try the
2822 other registries given in @var{alternate-registries}, one by one,
2823 until it finds a registry that does exist.
2824 @end defopt
2826   Emacs can make use of scalable fonts, but by default it does not use
2827 them.
2829 @defopt scalable-fonts-allowed
2830 This variable controls which scalable fonts to use.  A value of
2831 @code{nil}, the default, means do not use scalable fonts.  @code{t}
2832 means to use any scalable font that seems appropriate for the text.
2834 Otherwise, the value must be a list of regular expressions.  Then a
2835 scalable font is enabled for use if its name matches any regular
2836 expression in the list.  For example,
2838 @example
2839 (setq scalable-fonts-allowed '("muleindian-2$"))
2840 @end example
2842 @noindent
2843 allows the use of scalable fonts with registry @code{muleindian-2}.
2844 @end defopt
2846 @defvar face-font-rescale-alist
2847 This variable specifies scaling for certain faces.  Its value should
2848 be a list of elements of the form
2850 @example
2851 (@var{fontname-regexp} . @var{scale-factor})
2852 @end example
2854 If @var{fontname-regexp} matches the font name that is about to be
2855 used, this says to choose a larger similar font according to the
2856 factor @var{scale-factor}.  You would use this feature to normalize
2857 the font size if certain fonts are bigger or smaller than their
2858 nominal heights and widths would suggest.
2859 @end defvar
2861 @node Font Lookup
2862 @subsection Looking Up Fonts
2864 @defun x-list-fonts name &optional reference-face frame maximum width
2865 This function returns a list of available font names that match
2866 @var{name}.  @var{name} should be a string containing a font name in
2867 either the Fontconfig, GTK, or XLFD format (@pxref{Fonts,,, emacs, The
2868 GNU Emacs Manual}).  Within an XLFD string, wildcard characters may be
2869 used: the @samp{*} character matches any substring, and the @samp{?}
2870 character matches any single character.  Case is ignored when matching
2871 font names.
2873 If the optional arguments @var{reference-face} and @var{frame} are
2874 specified, the returned list includes only fonts that are the same
2875 size as @var{reference-face} (a face name) currently is on the frame
2876 @var{frame}.
2878 The optional argument @var{maximum} sets a limit on how many fonts to
2879 return.  If it is non-@code{nil}, then the return value is truncated
2880 after the first @var{maximum} matching fonts.  Specifying a small
2881 value for @var{maximum} can make this function much faster, in cases
2882 where many fonts match the pattern.
2884 The optional argument @var{width} specifies a desired font width.  If
2885 it is non-@code{nil}, the function only returns those fonts whose
2886 characters are (on average) @var{width} times as wide as
2887 @var{reference-face}.
2888 @end defun
2890 @defun x-family-fonts &optional family frame
2891 This function returns a list describing the available fonts for family
2892 @var{family} on @var{frame}.  If @var{family} is omitted or @code{nil},
2893 this list applies to all families, and therefore, it contains all
2894 available fonts.  Otherwise, @var{family} must be a string; it may
2895 contain the wildcards @samp{?} and @samp{*}.
2897 The list describes the display that @var{frame} is on; if @var{frame} is
2898 omitted or @code{nil}, it applies to the selected frame's display
2899 (@pxref{Input Focus}).
2901 Each element in the list is a vector of the following form:
2903 @example
2904 [@var{family} @var{width} @var{point-size} @var{weight} @var{slant}
2905  @var{fixed-p} @var{full} @var{registry-and-encoding}]
2906 @end example
2908 The first five elements correspond to face attributes; if you
2909 specify these attributes for a face, it will use this font.
2911 The last three elements give additional information about the font.
2912 @var{fixed-p} is non-@code{nil} if the font is fixed-pitch.
2913 @var{full} is the full name of the font, and
2914 @var{registry-and-encoding} is a string giving the registry and
2915 encoding of the font.
2916 @end defun
2918 @defvar font-list-limit
2919 This variable specifies maximum number of fonts to consider in font
2920 matching.  The function @code{x-family-fonts} will not return more than
2921 that many fonts, and font selection will consider only that many fonts
2922 when searching a matching font for face attributes.  The default is
2923 currently 100.
2924 @end defvar
2926 @node Fontsets
2927 @subsection Fontsets
2929   A @dfn{fontset} is a list of fonts, each assigned to a range of
2930 character codes.  An individual font cannot display the whole range of
2931 characters that Emacs supports, but a fontset can.  Fontsets have names,
2932 just as fonts do, and you can use a fontset name in place of a font name
2933 when you specify the ``font'' for a frame or a face.  Here is
2934 information about defining a fontset under Lisp program control.
2936 @defun create-fontset-from-fontset-spec fontset-spec &optional style-variant-p noerror
2937 This function defines a new fontset according to the specification
2938 string @var{fontset-spec}.  The string should have this format:
2940 @smallexample
2941 @var{fontpattern}, @r{[}@var{charset}:@var{font}@r{]@dots{}}
2942 @end smallexample
2944 @noindent
2945 Whitespace characters before and after the commas are ignored.
2947 The first part of the string, @var{fontpattern}, should have the form of
2948 a standard X font name, except that the last two fields should be
2949 @samp{fontset-@var{alias}}.
2951 The new fontset has two names, one long and one short.  The long name is
2952 @var{fontpattern} in its entirety.  The short name is
2953 @samp{fontset-@var{alias}}.  You can refer to the fontset by either
2954 name.  If a fontset with the same name already exists, an error is
2955 signaled, unless @var{noerror} is non-@code{nil}, in which case this
2956 function does nothing.
2958 If optional argument @var{style-variant-p} is non-@code{nil}, that says
2959 to create bold, italic and bold-italic variants of the fontset as well.
2960 These variant fontsets do not have a short name, only a long one, which
2961 is made by altering @var{fontpattern} to indicate the bold or italic
2962 status.
2964 The specification string also says which fonts to use in the fontset.
2965 See below for the details.
2966 @end defun
2968   The construct @samp{@var{charset}:@var{font}} specifies which font to
2969 use (in this fontset) for one particular character set.  Here,
2970 @var{charset} is the name of a character set, and @var{font} is the font
2971 to use for that character set.  You can use this construct any number of
2972 times in the specification string.
2974   For the remaining character sets, those that you don't specify
2975 explicitly, Emacs chooses a font based on @var{fontpattern}: it replaces
2976 @samp{fontset-@var{alias}} with a value that names one character set.
2977 For the @acronym{ASCII} character set, @samp{fontset-@var{alias}} is replaced
2978 with @samp{ISO8859-1}.
2980   In addition, when several consecutive fields are wildcards, Emacs
2981 collapses them into a single wildcard.  This is to prevent use of
2982 auto-scaled fonts.  Fonts made by scaling larger fonts are not usable
2983 for editing, and scaling a smaller font is not useful because it is
2984 better to use the smaller font in its own size, which Emacs does.
2986   Thus if @var{fontpattern} is this,
2988 @example
2989 -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24
2990 @end example
2992 @noindent
2993 the font specification for @acronym{ASCII} characters would be this:
2995 @example
2996 -*-fixed-medium-r-normal-*-24-*-ISO8859-1
2997 @end example
2999 @noindent
3000 and the font specification for Chinese GB2312 characters would be this:
3002 @example
3003 -*-fixed-medium-r-normal-*-24-*-gb2312*-*
3004 @end example
3006   You may not have any Chinese font matching the above font
3007 specification.  Most X distributions include only Chinese fonts that
3008 have @samp{song ti} or @samp{fangsong ti} in the @var{family} field.  In
3009 such a case, @samp{Fontset-@var{n}} can be specified as below:
3011 @smallexample
3012 Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
3013         chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*
3014 @end smallexample
3016 @noindent
3017 Then, the font specifications for all but Chinese GB2312 characters have
3018 @samp{fixed} in the @var{family} field, and the font specification for
3019 Chinese GB2312 characters has a wild card @samp{*} in the @var{family}
3020 field.
3022 @defun set-fontset-font name character font-spec &optional frame add
3023 This function modifies the existing fontset @var{name} to use the font
3024 matching with @var{font-spec} for the character @var{character}.
3026 If @var{name} is @code{nil}, this function modifies the fontset of the
3027 selected frame or that of @var{frame} if @var{frame} is not
3028 @code{nil}.
3030 If @var{name} is @code{t}, this function modifies the default
3031 fontset, whose short name is @samp{fontset-default}.
3033 @var{character} may be a cons; @code{(@var{from} . @var{to})}, where
3034 @var{from} and @var{to} are character codepoints.  In that case, use
3035 @var{font-spec} for all characters in the range @var{from} and @var{to}
3036 (inclusive).
3038 @var{character} may be a charset.  In that case, use
3039 @var{font-spec} for all character in the charsets.
3041 @var{character} may be a script name.  In that case, use
3042 @var{font-spec} for all character in the charsets.
3044 @var{font-spec} may be a cons; @code{(@var{family} . @var{registry})},
3045 where @var{family} is a family name of a font (possibly including a
3046 foundry name at the head), @var{registry} is a registry name of a font
3047 (possibly including an encoding name at the tail).
3049 @var{font-spec} may be a font name string.
3051 The optional argument @var{add}, if non-@code{nil}, specifies how to
3052 add @var{font-spec} to the font specifications previously set.  If it
3053 is @code{prepend}, @var{font-spec} is prepended.  If it is
3054 @code{append}, @var{font-spec} is appended.  By default,
3055 @var{font-spec} overrides the previous settings.
3057 For instance, this changes the default fontset to use a font of which
3058 family name is @samp{Kochi Gothic} for all characters belonging to
3059 the charset @code{japanese-jisx0208}.
3061 @smallexample
3062 (set-fontset-font t 'japanese-jisx0208
3063                   (font-spec :family "Kochi Gothic"))
3064 @end smallexample
3065 @end defun
3067 @defun char-displayable-p char
3068 This function returns @code{t} if Emacs ought to be able to display
3069 @var{char}.  More precisely, if the selected frame's fontset has a
3070 font to display the character set that @var{char} belongs to.
3072 Fontsets can specify a font on a per-character basis; when the fontset
3073 does that, this function's value may not be accurate.
3074 @end defun
3076 @node Low-Level Font
3077 @subsection Low-Level Font Representation
3079   Normally, it is not necessary to manipulate fonts directly.  In case
3080 you need to do so, this section explains how.
3082   In Emacs Lisp, fonts are represented using three different Lisp
3083 object types: @dfn{font objects}, @dfn{font specs}, and @dfn{font
3084 entities}.
3086 @defun fontp object &optional type
3087 Return @code{t} if @var{object} is a font object, font spec, or font
3088 entity.  Otherwise, return @code{nil}.
3090 The optional argument @var{type}, if non-@code{nil}, determines the
3091 exact type of Lisp object to check for.  In that case, @var{type}
3092 should be one of @code{font-object}, @code{font-spec}, or
3093 @code{font-entity}.
3094 @end defun
3096   A font object is a Lisp object that represents a font that Emacs has
3097 @dfn{opened}.  Font objects cannot be modified in Lisp, but they can
3098 be inspected.
3100 @defun font-at position &optional window string
3101 Return the font object that is being used to display the character at
3102 position @var{position} in the window @var{window}.  If @var{window}
3103 is @code{nil}, it defaults to the selected window.  If @var{string} is
3104 @code{nil}, @var{position} specifies a position in the current buffer;
3105 otherwise, @var{string} should be a string, and @var{position}
3106 specifies a position in that string.
3107 @end defun
3109   A font spec is a Lisp object that contains a set of specifications
3110 that can be used to find a font.  More than one font may match the
3111 specifications in a font spec.
3113 @defun font-spec &rest arguments
3114 Return a new font spec using the specifications in @var{arguments},
3115 which should come in @code{property}-@code{value} pairs.  The possible
3116 specifications are as follows:
3118 @table @code
3119 @item :name
3120 The font name (a string), in either XLFD, Fontconfig, or GTK format.
3121 @xref{Fonts,,, emacs, The GNU Emacs Manual}.
3123 @item :family
3124 @itemx :foundry
3125 @itemx :weight
3126 @itemx :slant
3127 @itemx :width
3128 These have the same meanings as the face attributes of the same name.
3129 @xref{Face Attributes}.
3131 @item :size
3132 The font size---either a non-negative integer that specifies the pixel
3133 size, or a floating point number that specifies the point size.
3135 @item :adstyle
3136 Additional typographic style information for the font, such as
3137 @samp{sans}.  The value should be a string or a symbol.
3139 @item :registry
3140 The charset registry and encoding of the font, such as
3141 @samp{iso8859-1}.  The value should be a string or a symbol.
3143 @item :script
3144 The script that the font must support (a symbol).
3146 @item :otf
3147 The font must be an OpenType font that supports these OpenType
3148 features, provided Emacs is compiled with support for @samp{libotf} (a
3149 library for performing complex text layout in certain scripts).  The
3150 value must be a list of the form
3152 @smallexample
3153 @code{(@var{script-tag} @var{langsys-tag} @var{gsub} @var{gpos})}
3154 @end smallexample
3156 where @var{script-tag} is the OpenType script tag symbol;
3157 @var{langsys-tag} is the OpenType language system tag symbol, or
3158 @code{nil} to use the default language system; @code{gsub} is a list
3159 of OpenType GSUB feature tag symbols, or @code{nil} if none is
3160 required; and @code{gpos} is a list of OpenType GPOS feature tag
3161 symbols, or @code{nil} if none is required.  If @code{gsub} or
3162 @code{gpos} is a list, a @code{nil} element in that list means that
3163 the font must not match any of the remaining tag symbols.  The
3164 @code{gpos} element may be omitted.
3165 @end table
3166 @end defun
3168 @defun font-put font-spec property value
3169 Set the font property @var{property} in the font-spec @var{font-spec}
3170 to @var{value}.
3171 @end defun
3173   A font entity is a reference to a font that need not be open.  Its
3174 properties are intermediate between a font object and a font spec:
3175 like a font object, and unlike a font spec, it refers to a single,
3176 specific font.  Unlike a font object, creating a font entity does not
3177 load the contents of that font into computer memory.
3179 @defun find-font font-spec &optional frame
3180 This function returns a font entity that best matches the font spec
3181 @var{font-spec} on frame @var{frame}.  If @var{frame} is @code{nil},
3182 it defaults to the selected frame.
3183 @end defun
3185 @defun list-fonts font-spec &optional frame num prefer
3186 This function returns a list of all font entities that match the font
3187 spec @var{font-spec}.
3189 The optional argument @var{frame}, if non-@code{nil}, specifies the
3190 frame on which the fonts are to be displayed.  The optional argument
3191 @var{num}, if non-@code{nil}, should be an integer that specifies the
3192 maximum length of the returned list.  The optional argument
3193 @var{prefer}, if non-@code{nil}, should be another font spec, which is
3194 used to control the order of the returned list; the returned font
3195 entities are sorted in order of decreasing ``closeness'' to that font
3196 spec.
3197 @end defun
3199   If you call @code{set-face-attribute} and pass a font spec, font
3200 entity, or font name string as the value of the @code{:font}
3201 attribute, Emacs opens the best ``matching'' font that is available
3202 for display.  It then stores the corresponding font object as the
3203 actual value of the @code{:font} attribute for that face.
3205   The following functions can be used to obtain information about a
3206 font.  For these functions, the @var{font} argument can be a font
3207 object, a font entity, or a font spec.
3209 @defun font-get font property
3210 This function returns the value of the font property @var{property}
3211 for @var{font}.
3213 If @var{font} is a font spec and the font spec does not specify
3214 @var{property}, the return value is @code{nil}.  If @var{font} is a
3215 font object or font entity, the value for the @var{:script} property
3216 may be a list of scripts supported by the font.
3217 @end defun
3219 @defun font-face-attributes font &optional frame
3220 This function returns a list of face attributes corresponding to
3221 @var{font}.  The optional argument @var{frame} specifies the frame on
3222 which the font is to be displayed.  If it is @code{nil}, the selected
3223 frame is used.  The return value has the form
3225 @smallexample
3226 (:family @var{family} :height @var{height} :weight @var{weight}
3227    :slant @var{slant} :width @var{width})
3228 @end smallexample
3230 where the values of @var{family}, @var{height}, @var{weight},
3231 @var{slant}, and @var{width} are face attribute values.  Some of these
3232 key-attribute pairs may be omitted from the list if they are not
3233 specified by @var{font}.
3234 @end defun
3236 @defun font-xlfd-name font &optional fold-wildcards
3237 This function returns the XLFD (X Logical Font Descriptor), a string,
3238 matching @var{font}.  @xref{Fonts,,, emacs, The GNU Emacs Manual}, for
3239 information about XLFDs.  If the name is too long for an XLFD (which
3240 can contain at most 255 characters), the function returns @code{nil}.
3242 If the optional argument @var{fold-wildcards} is non-@code{nil},
3243 consecutive wildcards in the XLFD are folded into one.
3244 @end defun
3246 @node Fringes
3247 @section Fringes
3248 @cindex fringes
3250   The @dfn{fringes} of a window are thin vertical strips down the
3251 sides that are used for displaying bitmaps that indicate truncation,
3252 continuation, horizontal scrolling, and the overlay arrow.
3254 @menu
3255 * Fringe Size/Pos::     Specifying where to put the window fringes.
3256 * Fringe Indicators::   Displaying indicator icons in the window fringes.
3257 * Fringe Cursors::      Displaying cursors in the right fringe.
3258 * Fringe Bitmaps::      Specifying bitmaps for fringe indicators.
3259 * Customizing Bitmaps:: Specifying your own bitmaps to use in the fringes.
3260 * Overlay Arrow::       Display of an arrow to indicate position.
3261 @end menu
3263 @node Fringe Size/Pos
3264 @subsection Fringe Size and Position
3266   The following buffer-local variables control the position and width
3267 of the window fringes.
3269 @defvar fringes-outside-margins
3270 The fringes normally appear between the display margins and the window
3271 text.  If the value is non-@code{nil}, they appear outside the display
3272 margins.  @xref{Display Margins}.
3273 @end defvar
3275 @defvar left-fringe-width
3276 This variable, if non-@code{nil}, specifies the width of the left
3277 fringe in pixels.  A value of @code{nil} means to use the left fringe
3278 width from the window's frame.
3279 @end defvar
3281 @defvar right-fringe-width
3282 This variable, if non-@code{nil}, specifies the width of the right
3283 fringe in pixels.  A value of @code{nil} means to use the right fringe
3284 width from the window's frame.
3285 @end defvar
3287   The values of these variables take effect when you display the
3288 buffer in a window.  If you change them while the buffer is visible,
3289 you can call @code{set-window-buffer} to display it once again in the
3290 same window, to make the changes take effect.  A buffer that does not
3291 specify values for these variables will use the default values
3292 specified for the frame; see @ref{Layout Parameters}.
3294 @defun set-window-fringes window left &optional right outside-margins
3295 This function sets the fringe widths of window @var{window}.
3296 If @var{window} is @code{nil}, the selected window is used.
3298 The argument @var{left} specifies the width in pixels of the left
3299 fringe, and likewise @var{right} for the right fringe.  A value of
3300 @code{nil} for either one stands for the default width.  If
3301 @var{outside-margins} is non-@code{nil}, that specifies that fringes
3302 should appear outside of the display margins.
3303 @end defun
3305 @defun window-fringes &optional window
3306 This function returns information about the fringes of a window
3307 @var{window}.  If @var{window} is omitted or @code{nil}, the selected
3308 window is used.  The value has the form @code{(@var{left-width}
3309 @var{right-width} @var{outside-margins})}.
3310 @end defun
3313 @node Fringe Indicators
3314 @subsection Fringe Indicators
3315 @cindex fringe indicators
3316 @cindex indicators, fringe
3318   The @dfn{fringe indicators} are tiny icons Emacs displays in the
3319 window fringe (on a graphic display) to indicate truncated or
3320 continued lines, buffer boundaries, overlay arrow, etc.
3322 @defopt indicate-empty-lines
3323 @cindex fringes, and empty line indication
3324 When this is non-@code{nil}, Emacs displays a special glyph in the
3325 fringe of each empty line at the end of the buffer, on graphical
3326 displays.  @xref{Fringes}.  This variable is automatically
3327 buffer-local in every buffer.
3328 @end defopt
3330 @defopt indicate-buffer-boundaries
3331 This buffer-local variable controls how the buffer boundaries and
3332 window scrolling are indicated in the window fringes.
3334 Emacs can indicate the buffer boundaries---that is, the first and last
3335 line in the buffer---with angle icons when they appear on the screen.
3336 In addition, Emacs can display an up-arrow in the fringe to show
3337 that there is text above the screen, and a down-arrow to show
3338 there is text below the screen.
3340 There are three kinds of basic values:
3342 @table @asis
3343 @item @code{nil}
3344 Don't display any of these fringe icons.
3345 @item @code{left}
3346 Display the angle icons and arrows in the left fringe.
3347 @item @code{right}
3348 Display the angle icons and arrows in the right fringe.
3349 @item any non-alist
3350 Display the angle icons in the left fringe
3351 and don't display the arrows.
3352 @end table
3354 Otherwise the value should be an alist that specifies which fringe
3355 indicators to display and where.  Each element of the alist should
3356 have the form @code{(@var{indicator} . @var{position})}.  Here,
3357 @var{indicator} is one of @code{top}, @code{bottom}, @code{up},
3358 @code{down}, and @code{t} (which covers all the icons not yet
3359 specified), while @var{position} is one of @code{left}, @code{right}
3360 and @code{nil}.
3362 For example, @code{((top . left) (t . right))} places the top angle
3363 bitmap in left fringe, and the bottom angle bitmap as well as both
3364 arrow bitmaps in right fringe.  To show the angle bitmaps in the left
3365 fringe, and no arrow bitmaps, use @code{((top .  left) (bottom . left))}.
3366 @end defopt
3368 @defvar fringe-indicator-alist
3369 This buffer-local variable specifies the mapping from logical fringe
3370 indicators to the actual bitmaps displayed in the window fringes.
3372 These symbols identify the logical fringe indicators:
3374 @table @asis
3375 @item Truncation and continuation line indicators:
3376 @code{truncation}, @code{continuation}.
3378 @item Buffer position indicators:
3379 @code{up}, @code{down},
3380 @code{top}, @code{bottom},
3381 @code{top-bottom}.
3383 @item Empty line indicator:
3384 @code{empty-line}.
3386 @item Overlay arrow indicator:
3387 @code{overlay-arrow}.
3389 @item Unknown bitmap indicator:
3390 @code{unknown}.
3391 @end table
3393   The value is an alist where each element @code{(@var{indicator} . @var{bitmaps})}
3394 specifies the fringe bitmaps used to display a specific logical
3395 fringe indicator.
3397 Here, @var{indicator} specifies the logical indicator type, and
3398 @var{bitmaps} is list of symbols @code{(@var{left} @var{right}
3399 [@var{left1} @var{right1}])} which specifies the actual bitmap shown
3400 in the left or right fringe for the logical indicator.
3402 The @var{left} and @var{right} symbols specify the bitmaps shown in
3403 the left and/or right fringe for the specific indicator.  The
3404 @var{left1} or @var{right1} bitmaps are used only for the `bottom' and
3405 `top-bottom indicators when the last (only) line in has no final
3406 newline.  Alternatively, @var{bitmaps} may be a single symbol which is
3407 used in both left and right fringes.
3409 When @code{fringe-indicator-alist} has a buffer-local value, and there
3410 is no bitmap defined for a logical indicator, or the bitmap is
3411 @code{t}, the corresponding value from the default value of
3412 @code{fringe-indicator-alist} is used.
3414 To completely hide a specific indicator, set the bitmap to @code{nil}.
3415 @end defvar
3417 Standard fringe bitmaps for indicators:
3418 @example
3419 left-arrow right-arrow up-arrow down-arrow
3420 left-curly-arrow right-curly-arrow
3421 left-triangle right-triangle
3422 top-left-angle top-right-angle
3423 bottom-left-angle bottom-right-angle
3424 left-bracket right-bracket
3425 filled-rectangle hollow-rectangle
3426 filled-square hollow-square
3427 vertical-bar horizontal-bar
3428 empty-line question-mark
3429 @end example
3431 @node Fringe Cursors
3432 @subsection Fringe Cursors
3433 @cindex fringe cursors
3434 @cindex cursor, fringe
3436   When a line is exactly as wide as the window, Emacs displays the
3437 cursor in the right fringe instead of using two lines.  Different
3438 bitmaps are used to represent the cursor in the fringe depending on
3439 the current buffer's cursor type.
3441 @table @asis
3442 @item Logical cursor types:
3443 @code{box} , @code{hollow}, @code{bar},
3444 @code{hbar}, @code{hollow-small}.
3445 @end table
3447 The @code{hollow-small} type is used instead of @code{hollow} when the
3448 normal @code{hollow-rectangle} bitmap is too tall to fit on a specific
3449 display line.
3451 @defopt overflow-newline-into-fringe
3452 If this is non-@code{nil}, lines exactly as wide as the window (not
3453 counting the final newline character) are not continued.  Instead,
3454 when point is at the end of the line, the cursor appears in the right
3455 fringe.
3456 @end defopt
3458 @defvar fringe-cursor-alist
3459 This variable specifies the mapping from logical cursor type to the
3460 actual fringe bitmaps displayed in the right fringe.  The value is an
3461 alist where each element @code{(@var{cursor} . @var{bitmap})} specifies
3462 the fringe bitmaps used to display a specific logical cursor type in
3463 the fringe.  Here, @var{cursor} specifies the logical cursor type and
3464 @var{bitmap} is a symbol specifying the fringe bitmap to be displayed
3465 for that logical cursor type.
3467 When @code{fringe-cursor-alist} has a buffer-local value, and there is
3468 no bitmap defined for a cursor type, the corresponding value from the
3469 default value of @code{fringes-indicator-alist} is used.
3470 @end defvar
3472 Standard bitmaps for displaying the cursor in right fringe:
3473 @example
3474 filled-rectangle hollow-rectangle filled-square hollow-square
3475 vertical-bar horizontal-bar
3476 @end example
3479 @node Fringe Bitmaps
3480 @subsection Fringe Bitmaps
3481 @cindex fringe bitmaps
3482 @cindex bitmaps, fringe
3484   The @dfn{fringe bitmaps} are the actual bitmaps which represent the
3485 logical fringe indicators for truncated or continued lines, buffer
3486 boundaries, overlay arrow, etc.  Fringe bitmap symbols have their own
3487 name space.  The fringe bitmaps are shared by all frames and windows.
3488 You can redefine the built-in fringe bitmaps, and you can define new
3489 fringe bitmaps.
3491   The way to display a bitmap in the left or right fringes for a given
3492 line in a window is by specifying the @code{display} property for one
3493 of the characters that appears in it.  Use a display specification of
3494 the form @code{(left-fringe @var{bitmap} [@var{face}])} or
3495 @code{(right-fringe @var{bitmap} [@var{face}])} (@pxref{Display
3496 Property}).  Here, @var{bitmap} is a symbol identifying the bitmap you
3497 want, and @var{face} (which is optional) is the name of the face whose
3498 colors should be used for displaying the bitmap, instead of the
3499 default @code{fringe} face.  @var{face} is automatically merged with
3500 the @code{fringe} face, so normally @var{face} need only specify the
3501 foreground color for the bitmap.
3503 @defun fringe-bitmaps-at-pos &optional pos window
3504 This function returns the fringe bitmaps of the display line
3505 containing position @var{pos} in window @var{window}.  The return
3506 value has the form @code{(@var{left} @var{right} @var{ov})}, where @var{left}
3507 is the symbol for the fringe bitmap in the left fringe (or @code{nil}
3508 if no bitmap), @var{right} is similar for the right fringe, and @var{ov}
3509 is non-@code{nil} if there is an overlay arrow in the left fringe.
3511 The value is @code{nil} if @var{pos} is not visible in @var{window}.
3512 If @var{window} is @code{nil}, that stands for the selected window.
3513 If @var{pos} is @code{nil}, that stands for the value of point in
3514 @var{window}.
3515 @end defun
3517 @node Customizing Bitmaps
3518 @subsection Customizing Fringe Bitmaps
3520 @defun define-fringe-bitmap bitmap bits &optional height width align
3521 This function defines the symbol @var{bitmap} as a new fringe bitmap,
3522 or replaces an existing bitmap with that name.
3524 The argument @var{bits} specifies the image to use.  It should be
3525 either a string or a vector of integers, where each element (an
3526 integer) corresponds to one row of the bitmap.  Each bit of an integer
3527 corresponds to one pixel of the bitmap, where the low bit corresponds
3528 to the rightmost pixel of the bitmap.
3530 The height is normally the length of @var{bits}.  However, you
3531 can specify a different height with non-@code{nil} @var{height}.  The width
3532 is normally 8, but you can specify a different width with non-@code{nil}
3533 @var{width}.  The width must be an integer between 1 and 16.
3535 The argument @var{align} specifies the positioning of the bitmap
3536 relative to the range of rows where it is used; the default is to
3537 center the bitmap.  The allowed values are @code{top}, @code{center},
3538 or @code{bottom}.
3540 The @var{align} argument may also be a list @code{(@var{align}
3541 @var{periodic})} where @var{align} is interpreted as described above.
3542 If @var{periodic} is non-@code{nil}, it specifies that the rows in
3543 @code{bits} should be repeated enough times to reach the specified
3544 height.
3545 @end defun
3547 @defun destroy-fringe-bitmap bitmap
3548 This function destroy the fringe bitmap identified by @var{bitmap}.
3549 If @var{bitmap} identifies a standard fringe bitmap, it actually
3550 restores the standard definition of that bitmap, instead of
3551 eliminating it entirely.
3552 @end defun
3554 @defun set-fringe-bitmap-face bitmap &optional face
3555 This sets the face for the fringe bitmap @var{bitmap} to @var{face}.
3556 If @var{face} is @code{nil}, it selects the @code{fringe} face.  The
3557 bitmap's face controls the color to draw it in.
3559 @var{face} is merged with the @code{fringe} face, so normally
3560 @var{face} should specify only the foreground color.
3561 @end defun
3563 @node Overlay Arrow
3564 @subsection The Overlay Arrow
3565 @c @cindex overlay arrow  Duplicates variable names
3567   The @dfn{overlay arrow} is useful for directing the user's attention
3568 to a particular line in a buffer.  For example, in the modes used for
3569 interface to debuggers, the overlay arrow indicates the line of code
3570 about to be executed.  This feature has nothing to do with
3571 @dfn{overlays} (@pxref{Overlays}).
3573 @defvar overlay-arrow-string
3574 This variable holds the string to display to call attention to a
3575 particular line, or @code{nil} if the arrow feature is not in use.
3576 On a graphical display the contents of the string are ignored; instead a
3577 glyph is displayed in the fringe area to the left of the display area.
3578 @end defvar
3580 @defvar overlay-arrow-position
3581 This variable holds a marker that indicates where to display the overlay
3582 arrow.  It should point at the beginning of a line.  On a non-graphical
3583 display the arrow text
3584 appears at the beginning of that line, overlaying any text that would
3585 otherwise appear.  Since the arrow is usually short, and the line
3586 usually begins with indentation, normally nothing significant is
3587 overwritten.
3589 The overlay-arrow string is displayed in any given buffer if the value
3590 of @code{overlay-arrow-position} in that buffer points into that
3591 buffer.  Thus, it is possible to display multiple overlay arrow strings
3592 by creating buffer-local bindings of @code{overlay-arrow-position}.
3593 However, it is usually cleaner to use
3594 @code{overlay-arrow-variable-list} to achieve this result.
3595 @c !!! overlay-arrow-position: but the overlay string may remain in the display
3596 @c of some other buffer until an update is required.  This should be fixed
3597 @c now.  Is it?
3598 @end defvar
3600   You can do a similar job by creating an overlay with a
3601 @code{before-string} property.  @xref{Overlay Properties}.
3603   You can define multiple overlay arrows via the variable
3604 @code{overlay-arrow-variable-list}.
3606 @defvar overlay-arrow-variable-list
3607 This variable's value is a list of variables, each of which specifies
3608 the position of an overlay arrow.  The variable
3609 @code{overlay-arrow-position} has its normal meaning because it is on
3610 this list.
3611 @end defvar
3613 Each variable on this list can have properties
3614 @code{overlay-arrow-string} and @code{overlay-arrow-bitmap} that
3615 specify an overlay arrow string (for text-only terminals) or fringe
3616 bitmap (for graphical terminals) to display at the corresponding
3617 overlay arrow position.  If either property is not set, the default
3618 @code{overlay-arrow-string} or @code{overlay-arrow} fringe indicator
3619 is used.
3621 @node Scroll Bars
3622 @section Scroll Bars
3623 @cindex scroll bars
3625 Normally the frame parameter @code{vertical-scroll-bars} controls
3626 whether the windows in the frame have vertical scroll bars, and
3627 whether they are on the left or right.  The frame parameter
3628 @code{scroll-bar-width} specifies how wide they are (@code{nil}
3629 meaning the default).  @xref{Layout Parameters}.
3631 @defun frame-current-scroll-bars &optional frame
3632 This function reports the scroll bar type settings for frame
3633 @var{frame}.  The value is a cons cell
3634 @code{(@var{vertical-type} .@: @var{horizontal-type})}, where
3635 @var{vertical-type} is either @code{left}, @code{right}, or @code{nil}
3636 (which means no scroll bar.)  @var{horizontal-type} is meant to
3637 specify the horizontal scroll bar type, but since they are not
3638 implemented, it is always @code{nil}.
3639 @end defun
3641 @vindex vertical-scroll-bar
3642   You can enable or disable scroll bars for a particular buffer,
3643 by setting the variable @code{vertical-scroll-bar}.  This variable
3644 automatically becomes buffer-local when set.  The possible values are
3645 @code{left}, @code{right}, @code{t}, which means to use the
3646 frame's default, and @code{nil} for no scroll bar.
3648   You can also control this for individual windows.  Call the function
3649 @code{set-window-scroll-bars} to specify what to do for a specific window:
3651 @defun set-window-scroll-bars window width &optional vertical-type horizontal-type
3652 This function sets the width and type of scroll bars for window
3653 @var{window}.
3655 @var{width} specifies the scroll bar width in pixels (@code{nil} means
3656 use the width specified for the frame).  @var{vertical-type} specifies
3657 whether to have a vertical scroll bar and, if so, where.  The possible
3658 values are @code{left}, @code{right} and @code{nil}, just like the
3659 values of the @code{vertical-scroll-bars} frame parameter.
3661 The argument @var{horizontal-type} is meant to specify whether and
3662 where to have horizontal scroll bars, but since they are not
3663 implemented, it has no effect.  If @var{window} is @code{nil}, the
3664 selected window is used.
3665 @end defun
3667 @defun window-scroll-bars &optional window
3668 Report the width and type of scroll bars specified for @var{window}.
3669 If @var{window} is omitted or @code{nil}, the selected window is used.
3670 The value is a list of the form @code{(@var{width}
3671 @var{cols} @var{vertical-type} @var{horizontal-type})}.  The value
3672 @var{width} is the value that was specified for the width (which may
3673 be @code{nil}); @var{cols} is the number of columns that the scroll
3674 bar actually occupies.
3676 @var{horizontal-type} is not actually meaningful.
3677 @end defun
3679 If you don't specify these values for a window with
3680 @code{set-window-scroll-bars}, the buffer-local variables
3681 @code{scroll-bar-mode} and @code{scroll-bar-width} in the buffer being
3682 displayed control the window's vertical scroll bars.  The function
3683 @code{set-window-buffer} examines these variables.  If you change them
3684 in a buffer that is already visible in a window, you can make the
3685 window take note of the new values by calling @code{set-window-buffer}
3686 specifying the same buffer that is already displayed.
3688 @defopt scroll-bar-mode
3689 This variable, always local in all buffers, controls whether and where
3690 to put scroll bars in windows displaying the buffer.  The possible values
3691 are @code{nil} for no scroll bar, @code{left} to put a scroll bar on
3692 the left, and @code{right} to put a scroll bar on the right.
3693 @end defopt
3695 @defun window-current-scroll-bars &optional window
3696 This function reports the scroll bar type for window @var{window}.
3697 If @var{window} is omitted or @code{nil}, the selected window is used.
3698 The value is a cons cell
3699 @code{(@var{vertical-type} .@: @var{horizontal-type})}.  Unlike
3700 @code{window-scroll-bars}, this reports the scroll bar type actually
3701 used, once frame defaults and @code{scroll-bar-mode} are taken into
3702 account.
3703 @end defun
3705 @defvar scroll-bar-width
3706 This variable, always local in all buffers, specifies the width of the
3707 buffer's scroll bars, measured in pixels.  A value of @code{nil} means
3708 to use the value specified by the frame.
3709 @end defvar
3711 @node Display Property
3712 @section The @code{display} Property
3713 @cindex display specification
3714 @kindex display @r{(text property)}
3716   The @code{display} text property (or overlay property) is used to
3717 insert images into text, and also control other aspects of how text
3718 displays.  The value of the @code{display} property should be a
3719 display specification, or a list or vector containing several display
3720 specifications.  Display specifications in the same @code{display}
3721 property value generally apply in parallel to the text they cover.
3723   If several sources (overlays and/or a text property) specify values
3724 for the @code{display} property, only one of the values takes effect,
3725 following the rules of @code{get-char-property}.  @xref{Examining
3726 Properties}.
3728   The rest of this section describes several kinds of
3729 display specifications and what they mean.
3731 @menu
3732 * Replacing Specs::      Display specs that replace the text.
3733 * Specified Space::      Displaying one space with a specified width.
3734 * Pixel Specification::  Specifying space width or height in pixels.
3735 * Other Display Specs::     Displaying an image; adjusting the height,
3736                               spacing, and other properties of text.
3737 * Display Margins::     Displaying text or images to the side of the main text.
3738 @end menu
3740 @node Replacing Specs
3741 @subsection Display Specs That Replace The Text
3743   Some kinds of @code{display} specifications specify something to
3744 display instead of the text that has the property.  These are called
3745 @dfn{replacing} display specifications.  Emacs does not allow the user
3746 to interactively move point into the middle of buffer text that is
3747 replaced in this way.
3749   If a list of display specifications includes more than one replacing
3750 display specification, the first overrides the rest.  Replacing
3751 display specifications make most other display specifications
3752 irrelevant, since those don't apply to the replacement.
3754   For replacing display specifications, ``the text that has the
3755 property'' means all the consecutive characters that have the same
3756 Lisp object as their @code{display} property; these characters are
3757 replaced as a single unit.  By contrast, characters that have similar
3758 but distinct Lisp objects as their @code{display} properties are
3759 handled separately.  Here's a function that illustrates this point:
3761 @smallexample
3762 (defun foo ()
3763   (goto-char (point-min))
3764   (dotimes (i 5)
3765     (let ((string (concat "A")))
3766       (put-text-property (point) (1+ (point)) 'display string)
3767       (forward-char 1)
3768       (put-text-property (point) (1+ (point)) 'display string)
3769       (forward-char 1))))
3770 @end smallexample
3772 @noindent
3773 It gives each of the first ten characters in the buffer string
3774 @code{"A"} as the @code{display} property, but they don't all get the
3775 same string.  The first two characters get the same string, so they
3776 together are replaced with one @samp{A}.  The next two characters get
3777 a second string, so they together are replaced with one @samp{A}.
3778 Likewise for each following pair of characters.  Thus, the ten
3779 characters appear as five A's.  This function would have the same
3780 results:
3782 @smallexample
3783 (defun foo ()
3784   (goto-char (point-min))
3785   (dotimes (i 5)
3786     (let ((string (concat "A")))
3787       (put-text-property (point) (+ 2 (point)) 'display string)
3788       (put-text-property (point) (1+ (point)) 'display string)
3789       (forward-char 2))))
3790 @end smallexample
3792 @noindent
3793 This illustrates that what matters is the property value for
3794 each character.  If two consecutive characters have the same
3795 object as the @code{display} property value, it's irrelevant
3796 whether they got this property from a single call to
3797 @code{put-text-property} or from two different calls.
3799 @node Specified Space
3800 @subsection Specified Spaces
3801 @cindex spaces, specified height or width
3802 @cindex variable-width spaces
3804   To display a space of specified width and/or height, use a display
3805 specification of the form @code{(space . @var{props})}, where
3806 @var{props} is a property list (a list of alternating properties and
3807 values).  You can put this property on one or more consecutive
3808 characters; a space of the specified height and width is displayed in
3809 place of @emph{all} of those characters.  These are the properties you
3810 can use in @var{props} to specify the weight of the space:
3812 @table @code
3813 @item :width @var{width}
3814 If @var{width} is an integer or floating point number, it specifies
3815 that the space width should be @var{width} times the normal character
3816 width.  @var{width} can also be a @dfn{pixel width} specification
3817 (@pxref{Pixel Specification}).
3819 @item :relative-width @var{factor}
3820 Specifies that the width of the stretch should be computed from the
3821 first character in the group of consecutive characters that have the
3822 same @code{display} property.  The space width is the width of that
3823 character, multiplied by @var{factor}.
3825 @item :align-to @var{hpos}
3826 Specifies that the space should be wide enough to reach @var{hpos}.
3827 If @var{hpos} is a number, it is measured in units of the normal
3828 character width.  @var{hpos} can also be a @dfn{pixel width}
3829 specification (@pxref{Pixel Specification}).
3830 @end table
3832   You should use one and only one of the above properties.  You can
3833 also specify the height of the space, with these properties:
3835 @table @code
3836 @item :height @var{height}
3837 Specifies the height of the space.
3838 If @var{height} is an integer or floating point number, it specifies
3839 that the space height should be @var{height} times the normal character
3840 height.  The @var{height} may also be a @dfn{pixel height} specification
3841 (@pxref{Pixel Specification}).
3843 @item :relative-height @var{factor}
3844 Specifies the height of the space, multiplying the ordinary height
3845 of the text having this display specification by @var{factor}.
3847 @item :ascent @var{ascent}
3848 If the value of @var{ascent} is a non-negative number no greater than
3849 100, it specifies that @var{ascent} percent of the height of the space
3850 should be considered as the ascent of the space---that is, the part
3851 above the baseline.  The ascent may also be specified in pixel units
3852 with a @dfn{pixel ascent} specification (@pxref{Pixel Specification}).
3854 @end table
3856   Don't use both @code{:height} and @code{:relative-height} together.
3858   The @code{:width} and @code{:align-to} properties are supported on
3859 non-graphic terminals, but the other space properties in this section
3860 are not.
3862   Note that space properties are treated as paragraph separators for
3863 the purposes of reordering bidirectional text for display.
3864 @xref{Bidirectional Display}, for the details.
3866 @node Pixel Specification
3867 @subsection Pixel Specification for Spaces
3868 @cindex spaces, pixel specification
3870   The value of the @code{:width}, @code{:align-to}, @code{:height},
3871 and @code{:ascent} properties can be a special kind of expression that
3872 is evaluated during redisplay.  The result of the evaluation is used
3873 as an absolute number of pixels.
3875   The following expressions are supported:
3877 @smallexample
3878 @group
3879   @var{expr} ::= @var{num} | (@var{num}) | @var{unit} | @var{elem} | @var{pos} | @var{image} | @var{form}
3880   @var{num}  ::= @var{integer} | @var{float} | @var{symbol}
3881   @var{unit} ::= in | mm | cm | width | height
3882 @end group
3883 @group
3884   @var{elem} ::= left-fringe | right-fringe | left-margin | right-margin
3885         |  scroll-bar | text
3886   @var{pos}  ::= left | center | right
3887   @var{form} ::= (@var{num} . @var{expr}) | (@var{op} @var{expr} ...)
3888   @var{op}   ::= + | -
3889 @end group
3890 @end smallexample
3892   The form @var{num} specifies a fraction of the default frame font
3893 height or width.  The form @code{(@var{num})} specifies an absolute
3894 number of pixels.  If @var{num} is a symbol, @var{symbol}, its
3895 buffer-local variable binding is used.
3897   The @code{in}, @code{mm}, and @code{cm} units specify the number of
3898 pixels per inch, millimeter, and centimeter, respectively.  The
3899 @code{width} and @code{height} units correspond to the default width
3900 and height of the current face.  An image specification @code{image}
3901 corresponds to the width or height of the image.
3903   The elements @code{left-fringe}, @code{right-fringe},
3904 @code{left-margin}, @code{right-margin}, @code{scroll-bar}, and
3905 @code{text} specify to the width of the corresponding area of the
3906 window.
3908   The @code{left}, @code{center}, and @code{right} positions can be
3909 used with @code{:align-to} to specify a position relative to the left
3910 edge, center, or right edge of the text area.
3912   Any of the above window elements (except @code{text}) can also be
3913 used with @code{:align-to} to specify that the position is relative to
3914 the left edge of the given area.  Once the base offset for a relative
3915 position has been set (by the first occurrence of one of these
3916 symbols), further occurrences of these symbols are interpreted as the
3917 width of the specified area.  For example, to align to the center of
3918 the left-margin, use
3920 @example
3921 :align-to (+ left-margin (0.5 . left-margin))
3922 @end example
3924   If no specific base offset is set for alignment, it is always relative
3925 to the left edge of the text area.  For example, @samp{:align-to 0} in a
3926 header-line aligns with the first text column in the text area.
3928   A value of the form @code{(@var{num} . @var{expr})} stands for the
3929 product of the values of @var{num} and @var{expr}.  For example,
3930 @code{(2 . in)} specifies a width of 2 inches, while @code{(0.5 .
3931 @var{image})} specifies half the width (or height) of the specified
3932 image.
3934   The form @code{(+ @var{expr} ...)} adds up the value of the
3935 expressions.  The form @code{(- @var{expr} ...)} negates or subtracts
3936 the value of the expressions.
3938 @node Other Display Specs
3939 @subsection Other Display Specifications
3941   Here are the other sorts of display specifications that you can use
3942 in the @code{display} text property.
3944 @table @code
3945 @item @var{string}
3946 Display @var{string} instead of the text that has this property.
3948 Recursive display specifications are not supported---@var{string}'s
3949 @code{display} properties, if any, are not used.
3951 @item (image . @var{image-props})
3952 This kind of display specification is an image descriptor (@pxref{Images}).
3953 When used as a display specification, it means to display the image
3954 instead of the text that has the display specification.
3956 @item (slice @var{x} @var{y} @var{width} @var{height})
3957 This specification together with @code{image} specifies a @dfn{slice}
3958 (a partial area) of the image to display.  The elements @var{y} and
3959 @var{x} specify the top left corner of the slice, within the image;
3960 @var{width} and @var{height} specify the width and height of the
3961 slice.  Integer values are numbers of pixels.  A floating point number
3962 in the range 0.0--1.0 stands for that fraction of the width or height
3963 of the entire image.
3965 @item ((margin nil) @var{string})
3966 A display specification of this form means to display @var{string}
3967 instead of the text that has the display specification, at the same
3968 position as that text.  It is equivalent to using just @var{string},
3969 but it is done as a special case of marginal display (@pxref{Display
3970 Margins}).
3972 @item (left-fringe @var{bitmap} @r{[}@var{face}@r{]})
3973 @itemx (right-fringe @var{bitmap} @r{[}@var{face}@r{]})
3974 This display specification on any character of a line of text causes
3975 the specified @var{bitmap} be displayed in the left or right fringes
3976 for that line, instead of the characters that have the display
3977 specification.  The optional @var{face} specifies the colors to be
3978 used for the bitmap.  @xref{Fringe Bitmaps}, for the details.
3980 @item (space-width @var{factor})
3981 This display specification affects all the space characters within the
3982 text that has the specification.  It displays all of these spaces
3983 @var{factor} times as wide as normal.  The element @var{factor} should
3984 be an integer or float.  Characters other than spaces are not affected
3985 at all; in particular, this has no effect on tab characters.
3987 @item (height @var{height})
3988 This display specification makes the text taller or shorter.
3989 Here are the possibilities for @var{height}:
3991 @table @asis
3992 @item @code{(+ @var{n})}
3993 This means to use a font that is @var{n} steps larger.  A ``step'' is
3994 defined by the set of available fonts---specifically, those that match
3995 what was otherwise specified for this text, in all attributes except
3996 height.  Each size for which a suitable font is available counts as
3997 another step.  @var{n} should be an integer.
3999 @item @code{(- @var{n})}
4000 This means to use a font that is @var{n} steps smaller.
4002 @item a number, @var{factor}
4003 A number, @var{factor}, means to use a font that is @var{factor} times
4004 as tall as the default font.
4006 @item a symbol, @var{function}
4007 A symbol is a function to compute the height.  It is called with the
4008 current height as argument, and should return the new height to use.
4010 @item anything else, @var{form}
4011 If the @var{height} value doesn't fit the previous possibilities, it is
4012 a form.  Emacs evaluates it to get the new height, with the symbol
4013 @code{height} bound to the current specified font height.
4014 @end table
4016 @item (raise @var{factor})
4017 This kind of display specification raises or lowers the text
4018 it applies to, relative to the baseline of the line.
4020 @var{factor} must be a number, which is interpreted as a multiple of the
4021 height of the affected text.  If it is positive, that means to display
4022 the characters raised.  If it is negative, that means to display them
4023 lower down.
4025 If the text also has a @code{height} display specification, that does
4026 not affect the amount of raising or lowering, which is based on the
4027 faces used for the text.
4028 @end table
4030 @c We put all the `@code{(when ...)}' on one line to encourage
4031 @c makeinfo's end-of-sentence heuristics to DTRT.  Previously, the dot
4032 @c was at eol; the info file ended up w/ two spaces rendered after it.
4033   You can make any display specification conditional.  To do that,
4034 package it in another list of the form
4035 @code{(when @var{condition} . @var{spec})}.
4036 Then the specification @var{spec} applies only when
4037 @var{condition} evaluates to a non-@code{nil} value.  During the
4038 evaluation, @code{object} is bound to the string or buffer having the
4039 conditional @code{display} property.  @code{position} and
4040 @code{buffer-position} are bound to the position within @code{object}
4041 and the buffer position where the @code{display} property was found,
4042 respectively.  Both positions can be different when @code{object} is a
4043 string.
4045 @node Display Margins
4046 @subsection Displaying in the Margins
4047 @cindex display margins
4048 @cindex margins, display
4050   A buffer can have blank areas called @dfn{display margins} on the
4051 left and on the right.  Ordinary text never appears in these areas,
4052 but you can put things into the display margins using the
4053 @code{display} property.  There is currently no way to make text or
4054 images in the margin mouse-sensitive.
4056   The way to display something in the margins is to specify it in a
4057 margin display specification in the @code{display} property of some
4058 text.  This is a replacing display specification, meaning that the
4059 text you put it on does not get displayed; the margin display appears,
4060 but that text does not.
4062   A margin display specification looks like @code{((margin
4063 right-margin) @var{spec})} or @code{((margin left-margin) @var{spec})}.
4064 Here, @var{spec} is another display specification that says what to
4065 display in the margin.  Typically it is a string of text to display,
4066 or an image descriptor.
4068   To display something in the margin @emph{in association with}
4069 certain buffer text, without altering or preventing the display of
4070 that text, put a @code{before-string} property on the text and put the
4071 margin display specification on the contents of the before-string.
4073   Before the display margins can display anything, you must give
4074 them a nonzero width.  The usual way to do that is to set these
4075 variables:
4077 @defvar left-margin-width
4078 This variable specifies the width of the left margin.
4079 It is buffer-local in all buffers.
4080 @end defvar
4082 @defvar right-margin-width
4083 This variable specifies the width of the right margin.
4084 It is buffer-local in all buffers.
4085 @end defvar
4087   Setting these variables does not immediately affect the window.  These
4088 variables are checked when a new buffer is displayed in the window.
4089 Thus, you can make changes take effect by calling
4090 @code{set-window-buffer}.
4092   You can also set the margin widths immediately.
4094 @defun set-window-margins window left &optional right
4095 This function specifies the margin widths for window @var{window}.
4096 The argument @var{left} controls the left margin and
4097 @var{right} controls the right margin (default @code{0}).
4098 @end defun
4100 @defun window-margins &optional window
4101 This function returns the left and right margins of @var{window}
4102 as a cons cell of the form @code{(@var{left} . @var{right})}.
4103 If @var{window} is @code{nil}, the selected window is used.
4104 @end defun
4106 @node Images
4107 @section Images
4108 @cindex images in buffers
4110   To display an image in an Emacs buffer, you must first create an image
4111 descriptor, then use it as a display specifier in the @code{display}
4112 property of text that is displayed (@pxref{Display Property}).
4114   Emacs is usually able to display images when it is run on a
4115 graphical terminal.  Images cannot be displayed in a text terminal, on
4116 certain graphical terminals that lack the support for this, or if
4117 Emacs is compiled without image support.  You can use the function
4118 @code{display-images-p} to determine if images can in principle be
4119 displayed (@pxref{Display Feature Testing}).
4121 @menu
4122 * Image Formats::       Supported image formats.
4123 * Image Descriptors::   How to specify an image for use in @code{:display}.
4124 * XBM Images::          Special features for XBM format.
4125 * XPM Images::          Special features for XPM format.
4126 * GIF Images::          Special features for GIF format.
4127 * TIFF Images::         Special features for TIFF format.
4128 * PostScript Images::   Special features for PostScript format.
4129 * ImageMagick Images::  Special features available through ImageMagick.
4130 * Other Image Types::   Various other formats are supported.
4131 * Defining Images::     Convenient ways to define an image for later use.
4132 * Showing Images::      Convenient ways to display an image once it is defined.
4133 * Image Cache::         Internal mechanisms of image display.
4134 @end menu
4136 @node Image Formats
4137 @subsection Image Formats
4138 @cindex image formats
4139 @cindex image types
4141   Emacs can display a number of different image formats; some of them
4142 are supported only if particular support libraries are installed on
4143 your machine.  In some environments, Emacs can load support libraries
4144 on demand; if so, the variable @code{dynamic-library-alist}
4145 (@pxref{Dynamic Libraries}) can be used to modify the set of known
4146 names for these dynamic libraries (though it is not possible to add
4147 new image formats).  Note that image types @code{pbm} and @code{xbm}
4148 do not depend on external libraries and are always available in Emacs.
4150   The supported image formats include XBM, XPM (this requires the
4151 libraries @code{libXpm} version 3.4k and @code{libz}), GIF (requiring
4152 @code{libungif} 4.1.0), PostScript, PBM, JPEG (requiring the
4153 @code{libjpeg} library version v6a), TIFF (requiring @code{libtiff}
4154 v3.4), PNG (requiring @code{libpng} 1.0.2), and SVG (requiring
4155 @code{librsvg} 2.0.0).
4157   You specify one of these formats with an image type symbol.  The image
4158 type symbols are @code{xbm}, @code{xpm}, @code{gif}, @code{postscript},
4159 @code{pbm}, @code{jpeg}, @code{tiff}, @code{png}, and @code{svg}.
4161 @defvar image-types
4162 This variable contains a list of those image type symbols that are
4163 potentially supported in the current configuration.
4164 @emph{Potentially} here means that Emacs knows about the image types,
4165 not necessarily that they can be loaded (they could depend on
4166 unavailable dynamic libraries, for example).
4168 To know which image types are really available, use
4169 @code{image-type-available-p}.
4170 @end defvar
4172 @defun image-type-available-p type
4173 This function returns non-@code{nil} if image type @var{type} is
4174 available, i.e., if images of this type can be loaded and displayed in
4175 Emacs.  @var{type} should be one of the types contained in
4176 @code{image-types}.
4178 For image types whose support libraries are statically linked, this
4179 function always returns @code{t}; for other image types, it returns
4180 @code{t} if the dynamic library could be loaded, @code{nil} otherwise.
4181 @end defun
4183 @node Image Descriptors
4184 @subsection Image Descriptors
4185 @cindex image descriptor
4187   An image description is a list of the form @code{(image . @var{props})},
4188 where @var{props} is a property list containing alternating keyword
4189 symbols (symbols whose names start with a colon) and their values.
4190 You can use any Lisp object as a property, but the only properties
4191 that have any special meaning are certain symbols, all of them keywords.
4193   Every image descriptor must contain the property @code{:type
4194 @var{type}} to specify the format of the image.  The value of @var{type}
4195 should be an image type symbol; for example, @code{xpm} for an image in
4196 XPM format.
4198   Here is a list of other properties that are meaningful for all image
4199 types:
4201 @table @code
4202 @item :file @var{file}
4203 The @code{:file} property says to load the image from file
4204 @var{file}.  If @var{file} is not an absolute file name, it is expanded
4205 in @code{data-directory}.
4207 @item :data @var{data}
4208 The @code{:data} property says the actual contents of the image.
4209 Each image must use either @code{:data} or @code{:file}, but not both.
4210 For most image types, the value of the @code{:data} property should be a
4211 string containing the image data; we recommend using a unibyte string.
4213 Before using @code{:data}, look for further information in the section
4214 below describing the specific image format.  For some image types,
4215 @code{:data} may not be supported; for some, it allows other data types;
4216 for some, @code{:data} alone is not enough, so you need to use other
4217 image properties along with @code{:data}.
4219 @item :margin @var{margin}
4220 The @code{:margin} property specifies how many pixels to add as an
4221 extra margin around the image.  The value, @var{margin}, must be a
4222 non-negative number, or a pair @code{(@var{x} . @var{y})} of such
4223 numbers.  If it is a pair, @var{x} specifies how many pixels to add
4224 horizontally, and @var{y} specifies how many pixels to add vertically.
4225 If @code{:margin} is not specified, the default is zero.
4227 @item :ascent @var{ascent}
4228 The @code{:ascent} property specifies the amount of the image's
4229 height to use for its ascent---that is, the part above the baseline.
4230 The value, @var{ascent}, must be a number in the range 0 to 100, or
4231 the symbol @code{center}.
4233 If @var{ascent} is a number, that percentage of the image's height is
4234 used for its ascent.
4236 If @var{ascent} is @code{center}, the image is vertically centered
4237 around a centerline which would be the vertical centerline of text drawn
4238 at the position of the image, in the manner specified by the text
4239 properties and overlays that apply to the image.
4241 If this property is omitted, it defaults to 50.
4243 @item :relief @var{relief}
4244 The @code{:relief} property, if non-@code{nil}, adds a shadow rectangle
4245 around the image.  The value, @var{relief}, specifies the width of the
4246 shadow lines, in pixels.  If @var{relief} is negative, shadows are drawn
4247 so that the image appears as a pressed button; otherwise, it appears as
4248 an unpressed button.
4250 @item :conversion @var{algorithm}
4251 The @code{:conversion} property, if non-@code{nil}, specifies a
4252 conversion algorithm that should be applied to the image before it is
4253 displayed; the value, @var{algorithm}, specifies which algorithm.
4255 @table @code
4256 @item laplace
4257 @itemx emboss
4258 Specifies the Laplace edge detection algorithm, which blurs out small
4259 differences in color while highlighting larger differences.  People
4260 sometimes consider this useful for displaying the image for a
4261 ``disabled'' button.
4263 @item (edge-detection :matrix @var{matrix} :color-adjust @var{adjust})
4264 Specifies a general edge-detection algorithm.  @var{matrix} must be
4265 either a nine-element list or a nine-element vector of numbers.  A pixel
4266 at position @math{x/y} in the transformed image is computed from
4267 original pixels around that position.  @var{matrix} specifies, for each
4268 pixel in the neighborhood of @math{x/y}, a factor with which that pixel
4269 will influence the transformed pixel; element @math{0} specifies the
4270 factor for the pixel at @math{x-1/y-1}, element @math{1} the factor for
4271 the pixel at @math{x/y-1} etc., as shown below:
4272 @iftex
4273 @tex
4274 $$\pmatrix{x-1/y-1 & x/y-1  & x+1/y-1 \cr
4275    x-1/y  &   x/y &    x+1/y \cr
4276    x-1/y+1&   x/y+1 &  x+1/y+1 \cr}$$
4277 @end tex
4278 @end iftex
4279 @ifnottex
4280 @display
4281   (x-1/y-1  x/y-1  x+1/y-1
4282    x-1/y    x/y    x+1/y
4283    x-1/y+1  x/y+1  x+1/y+1)
4284 @end display
4285 @end ifnottex
4287 The resulting pixel is computed from the color intensity of the color
4288 resulting from summing up the RGB values of surrounding pixels,
4289 multiplied by the specified factors, and dividing that sum by the sum
4290 of the factors' absolute values.
4292 Laplace edge-detection currently uses a matrix of
4293 @iftex
4294 @tex
4295 $$\pmatrix{1 & 0 & 0 \cr
4296    0&  0 &  0 \cr
4297    0 & 0 & -1 \cr}$$
4298 @end tex
4299 @end iftex
4300 @ifnottex
4301 @display
4302   (1  0  0
4303    0  0  0
4304    0  0 -1)
4305 @end display
4306 @end ifnottex
4308 Emboss edge-detection uses a matrix of
4309 @iftex
4310 @tex
4311 $$\pmatrix{ 2 & -1 &  0 \cr
4312    -1 &  0 &  1 \cr
4313     0  & 1 & -2 \cr}$$
4314 @end tex
4315 @end iftex
4316 @ifnottex
4317 @display
4318   ( 2 -1  0
4319    -1  0  1
4320     0  1 -2)
4321 @end display
4322 @end ifnottex
4324 @item disabled
4325 Specifies transforming the image so that it looks ``disabled.''
4326 @end table
4328 @item :mask @var{mask}
4329 If @var{mask} is @code{heuristic} or @code{(heuristic @var{bg})}, build
4330 a clipping mask for the image, so that the background of a frame is
4331 visible behind the image.  If @var{bg} is not specified, or if @var{bg}
4332 is @code{t}, determine the background color of the image by looking at
4333 the four corners of the image, assuming the most frequently occurring
4334 color from the corners is the background color of the image.  Otherwise,
4335 @var{bg} must be a list @code{(@var{red} @var{green} @var{blue})}
4336 specifying the color to assume for the background of the image.
4338 If @var{mask} is @code{nil}, remove a mask from the image, if it has
4339 one.  Images in some formats include a mask which can be removed by
4340 specifying @code{:mask nil}.
4342 @item :pointer @var{shape}
4343 This specifies the pointer shape when the mouse pointer is over this
4344 image.  @xref{Pointer Shape}, for available pointer shapes.
4346 @item :map @var{map}
4347 This associates an image map of @dfn{hot spots} with this image.
4349 An image map is an alist where each element has the format
4350 @code{(@var{area} @var{id} @var{plist})}.  An @var{area} is specified
4351 as either a rectangle, a circle, or a polygon.
4353 A rectangle is a cons
4354 @code{(rect . ((@var{x0} . @var{y0}) . (@var{x1} . @var{y1})))}
4355 which specifies the pixel coordinates of the upper left and bottom right
4356 corners of the rectangle area.
4358 A circle is a cons
4359 @code{(circle . ((@var{x0} . @var{y0}) . @var{r}))}
4360 which specifies the center and the radius of the circle; @var{r} may
4361 be a float or integer.
4363 A polygon is a cons
4364 @code{(poly . [@var{x0} @var{y0} @var{x1} @var{y1} ...])}
4365 where each pair in the vector describes one corner in the polygon.
4367 When the mouse pointer lies on a hot-spot area of an image, the
4368 @var{plist} of that hot-spot is consulted; if it contains a @code{help-echo}
4369 property, that defines a tool-tip for the hot-spot, and if it contains
4370 a @code{pointer} property, that defines the shape of the mouse cursor when
4371 it is on the hot-spot.
4372 @xref{Pointer Shape}, for available pointer shapes.
4374 When you click the mouse when the mouse pointer is over a hot-spot, an
4375 event is composed by combining the @var{id} of the hot-spot with the
4376 mouse event; for instance, @code{[area4 mouse-1]} if the hot-spot's
4377 @var{id} is @code{area4}.
4378 @end table
4380 @defun image-mask-p spec &optional frame
4381 This function returns @code{t} if image @var{spec} has a mask bitmap.
4382 @var{frame} is the frame on which the image will be displayed.
4383 @var{frame} @code{nil} or omitted means to use the selected frame
4384 (@pxref{Input Focus}).
4385 @end defun
4387 @node XBM Images
4388 @subsection XBM Images
4389 @cindex XBM
4391   To use XBM format, specify @code{xbm} as the image type.  This image
4392 format doesn't require an external library, so images of this type are
4393 always supported.
4395   Additional image properties supported for the @code{xbm} image type are:
4397 @table @code
4398 @item :foreground @var{foreground}
4399 The value, @var{foreground}, should be a string specifying the image
4400 foreground color, or @code{nil} for the default color.  This color is
4401 used for each pixel in the XBM that is 1.  The default is the frame's
4402 foreground color.
4404 @item :background @var{background}
4405 The value, @var{background}, should be a string specifying the image
4406 background color, or @code{nil} for the default color.  This color is
4407 used for each pixel in the XBM that is 0.  The default is the frame's
4408 background color.
4409 @end table
4411   If you specify an XBM image using data within Emacs instead of an
4412 external file, use the following three properties:
4414 @table @code
4415 @item :data @var{data}
4416 The value, @var{data}, specifies the contents of the image.
4417 There are three formats you can use for @var{data}:
4419 @itemize @bullet
4420 @item
4421 A vector of strings or bool-vectors, each specifying one line of the
4422 image.  Do specify @code{:height} and @code{:width}.
4424 @item
4425 A string containing the same byte sequence as an XBM file would contain.
4426 You must not specify @code{:height} and @code{:width} in this case,
4427 because omitting them is what indicates the data has the format of an
4428 XBM file.  The file contents specify the height and width of the image.
4430 @item
4431 A string or a bool-vector containing the bits of the image (plus perhaps
4432 some extra bits at the end that will not be used).  It should contain at
4433 least @var{width} * @code{height} bits.  In this case, you must specify
4434 @code{:height} and @code{:width}, both to indicate that the string
4435 contains just the bits rather than a whole XBM file, and to specify the
4436 size of the image.
4437 @end itemize
4439 @item :width @var{width}
4440 The value, @var{width}, specifies the width of the image, in pixels.
4442 @item :height @var{height}
4443 The value, @var{height}, specifies the height of the image, in pixels.
4444 @end table
4446 @node XPM Images
4447 @subsection XPM Images
4448 @cindex XPM
4450   To use XPM format, specify @code{xpm} as the image type.  The
4451 additional image property @code{:color-symbols} is also meaningful with
4452 the @code{xpm} image type:
4454 @table @code
4455 @item :color-symbols @var{symbols}
4456 The value, @var{symbols}, should be an alist whose elements have the
4457 form @code{(@var{name} . @var{color})}.  In each element, @var{name} is
4458 the name of a color as it appears in the image file, and @var{color}
4459 specifies the actual color to use for displaying that name.
4460 @end table
4462 @node GIF Images
4463 @subsection GIF Images
4464 @cindex GIF
4466   For GIF images, specify image type @code{gif}.
4468 @table @code
4469 @item :index @var{index}
4470 You can use @code{:index} to specify one image from a GIF file that
4471 contains more than one image.  This property specifies use of image
4472 number @var{index} from the file.  If the GIF file doesn't contain an
4473 image with index @var{index}, the image displays as a hollow box.
4474 @end table
4476 @ignore
4477 This could be used to implement limited support for animated GIFs.
4478 For example, the following function displays a multi-image GIF file
4479 at point-min in the current buffer, switching between sub-images
4480 every 0.1 seconds.
4482 (defun show-anim (file max)
4483   "Display multi-image GIF file FILE which contains MAX subimages."
4484   (display-anim (current-buffer) file 0 max t))
4486 (defun display-anim (buffer file idx max first-time)
4487   (when (= idx max)
4488     (setq idx 0))
4489   (let ((img (create-image file nil :image idx)))
4490     (with-current-buffer buffer
4491       (goto-char (point-min))
4492       (unless first-time (delete-char 1))
4493       (insert-image img))
4494     (run-with-timer 0.1 nil 'display-anim buffer file (1+ idx) max nil)))
4495 @end ignore
4497 @node TIFF Images
4498 @subsection TIFF Images
4499 @cindex TIFF
4501   For TIFF images, specify image type @code{tiff}.
4503 @table @code
4504 @item :index @var{index}
4505 You can use @code{:index} to specify one image from a TIFF file that
4506 contains more than one image.  This property specifies use of image
4507 number @var{index} from the file.  If the TIFF file doesn't contain an
4508 image with index @var{index}, the image displays as a hollow box.
4509 @end table
4511 @node PostScript Images
4512 @subsection PostScript Images
4513 @cindex postscript images
4515   To use PostScript for an image, specify image type @code{postscript}.
4516 This works only if you have Ghostscript installed.  You must always use
4517 these three properties:
4519 @table @code
4520 @item :pt-width @var{width}
4521 The value, @var{width}, specifies the width of the image measured in
4522 points (1/72 inch).  @var{width} must be an integer.
4524 @item :pt-height @var{height}
4525 The value, @var{height}, specifies the height of the image in points
4526 (1/72 inch).  @var{height} must be an integer.
4528 @item :bounding-box @var{box}
4529 The value, @var{box}, must be a list or vector of four integers, which
4530 specifying the bounding box of the PostScript image, analogous to the
4531 @samp{BoundingBox} comment found in PostScript files.
4533 @example
4534 %%BoundingBox: 22 171 567 738
4535 @end example
4536 @end table
4538 @node ImageMagick Images
4539 @subsection ImageMagick Images
4540 @cindex ImageMagick images
4541 @cindex images, support for more formats
4543   If you build Emacs with ImageMagick (@url{http://www.imagemagick.org})
4544 support, you can use the ImageMagick library to load many image formats.
4546 @findex imagemagick-types
4547 The function @code{imagemagick-types} returns a list of image file
4548 extensions that your installation of ImageMagick supports.  To enable
4549 support, you must call the function @code{imagemagick-register-types}.
4551 @vindex imagemagick-types-inhibit
4552 The variable @code{imagemagick-types-inhibit} specifies a list of
4553 image types that you do @emph{not} want ImageMagick to handle.  There
4554 may be overlap between image loaders in your Emacs installation, and
4555 you may prefer to use a different one for a given image type (which
4556 @c FIXME how is this priority determined?
4557 loader will be used in practice depends on the priority of the loaders).
4558 @c FIXME why are these uppercase when image-types is lower-case?
4559 @c FIXME what are the possible options?  Are these actually file extensions?
4560 For example, if you never want to use the ImageMagick loader to use
4561 JPEG files, add @code{JPG} to this list.
4563 @vindex imagemagick-render-type
4564 You can set the variable @code{imagemagick-render-type} to choose
4565 between screen render methods for the ImageMagick loader.  The options
4566 are: @code{0}, a conservative method which works with older
4567 @c FIXME details of this "newer method"?
4568 @c Presumably it is faster but may be less "robust"?
4569 ImageMagick versions (it is a bit slow, but robust); and @code{1},
4570 a newer ImageMagick method.
4572 Images loaded with ImageMagick support a few new display specifications:
4574 @table @code
4575 @item :width, :height
4576 The @code{:width} and @code{:height} keywords are used for scaling the
4577 image.  If only one of them is specified, the other one will be
4578 calculated so as to preserve the aspect ratio.  If both are specified,
4579 aspect ratio may not be preserved.
4581 @item :rotation
4582 Specifies a rotation angle in degrees.
4584 @item :index
4585 Specifies which image to view inside an image bundle file format, such
4586 as TIFF or DJVM.  You can use the @code{image-metadata} function to
4587 retrieve the total number of images in an image bundle (this is
4588 similar to how GIF files work).
4589 @end table
4592 @node Other Image Types
4593 @subsection Other Image Types
4594 @cindex PBM
4596   For PBM images, specify image type @code{pbm}.  Color, gray-scale and
4597 monochromatic images are supported.   For mono PBM images, two additional
4598 image properties are supported.
4600 @table @code
4601 @item :foreground @var{foreground}
4602 The value, @var{foreground}, should be a string specifying the image
4603 foreground color, or @code{nil} for the default color.  This color is
4604 used for each pixel in the PBM that is 1.  The default is the frame's
4605 foreground color.
4607 @item :background @var{background}
4608 The value, @var{background}, should be a string specifying the image
4609 background color, or @code{nil} for the default color.  This color is
4610 used for each pixel in the PBM that is 0.  The default is the frame's
4611 background color.
4612 @end table
4614   For JPEG images, specify image type @code{jpeg}.
4616   For TIFF images, specify image type @code{tiff}.
4618   For PNG images, specify image type @code{png}.
4620   For SVG images, specify image type @code{svg}.
4622 @node Defining Images
4623 @subsection Defining Images
4625   The functions @code{create-image}, @code{defimage} and
4626 @code{find-image} provide convenient ways to create image descriptors.
4628 @defun create-image file-or-data &optional type data-p &rest props
4629 This function creates and returns an image descriptor which uses the
4630 data in @var{file-or-data}.  @var{file-or-data} can be a file name or
4631 a string containing the image data; @var{data-p} should be @code{nil}
4632 for the former case, non-@code{nil} for the latter case.
4634 The optional argument @var{type} is a symbol specifying the image type.
4635 If @var{type} is omitted or @code{nil}, @code{create-image} tries to
4636 determine the image type from the file's first few bytes, or else
4637 from the file's name.
4639 The remaining arguments, @var{props}, specify additional image
4640 properties---for example,
4642 @example
4643 (create-image "foo.xpm" 'xpm nil :heuristic-mask t)
4644 @end example
4646 The function returns @code{nil} if images of this type are not
4647 supported.  Otherwise it returns an image descriptor.
4648 @end defun
4650 @defmac defimage symbol specs &optional doc
4651 This macro defines @var{symbol} as an image name.  The arguments
4652 @var{specs} is a list which specifies how to display the image.
4653 The third argument, @var{doc}, is an optional documentation string.
4655 Each argument in @var{specs} has the form of a property list, and each
4656 one should specify at least the @code{:type} property and either the
4657 @code{:file} or the @code{:data} property.  The value of @code{:type}
4658 should be a symbol specifying the image type, the value of
4659 @code{:file} is the file to load the image from, and the value of
4660 @code{:data} is a string containing the actual image data.  Here is an
4661 example:
4663 @example
4664 (defimage test-image
4665   ((:type xpm :file "~/test1.xpm")
4666    (:type xbm :file "~/test1.xbm")))
4667 @end example
4669 @code{defimage} tests each argument, one by one, to see if it is
4670 usable---that is, if the type is supported and the file exists.  The
4671 first usable argument is used to make an image descriptor which is
4672 stored in @var{symbol}.
4674 If none of the alternatives will work, then @var{symbol} is defined
4675 as @code{nil}.
4676 @end defmac
4678 @defun find-image specs
4679 This function provides a convenient way to find an image satisfying one
4680 of a list of image specifications @var{specs}.
4682 Each specification in @var{specs} is a property list with contents
4683 depending on image type.  All specifications must at least contain the
4684 properties @code{:type @var{type}} and either @w{@code{:file @var{file}}}
4685 or @w{@code{:data @var{DATA}}}, where @var{type} is a symbol specifying
4686 the image type, e.g.@: @code{xbm}, @var{file} is the file to load the
4687 image from, and @var{data} is a string containing the actual image data.
4688 The first specification in the list whose @var{type} is supported, and
4689 @var{file} exists, is used to construct the image specification to be
4690 returned.  If no specification is satisfied, @code{nil} is returned.
4692 The image is looked for in @code{image-load-path}.
4693 @end defun
4695 @defvar image-load-path
4696 This variable's value is a list of locations in which to search for
4697 image files.  If an element is a string or a variable symbol whose
4698 value is a string, the string is taken to be the name of a directory
4699 to search.  If an element is a variable symbol whose value is a list,
4700 that is taken to be a list of directory names to search.
4702 The default is to search in the @file{images} subdirectory of the
4703 directory specified by @code{data-directory}, then the directory
4704 specified by @code{data-directory}, and finally in the directories in
4705 @code{load-path}.  Subdirectories are not automatically included in
4706 the search, so if you put an image file in a subdirectory, you have to
4707 supply the subdirectory name explicitly.  For example, to find the
4708 image @file{images/foo/bar.xpm} within @code{data-directory}, you
4709 should specify the image as follows:
4711 @example
4712 (defimage foo-image '((:type xpm :file "foo/bar.xpm")))
4713 @end example
4714 @end defvar
4716 @defun image-load-path-for-library library image &optional path no-error
4717 This function returns a suitable search path for images used by the
4718 Lisp package @var{library}.
4720 The function searches for @var{image} first using @code{image-load-path},
4721 excluding @file{@code{data-directory}/images}, and then in
4722 @code{load-path}, followed by a path suitable for @var{library}, which
4723 includes @file{../../etc/images} and @file{../etc/images} relative to
4724 the library file itself, and finally in
4725 @file{@code{data-directory}/images}.
4727 Then this function returns a list of directories which contains first
4728 the directory in which @var{image} was found, followed by the value of
4729 @code{load-path}.  If @var{path} is given, it is used instead of
4730 @code{load-path}.
4732 If @var{no-error} is non-@code{nil} and a suitable path can't be
4733 found, don't signal an error.  Instead, return a list of directories as
4734 before, except that @code{nil} appears in place of the image directory.
4736 Here is an example of using @code{image-load-path-for-library}:
4738 @example
4739 (defvar image-load-path) ; shush compiler
4740 (let* ((load-path (image-load-path-for-library
4741                     "mh-e" "mh-logo.xpm"))
4742        (image-load-path (cons (car load-path)
4743                               image-load-path)))
4744   (mh-tool-bar-folder-buttons-init))
4745 @end example
4746 @end defun
4748 @node Showing Images
4749 @subsection Showing Images
4751   You can use an image descriptor by setting up the @code{display}
4752 property yourself, but it is easier to use the functions in this
4753 section.
4755 @defun insert-image image &optional string area slice
4756 This function inserts @var{image} in the current buffer at point.  The
4757 value @var{image} should be an image descriptor; it could be a value
4758 returned by @code{create-image}, or the value of a symbol defined with
4759 @code{defimage}.  The argument @var{string} specifies the text to put
4760 in the buffer to hold the image.  If it is omitted or @code{nil},
4761 @code{insert-image} uses @code{" "} by default.
4763 The argument @var{area} specifies whether to put the image in a margin.
4764 If it is @code{left-margin}, the image appears in the left margin;
4765 @code{right-margin} specifies the right margin.  If @var{area} is
4766 @code{nil} or omitted, the image is displayed at point within the
4767 buffer's text.
4769 The argument @var{slice} specifies a slice of the image to insert.  If
4770 @var{slice} is @code{nil} or omitted the whole image is inserted.
4771 Otherwise, @var{slice} is a list @code{(@var{x} @var{y} @var{width}
4772 @var{height})} which specifies the @var{x} and @var{y} positions and
4773 @var{width} and @var{height} of the image area to insert.  Integer
4774 values are in units of pixels.  A floating point number in the range
4775 0.0--1.0 stands for that fraction of the width or height of the entire
4776 image.
4778 Internally, this function inserts @var{string} in the buffer, and gives
4779 it a @code{display} property which specifies @var{image}.  @xref{Display
4780 Property}.
4781 @end defun
4783 @cindex slice, image
4784 @cindex image slice
4785 @defun insert-sliced-image image &optional string area rows cols
4786 This function inserts @var{image} in the current buffer at point, like
4787 @code{insert-image}, but splits the image into @var{rows}x@var{cols}
4788 equally sized slices.
4790 If an image is inserted ``sliced'', then the Emacs display engine will
4791 treat each slice as a separate image, and allow more intuitive
4792 scrolling up/down, instead of jumping up/down the entire image when
4793 paging through a buffer that displays (large) images.
4794 @end defun
4796 @defun put-image image pos &optional string area
4797 This function puts image @var{image} in front of @var{pos} in the
4798 current buffer.  The argument @var{pos} should be an integer or a
4799 marker.  It specifies the buffer position where the image should appear.
4800 The argument @var{string} specifies the text that should hold the image
4801 as an alternative to the default.
4803 The argument @var{image} must be an image descriptor, perhaps returned
4804 by @code{create-image} or stored by @code{defimage}.
4806 The argument @var{area} specifies whether to put the image in a margin.
4807 If it is @code{left-margin}, the image appears in the left margin;
4808 @code{right-margin} specifies the right margin.  If @var{area} is
4809 @code{nil} or omitted, the image is displayed at point within the
4810 buffer's text.
4812 Internally, this function creates an overlay, and gives it a
4813 @code{before-string} property containing text that has a @code{display}
4814 property whose value is the image.  (Whew!)
4815 @end defun
4817 @defun remove-images start end &optional buffer
4818 This function removes images in @var{buffer} between positions
4819 @var{start} and @var{end}.  If @var{buffer} is omitted or @code{nil},
4820 images are removed from the current buffer.
4822 This removes only images that were put into @var{buffer} the way
4823 @code{put-image} does it, not images that were inserted with
4824 @code{insert-image} or in other ways.
4825 @end defun
4827 @defun image-size spec &optional pixels frame
4828 This function returns the size of an image as a pair
4829 @w{@code{(@var{width} . @var{height})}}.  @var{spec} is an image
4830 specification.  @var{pixels} non-@code{nil} means return sizes
4831 measured in pixels, otherwise return sizes measured in canonical
4832 character units (fractions of the width/height of the frame's default
4833 font).  @var{frame} is the frame on which the image will be displayed.
4834 @var{frame} null or omitted means use the selected frame (@pxref{Input
4835 Focus}).
4836 @end defun
4838 @defvar max-image-size
4839 This variable is used to define the maximum size of image that Emacs
4840 will load.  Emacs will refuse to load (and display) any image that is
4841 larger than this limit.
4843 If the value is an integer, it directly specifies the maximum
4844 image height and width, measured in pixels.  If it is a floating
4845 point number, it specifies the maximum image height and width
4846 as a ratio to the frame height and width.  If the value is
4847 non-numeric, there is no explicit limit on the size of images.
4849 The purpose of this variable is to prevent unreasonably large images
4850 from accidentally being loaded into Emacs.  It only takes effect the
4851 first time an image is loaded.  Once an image is placed in the image
4852 cache, it can always be displayed, even if the value of
4853 @var{max-image-size} is subsequently changed (@pxref{Image Cache}).
4854 @end defvar
4856 @node Image Cache
4857 @subsection Image Cache
4858 @cindex image cache
4860   Emacs caches images so that it can display them again more
4861 efficiently.  When Emacs displays an image, it searches the image
4862 cache for an existing image specification @code{equal} to the desired
4863 specification.  If a match is found, the image is displayed from the
4864 cache.  Otherwise, Emacs loads the image normally.
4866 @defun image-flush spec &optional frame
4867 This function removes the image with specification @var{spec} from the
4868 image cache of frame @var{frame}.  Image specifications are compared
4869 using @code{equal}.  If @var{frame} is @code{nil}, it defaults to the
4870 selected frame.  If @var{frame} is @code{t}, the image is flushed on
4871 all existing frames.
4873 In Emacs' current implementation, each graphical terminal possesses an
4874 image cache, which is shared by all the frames on that terminal
4875 (@pxref{Multiple Terminals}).  Thus, refreshing an image in one frame
4876 also refreshes it in all other frames on the same terminal.
4877 @end defun
4879   One use for @code{image-flush} is to tell Emacs about a change in an
4880 image file.  If an image specification contains a @code{:file}
4881 property, the image is cached based on the file's contents when the
4882 image is first displayed.  Even if the file subsequently changes,
4883 Emacs continues displaying the old version of the image.  Calling
4884 @code{image-flush} flushes the image from the cache, forcing Emacs to
4885 re-read the file the next time it needs to display that image.
4887   Another use for @code{image-flush} is for memory conservation.  If
4888 your Lisp program creates a large number of temporary images over a
4889 period much shorter than @code{image-cache-eviction-delay} (see
4890 below), you can opt to flush unused images yourself, instead of
4891 waiting for Emacs to do it automatically.
4893 @defun clear-image-cache &optional filter
4894 This function clears an image cache, removing all the images stored in
4895 it.  If @var{filter} is omitted or @code{nil}, it clears the cache for
4896 the selected frame.  If @var{filter} is a frame, it clears the cache
4897 for that frame.  If @var{filter} is @code{t}, all image caches are
4898 cleared.  Otherwise, @var{filter} is taken to be a file name, and all
4899 images associated with that file name are removed from all image
4900 caches.
4901 @end defun
4903 If an image in the image cache has not been displayed for a specified
4904 period of time, Emacs removes it from the cache and frees the
4905 associated memory.
4907 @defvar image-cache-eviction-delay
4908 This variable specifies the number of seconds an image can remain in
4909 the cache without being displayed.  When an image is not displayed for
4910 this length of time, Emacs removes it from the image cache.
4912 Under some circumstances, if the number of images in the cache grows
4913 too large, the actual eviction delay may be shorter than this.
4915 If the value is @code{nil}, Emacs does not remove images from the cache
4916 except when you explicitly clear it.  This mode can be useful for
4917 debugging.
4918 @end defvar
4920 @node Buttons
4921 @section Buttons
4922 @cindex buttons in buffers
4923 @cindex clickable buttons in buffers
4925   The @emph{button} package defines functions for inserting and
4926 manipulating clickable (with the mouse, or via keyboard commands)
4927 buttons in Emacs buffers, such as might be used for help hyper-links,
4928 etc.  Emacs uses buttons for the hyper-links in help text and the like.
4930   A button is essentially a set of properties attached (via text
4931 properties or overlays) to a region of text in an Emacs buffer.  These
4932 properties are called @dfn{button properties}.
4934   One of these properties (@code{action}) is a function, which will
4935 be called when the user invokes it using the keyboard or the mouse.
4936 The invoked function may then examine the button and use its other
4937 properties as desired.
4939   In some ways the Emacs button package duplicates functionality offered
4940 by the widget package (@pxref{Top, , Introduction, widget, The Emacs
4941 Widget Library}), but the button package has the advantage that it is
4942 much faster, much smaller, and much simpler to use (for elisp
4943 programmers---for users, the result is about the same).  The extra
4944 speed and space savings are useful mainly if you need to create many
4945 buttons in a buffer (for instance an @code{*Apropos*} buffer uses
4946 buttons to make entries clickable, and may contain many thousands of
4947 entries).
4949 @menu
4950 * Button Properties::      Button properties with special meanings.
4951 * Button Types::           Defining common properties for classes of buttons.
4952 * Making Buttons::         Adding buttons to Emacs buffers.
4953 * Manipulating Buttons::   Getting and setting properties of buttons.
4954 * Button Buffer Commands:: Buffer-wide commands and bindings for buttons.
4955 @end menu
4957 @node Button Properties
4958 @subsection Button Properties
4959 @cindex button properties
4961   Buttons have an associated list of properties defining their
4962 appearance and behavior, and other arbitrary properties may be used
4963 for application specific purposes.  Some properties that have special
4964 meaning to the button package include:
4966 @table @code
4967 @item action
4968 @kindex action @r{(button property)}
4969 The function to call when the user invokes the button, which is passed
4970 the single argument @var{button}.  By default this is @code{ignore},
4971 which does nothing.
4973 @item mouse-action
4974 @kindex mouse-action @r{(button property)}
4975 This is similar to @code{action}, and when present, will be used
4976 instead of @code{action} for button invocations resulting from
4977 mouse-clicks (instead of the user hitting @key{RET}).  If not
4978 present, mouse-clicks use @code{action} instead.
4980 @item face
4981 @kindex face @r{(button property)}
4982 This is an Emacs face controlling how buttons of this type are
4983 displayed; by default this is the @code{button} face.
4985 @item mouse-face
4986 @kindex mouse-face @r{(button property)}
4987 This is an additional face which controls appearance during
4988 mouse-overs (merged with the usual button face); by default this is
4989 the usual Emacs @code{highlight} face.
4991 @item keymap
4992 @kindex keymap @r{(button property)}
4993 The button's keymap, defining bindings active within the button
4994 region.  By default this is the usual button region keymap, stored
4995 in the variable @code{button-map}, which defines @key{RET} and
4996 @key{mouse-2} to invoke the button.
4998 @item type
4999 @kindex type @r{(button property)}
5000 The button-type of the button.  When creating a button, this is
5001 usually specified using the @code{:type} keyword argument.
5002 @xref{Button Types}.
5004 @item help-echo
5005 @kindex help-index @r{(button property)}
5006 A string displayed by the Emacs tool-tip help system; by default,
5007 @code{"mouse-2, RET: Push this button"}.
5009 @item follow-link
5010 @kindex follow-link @r{(button property)}
5011 The follow-link property, defining how a @key{Mouse-1} click behaves
5012 on this button, @xref{Clickable Text}.
5014 @item button
5015 @kindex button @r{(button property)}
5016 All buttons have a non-@code{nil} @code{button} property, which may be useful
5017 in finding regions of text that comprise buttons (which is what the
5018 standard button functions do).
5019 @end table
5021   There are other properties defined for the regions of text in a
5022 button, but these are not generally interesting for typical uses.
5024 @node Button Types
5025 @subsection Button Types
5026 @cindex button types
5028   Every button has a button @emph{type}, which defines default values
5029 for the button's properties.  Button types are arranged in a
5030 hierarchy, with specialized types inheriting from more general types,
5031 so that it's easy to define special-purpose types of buttons for
5032 specific tasks.
5034 @defun define-button-type name &rest properties
5035 Define a `button type' called @var{name} (a symbol).
5036 The remaining arguments
5037 form a sequence of @var{property value} pairs, specifying default
5038 property values for buttons with this type (a button's type may be set
5039 by giving it a @code{type} property when creating the button, using
5040 the @code{:type} keyword argument).
5042 In addition, the keyword argument @code{:supertype} may be used to
5043 specify a button-type from which @var{name} inherits its default
5044 property values.  Note that this inheritance happens only when
5045 @var{name} is defined; subsequent changes to a supertype are not
5046 reflected in its subtypes.
5047 @end defun
5049   Using @code{define-button-type} to define default properties for
5050 buttons is not necessary---buttons without any specified type use the
5051 built-in button-type @code{button}---but it is encouraged, since
5052 doing so usually makes the resulting code clearer and more efficient.
5054 @node Making Buttons
5055 @subsection Making Buttons
5056 @cindex making buttons
5058   Buttons are associated with a region of text, using an overlay or
5059 text properties to hold button-specific information, all of which are
5060 initialized from the button's type (which defaults to the built-in
5061 button type @code{button}).  Like all Emacs text, the appearance of
5062 the button is governed by the @code{face} property; by default (via
5063 the @code{face} property inherited from the @code{button} button-type)
5064 this is a simple underline, like a typical web-page link.
5066   For convenience, there are two sorts of button-creation functions,
5067 those that add button properties to an existing region of a buffer,
5068 called @code{make-...button}, and those that also insert the button
5069 text, called @code{insert-...button}.
5071   The button-creation functions all take the @code{&rest} argument
5072 @var{properties}, which should be a sequence of @var{property value}
5073 pairs, specifying properties to add to the button; see @ref{Button
5074 Properties}.  In addition, the keyword argument @code{:type} may be
5075 used to specify a button-type from which to inherit other properties;
5076 see @ref{Button Types}.  Any properties not explicitly specified
5077 during creation will be inherited from the button's type (if the type
5078 defines such a property).
5080   The following functions add a button using an overlay
5081 (@pxref{Overlays}) to hold the button properties:
5083 @defun make-button beg end &rest properties
5084 This makes a button from @var{beg} to @var{end} in the
5085 current buffer, and returns it.
5086 @end defun
5088 @defun insert-button label &rest properties
5089 This insert a button with the label @var{label} at point,
5090 and returns it.
5091 @end defun
5093   The following functions are similar, but use Emacs text properties
5094 (@pxref{Text Properties}) to hold the button properties, making the
5095 button actually part of the text instead of being a property of the
5096 buffer.  Buttons using text properties do not create markers into the
5097 buffer, which is important for speed when you use extremely large
5098 numbers of buttons.  (However, if there is an existing face text
5099 property at the site of the button, the button face may not be visible.)
5100 Both functions return the position of the start of the new button:
5102 @defun make-text-button beg end &rest properties
5103 This makes a button from @var{beg} to @var{end} in the current buffer, using
5104 text properties.
5105 @end defun
5107 @defun insert-text-button label &rest properties
5108 This inserts a button with the label @var{label} at point, using text
5109 properties.
5110 @end defun
5112 @node Manipulating Buttons
5113 @subsection Manipulating Buttons
5114 @cindex manipulating buttons
5116 These are functions for getting and setting properties of buttons.
5117 Often these are used by a button's invocation function to determine
5118 what to do.
5120 Where a @var{button} parameter is specified, it means an object
5121 referring to a specific button, either an overlay (for overlay
5122 buttons), or a buffer-position or marker (for text property buttons).
5123 Such an object is passed as the first argument to a button's
5124 invocation function when it is invoked.
5126 @defun button-start button
5127 Return the position at which @var{button} starts.
5128 @end defun
5130 @defun button-end button
5131 Return the position at which @var{button} ends.
5132 @end defun
5134 @defun button-get button prop
5135 Get the property of button @var{button} named @var{prop}.
5136 @end defun
5138 @defun button-put button prop val
5139 Set @var{button}'s @var{prop} property to @var{val}.
5140 @end defun
5142 @defun button-activate button &optional use-mouse-action
5143 Call @var{button}'s @code{action} property (i.e., invoke it).  If
5144 @var{use-mouse-action} is non-@code{nil}, try to invoke the button's
5145 @code{mouse-action} property instead of @code{action}; if the button
5146 has no @code{mouse-action} property, use @code{action} as normal.
5147 @end defun
5149 @defun button-label button
5150 Return @var{button}'s text label.
5151 @end defun
5153 @defun button-type button
5154 Return @var{button}'s button-type.
5155 @end defun
5157 @defun button-has-type-p button type
5158 Return @code{t} if @var{button} has button-type @var{type}, or one of
5159 @var{type}'s subtypes.
5160 @end defun
5162 @defun button-at pos
5163 Return the button at position @var{pos} in the current buffer, or @code{nil}.
5164 @end defun
5166 @defun button-type-put type prop val
5167 Set the button-type @var{type}'s @var{prop} property to @var{val}.
5168 @end defun
5170 @defun button-type-get type prop
5171 Get the property of button-type @var{type} named @var{prop}.
5172 @end defun
5174 @defun button-type-subtype-p type supertype
5175 Return @code{t} if button-type @var{type} is a subtype of @var{supertype}.
5176 @end defun
5178 @node Button Buffer Commands
5179 @subsection Button Buffer Commands
5180 @cindex button buffer commands
5182 These are commands and functions for locating and operating on
5183 buttons in an Emacs buffer.
5185 @code{push-button} is the command that a user uses to actually `push'
5186 a button, and is bound by default in the button itself to @key{RET}
5187 and to @key{mouse-2} using a region-specific keymap.  Commands
5188 that are useful outside the buttons itself, such as
5189 @code{forward-button} and @code{backward-button} are additionally
5190 available in the keymap stored in @code{button-buffer-map}; a mode
5191 which uses buttons may want to use @code{button-buffer-map} as a
5192 parent keymap for its keymap.
5194 If the button has a non-@code{nil} @code{follow-link} property, and
5195 @var{mouse-1-click-follows-link} is set, a quick @key{Mouse-1} click
5196 will also activate the @code{push-button} command.
5197 @xref{Clickable Text}.
5199 @deffn Command push-button &optional pos use-mouse-action
5200 Perform the action specified by a button at location @var{pos}.
5201 @var{pos} may be either a buffer position or a mouse-event.  If
5202 @var{use-mouse-action} is non-@code{nil}, or @var{pos} is a
5203 mouse-event (@pxref{Mouse Events}), try to invoke the button's
5204 @code{mouse-action} property instead of @code{action}; if the button
5205 has no @code{mouse-action} property, use @code{action} as normal.
5206 @var{pos} defaults to point, except when @code{push-button} is invoked
5207 interactively as the result of a mouse-event, in which case, the mouse
5208 event's position is used.  If there's no button at @var{pos}, do
5209 nothing and return @code{nil}, otherwise return @code{t}.
5210 @end deffn
5212 @deffn Command forward-button n &optional wrap display-message
5213 Move to the @var{n}th next button, or @var{n}th previous button if
5214 @var{n} is negative.  If @var{n} is zero, move to the start of any
5215 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5216 end of the buffer continues from the other end.  If
5217 @var{display-message} is non-@code{nil}, the button's help-echo string
5218 is displayed.  Any button with a non-@code{nil} @code{skip} property
5219 is skipped over.  Returns the button found.
5220 @end deffn
5222 @deffn Command backward-button n &optional wrap display-message
5223 Move to the @var{n}th previous button, or @var{n}th next button if
5224 @var{n} is negative.  If @var{n} is zero, move to the start of any
5225 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5226 end of the buffer continues from the other end.  If
5227 @var{display-message} is non-@code{nil}, the button's help-echo string
5228 is displayed.  Any button with a non-@code{nil} @code{skip} property
5229 is skipped over.  Returns the button found.
5230 @end deffn
5232 @defun next-button pos &optional count-current
5233 @defunx previous-button pos &optional count-current
5234 Return the next button after (for @code{next-button} or before (for
5235 @code{previous-button}) position @var{pos} in the current buffer.  If
5236 @var{count-current} is non-@code{nil}, count any button at @var{pos}
5237 in the search, instead of starting at the next button.
5238 @end defun
5240 @node Abstract Display
5241 @section Abstract Display
5242 @cindex ewoc
5243 @cindex display, abstract
5244 @cindex display, arbitrary objects
5245 @cindex model/view/controller
5246 @cindex view part, model/view/controller
5248   The Ewoc package constructs buffer text that represents a structure
5249 of Lisp objects, and updates the text to follow changes in that
5250 structure.  This is like the ``view'' component in the
5251 ``model/view/controller'' design paradigm.
5253   An @dfn{ewoc} is a structure that organizes information required to
5254 construct buffer text that represents certain Lisp data.  The buffer
5255 text of the ewoc has three parts, in order: first, fixed @dfn{header}
5256 text; next, textual descriptions of a series of data elements (Lisp
5257 objects that you specify); and last, fixed @dfn{footer} text.
5258 Specifically, an ewoc contains information on:
5260 @itemize @bullet
5261 @item
5262 The buffer which its text is generated in.
5264 @item
5265 The text's start position in the buffer.
5267 @item
5268 The header and footer strings.
5270 @item
5271 A doubly-linked chain of @dfn{nodes}, each of which contains:
5273 @itemize
5274 @item
5275 A @dfn{data element}, a single Lisp object.
5277 @item
5278 Links to the preceding and following nodes in the chain.
5279 @end itemize
5281 @item
5282 A @dfn{pretty-printer} function which is responsible for
5283 inserting the textual representation of a data
5284 element value into the current buffer.
5285 @end itemize
5287   Typically, you define an ewoc with @code{ewoc-create}, and then pass
5288 the resulting ewoc structure to other functions in the Ewoc package to
5289 build nodes within it, and display it in the buffer.  Once it is
5290 displayed in the buffer, other functions determine the correspondence
5291 between buffer positions and nodes, move point from one node's textual
5292 representation to another, and so forth.  @xref{Abstract Display
5293 Functions}.
5295   A node @dfn{encapsulates} a data element much the way a variable
5296 holds a value.  Normally, encapsulation occurs as a part of adding a
5297 node to the ewoc.  You can retrieve the data element value and place a
5298 new value in its place, like so:
5300 @lisp
5301 (ewoc-data @var{node})
5302 @result{} value
5304 (ewoc-set-data @var{node} @var{new-value})
5305 @result{} @var{new-value}
5306 @end lisp
5308 @noindent
5309 You can also use, as the data element value, a Lisp object (list or
5310 vector) that is a container for the ``real'' value, or an index into
5311 some other structure.  The example (@pxref{Abstract Display Example})
5312 uses the latter approach.
5314   When the data changes, you will want to update the text in the
5315 buffer.  You can update all nodes by calling @code{ewoc-refresh}, or
5316 just specific nodes using @code{ewoc-invalidate}, or all nodes
5317 satisfying a predicate using @code{ewoc-map}.  Alternatively, you can
5318 delete invalid nodes using @code{ewoc-delete} or @code{ewoc-filter},
5319 and add new nodes in their place.  Deleting a node from an ewoc deletes
5320 its associated textual description from buffer, as well.
5322 @menu
5323 * Abstract Display Functions::  Functions in the Ewoc package.
5324 * Abstract Display Example::    Example of using Ewoc.
5325 @end menu
5327 @node Abstract Display Functions
5328 @subsection Abstract Display Functions
5330   In this subsection, @var{ewoc} and @var{node} stand for the
5331 structures described above (@pxref{Abstract Display}), while
5332 @var{data} stands for an arbitrary Lisp object used as a data element.
5334 @defun ewoc-create pretty-printer &optional header footer nosep
5335 This constructs and returns a new ewoc, with no nodes (and thus no data
5336 elements).  @var{pretty-printer} should be a function that takes one
5337 argument, a data element of the sort you plan to use in this ewoc, and
5338 inserts its textual description at point using @code{insert} (and never
5339 @code{insert-before-markers}, because that would interfere with the
5340 Ewoc package's internal mechanisms).
5342 Normally, a newline is automatically inserted after the header,
5343 the footer and every node's textual description.  If @var{nosep}
5344 is non-@code{nil}, no newline is inserted.  This may be useful for
5345 displaying an entire ewoc on a single line, for example, or for
5346 making nodes ``invisible'' by arranging for @var{pretty-printer}
5347 to do nothing for those nodes.
5349 An ewoc maintains its text in the buffer that is current when
5350 you create it, so switch to the intended buffer before calling
5351 @code{ewoc-create}.
5352 @end defun
5354 @defun ewoc-buffer ewoc
5355 This returns the buffer where @var{ewoc} maintains its text.
5356 @end defun
5358 @defun ewoc-get-hf ewoc
5359 This returns a cons cell @code{(@var{header} . @var{footer})}
5360 made from @var{ewoc}'s header and footer.
5361 @end defun
5363 @defun ewoc-set-hf ewoc header footer
5364 This sets the header and footer of @var{ewoc} to the strings
5365 @var{header} and @var{footer}, respectively.
5366 @end defun
5368 @defun ewoc-enter-first ewoc data
5369 @defunx ewoc-enter-last ewoc data
5370 These add a new node encapsulating @var{data}, putting it, respectively,
5371 at the beginning or end of @var{ewoc}'s chain of nodes.
5372 @end defun
5374 @defun ewoc-enter-before ewoc node data
5375 @defunx ewoc-enter-after ewoc node data
5376 These add a new node encapsulating @var{data}, adding it to
5377 @var{ewoc} before or after @var{node}, respectively.
5378 @end defun
5380 @defun ewoc-prev ewoc node
5381 @defunx ewoc-next ewoc node
5382 These return, respectively, the previous node and the next node of @var{node}
5383 in @var{ewoc}.
5384 @end defun
5386 @defun ewoc-nth ewoc n
5387 This returns the node in @var{ewoc} found at zero-based index @var{n}.
5388 A negative @var{n} means count from the end.  @code{ewoc-nth} returns
5389 @code{nil} if @var{n} is out of range.
5390 @end defun
5392 @defun ewoc-data node
5393 This extracts the data encapsulated by @var{node} and returns it.
5394 @end defun
5396 @defun ewoc-set-data node data
5397 This sets the data encapsulated by @var{node} to @var{data}.
5398 @end defun
5400 @defun ewoc-locate ewoc &optional pos guess
5401 This determines the node in @var{ewoc} which contains point (or
5402 @var{pos} if specified), and returns that node.  If @var{ewoc} has no
5403 nodes, it returns @code{nil}.  If @var{pos} is before the first node,
5404 it returns the first node; if @var{pos} is after the last node, it returns
5405 the last node.  The optional third arg @var{guess}
5406 should be a node that is likely to be near @var{pos}; this doesn't
5407 alter the result, but makes the function run faster.
5408 @end defun
5410 @defun ewoc-location node
5411 This returns the start position of @var{node}.
5412 @end defun
5414 @defun ewoc-goto-prev ewoc arg
5415 @defunx ewoc-goto-next ewoc arg
5416 These move point to the previous or next, respectively, @var{arg}th node
5417 in @var{ewoc}.  @code{ewoc-goto-prev} does not move if it is already at
5418 the first node or if @var{ewoc} is empty, whereas @code{ewoc-goto-next}
5419 moves past the last node, returning @code{nil}.  Excepting this special
5420 case, these functions return the node moved to.
5421 @end defun
5423 @defun ewoc-goto-node ewoc node
5424 This moves point to the start of @var{node} in @var{ewoc}.
5425 @end defun
5427 @defun ewoc-refresh ewoc
5428 This function regenerates the text of @var{ewoc}.  It works by
5429 deleting the text between the header and the footer, i.e., all the
5430 data elements' representations, and then calling the pretty-printer
5431 function for each node, one by one, in order.
5432 @end defun
5434 @defun ewoc-invalidate ewoc &rest nodes
5435 This is similar to @code{ewoc-refresh}, except that only @var{nodes} in
5436 @var{ewoc} are updated instead of the entire set.
5437 @end defun
5439 @defun ewoc-delete ewoc &rest nodes
5440 This deletes each node in @var{nodes} from @var{ewoc}.
5441 @end defun
5443 @defun ewoc-filter ewoc predicate &rest args
5444 This calls @var{predicate} for each data element in @var{ewoc} and
5445 deletes those nodes for which @var{predicate} returns @code{nil}.
5446 Any @var{args} are passed to @var{predicate}.
5447 @end defun
5449 @defun ewoc-collect ewoc predicate &rest args
5450 This calls @var{predicate} for each data element in @var{ewoc}
5451 and returns a list of those elements for which @var{predicate}
5452 returns non-@code{nil}.  The elements in the list are ordered
5453 as in the buffer.  Any @var{args} are passed to @var{predicate}.
5454 @end defun
5456 @defun ewoc-map map-function ewoc &rest args
5457 This calls @var{map-function} for each data element in @var{ewoc} and
5458 updates those nodes for which @var{map-function} returns non-@code{nil}.
5459 Any @var{args} are passed to @var{map-function}.
5460 @end defun
5462 @node Abstract Display Example
5463 @subsection Abstract Display Example
5465   Here is a simple example using functions of the ewoc package to
5466 implement a ``color components display,'' an area in a buffer that
5467 represents a vector of three integers (itself representing a 24-bit RGB
5468 value) in various ways.
5470 @example
5471 (setq colorcomp-ewoc nil
5472       colorcomp-data nil
5473       colorcomp-mode-map nil
5474       colorcomp-labels ["Red" "Green" "Blue"])
5476 (defun colorcomp-pp (data)
5477   (if data
5478       (let ((comp (aref colorcomp-data data)))
5479         (insert (aref colorcomp-labels data) "\t: #x"
5480                 (format "%02X" comp) " "
5481                 (make-string (ash comp -2) ?#) "\n"))
5482     (let ((cstr (format "#%02X%02X%02X"
5483                         (aref colorcomp-data 0)
5484                         (aref colorcomp-data 1)
5485                         (aref colorcomp-data 2)))
5486           (samp " (sample text) "))
5487       (insert "Color\t: "
5488               (propertize samp 'face
5489                           `(foreground-color . ,cstr))
5490               (propertize samp 'face
5491                           `(background-color . ,cstr))
5492               "\n"))))
5494 (defun colorcomp (color)
5495   "Allow fiddling with COLOR in a new buffer.
5496 The buffer is in Color Components mode."
5497   (interactive "sColor (name or #RGB or #RRGGBB): ")
5498   (when (string= "" color)
5499     (setq color "green"))
5500   (unless (color-values color)
5501     (error "No such color: %S" color))
5502   (switch-to-buffer
5503    (generate-new-buffer (format "originally: %s" color)))
5504   (kill-all-local-variables)
5505   (setq major-mode 'colorcomp-mode
5506         mode-name "Color Components")
5507   (use-local-map colorcomp-mode-map)
5508   (erase-buffer)
5509   (buffer-disable-undo)
5510   (let ((data (apply 'vector (mapcar (lambda (n) (ash n -8))
5511                                      (color-values color))))
5512         (ewoc (ewoc-create 'colorcomp-pp
5513                            "\nColor Components\n\n"
5514                            (substitute-command-keys
5515                             "\n\\@{colorcomp-mode-map@}"))))
5516     (set (make-local-variable 'colorcomp-data) data)
5517     (set (make-local-variable 'colorcomp-ewoc) ewoc)
5518     (ewoc-enter-last ewoc 0)
5519     (ewoc-enter-last ewoc 1)
5520     (ewoc-enter-last ewoc 2)
5521     (ewoc-enter-last ewoc nil)))
5522 @end example
5524 @cindex controller part, model/view/controller
5525   This example can be extended to be a ``color selection widget'' (in
5526 other words, the controller part of the ``model/view/controller''
5527 design paradigm) by defining commands to modify @code{colorcomp-data}
5528 and to ``finish'' the selection process, and a keymap to tie it all
5529 together conveniently.
5531 @smallexample
5532 (defun colorcomp-mod (index limit delta)
5533   (let ((cur (aref colorcomp-data index)))
5534     (unless (= limit cur)
5535       (aset colorcomp-data index (+ cur delta)))
5536     (ewoc-invalidate
5537      colorcomp-ewoc
5538      (ewoc-nth colorcomp-ewoc index)
5539      (ewoc-nth colorcomp-ewoc -1))))
5541 (defun colorcomp-R-more () (interactive) (colorcomp-mod 0 255 1))
5542 (defun colorcomp-G-more () (interactive) (colorcomp-mod 1 255 1))
5543 (defun colorcomp-B-more () (interactive) (colorcomp-mod 2 255 1))
5544 (defun colorcomp-R-less () (interactive) (colorcomp-mod 0 0 -1))
5545 (defun colorcomp-G-less () (interactive) (colorcomp-mod 1 0 -1))
5546 (defun colorcomp-B-less () (interactive) (colorcomp-mod 2 0 -1))
5548 (defun colorcomp-copy-as-kill-and-exit ()
5549   "Copy the color components into the kill ring and kill the buffer.
5550 The string is formatted #RRGGBB (hash followed by six hex digits)."
5551   (interactive)
5552   (kill-new (format "#%02X%02X%02X"
5553                     (aref colorcomp-data 0)
5554                     (aref colorcomp-data 1)
5555                     (aref colorcomp-data 2)))
5556   (kill-buffer nil))
5558 (setq colorcomp-mode-map
5559       (let ((m (make-sparse-keymap)))
5560         (suppress-keymap m)
5561         (define-key m "i" 'colorcomp-R-less)
5562         (define-key m "o" 'colorcomp-R-more)
5563         (define-key m "k" 'colorcomp-G-less)
5564         (define-key m "l" 'colorcomp-G-more)
5565         (define-key m "," 'colorcomp-B-less)
5566         (define-key m "." 'colorcomp-B-more)
5567         (define-key m " " 'colorcomp-copy-as-kill-and-exit)
5568         m))
5569 @end smallexample
5571 Note that we never modify the data in each node, which is fixed when the
5572 ewoc is created to be either @code{nil} or an index into the vector
5573 @code{colorcomp-data}, the actual color components.
5575 @node Blinking
5576 @section Blinking Parentheses
5577 @cindex parenthesis matching
5578 @cindex blinking parentheses
5579 @cindex balancing parentheses
5581   This section describes the mechanism by which Emacs shows a matching
5582 open parenthesis when the user inserts a close parenthesis.
5584 @defvar blink-paren-function
5585 The value of this variable should be a function (of no arguments) to
5586 be called whenever a character with close parenthesis syntax is inserted.
5587 The value of @code{blink-paren-function} may be @code{nil}, in which
5588 case nothing is done.
5589 @end defvar
5591 @defopt blink-matching-paren
5592 If this variable is @code{nil}, then @code{blink-matching-open} does
5593 nothing.
5594 @end defopt
5596 @defopt blink-matching-paren-distance
5597 This variable specifies the maximum distance to scan for a matching
5598 parenthesis before giving up.
5599 @end defopt
5601 @defopt blink-matching-delay
5602 This variable specifies the number of seconds for the cursor to remain
5603 at the matching parenthesis.  A fraction of a second often gives
5604 good results, but the default is 1, which works on all systems.
5605 @end defopt
5607 @deffn Command blink-matching-open
5608 This function is the default value of @code{blink-paren-function}.  It
5609 assumes that point follows a character with close parenthesis syntax and
5610 moves the cursor momentarily to the matching opening character.  If that
5611 character is not already on the screen, it displays the character's
5612 context in the echo area.  To avoid long delays, this function does not
5613 search farther than @code{blink-matching-paren-distance} characters.
5615 Here is an example of calling this function explicitly.
5617 @smallexample
5618 @group
5619 (defun interactive-blink-matching-open ()
5620 @c Do not break this line! -- rms.
5621 @c The first line of a doc string
5622 @c must stand alone.
5623   "Indicate momentarily the start of sexp before point."
5624   (interactive)
5625 @end group
5626 @group
5627   (let ((blink-matching-paren-distance
5628          (buffer-size))
5629         (blink-matching-paren t))
5630     (blink-matching-open)))
5631 @end group
5632 @end smallexample
5633 @end deffn
5635 @node Usual Display
5636 @section Usual Display Conventions
5638   The usual display conventions define how to display each character
5639 code.  You can override these conventions by setting up a display table
5640 (@pxref{Display Tables}).  Here are the usual display conventions:
5642 @itemize @bullet
5643 @item
5644 Character codes 32 through 126 map to glyph codes 32 through 126.
5645 Normally this means they display as themselves, but a display table
5646 can change that.
5648 @item
5649 Character code 9 is a horizontal tab.  It displays as whitespace
5650 up to a position determined by @code{tab-width}.
5652 @item
5653 Character code 10 is a newline.  It is normally invisible on display,
5654 and has the effect of ending the preceding line and starting a new
5655 line.
5657 @item
5658 All other codes in the range 0 through 31 display in one of two ways
5659 according to the value of @code{ctl-arrow}.  If it is non-@code{nil},
5660 these codes map to sequences of two glyphs, where the first glyph is
5661 the @acronym{ASCII} code for @samp{^}.  (A display table can specify a
5662 glyph to use instead of @samp{^}.)  Otherwise, these codes map just
5663 like the raw bytes in the range 128 to 255 (described below).
5665 @cindex octal escapes
5666 @item
5667 Raw bytes (@pxref{Text Representations}) with codes 128 through 255,
5668 and the @acronym{ASCII} control character with code 127, display as
5669 sequences of four glyphs, where the first glyph is the @acronym{ASCII}
5670 code for @samp{\}, and the others are digit characters representing
5671 the character code in octal.  (A display table can specify a glyph to
5672 use instead of @samp{\}.)  This is known as the @dfn{octal escape}
5673 display.
5675 @item
5676 Non-@acronym{ASCII} character codes above 127 are displayed as
5677 themselves, if the terminal and the available fonts support them.
5678 Characters that are not supported by the terminal, or (on window
5679 systems) have no fonts available for them, are displayed as a question
5680 mark or a hex code or an empty box.  @xref{Glyphless Chars}, for how
5681 to control display of the characters not supported by the terminal or
5682 fonts.  Display tables can change how a character is displayed, even
5683 if it is supported.
5684 @end itemize
5686   The usual display conventions apply even when there is a display
5687 table, for any character whose entry in the active display table is
5688 @code{nil}.  Thus, when you set up a display table, you need only
5689 specify the characters for which you want special behavior.
5691   These display rules apply to carriage return (character code 13), when
5692 it appears in the buffer.  But that character may not appear in the
5693 buffer where you expect it, if it was eliminated as part of end-of-line
5694 conversion (@pxref{Coding System Basics}).
5696   These variables affect the way certain characters are displayed on the
5697 screen.  Since they change the number of columns the characters occupy,
5698 they also affect the indentation functions.  These variables also affect
5699 how the mode line is displayed; if you want to force redisplay of the
5700 mode line using the new values, call the function
5701 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5703 @defopt ctl-arrow
5704 @cindex control characters in display
5705 This buffer-local variable controls how control characters are
5706 displayed.  If it is non-@code{nil}, they are displayed as a caret
5707 followed by the character: @samp{^A}.  If it is @code{nil}, they are
5708 displayed as octal escapes: a backslash followed by three octal
5709 digits, as in @samp{\001}.
5710 @end defopt
5712 @defopt tab-width
5713 The value of this buffer-local variable is the spacing between tab
5714 stops used for displaying tab characters in Emacs buffers.  The value
5715 is in units of columns, and the default is 8.  Note that this feature
5716 is completely independent of the user-settable tab stops used by the
5717 command @code{tab-to-tab-stop}.  @xref{Indent Tabs}.
5718 @end defopt
5720 @node Display Tables
5721 @section Display Tables
5723 @cindex display table
5724 You can use the @dfn{display table} feature to control how all possible
5725 character codes display on the screen.  This is useful for displaying
5726 European languages that have letters not in the @acronym{ASCII} character
5727 set.
5729 The display table maps each character code into a sequence of
5730 @dfn{glyphs}, each glyph being a graphic that takes up one character
5731 position on the screen.  You can also define how to display each glyph
5732 on your terminal, using the @dfn{glyph table}.
5734 Display tables affect how the mode line is displayed; if you want to
5735 force redisplay of the mode line using a new display table, call
5736 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5738 @menu
5739 * Display Table Format::  What a display table consists of.
5740 * Active Display Table::  How Emacs selects a display table to use.
5741 * Glyphs::              How to define a glyph, and what glyphs mean.
5742 @end menu
5744 @node Display Table Format
5745 @subsection Display Table Format
5747   A display table is actually a char-table (@pxref{Char-Tables}) with
5748 @code{display-table} as its subtype.
5750 @defun make-display-table
5751 This creates and returns a display table.  The table initially has
5752 @code{nil} in all elements.
5753 @end defun
5755   The ordinary elements of the display table are indexed by character
5756 codes; the element at index @var{c} says how to display the character
5757 code @var{c}.  The value should be @code{nil} or a vector of the
5758 glyphs to be output (@pxref{Glyphs}).  @code{nil} says to display the
5759 character @var{c} according to the usual display conventions
5760 (@pxref{Usual Display}).
5762   @strong{Warning:} if you use the display table to change the display
5763 of newline characters, the whole buffer will be displayed as one long
5764 ``line.''
5766   The display table also has six ``extra slots'' which serve special
5767 purposes.  Here is a table of their meanings; @code{nil} in any slot
5768 means to use the default for that slot, as stated below.
5770 @table @asis
5771 @item 0
5772 The glyph for the end of a truncated screen line (the default for this
5773 is @samp{$}).  @xref{Glyphs}.  On graphical terminals, Emacs uses
5774 arrows in the fringes to indicate truncation, so the display table has
5775 no effect.
5777 @item 1
5778 The glyph for the end of a continued line (the default is @samp{\}).
5779 On graphical terminals, Emacs uses curved arrows in the fringes to
5780 indicate continuation, so the display table has no effect.
5782 @item 2
5783 The glyph for indicating a character displayed as an octal character
5784 code (the default is @samp{\}).
5786 @item 3
5787 The glyph for indicating a control character (the default is @samp{^}).
5789 @item 4
5790 A vector of glyphs for indicating the presence of invisible lines (the
5791 default is @samp{...}).  @xref{Selective Display}.
5793 @item 5
5794 The glyph used to draw the border between side-by-side windows (the
5795 default is @samp{|}).  @xref{Splitting Windows}.  This takes effect only
5796 when there are no scroll bars; if scroll bars are supported and in use,
5797 a scroll bar separates the two windows.
5798 @end table
5800   For example, here is how to construct a display table that mimics the
5801 effect of setting @code{ctl-arrow} to a non-@code{nil} value:
5803 @example
5804 (setq disptab (make-display-table))
5805 (let ((i 0))
5806   (while (< i 32)
5807     (or (= i ?\t) (= i ?\n)
5808         (aset disptab i (vector ?^ (+ i 64))))
5809     (setq i (1+ i)))
5810   (aset disptab 127 (vector ?^ ??)))
5811 @end example
5813 @defun display-table-slot display-table slot
5814 This function returns the value of the extra slot @var{slot} of
5815 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5816 5 inclusive, or a slot name (symbol).  Valid symbols are
5817 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5818 @code{selective-display}, and @code{vertical-border}.
5819 @end defun
5821 @defun set-display-table-slot display-table slot value
5822 This function stores @var{value} in the extra slot @var{slot} of
5823 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5824 5 inclusive, or a slot name (symbol).  Valid symbols are
5825 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5826 @code{selective-display}, and @code{vertical-border}.
5827 @end defun
5829 @defun describe-display-table display-table
5830 This function displays a description of the display table
5831 @var{display-table} in a help buffer.
5832 @end defun
5834 @deffn Command describe-current-display-table
5835 This command displays a description of the current display table in a
5836 help buffer.
5837 @end deffn
5839 @node Active Display Table
5840 @subsection Active Display Table
5841 @cindex active display table
5843   Each window can specify a display table, and so can each buffer.  When
5844 a buffer @var{b} is displayed in window @var{w}, display uses the
5845 display table for window @var{w} if it has one; otherwise, the display
5846 table for buffer @var{b} if it has one; otherwise, the standard display
5847 table if any.  The display table chosen is called the @dfn{active}
5848 display table.
5850 @defun window-display-table &optional window
5851 This function returns @var{window}'s display table, or @code{nil}
5852 if @var{window} does not have an assigned display table.  The default
5853 for @var{window} is the selected window.
5854 @end defun
5856 @defun set-window-display-table window table
5857 This function sets the display table of @var{window} to @var{table}.
5858 The argument @var{table} should be either a display table or
5859 @code{nil}.
5860 @end defun
5862 @defvar buffer-display-table
5863 This variable is automatically buffer-local in all buffers; its value in
5864 a particular buffer specifies the display table for that buffer.  If it
5865 is @code{nil}, that means the buffer does not have an assigned display
5866 table.
5867 @end defvar
5869 @defvar standard-display-table
5870 This variable's value is the default display table, used whenever a
5871 window has no display table and neither does the buffer displayed in
5872 that window.  This variable is @code{nil} by default.
5873 @end defvar
5875   If there is no display table to use for a particular window---that is,
5876 if the window specifies none, its buffer specifies none, and
5877 @code{standard-display-table} is @code{nil}---then Emacs uses the usual
5878 display conventions for all character codes in that window.  @xref{Usual
5879 Display}.
5881 A number of functions for changing the standard display table
5882 are defined in the library @file{disp-table}.
5884 @node Glyphs
5885 @subsection Glyphs
5887 @cindex glyph
5888   A @dfn{glyph} is a generalization of a character; it stands for an
5889 image that takes up a single character position on the screen.  Normally
5890 glyphs come from vectors in the display table (@pxref{Display Tables}).
5892   A glyph is represented in Lisp as a @dfn{glyph code}.  A glyph code
5893 can be @dfn{simple} or it can be defined by the @dfn{glyph table}.  A
5894 simple glyph code is just a way of specifying a character and a face
5895 to output it in.  @xref{Faces}.
5897   The following functions are used to manipulate simple glyph codes:
5899 @defun make-glyph-code char &optional face
5900 This function returns a simple glyph code representing char @var{char}
5901 with face @var{face}.
5902 @end defun
5904 @defun glyph-char glyph
5905 This function returns the character of simple glyph code @var{glyph}.
5906 @end defun
5908 @defun glyph-face glyph
5909 This function returns face of simple glyph code @var{glyph}, or
5910 @code{nil} if @var{glyph} has the default face (face-id 0).
5911 @xref{Face Functions}.
5912 @end defun
5914   On character terminals, you can set up a @dfn{glyph table} to define
5915 the meaning of glyph codes (represented as small integers).
5917 @defvar glyph-table
5918 The value of this variable is the current glyph table.  It should be
5919 @code{nil} or a vector whose @var{g}th element defines glyph code
5920 @var{g}.
5922 If a glyph code is greater than or equal to the length of the glyph
5923 table, that code is automatically simple.  If @code{glyph-table} is
5924 @code{nil} then all glyph codes are simple.
5926 The glyph table is used only on character terminals.  On graphical
5927 displays, all glyph codes are simple.
5928 @end defvar
5930   Here are the meaningful types of elements in the glyph table:
5932 @table @asis
5933 @item @var{string}
5934 Send the characters in @var{string} to the terminal to output
5935 this glyph code.
5937 @item @var{code}
5938 Define this glyph code as an alias for glyph code @var{code} created
5939 by @code{make-glyph-code}.  You can use such an alias to define a
5940 small-numbered glyph code which specifies a character with a face.
5942 @item @code{nil}
5943 This glyph code is simple.
5944 @end table
5946 @defun create-glyph string
5947 This function returns a newly-allocated glyph code which is set up to
5948 display by sending @var{string} to the terminal.
5949 @end defun
5951 @node Beeping
5952 @section Beeping
5953 @c  @cindex beeping   "beep" is adjacent
5954 @cindex bell
5956   This section describes how to make Emacs ring the bell (or blink the
5957 screen) to attract the user's attention.  Be conservative about how
5958 often you do this; frequent bells can become irritating.  Also be
5959 careful not to use just beeping when signaling an error is more
5960 appropriate.  (@xref{Errors}.)
5962 @defun ding &optional do-not-terminate
5963 @cindex keyboard macro termination
5964 This function beeps, or flashes the screen (see @code{visible-bell} below).
5965 It also terminates any keyboard macro currently executing unless
5966 @var{do-not-terminate} is non-@code{nil}.
5967 @end defun
5969 @defun beep &optional do-not-terminate
5970 This is a synonym for @code{ding}.
5971 @end defun
5973 @defopt visible-bell
5974 This variable determines whether Emacs should flash the screen to
5975 represent a bell.  Non-@code{nil} means yes, @code{nil} means no.  This
5976 is effective on graphical displays, and on text-only terminals
5977 provided the terminal's Termcap entry defines the visible bell
5978 capability (@samp{vb}).
5979 @end defopt
5981 @defvar ring-bell-function
5982 If this is non-@code{nil}, it specifies how Emacs should ``ring the
5983 bell.''  Its value should be a function of no arguments.  If this is
5984 non-@code{nil}, it takes precedence over the @code{visible-bell}
5985 variable.
5986 @end defvar
5988 @node Window Systems
5989 @section Window Systems
5991   Emacs works with several window systems, most notably the X Window
5992 System.  Both Emacs and X use the term ``window,'' but use it
5993 differently.  An Emacs frame is a single window as far as X is
5994 concerned; the individual Emacs windows are not known to X at all.
5996 @defvar window-system
5997 This terminal-local variable tells Lisp programs what window system
5998 Emacs is using for displaying the frame.  The possible values are
6000 @table @code
6001 @item x
6002 @cindex X Window System
6003 Emacs is displaying the frame using X.
6004 @item w32
6005 Emacs is displaying the frame using native MS-Windows GUI.
6006 @item ns
6007 Emacs is displaying the frame using the Nextstep interface (used on
6008 GNUstep and Mac OS X).
6009 @item pc
6010 Emacs is displaying the frame using MS-DOS direct screen writes.
6011 @item nil
6012 Emacs is displaying the frame on a character-based terminal.
6013 @end table
6014 @end defvar
6016 @defvar initial-window-system
6017 This variable holds the value of @code{window-system} used for the
6018 first frame created by Emacs during startup.  (When Emacs is invoked
6019 with the @option{--daemon} option, it does not create any initial
6020 frames, so @code{initial-window-system} is @code{nil}.  @xref{Initial
6021 Options, daemon,, emacs, The GNU Emacs Manual}.)
6022 @end defvar
6024 @defun window-system &optional frame
6025 This function returns a symbol whose name tells what window system is
6026 used for displaying @var{frame} (which defaults to the currently
6027 selected frame).  The list of possible symbols it returns is the same
6028 one documented for the variable @code{window-system} above.
6029 @end defun
6031   Do @emph{not} use @code{window-system} and
6032 @code{initial-window-system} as predicates or boolean flag variables,
6033 if you want to write code that works differently on text terminals and
6034 graphic displays.  That is because @code{window-system} is not a good
6035 indicator of Emacs capabilities on a given display type.  Instead, use
6036 @code{display-graphic-p} or any of the other @code{display-*-p}
6037 predicates described in @ref{Display Feature Testing}.
6039 @defvar window-setup-hook
6040 This variable is a normal hook which Emacs runs after handling the
6041 initialization files.  Emacs runs this hook after it has completed
6042 loading your init file, the default initialization file (if
6043 any), and the terminal-specific Lisp code, and running the hook
6044 @code{term-setup-hook}.
6046 This hook is used for internal purposes: setting up communication with
6047 the window system, and creating the initial window.  Users should not
6048 interfere with it.
6049 @end defvar
6051 @node Bidirectional Display
6052 @section Bidirectional Display
6053 @cindex bidirectional display
6054 @cindex right-to-left text
6056   Emacs can display text written in scripts, such as Arabic, Farsi,
6057 and Hebrew, whose natural ordering of horizontal text for display is
6058 from right to left.  However, digits and Latin text embedded in these
6059 scripts are still displayed left to right.  It is also not uncommon to
6060 have small portions of text in Arabic or Hebrew embedded in otherwise
6061 Latin document, e.g., as comments and strings in a program source
6062 file.  Likewise, small portions of Latin text can be embedded in an
6063 Arabic or Farsi document.  For these reasons, text that uses these
6064 scripts is actually @dfn{bidirectional}: a mixture of runs of
6065 left-to-right and right-to-left characters.
6067   This section describes the facilities and options provided by Emacs
6068 for editing and displaying bidirectional text.
6070 @cindex logical order
6071 @cindex reading order
6072 @cindex visual order
6073 @cindex unicode bidirectional algorithm
6074   Emacs stores right-to-left and bidirectional text in the so-called
6075 @dfn{logical} (or @dfn{reading}) order: the buffer or string position
6076 of the first character you read precedes that of the next character.
6077 Reordering of bidirectional text into the @dfn{visual} order happens
6078 at display time.  As result, character positions no longer increase
6079 monotonically with their positions on display.  Emacs implements the
6080 Unicode Bidirectional Algorithm (a.k.a.@: @acronym{UBA}) described in
6081 the Unicode Standard Annex #9, for reordering of bidirectional text
6082 for display.  Reordering of bidirectional text for display in Emacs is
6083 a ``Full bidirectionality'' class implementation of the @acronym{UBA}.
6085 @defvar bidi-display-reordering
6086   This buffer-local variable controls whether text in the buffer is
6087 reordered for display.  If its value is non-@code{nil}, Emacs reorders
6088 characters that have right-to-left directionality when they are
6089 displayed.  The default value is @code{t}.  Text in overlay strings
6090 (@pxref{Overlay Properties,,before-string}), display strings
6091 (@pxref{Overlay Properties,,display}), and @code{display} text
6092 properties (@pxref{Display Property}) is also reordered for display if
6093 the buffer whose text includes these strings is reordered.  Turning
6094 off @code{bidi-display-reordering} for a buffer turns off reordering
6095 of all the overlay and display strings in that buffer.
6097   Reordering of strings that are unrelated to any buffer, such as text
6098 displayed on the mode line (@pxref{Mode Line Format}) or header line
6099 (@pxref{Header Lines}), is controlled by the default value of
6100 @code{bidi-display-reordering}.
6101 @end defvar
6103 @cindex unibyte buffers, and bidi reordering
6104   Emacs does not reorder text in unibyte buffers, even if
6105 @code{bidi-display-reordering} is non-@code{nil} in such a buffer.
6106 This is because unibyte buffers contain raw bytes, not characters, and
6107 thus don't have bidirectional properties defined for them which are
6108 required for correct reordering.  Therefore, to test whether text in a
6109 buffer will be reordered for display, it is not enough to test the
6110 value of @code{bidi-display-reordering} alone.  The correct test is
6111 this:
6113 @example
6114  (if (and enable-multibyte-characters
6115           bidi-display-reordering)
6116      ;; Buffer is being reordered for display
6117    )
6118 @end example
6120   In contrast to unibyte buffers, unibyte display and overlay strings
6121 @emph{are} reordered, if their parent buffer is reordered.  This is
6122 because plain-@sc{ascii} strings are stored by Emacs as unibyte
6123 strings.  If a unibyte display or overlay string includes
6124 non-@sc{ascii} characters, these characters are assumed to have
6125 left-to-right direction.
6127 @cindex display properties, and bidi reordering of text
6128   Text covered by @code{display} text properties, by overlays with
6129 @code{display} properties whose value is a string, and by any other
6130 properties that replace buffer text, is treated as a single unit when
6131 it is reordered for display.  That is, the entire chunk of text
6132 covered by these properties is reordered together.  Moreover, the
6133 bidirectional properties of the characters in this chunk of text are
6134 ignored, and Emacs reorders them as if they were replaced with a
6135 single character @code{U+FFFC}, known as the @dfn{Object Replacement
6136 Character}.  This means that placing a display property over a portion
6137 of text may change the way that the surrounding text is reordered for
6138 display.  To prevent this unexpected effect, always place such
6139 properties on text whose directionality is identical with text that
6140 surrounds it.
6142 @cindex base direction of a paragraph
6143   Each paragraph of bidirectional text can have its own @dfn{base
6144 direction}, either right-to-left or left-to-right.  Text in
6145 left-to-right paragraphs is displayed beginning at the left margin of
6146 the window and is truncated or continued when it reaches the right
6147 margin.  By contrast, display of text in right-to-left paragraphs
6148 begins at the right margin and is continued or truncated at the left
6149 margin.
6151 @defvar bidi-paragraph-direction
6152   By default, Emacs determines the base direction of each paragraph
6153 dynamically, based on the text at the beginning of the paragraph.  The
6154 precise method of determining the base direction is specified by the
6155 @acronym{UBA}; in a nutshell, the first character in a paragraph that
6156 has an explicit directionality determines the base direction of the
6157 paragraph.  However, sometimes a buffer may need to force a certain
6158 base direction for its paragraphs.  For example, a buffer that visits
6159 a source code of a program should force all its paragraphs to be
6160 displayed left to right.  The variable
6161 @code{bidi-paragraph-direction}, if non-@code{nil}, disables the
6162 dynamic determination of the base direction, and instead forces all
6163 paragraphs in the buffer to have the direction specified by its
6164 buffer-local value.  The value can be either @code{right-to-left} or
6165 @code{left-to-right}.  Any other value is interpreted as @code{nil}.
6166 The default is @code{nil}.
6168 @cindex @code{prog-mode}, and @code{bidi-paragraph-direction}
6169 Modes that are meant to display program source code should force a
6170 @code{left-to-right} paragraph direction.  The easiest way of doing so
6171 is to derive the mode from Prog Mode, which already sets
6172 @code{bidi-paragraph-direction} to that value.
6173 @end defvar
6175 @defun current-bidi-paragraph-direction &optional buffer
6176 This function returns the paragraph direction at point in the named
6177 @var{buffer}.  The returned value is a symbol, either
6178 @code{left-to-right} or @code{right-to-left}.  If @var{buffer} is
6179 omitted or @code{nil}, it defaults to the current buffer.  If the
6180 buffer-local value of the variable @code{bidi-paragraph-direction} is
6181 non-@code{nil}, the returned value will be identical to that value;
6182 otherwise, the returned value reflects the paragraph direction
6183 determined dynamically by Emacs.  For buffers whose value of
6184 @code{bidi-display-reordering} is @code{nil} as well as unibyte
6185 buffers, this function always returns @code{left-to-right}.
6186 @end defun
6188 @cindex layout on display, and bidirectional text
6189 @cindex jumbled display of bidirectional text
6190 @cindex concatenating bidirectional strings
6191   Reordering of bidirectional text for display can have surprising and
6192 unpleasant effects when two strings with bidirectional content are
6193 juxtaposed in a buffer, or otherwise programmatically concatenated
6194 into a string of text.  A typical example is a buffer whose lines are
6195 actually sequences of items, or fields, separated by whitespace or
6196 punctuation characters.  This is used in specialized modes such as
6197 Buffer-menu Mode or various email summary modes, like Rmail Summary
6198 Mode.  Because these separator characters are @dfn{weak}, i.e.@: have
6199 no strong directionality, they take on the directionality of
6200 surrounding text.  As result, a numeric field that follows a field
6201 with bidirectional content can be displayed @emph{to the left} of the
6202 preceding field, producing a jumbled display and messing up the
6203 expected layout.
6205   To countermand this, we recommend that you use one of the following
6206 techniques for forcing correct order of fields on display:
6208 @itemize @minus
6209 @item
6210 Append the special character @code{U+200E}, LEFT-TO-RIGHT MARK, or
6211 @acronym{LRM}, to the end of each field that may have bidirectional
6212 content, or prepend it to the beginning of the following field.  The
6213 function @code{bidi-string-mark-left-to-right}, described below, comes
6214 in handy for this purpose.  (In a right-to-left paragraph, use
6215 @code{U+200F}, RIGHT-TO-LEFT MARK, or @acronym{RLM}, instead.)  This
6216 is one of the solutions recommended by
6217 @uref{http://www.unicode.org/reports/tr9/#Separators, the
6218 @acronym{UBA}}.
6220 @item
6221 Include the tab character in the field separator.  The tab character
6222 plays the role of @dfn{segment separator} in the @acronym{UBA}
6223 reordering, whose effect is to make each field a separate segment, and
6224 thus reorder them separately.
6226 @cindex @code{space} display spec, and bidirectional text
6227 @item
6228 Separate fields with a @code{display} property or overlay with the
6229 property value of the form @code{(space . PROPS)} (@pxref{Specified
6230 Space}).  This display specification is treated by Emacs as a
6231 @dfn{paragraph separator}; the text before and after the separator is
6232 reordered separately, which avoids the influence of any field on its
6233 neighboring fields.
6234 @end itemize
6236 @defun bidi-string-mark-left-to-right string
6237 This subroutine returns its argument @var{string}, possibly modified,
6238 such that the result can be safely concatenated with another string,
6239 or juxtaposed with another string in a buffer, without disrupting the
6240 relative layout of this string and the next one on display.  If the
6241 string returned by this function is displayed as part of a
6242 left-to-right paragraph, it will always appear on display to the left
6243 of the text that follows it.  The function works by examining the
6244 characters of its argument, and if any of those characters could cause
6245 reordering on display, the function appends the @acronym{LRM}
6246 character to the string.  The appended @acronym{LRM} character is made
6247 @emph{invisible} (@pxref{Invisible Text}), to hide it on display.
6248 @end defun
6250   The reordering algorithm uses the bidirectional properties of the
6251 characters stored as their @code{bidi-class} property
6252 (@pxref{Character Properties}).  Lisp programs can change these
6253 properties by calling the @code{put-char-code-property} function.
6254 However, doing this requires a thorough understanding of the
6255 @acronym{UBA}, and is therefore not recommended.  Any changes to the
6256 bidirectional properties of a character have global effect: they
6257 affect all Emacs frames and windows.
6259   Similarly, the @code{mirroring} property is used to display the
6260 appropriate mirrored character in the reordered text.  Lisp programs
6261 can affect the mirrored display by changing this property.  Again, any
6262 such changes affect all of Emacs display.
6264 @node Glyphless Chars
6265 @section Glyphless Character Display
6266 @cindex glyphless characters
6268   @dfn{Glyphless characters} are not displayed in the usual way when
6269 they appear in a buffer, but in some special way (e.g. as a box
6270 containing a hexadecimal code).  These include characters that cannot
6271 be displayed with any available font (on a graphical display), or that
6272 cannot be encoded by the terminal's coding system (on a text-only
6273 terminal).  Specific characters can also be defined to be glyphless.
6275 @defvar glyphless-char-display
6276 The value of this variable is a char-table that defines glyphless
6277 characters and how they are displayed.  If an entry is @code{nil}, the
6278 corresponding character is displayed in its usual way.  Otherwise, an
6279 entry should be one of the following display methods:
6281 @table @asis
6282 @item @code{zero-width}
6283 Don't display the character.
6285 @item @code{thin-space}
6286 Display a thin space, 1-pixel wide on graphical displays, or
6287 1-character wide on text-only terminals.
6289 @item @code{empty-box}
6290 Display an empty box.
6292 @item @code{hex-code}
6293 Display a box containing the Unicode codepoint of the character, in
6294 hexadecimal notation.
6296 @item an @acronym{ASCII} string
6297 Display a box containing that string.
6298 @end table
6300 @noindent
6301 Except for @code{zero-width}, these methods display using the
6302 @code{glyphless-char} face.
6304 An entry can also be a cons cell @code{(@var{graphical}
6305 . @var{text})}, where @var{graphical} and @var{text} are the display
6306 methods on graphical displays and text-only terminals respectively.
6308 The char-table has one extra slot, which determines how to display any
6309 character that cannot be displayed with any available font, or cannot
6310 be encoded by the terminal's coding system.  Its value should be one
6311 of the above display methods, except @code{zero-width} or a cons cell.
6312 @end defvar
6314 @defopt glyphless-char-display-control
6315 This user option provides a convenient way to set
6316 @code{glyphless-char-display} for groups of similar characters.  It
6317 takes effect via a custom @code{:set} function (@pxref{Variable
6318 Definitions}), which update @code{glyphless-char-display}.
6320 Its value should be an alist of elements @code{(@var{group}
6321 . @var{method})}, where @var{group} is a symbol specifying a group of
6322 characters, and @var{method} is a symbol specifying how to display
6323 them.
6325 @var{group} should be one of the following:
6327 @table @code
6328 @item c0-control
6329 @acronym{ASCII} control characters @code{U+0000} to @code{U+001F},
6330 excluding the newline and tab characters (normally displayed as escape
6331 sequences like @samp{^A}; @pxref{Text Display,, How Text Is Displayed,
6332 emacs, The GNU Emacs Manual}).
6334 @item c1-control
6335 Non-@acronym{ASCII}, non-printing characters @code{U+0080} to
6336 @code{U+009F} (normally displayed as octal escape sequences like
6337 @samp{\230}).
6339 @item format-control
6340 Characters of Unicode General Category `Cf', such as @samp{U+200E}
6341 (Left-to-Right Mark), but excluding characters that have graphic
6342 images, such as @samp{U+00AD} (Soft Hyphen).
6344 @item no-font
6345 Characters for there is no suitable font, or which cannot be encoded
6346 by the terminal's coding system.
6347 @end table
6349 @c FIXME: this can also be `acronym', but that's not currently
6350 @c completely implemented; it applies only to the format-control
6351 @c group, and only works if the acronym is in `char-acronym-table'.
6352 The @var{method} symbol should be one of @code{zero-width},
6353 @code{thin-space}, @code{empty-box}, or @code{hex-code}.  These have
6354 the same meanings as in @code{glyphless-char-display}, above.
6355 @end defopt