* lisp/dabbrev.el: Fix cycle completion.
[emacs.git] / doc / lispref / display.texi
blobc70418be52b940c59b50e5a46f0564e8b230d2f0
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-2012 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's 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 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 @defmac 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 defmac
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 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 terminals which 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 terminals that support variable-brightness text, slanted text is
2070 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.  The
3371 value is an alist of elements @code{(@var{indicator}
3372 . @var{bitmaps})}, where @var{indicator} specifies a logical indicator
3373 type and @var{bitmaps} specifies the fringe bitmaps to use for that
3374 indicator.
3376   Each @var{indicator} should be one of the following symbols:
3378 @table @asis
3379 @item @code{truncation}, @code{continuation}.
3380 Used for truncation and continuation lines.
3382 @item @code{up}, @code{down}, @code{top}, @code{bottom}, @code{top-bottom}
3383 Used when @code{indicate-buffer-boundaries} is non-@code{nil}:
3384 @code{up} and @code{down} indicate a buffer boundary lying above or
3385 below the window edge; @code{top} and @code{bottom} indicate the
3386 topmost and bottommost buffer text line; and @code{top-bottom}
3387 indicates where there is just one line of text in the buffer.
3389 @item @code{empty-line}
3390 Used to indicate empty lines when @code{indicate-empty-lines} is
3391 non-@code{nil}.
3393 @item @code{overlay-arrow}
3394 Used for overlay arrows (@pxref{Overlay Arrow}).
3395 @c Is this used anywhere?
3396 @c @item Unknown bitmap indicator:
3397 @c @code{unknown}.
3398 @end table
3400   Each @var{bitmaps} value may be a list of symbols @code{(@var{left}
3401 @var{right} [@var{left1} @var{right1}])}.  The @var{left} and
3402 @var{right} symbols specify the bitmaps shown in the left and/or right
3403 fringe, for the specific indicator.  @var{left1} and @var{right1} are
3404 specific to the @code{bottom} and @code{top-bottom} indicators, and
3405 are used to indicate that the last text line has no final newline.
3406 Alternatively, @var{bitmaps} may be a single symbol which is used in
3407 both left and right fringes.
3409   @xref{Fringe Bitmaps}, for a list of standard bitmap symbols and how
3410 to define your own.  In addition, @code{nil} represents the empty
3411 bitmap (i.e.@: an indicator that is not shown).
3413   When @code{fringe-indicator-alist} has a buffer-local value, and
3414 there is no bitmap defined for a logical indicator, or the bitmap is
3415 @code{t}, the corresponding value from the default value of
3416 @code{fringe-indicator-alist} is used.
3417 @end defvar
3419 @node Fringe Cursors
3420 @subsection Fringe Cursors
3421 @cindex fringe cursors
3422 @cindex cursor, fringe
3424   When a line is exactly as wide as the window, Emacs displays the
3425 cursor in the right fringe instead of using two lines.  Different
3426 bitmaps are used to represent the cursor in the fringe depending on
3427 the current buffer's cursor type.
3429 @defopt overflow-newline-into-fringe
3430 If this is non-@code{nil}, lines exactly as wide as the window (not
3431 counting the final newline character) are not continued.  Instead,
3432 when point is at the end of the line, the cursor appears in the right
3433 fringe.
3434 @end defopt
3436 @defvar fringe-cursor-alist
3437 This variable specifies the mapping from logical cursor type to the
3438 actual fringe bitmaps displayed in the right fringe.  The value is an
3439 alist where each element has the form @code{(@var{cursor-type}
3440 . @var{bitmap})}, which means to use the fringe bitmap @var{bitmap} to
3441 display cursors of type @var{cursor-type}.
3443 Each @var{cursor-type} should be one of @code{box}, @code{hollow},
3444 @code{bar}, @code{hbar}, or @code{hollow-small}.  The first four have
3445 the same meanings as in the @code{cursor-type} frame parameter
3446 (@pxref{Cursor Parameters}).  The @code{hollow-small} type is used
3447 instead of @code{hollow} when the normal @code{hollow-rectangle}
3448 bitmap is too tall to fit on a specific display line.
3450 Each @var{bitmap} should be a symbol specifying the fringe bitmap to
3451 be displayed for that logical cursor type.
3452 @iftex
3453 See the next subsection for details.
3454 @end iftex
3455 @ifnottex
3456 @xref{Fringe Bitmaps}.
3457 @end ifnottex
3459 When @code{fringe-cursor-alist} has a buffer-local value, and there is
3460 no bitmap defined for a cursor type, the corresponding value from the
3461 default value of @code{fringes-indicator-alist} is used.
3462 @end defvar
3464 @node Fringe Bitmaps
3465 @subsection Fringe Bitmaps
3466 @cindex fringe bitmaps
3467 @cindex bitmaps, fringe
3469   The @dfn{fringe bitmaps} are the actual bitmaps which represent the
3470 logical fringe indicators for truncated or continued lines, buffer
3471 boundaries, overlay arrows, etc.  Each bitmap is represented by a
3472 symbol.
3473 @iftex
3474 These symbols are referred to by the variables
3475 @code{fringe-indicator-alist} and @code{fringe-cursor-alist},
3476 described in the previous subsections.
3477 @end iftex
3478 @ifnottex
3479 These symbols are referred to by the variable
3480 @code{fringe-indicator-alist}, which maps fringe indicators to bitmaps
3481 (@pxref{Fringe Indicators}), and the variable
3482 @code{fringe-cursor-alist}, which maps fringe cursors to bitmaps
3483 (@pxref{Fringe Cursors}).
3484 @end ifnottex
3486   Lisp programs can also directly display a bitmap in the left or
3487 right fringe, by using a @code{display} property for one of the
3488 characters appearing in the line (@pxref{Other Display Specs}).  Such
3489 a display specification has the form
3491 @example
3492 (left-fringe @var{bitmap} [@var{face}])
3493 @end example
3495 @noindent
3498 @example
3499 (right-fringe @var{bitmap} [@var{face}])
3500 @end example
3502 @noindent
3503 The symbol @var{bitmap} identifies the bitmap to display.  The
3504 optional @var{face} names a face whose foreground color is used to
3505 display the bitmap; this face is automatically merged with the
3506 @code{fringe} face.
3508   Here is a list of the standard fringe bitmaps defined in Emacs, and
3509 how they are currently used in Emacs (via
3510 @code{fringe-indicator-alist} and @code{fringe-cursor-alist}):
3512 @table @asis
3513 @item @code{left-arrow}, @code{right-arrow}
3514 Used to indicate truncated lines.
3516 @item @code{left-curly-arrow}, @code{right-curly-arrow}
3517 Used to indicate continued lines.
3519 @item @code{right-triangle}, @code{left-triangle}
3520 The former is used by overlay arrows.  The latter is unused.
3522 @item @code{up-arrow}, @code{down-arrow}, @code{top-left-angle} @code{top-right-angle}
3523 @itemx @code{bottom-left-angle}, @code{bottom-right-angle}
3524 @itemx @code{top-right-angle}, @code{top-left-angle}
3525 @itemx @code{left-bracket}, @code{right-bracket}, @code{top-right-angle}, @code{top-left-angle}
3526 Used to indicate buffer boundaries.
3528 @item @code{filled-rectangle}, @code{hollow-rectangle}
3529 @itemx @code{filled-square}, @code{hollow-square}
3530 @itemx @code{vertical-bar}, @code{horizontal-bar}
3531 Used for different types of fringe cursors.
3533 @item @code{empty-line}, @code{question-mark}
3534 Unused.
3535 @end table
3537 @noindent
3538 The next subsection describes how to define your own fringe bitmaps.
3540 @defun fringe-bitmaps-at-pos &optional pos window
3541 This function returns the fringe bitmaps of the display line
3542 containing position @var{pos} in window @var{window}.  The return
3543 value has the form @code{(@var{left} @var{right} @var{ov})}, where @var{left}
3544 is the symbol for the fringe bitmap in the left fringe (or @code{nil}
3545 if no bitmap), @var{right} is similar for the right fringe, and @var{ov}
3546 is non-@code{nil} if there is an overlay arrow in the left fringe.
3548 The value is @code{nil} if @var{pos} is not visible in @var{window}.
3549 If @var{window} is @code{nil}, that stands for the selected window.
3550 If @var{pos} is @code{nil}, that stands for the value of point in
3551 @var{window}.
3552 @end defun
3554 @node Customizing Bitmaps
3555 @subsection Customizing Fringe Bitmaps
3557 @defun define-fringe-bitmap bitmap bits &optional height width align
3558 This function defines the symbol @var{bitmap} as a new fringe bitmap,
3559 or replaces an existing bitmap with that name.
3561 The argument @var{bits} specifies the image to use.  It should be
3562 either a string or a vector of integers, where each element (an
3563 integer) corresponds to one row of the bitmap.  Each bit of an integer
3564 corresponds to one pixel of the bitmap, where the low bit corresponds
3565 to the rightmost pixel of the bitmap.
3567 The height is normally the length of @var{bits}.  However, you
3568 can specify a different height with non-@code{nil} @var{height}.  The width
3569 is normally 8, but you can specify a different width with non-@code{nil}
3570 @var{width}.  The width must be an integer between 1 and 16.
3572 The argument @var{align} specifies the positioning of the bitmap
3573 relative to the range of rows where it is used; the default is to
3574 center the bitmap.  The allowed values are @code{top}, @code{center},
3575 or @code{bottom}.
3577 The @var{align} argument may also be a list @code{(@var{align}
3578 @var{periodic})} where @var{align} is interpreted as described above.
3579 If @var{periodic} is non-@code{nil}, it specifies that the rows in
3580 @code{bits} should be repeated enough times to reach the specified
3581 height.
3582 @end defun
3584 @defun destroy-fringe-bitmap bitmap
3585 This function destroy the fringe bitmap identified by @var{bitmap}.
3586 If @var{bitmap} identifies a standard fringe bitmap, it actually
3587 restores the standard definition of that bitmap, instead of
3588 eliminating it entirely.
3589 @end defun
3591 @defun set-fringe-bitmap-face bitmap &optional face
3592 This sets the face for the fringe bitmap @var{bitmap} to @var{face}.
3593 If @var{face} is @code{nil}, it selects the @code{fringe} face.  The
3594 bitmap's face controls the color to draw it in.
3596 @var{face} is merged with the @code{fringe} face, so normally
3597 @var{face} should specify only the foreground color.
3598 @end defun
3600 @node Overlay Arrow
3601 @subsection The Overlay Arrow
3602 @c @cindex overlay arrow  Duplicates variable names
3604   The @dfn{overlay arrow} is useful for directing the user's attention
3605 to a particular line in a buffer.  For example, in the modes used for
3606 interface to debuggers, the overlay arrow indicates the line of code
3607 about to be executed.  This feature has nothing to do with
3608 @dfn{overlays} (@pxref{Overlays}).
3610 @defvar overlay-arrow-string
3611 This variable holds the string to display to call attention to a
3612 particular line, or @code{nil} if the arrow feature is not in use.
3613 On a graphical display the contents of the string are ignored; instead a
3614 glyph is displayed in the fringe area to the left of the display area.
3615 @end defvar
3617 @defvar overlay-arrow-position
3618 This variable holds a marker that indicates where to display the overlay
3619 arrow.  It should point at the beginning of a line.  On a non-graphical
3620 display the arrow text
3621 appears at the beginning of that line, overlaying any text that would
3622 otherwise appear.  Since the arrow is usually short, and the line
3623 usually begins with indentation, normally nothing significant is
3624 overwritten.
3626 The overlay-arrow string is displayed in any given buffer if the value
3627 of @code{overlay-arrow-position} in that buffer points into that
3628 buffer.  Thus, it is possible to display multiple overlay arrow strings
3629 by creating buffer-local bindings of @code{overlay-arrow-position}.
3630 However, it is usually cleaner to use
3631 @code{overlay-arrow-variable-list} to achieve this result.
3632 @c !!! overlay-arrow-position: but the overlay string may remain in the display
3633 @c of some other buffer until an update is required.  This should be fixed
3634 @c now.  Is it?
3635 @end defvar
3637   You can do a similar job by creating an overlay with a
3638 @code{before-string} property.  @xref{Overlay Properties}.
3640   You can define multiple overlay arrows via the variable
3641 @code{overlay-arrow-variable-list}.
3643 @defvar overlay-arrow-variable-list
3644 This variable's value is a list of variables, each of which specifies
3645 the position of an overlay arrow.  The variable
3646 @code{overlay-arrow-position} has its normal meaning because it is on
3647 this list.
3648 @end defvar
3650 Each variable on this list can have properties
3651 @code{overlay-arrow-string} and @code{overlay-arrow-bitmap} that
3652 specify an overlay arrow string (for text terminals) or fringe bitmap
3653 (for graphical terminals) to display at the corresponding overlay
3654 arrow position.  If either property is not set, the default
3655 @code{overlay-arrow-string} or @code{overlay-arrow} fringe indicator
3656 is used.
3658 @node Scroll Bars
3659 @section Scroll Bars
3660 @cindex scroll bars
3662 Normally the frame parameter @code{vertical-scroll-bars} controls
3663 whether the windows in the frame have vertical scroll bars, and
3664 whether they are on the left or right.  The frame parameter
3665 @code{scroll-bar-width} specifies how wide they are (@code{nil}
3666 meaning the default).  @xref{Layout Parameters}.
3668 @defun frame-current-scroll-bars &optional frame
3669 This function reports the scroll bar type settings for frame
3670 @var{frame}.  The value is a cons cell
3671 @code{(@var{vertical-type} .@: @var{horizontal-type})}, where
3672 @var{vertical-type} is either @code{left}, @code{right}, or @code{nil}
3673 (which means no scroll bar.)  @var{horizontal-type} is meant to
3674 specify the horizontal scroll bar type, but since they are not
3675 implemented, it is always @code{nil}.
3676 @end defun
3678 @vindex vertical-scroll-bar
3679   You can enable or disable scroll bars for a particular buffer,
3680 by setting the variable @code{vertical-scroll-bar}.  This variable
3681 automatically becomes buffer-local when set.  The possible values are
3682 @code{left}, @code{right}, @code{t}, which means to use the
3683 frame's default, and @code{nil} for no scroll bar.
3685   You can also control this for individual windows.  Call the function
3686 @code{set-window-scroll-bars} to specify what to do for a specific window:
3688 @defun set-window-scroll-bars window width &optional vertical-type horizontal-type
3689 This function sets the width and type of scroll bars for window
3690 @var{window}.
3692 @var{width} specifies the scroll bar width in pixels (@code{nil} means
3693 use the width specified for the frame).  @var{vertical-type} specifies
3694 whether to have a vertical scroll bar and, if so, where.  The possible
3695 values are @code{left}, @code{right} and @code{nil}, just like the
3696 values of the @code{vertical-scroll-bars} frame parameter.
3698 The argument @var{horizontal-type} is meant to specify whether and
3699 where to have horizontal scroll bars, but since they are not
3700 implemented, it has no effect.  If @var{window} is @code{nil}, the
3701 selected window is used.
3702 @end defun
3704 @defun window-scroll-bars &optional window
3705 Report the width and type of scroll bars specified for @var{window}.
3706 If @var{window} is omitted or @code{nil}, the selected window is used.
3707 The value is a list of the form @code{(@var{width}
3708 @var{cols} @var{vertical-type} @var{horizontal-type})}.  The value
3709 @var{width} is the value that was specified for the width (which may
3710 be @code{nil}); @var{cols} is the number of columns that the scroll
3711 bar actually occupies.
3713 @var{horizontal-type} is not actually meaningful.
3714 @end defun
3716 If you don't specify these values for a window with
3717 @code{set-window-scroll-bars}, the buffer-local variables
3718 @code{scroll-bar-mode} and @code{scroll-bar-width} in the buffer being
3719 displayed control the window's vertical scroll bars.  The function
3720 @code{set-window-buffer} examines these variables.  If you change them
3721 in a buffer that is already visible in a window, you can make the
3722 window take note of the new values by calling @code{set-window-buffer}
3723 specifying the same buffer that is already displayed.
3725 @defopt scroll-bar-mode
3726 This variable, always local in all buffers, controls whether and where
3727 to put scroll bars in windows displaying the buffer.  The possible values
3728 are @code{nil} for no scroll bar, @code{left} to put a scroll bar on
3729 the left, and @code{right} to put a scroll bar on the right.
3730 @end defopt
3732 @defun window-current-scroll-bars &optional window
3733 This function reports the scroll bar type for window @var{window}.
3734 If @var{window} is omitted or @code{nil}, the selected window is used.
3735 The value is a cons cell
3736 @code{(@var{vertical-type} .@: @var{horizontal-type})}.  Unlike
3737 @code{window-scroll-bars}, this reports the scroll bar type actually
3738 used, once frame defaults and @code{scroll-bar-mode} are taken into
3739 account.
3740 @end defun
3742 @defvar scroll-bar-width
3743 This variable, always local in all buffers, specifies the width of the
3744 buffer's scroll bars, measured in pixels.  A value of @code{nil} means
3745 to use the value specified by the frame.
3746 @end defvar
3748 @node Display Property
3749 @section The @code{display} Property
3750 @cindex display specification
3751 @kindex display @r{(text property)}
3753   The @code{display} text property (or overlay property) is used to
3754 insert images into text, and also control other aspects of how text
3755 displays.  The value of the @code{display} property should be a
3756 display specification, or a list or vector containing several display
3757 specifications.  Display specifications in the same @code{display}
3758 property value generally apply in parallel to the text they cover.
3760   If several sources (overlays and/or a text property) specify values
3761 for the @code{display} property, only one of the values takes effect,
3762 following the rules of @code{get-char-property}.  @xref{Examining
3763 Properties}.
3765   The rest of this section describes several kinds of
3766 display specifications and what they mean.
3768 @menu
3769 * Replacing Specs::      Display specs that replace the text.
3770 * Specified Space::      Displaying one space with a specified width.
3771 * Pixel Specification::  Specifying space width or height in pixels.
3772 * Other Display Specs::     Displaying an image; adjusting the height,
3773                               spacing, and other properties of text.
3774 * Display Margins::     Displaying text or images to the side of the main text.
3775 @end menu
3777 @node Replacing Specs
3778 @subsection Display Specs That Replace The Text
3780   Some kinds of @code{display} specifications specify something to
3781 display instead of the text that has the property.  These are called
3782 @dfn{replacing} display specifications.  Emacs does not allow the user
3783 to interactively move point into the middle of buffer text that is
3784 replaced in this way.
3786   If a list of display specifications includes more than one replacing
3787 display specification, the first overrides the rest.  Replacing
3788 display specifications make most other display specifications
3789 irrelevant, since those don't apply to the replacement.
3791   For replacing display specifications, ``the text that has the
3792 property'' means all the consecutive characters that have the same
3793 Lisp object as their @code{display} property; these characters are
3794 replaced as a single unit.  By contrast, characters that have similar
3795 but distinct Lisp objects as their @code{display} properties are
3796 handled separately.  Here's a function that illustrates this point:
3798 @smallexample
3799 (defun foo ()
3800   (goto-char (point-min))
3801   (dotimes (i 5)
3802     (let ((string (concat "A")))
3803       (put-text-property (point) (1+ (point)) 'display string)
3804       (forward-char 1)
3805       (put-text-property (point) (1+ (point)) 'display string)
3806       (forward-char 1))))
3807 @end smallexample
3809 @noindent
3810 It gives each of the first ten characters in the buffer string
3811 @code{"A"} as the @code{display} property, but they don't all get the
3812 same string.  The first two characters get the same string, so they
3813 together are replaced with one @samp{A}.  The next two characters get
3814 a second string, so they together are replaced with one @samp{A}.
3815 Likewise for each following pair of characters.  Thus, the ten
3816 characters appear as five A's.  This function would have the same
3817 results:
3819 @smallexample
3820 (defun foo ()
3821   (goto-char (point-min))
3822   (dotimes (i 5)
3823     (let ((string (concat "A")))
3824       (put-text-property (point) (+ 2 (point)) 'display string)
3825       (put-text-property (point) (1+ (point)) 'display string)
3826       (forward-char 2))))
3827 @end smallexample
3829 @noindent
3830 This illustrates that what matters is the property value for
3831 each character.  If two consecutive characters have the same
3832 object as the @code{display} property value, it's irrelevant
3833 whether they got this property from a single call to
3834 @code{put-text-property} or from two different calls.
3836 @node Specified Space
3837 @subsection Specified Spaces
3838 @cindex spaces, specified height or width
3839 @cindex variable-width spaces
3841   To display a space of specified width and/or height, use a display
3842 specification of the form @code{(space . @var{props})}, where
3843 @var{props} is a property list (a list of alternating properties and
3844 values).  You can put this property on one or more consecutive
3845 characters; a space of the specified height and width is displayed in
3846 place of @emph{all} of those characters.  These are the properties you
3847 can use in @var{props} to specify the weight of the space:
3849 @table @code
3850 @item :width @var{width}
3851 If @var{width} is an integer or floating point number, it specifies
3852 that the space width should be @var{width} times the normal character
3853 width.  @var{width} can also be a @dfn{pixel width} specification
3854 (@pxref{Pixel Specification}).
3856 @item :relative-width @var{factor}
3857 Specifies that the width of the stretch should be computed from the
3858 first character in the group of consecutive characters that have the
3859 same @code{display} property.  The space width is the width of that
3860 character, multiplied by @var{factor}.
3862 @item :align-to @var{hpos}
3863 Specifies that the space should be wide enough to reach @var{hpos}.
3864 If @var{hpos} is a number, it is measured in units of the normal
3865 character width.  @var{hpos} can also be a @dfn{pixel width}
3866 specification (@pxref{Pixel Specification}).
3867 @end table
3869   You should use one and only one of the above properties.  You can
3870 also specify the height of the space, with these properties:
3872 @table @code
3873 @item :height @var{height}
3874 Specifies the height of the space.
3875 If @var{height} is an integer or floating point number, it specifies
3876 that the space height should be @var{height} times the normal character
3877 height.  The @var{height} may also be a @dfn{pixel height} specification
3878 (@pxref{Pixel Specification}).
3880 @item :relative-height @var{factor}
3881 Specifies the height of the space, multiplying the ordinary height
3882 of the text having this display specification by @var{factor}.
3884 @item :ascent @var{ascent}
3885 If the value of @var{ascent} is a non-negative number no greater than
3886 100, it specifies that @var{ascent} percent of the height of the space
3887 should be considered as the ascent of the space---that is, the part
3888 above the baseline.  The ascent may also be specified in pixel units
3889 with a @dfn{pixel ascent} specification (@pxref{Pixel Specification}).
3891 @end table
3893   Don't use both @code{:height} and @code{:relative-height} together.
3895   The @code{:width} and @code{:align-to} properties are supported on
3896 non-graphic terminals, but the other space properties in this section
3897 are not.
3899   Note that space properties are treated as paragraph separators for
3900 the purposes of reordering bidirectional text for display.
3901 @xref{Bidirectional Display}, for the details.
3903 @node Pixel Specification
3904 @subsection Pixel Specification for Spaces
3905 @cindex spaces, pixel specification
3907   The value of the @code{:width}, @code{:align-to}, @code{:height},
3908 and @code{:ascent} properties can be a special kind of expression that
3909 is evaluated during redisplay.  The result of the evaluation is used
3910 as an absolute number of pixels.
3912   The following expressions are supported:
3914 @smallexample
3915 @group
3916   @var{expr} ::= @var{num} | (@var{num}) | @var{unit} | @var{elem} | @var{pos} | @var{image} | @var{form}
3917   @var{num}  ::= @var{integer} | @var{float} | @var{symbol}
3918   @var{unit} ::= in | mm | cm | width | height
3919 @end group
3920 @group
3921   @var{elem} ::= left-fringe | right-fringe | left-margin | right-margin
3922         |  scroll-bar | text
3923   @var{pos}  ::= left | center | right
3924   @var{form} ::= (@var{num} . @var{expr}) | (@var{op} @var{expr} ...)
3925   @var{op}   ::= + | -
3926 @end group
3927 @end smallexample
3929   The form @var{num} specifies a fraction of the default frame font
3930 height or width.  The form @code{(@var{num})} specifies an absolute
3931 number of pixels.  If @var{num} is a symbol, @var{symbol}, its
3932 buffer-local variable binding is used.
3934   The @code{in}, @code{mm}, and @code{cm} units specify the number of
3935 pixels per inch, millimeter, and centimeter, respectively.  The
3936 @code{width} and @code{height} units correspond to the default width
3937 and height of the current face.  An image specification @code{image}
3938 corresponds to the width or height of the image.
3940   The elements @code{left-fringe}, @code{right-fringe},
3941 @code{left-margin}, @code{right-margin}, @code{scroll-bar}, and
3942 @code{text} specify to the width of the corresponding area of the
3943 window.
3945   The @code{left}, @code{center}, and @code{right} positions can be
3946 used with @code{:align-to} to specify a position relative to the left
3947 edge, center, or right edge of the text area.
3949   Any of the above window elements (except @code{text}) can also be
3950 used with @code{:align-to} to specify that the position is relative to
3951 the left edge of the given area.  Once the base offset for a relative
3952 position has been set (by the first occurrence of one of these
3953 symbols), further occurrences of these symbols are interpreted as the
3954 width of the specified area.  For example, to align to the center of
3955 the left-margin, use
3957 @example
3958 :align-to (+ left-margin (0.5 . left-margin))
3959 @end example
3961   If no specific base offset is set for alignment, it is always relative
3962 to the left edge of the text area.  For example, @samp{:align-to 0} in a
3963 header-line aligns with the first text column in the text area.
3965   A value of the form @code{(@var{num} . @var{expr})} stands for the
3966 product of the values of @var{num} and @var{expr}.  For example,
3967 @code{(2 . in)} specifies a width of 2 inches, while @code{(0.5 .
3968 @var{image})} specifies half the width (or height) of the specified
3969 image.
3971   The form @code{(+ @var{expr} ...)} adds up the value of the
3972 expressions.  The form @code{(- @var{expr} ...)} negates or subtracts
3973 the value of the expressions.
3975 @node Other Display Specs
3976 @subsection Other Display Specifications
3978   Here are the other sorts of display specifications that you can use
3979 in the @code{display} text property.
3981 @table @code
3982 @item @var{string}
3983 Display @var{string} instead of the text that has this property.
3985 Recursive display specifications are not supported---@var{string}'s
3986 @code{display} properties, if any, are not used.
3988 @item (image . @var{image-props})
3989 This kind of display specification is an image descriptor (@pxref{Images}).
3990 When used as a display specification, it means to display the image
3991 instead of the text that has the display specification.
3993 @item (slice @var{x} @var{y} @var{width} @var{height})
3994 This specification together with @code{image} specifies a @dfn{slice}
3995 (a partial area) of the image to display.  The elements @var{y} and
3996 @var{x} specify the top left corner of the slice, within the image;
3997 @var{width} and @var{height} specify the width and height of the
3998 slice.  Integer values are numbers of pixels.  A floating point number
3999 in the range 0.0--1.0 stands for that fraction of the width or height
4000 of the entire image.
4002 @item ((margin nil) @var{string})
4003 A display specification of this form means to display @var{string}
4004 instead of the text that has the display specification, at the same
4005 position as that text.  It is equivalent to using just @var{string},
4006 but it is done as a special case of marginal display (@pxref{Display
4007 Margins}).
4009 @item (left-fringe @var{bitmap} @r{[}@var{face}@r{]})
4010 @itemx (right-fringe @var{bitmap} @r{[}@var{face}@r{]})
4011 This display specification on any character of a line of text causes
4012 the specified @var{bitmap} be displayed in the left or right fringes
4013 for that line, instead of the characters that have the display
4014 specification.  The optional @var{face} specifies the colors to be
4015 used for the bitmap.  @xref{Fringe Bitmaps}, for the details.
4017 @item (space-width @var{factor})
4018 This display specification affects all the space characters within the
4019 text that has the specification.  It displays all of these spaces
4020 @var{factor} times as wide as normal.  The element @var{factor} should
4021 be an integer or float.  Characters other than spaces are not affected
4022 at all; in particular, this has no effect on tab characters.
4024 @item (height @var{height})
4025 This display specification makes the text taller or shorter.
4026 Here are the possibilities for @var{height}:
4028 @table @asis
4029 @item @code{(+ @var{n})}
4030 This means to use a font that is @var{n} steps larger.  A ``step'' is
4031 defined by the set of available fonts---specifically, those that match
4032 what was otherwise specified for this text, in all attributes except
4033 height.  Each size for which a suitable font is available counts as
4034 another step.  @var{n} should be an integer.
4036 @item @code{(- @var{n})}
4037 This means to use a font that is @var{n} steps smaller.
4039 @item a number, @var{factor}
4040 A number, @var{factor}, means to use a font that is @var{factor} times
4041 as tall as the default font.
4043 @item a symbol, @var{function}
4044 A symbol is a function to compute the height.  It is called with the
4045 current height as argument, and should return the new height to use.
4047 @item anything else, @var{form}
4048 If the @var{height} value doesn't fit the previous possibilities, it is
4049 a form.  Emacs evaluates it to get the new height, with the symbol
4050 @code{height} bound to the current specified font height.
4051 @end table
4053 @item (raise @var{factor})
4054 This kind of display specification raises or lowers the text
4055 it applies to, relative to the baseline of the line.
4057 @var{factor} must be a number, which is interpreted as a multiple of the
4058 height of the affected text.  If it is positive, that means to display
4059 the characters raised.  If it is negative, that means to display them
4060 lower down.
4062 If the text also has a @code{height} display specification, that does
4063 not affect the amount of raising or lowering, which is based on the
4064 faces used for the text.
4065 @end table
4067 @c We put all the `@code{(when ...)}' on one line to encourage
4068 @c makeinfo's end-of-sentence heuristics to DTRT.  Previously, the dot
4069 @c was at eol; the info file ended up w/ two spaces rendered after it.
4070   You can make any display specification conditional.  To do that,
4071 package it in another list of the form
4072 @code{(when @var{condition} . @var{spec})}.
4073 Then the specification @var{spec} applies only when
4074 @var{condition} evaluates to a non-@code{nil} value.  During the
4075 evaluation, @code{object} is bound to the string or buffer having the
4076 conditional @code{display} property.  @code{position} and
4077 @code{buffer-position} are bound to the position within @code{object}
4078 and the buffer position where the @code{display} property was found,
4079 respectively.  Both positions can be different when @code{object} is a
4080 string.
4082 @node Display Margins
4083 @subsection Displaying in the Margins
4084 @cindex display margins
4085 @cindex margins, display
4087   A buffer can have blank areas called @dfn{display margins} on the
4088 left and on the right.  Ordinary text never appears in these areas,
4089 but you can put things into the display margins using the
4090 @code{display} property.  There is currently no way to make text or
4091 images in the margin mouse-sensitive.
4093   The way to display something in the margins is to specify it in a
4094 margin display specification in the @code{display} property of some
4095 text.  This is a replacing display specification, meaning that the
4096 text you put it on does not get displayed; the margin display appears,
4097 but that text does not.
4099   A margin display specification looks like @code{((margin
4100 right-margin) @var{spec})} or @code{((margin left-margin) @var{spec})}.
4101 Here, @var{spec} is another display specification that says what to
4102 display in the margin.  Typically it is a string of text to display,
4103 or an image descriptor.
4105   To display something in the margin @emph{in association with}
4106 certain buffer text, without altering or preventing the display of
4107 that text, put a @code{before-string} property on the text and put the
4108 margin display specification on the contents of the before-string.
4110   Before the display margins can display anything, you must give
4111 them a nonzero width.  The usual way to do that is to set these
4112 variables:
4114 @defvar left-margin-width
4115 This variable specifies the width of the left margin.
4116 It is buffer-local in all buffers.
4117 @end defvar
4119 @defvar right-margin-width
4120 This variable specifies the width of the right margin.
4121 It is buffer-local in all buffers.
4122 @end defvar
4124   Setting these variables does not immediately affect the window.  These
4125 variables are checked when a new buffer is displayed in the window.
4126 Thus, you can make changes take effect by calling
4127 @code{set-window-buffer}.
4129   You can also set the margin widths immediately.
4131 @defun set-window-margins window left &optional right
4132 This function specifies the margin widths for window @var{window}.
4133 The argument @var{left} controls the left margin and
4134 @var{right} controls the right margin (default @code{0}).
4135 @end defun
4137 @defun window-margins &optional window
4138 This function returns the left and right margins of @var{window}
4139 as a cons cell of the form @code{(@var{left} . @var{right})}.
4140 If @var{window} is @code{nil}, the selected window is used.
4141 @end defun
4143 @node Images
4144 @section Images
4145 @cindex images in buffers
4147   To display an image in an Emacs buffer, you must first create an image
4148 descriptor, then use it as a display specifier in the @code{display}
4149 property of text that is displayed (@pxref{Display Property}).
4151   Emacs is usually able to display images when it is run on a
4152 graphical terminal.  Images cannot be displayed in a text terminal, on
4153 certain graphical terminals that lack the support for this, or if
4154 Emacs is compiled without image support.  You can use the function
4155 @code{display-images-p} to determine if images can in principle be
4156 displayed (@pxref{Display Feature Testing}).
4158 @menu
4159 * Image Formats::       Supported image formats.
4160 * Image Descriptors::   How to specify an image for use in @code{:display}.
4161 * XBM Images::          Special features for XBM format.
4162 * XPM Images::          Special features for XPM format.
4163 * GIF Images::          Special features for GIF format.
4164 * TIFF Images::         Special features for TIFF format.
4165 * PostScript Images::   Special features for PostScript format.
4166 * ImageMagick Images::  Special features available through ImageMagick.
4167 * Other Image Types::   Various other formats are supported.
4168 * Defining Images::     Convenient ways to define an image for later use.
4169 * Showing Images::      Convenient ways to display an image once it is defined.
4170 * Animated Images::     Some image formats can be animated.
4171 * Image Cache::         Internal mechanisms of image display.
4172 @end menu
4174 @node Image Formats
4175 @subsection Image Formats
4176 @cindex image formats
4177 @cindex image types
4179   Emacs can display a number of different image formats; some of them
4180 are supported only if particular support libraries are installed on
4181 your machine.  In some environments, Emacs can load support libraries
4182 on demand; if so, the variable @code{dynamic-library-alist}
4183 (@pxref{Dynamic Libraries}) can be used to modify the set of known
4184 names for these dynamic libraries (though it is not possible to add
4185 new image formats).  Note that image types @code{pbm} and @code{xbm}
4186 do not depend on external libraries and are always available in Emacs.
4188   The supported image formats (and the necessary library files)
4189 include XBM, XPM (@code{libXpm} and @code{libz}), GIF (@code{libgif}
4190 or @code{libungif}), PostScript, PBM, JPEG (@code{libjpeg}), TIFF
4191 (@code{libtiff}), PNG (@code{libpng}), and SVG (@code{librsvg}).
4193   You specify one of these formats with an image type symbol.  The image
4194 type symbols are @code{xbm}, @code{xpm}, @code{gif}, @code{postscript},
4195 @code{pbm}, @code{jpeg}, @code{tiff}, @code{png}, and @code{svg}.
4197 @defvar image-types
4198 This variable contains a list of those image type symbols that are
4199 potentially supported in the current configuration.
4200 @emph{Potentially} here means that Emacs knows about the image types,
4201 not necessarily that they can be loaded (they could depend on
4202 unavailable dynamic libraries, for example).
4204 To know which image types are really available, use
4205 @code{image-type-available-p}.
4206 @end defvar
4208 @defun image-type-available-p type
4209 This function returns non-@code{nil} if image type @var{type} is
4210 available, i.e., if images of this type can be loaded and displayed in
4211 Emacs.  @var{type} should be one of the types contained in
4212 @code{image-types}.
4214 For image types whose support libraries are statically linked, this
4215 function always returns @code{t}; for other image types, it returns
4216 @code{t} if the dynamic library could be loaded, @code{nil} otherwise.
4217 @end defun
4219 @node Image Descriptors
4220 @subsection Image Descriptors
4221 @cindex image descriptor
4223   An image description is a list of the form @code{(image . @var{props})},
4224 where @var{props} is a property list containing alternating keyword
4225 symbols (symbols whose names start with a colon) and their values.
4226 You can use any Lisp object as a property, but the only properties
4227 that have any special meaning are certain symbols, all of them keywords.
4229   Every image descriptor must contain the property @code{:type
4230 @var{type}} to specify the format of the image.  The value of @var{type}
4231 should be an image type symbol; for example, @code{xpm} for an image in
4232 XPM format.
4234   Here is a list of other properties that are meaningful for all image
4235 types:
4237 @table @code
4238 @item :file @var{file}
4239 The @code{:file} property says to load the image from file
4240 @var{file}.  If @var{file} is not an absolute file name, it is expanded
4241 in @code{data-directory}.
4243 @item :data @var{data}
4244 The @code{:data} property says the actual contents of the image.
4245 Each image must use either @code{:data} or @code{:file}, but not both.
4246 For most image types, the value of the @code{:data} property should be a
4247 string containing the image data; we recommend using a unibyte string.
4249 Before using @code{:data}, look for further information in the section
4250 below describing the specific image format.  For some image types,
4251 @code{:data} may not be supported; for some, it allows other data types;
4252 for some, @code{:data} alone is not enough, so you need to use other
4253 image properties along with @code{:data}.
4255 @item :margin @var{margin}
4256 The @code{:margin} property specifies how many pixels to add as an
4257 extra margin around the image.  The value, @var{margin}, must be a
4258 non-negative number, or a pair @code{(@var{x} . @var{y})} of such
4259 numbers.  If it is a pair, @var{x} specifies how many pixels to add
4260 horizontally, and @var{y} specifies how many pixels to add vertically.
4261 If @code{:margin} is not specified, the default is zero.
4263 @item :ascent @var{ascent}
4264 The @code{:ascent} property specifies the amount of the image's
4265 height to use for its ascent---that is, the part above the baseline.
4266 The value, @var{ascent}, must be a number in the range 0 to 100, or
4267 the symbol @code{center}.
4269 If @var{ascent} is a number, that percentage of the image's height is
4270 used for its ascent.
4272 If @var{ascent} is @code{center}, the image is vertically centered
4273 around a centerline which would be the vertical centerline of text drawn
4274 at the position of the image, in the manner specified by the text
4275 properties and overlays that apply to the image.
4277 If this property is omitted, it defaults to 50.
4279 @item :relief @var{relief}
4280 The @code{:relief} property, if non-@code{nil}, adds a shadow rectangle
4281 around the image.  The value, @var{relief}, specifies the width of the
4282 shadow lines, in pixels.  If @var{relief} is negative, shadows are drawn
4283 so that the image appears as a pressed button; otherwise, it appears as
4284 an unpressed button.
4286 @item :conversion @var{algorithm}
4287 The @code{:conversion} property, if non-@code{nil}, specifies a
4288 conversion algorithm that should be applied to the image before it is
4289 displayed; the value, @var{algorithm}, specifies which algorithm.
4291 @table @code
4292 @item laplace
4293 @itemx emboss
4294 Specifies the Laplace edge detection algorithm, which blurs out small
4295 differences in color while highlighting larger differences.  People
4296 sometimes consider this useful for displaying the image for a
4297 ``disabled'' button.
4299 @item (edge-detection :matrix @var{matrix} :color-adjust @var{adjust})
4300 Specifies a general edge-detection algorithm.  @var{matrix} must be
4301 either a nine-element list or a nine-element vector of numbers.  A pixel
4302 at position @math{x/y} in the transformed image is computed from
4303 original pixels around that position.  @var{matrix} specifies, for each
4304 pixel in the neighborhood of @math{x/y}, a factor with which that pixel
4305 will influence the transformed pixel; element @math{0} specifies the
4306 factor for the pixel at @math{x-1/y-1}, element @math{1} the factor for
4307 the pixel at @math{x/y-1} etc., as shown below:
4308 @iftex
4309 @tex
4310 $$\pmatrix{x-1/y-1 & x/y-1  & x+1/y-1 \cr
4311    x-1/y  &   x/y &    x+1/y \cr
4312    x-1/y+1&   x/y+1 &  x+1/y+1 \cr}$$
4313 @end tex
4314 @end iftex
4315 @ifnottex
4316 @display
4317   (x-1/y-1  x/y-1  x+1/y-1
4318    x-1/y    x/y    x+1/y
4319    x-1/y+1  x/y+1  x+1/y+1)
4320 @end display
4321 @end ifnottex
4323 The resulting pixel is computed from the color intensity of the color
4324 resulting from summing up the RGB values of surrounding pixels,
4325 multiplied by the specified factors, and dividing that sum by the sum
4326 of the factors' absolute values.
4328 Laplace edge-detection currently uses a matrix of
4329 @iftex
4330 @tex
4331 $$\pmatrix{1 & 0 & 0 \cr
4332    0&  0 &  0 \cr
4333    0 & 0 & -1 \cr}$$
4334 @end tex
4335 @end iftex
4336 @ifnottex
4337 @display
4338   (1  0  0
4339    0  0  0
4340    0  0 -1)
4341 @end display
4342 @end ifnottex
4344 Emboss edge-detection uses a matrix of
4345 @iftex
4346 @tex
4347 $$\pmatrix{ 2 & -1 &  0 \cr
4348    -1 &  0 &  1 \cr
4349     0  & 1 & -2 \cr}$$
4350 @end tex
4351 @end iftex
4352 @ifnottex
4353 @display
4354   ( 2 -1  0
4355    -1  0  1
4356     0  1 -2)
4357 @end display
4358 @end ifnottex
4360 @item disabled
4361 Specifies transforming the image so that it looks ``disabled.''
4362 @end table
4364 @item :mask @var{mask}
4365 If @var{mask} is @code{heuristic} or @code{(heuristic @var{bg})}, build
4366 a clipping mask for the image, so that the background of a frame is
4367 visible behind the image.  If @var{bg} is not specified, or if @var{bg}
4368 is @code{t}, determine the background color of the image by looking at
4369 the four corners of the image, assuming the most frequently occurring
4370 color from the corners is the background color of the image.  Otherwise,
4371 @var{bg} must be a list @code{(@var{red} @var{green} @var{blue})}
4372 specifying the color to assume for the background of the image.
4374 If @var{mask} is @code{nil}, remove a mask from the image, if it has
4375 one.  Images in some formats include a mask which can be removed by
4376 specifying @code{:mask nil}.
4378 @item :pointer @var{shape}
4379 This specifies the pointer shape when the mouse pointer is over this
4380 image.  @xref{Pointer Shape}, for available pointer shapes.
4382 @item :map @var{map}
4383 This associates an image map of @dfn{hot spots} with this image.
4385 An image map is an alist where each element has the format
4386 @code{(@var{area} @var{id} @var{plist})}.  An @var{area} is specified
4387 as either a rectangle, a circle, or a polygon.
4389 A rectangle is a cons
4390 @code{(rect . ((@var{x0} . @var{y0}) . (@var{x1} . @var{y1})))}
4391 which specifies the pixel coordinates of the upper left and bottom right
4392 corners of the rectangle area.
4394 A circle is a cons
4395 @code{(circle . ((@var{x0} . @var{y0}) . @var{r}))}
4396 which specifies the center and the radius of the circle; @var{r} may
4397 be a float or integer.
4399 A polygon is a cons
4400 @code{(poly . [@var{x0} @var{y0} @var{x1} @var{y1} ...])}
4401 where each pair in the vector describes one corner in the polygon.
4403 When the mouse pointer lies on a hot-spot area of an image, the
4404 @var{plist} of that hot-spot is consulted; if it contains a @code{help-echo}
4405 property, that defines a tool-tip for the hot-spot, and if it contains
4406 a @code{pointer} property, that defines the shape of the mouse cursor when
4407 it is on the hot-spot.
4408 @xref{Pointer Shape}, for available pointer shapes.
4410 When you click the mouse when the mouse pointer is over a hot-spot, an
4411 event is composed by combining the @var{id} of the hot-spot with the
4412 mouse event; for instance, @code{[area4 mouse-1]} if the hot-spot's
4413 @var{id} is @code{area4}.
4414 @end table
4416 @defun image-mask-p spec &optional frame
4417 This function returns @code{t} if image @var{spec} has a mask bitmap.
4418 @var{frame} is the frame on which the image will be displayed.
4419 @var{frame} @code{nil} or omitted means to use the selected frame
4420 (@pxref{Input Focus}).
4421 @end defun
4423 @node XBM Images
4424 @subsection XBM Images
4425 @cindex XBM
4427   To use XBM format, specify @code{xbm} as the image type.  This image
4428 format doesn't require an external library, so images of this type are
4429 always supported.
4431   Additional image properties supported for the @code{xbm} image type are:
4433 @table @code
4434 @item :foreground @var{foreground}
4435 The value, @var{foreground}, should be a string specifying the image
4436 foreground color, or @code{nil} for the default color.  This color is
4437 used for each pixel in the XBM that is 1.  The default is the frame's
4438 foreground color.
4440 @item :background @var{background}
4441 The value, @var{background}, should be a string specifying the image
4442 background color, or @code{nil} for the default color.  This color is
4443 used for each pixel in the XBM that is 0.  The default is the frame's
4444 background color.
4445 @end table
4447   If you specify an XBM image using data within Emacs instead of an
4448 external file, use the following three properties:
4450 @table @code
4451 @item :data @var{data}
4452 The value, @var{data}, specifies the contents of the image.
4453 There are three formats you can use for @var{data}:
4455 @itemize @bullet
4456 @item
4457 A vector of strings or bool-vectors, each specifying one line of the
4458 image.  Do specify @code{:height} and @code{:width}.
4460 @item
4461 A string containing the same byte sequence as an XBM file would contain.
4462 You must not specify @code{:height} and @code{:width} in this case,
4463 because omitting them is what indicates the data has the format of an
4464 XBM file.  The file contents specify the height and width of the image.
4466 @item
4467 A string or a bool-vector containing the bits of the image (plus perhaps
4468 some extra bits at the end that will not be used).  It should contain at
4469 least @var{width} * @code{height} bits.  In this case, you must specify
4470 @code{:height} and @code{:width}, both to indicate that the string
4471 contains just the bits rather than a whole XBM file, and to specify the
4472 size of the image.
4473 @end itemize
4475 @item :width @var{width}
4476 The value, @var{width}, specifies the width of the image, in pixels.
4478 @item :height @var{height}
4479 The value, @var{height}, specifies the height of the image, in pixels.
4480 @end table
4482 @node XPM Images
4483 @subsection XPM Images
4484 @cindex XPM
4486   To use XPM format, specify @code{xpm} as the image type.  The
4487 additional image property @code{:color-symbols} is also meaningful with
4488 the @code{xpm} image type:
4490 @table @code
4491 @item :color-symbols @var{symbols}
4492 The value, @var{symbols}, should be an alist whose elements have the
4493 form @code{(@var{name} . @var{color})}.  In each element, @var{name} is
4494 the name of a color as it appears in the image file, and @var{color}
4495 specifies the actual color to use for displaying that name.
4496 @end table
4498 @node GIF Images
4499 @subsection GIF Images
4500 @cindex GIF
4502   For GIF images, specify image type @code{gif}.
4504 @table @code
4505 @item :index @var{index}
4506 You can use @code{:index} to specify image number @var{index} from a
4507 GIF file that contains more than one image.  If the GIF file doesn't
4508 contain an image with the specified index, the image displays as a
4509 hollow box.  GIF files with more than one image can be animated,
4510 @pxref{Animated Images}.
4511 @end table
4513 @node TIFF Images
4514 @subsection TIFF Images
4515 @cindex TIFF
4517   For TIFF images, specify image type @code{tiff}.
4519 @table @code
4520 @item :index @var{index}
4521 You can use @code{:index} to specify image number @var{index} from a
4522 TIFF file that contains more than one image.  If the TIFF file doesn't
4523 contain an image with the specified index, the image displays as a
4524 hollow box.
4525 @end table
4527 @node PostScript Images
4528 @subsection PostScript Images
4529 @cindex postscript images
4531   To use PostScript for an image, specify image type @code{postscript}.
4532 This works only if you have Ghostscript installed.  You must always use
4533 these three properties:
4535 @table @code
4536 @item :pt-width @var{width}
4537 The value, @var{width}, specifies the width of the image measured in
4538 points (1/72 inch).  @var{width} must be an integer.
4540 @item :pt-height @var{height}
4541 The value, @var{height}, specifies the height of the image in points
4542 (1/72 inch).  @var{height} must be an integer.
4544 @item :bounding-box @var{box}
4545 The value, @var{box}, must be a list or vector of four integers, which
4546 specifying the bounding box of the PostScript image, analogous to the
4547 @samp{BoundingBox} comment found in PostScript files.
4549 @example
4550 %%BoundingBox: 22 171 567 738
4551 @end example
4552 @end table
4554 @node ImageMagick Images
4555 @subsection ImageMagick Images
4556 @cindex ImageMagick images
4557 @cindex images, support for more formats
4559   If you build Emacs with ImageMagick (@url{http://www.imagemagick.org})
4560 support, you can use the ImageMagick library to load many image formats.
4562 @findex imagemagick-types
4563 @findex imagemagick-register-types
4564 The function @code{imagemagick-types} returns a list of image file
4565 extensions that your installation of ImageMagick supports.  To enable
4566 support, you must call the function @code{imagemagick-register-types}.
4567 This enables Emacs to visit these file types in @code{image-mode}
4568 (@pxref{File Conveniences,,, emacs, The GNU Emacs Manual}).
4569 If your Emacs was not compiled with ImageMagick support, then
4570 @code{imagemagick-types} will be undefined and
4571 @code{imagemagick-register-types} will do nothing.
4573 @vindex imagemagick-types-inhibit
4574 The variable @code{imagemagick-types-inhibit} specifies a list of
4575 image types that you do @emph{not} want ImageMagick to handle.  It is
4576 a list of symbols, each of which has the same name as one of the
4577 format tags used internally by ImageMagick (i.e., as
4578 @code{imagemagick-types} returns).  ImageMagick has a very broad
4579 definition of what an image is, for example it includes such file
4580 types as C files and HTML files.  It is not appropriate to treat these
4581 as images in Emacs.  You can add any other ImageMagick type that you
4582 wish to this list.
4583 @ignore
4584 @c I don't know what this means.  I suspect it means eg loading jpg
4585 @c images via libjpeg or ImageMagick.  But it doesn't work.
4586 @c If you don't have libjpeg support compiled in, you cannot
4587 @c view jpeg images, even if you have imagemagick support:
4588 @c http://debbugs.gnu.org/9045
4589 @c And if you have both compiled in, then you always get
4590 @c the libjpeg version:
4591 @c http://debbugs.gnu.org/10746
4592 There may be overlap between image loaders in your Emacs installation,
4593 and you may prefer to use a different one for a given image type
4594 (which loader will be used in practice depends on the priority of the
4595 loaders).  
4596 For example, if you never want to use the ImageMagick loader to view
4597 JPEG files, add @code{JPG} to this list.
4598 @end ignore
4599 Note that ImageMagick often distinguishes between several different
4600 types of a particular format (e.g., @code{JPG}, @code{JPEG},
4601 @code{PJPEG}, etc.), and you may need to add all versions to this
4602 list.
4604 @c Not sure this should even be in the manual at all.
4605 @vindex imagemagick-render-type
4606 If you wish to experiment with the performance of the ImageMagick
4607 loader, see the variable @code{imagemagick-render-type}.
4609 Images loaded with ImageMagick support a few new display specifications:
4611 @table @code
4612 @item :width, :height
4613 The @code{:width} and @code{:height} keywords are used for scaling the
4614 image.  If only one of them is specified, the other one will be
4615 calculated so as to preserve the aspect ratio.  If both are specified,
4616 aspect ratio may not be preserved.
4618 @item :rotation
4619 Specifies a rotation angle in degrees.
4621 @item :index
4622 @c Doesn't work: http://debbugs.gnu.org/7978
4623 This has the same meaning as it does for GIF images (@pxref{GIF Images}),
4624 i.e. it specifies which image to view inside an image bundle file format
4625 such as DJVM.  You can use the @code{image-metadata} function to
4626 retrieve the total number of images in an image bundle.
4627 @end table
4630 @node Other Image Types
4631 @subsection Other Image Types
4632 @cindex PBM
4634   For PBM images, specify image type @code{pbm}.  Color, gray-scale and
4635 monochromatic images are supported.   For mono PBM images, two additional
4636 image properties are supported.
4638 @table @code
4639 @item :foreground @var{foreground}
4640 The value, @var{foreground}, should be a string specifying the image
4641 foreground color, or @code{nil} for the default color.  This color is
4642 used for each pixel in the PBM that is 1.  The default is the frame's
4643 foreground color.
4645 @item :background @var{background}
4646 The value, @var{background}, should be a string specifying the image
4647 background color, or @code{nil} for the default color.  This color is
4648 used for each pixel in the PBM that is 0.  The default is the frame's
4649 background color.
4650 @end table
4652   For JPEG images, specify image type @code{jpeg}.
4654   For TIFF images, specify image type @code{tiff}.
4656   For PNG images, specify image type @code{png}.
4658   For SVG images, specify image type @code{svg}.
4660 @node Defining Images
4661 @subsection Defining Images
4663   The functions @code{create-image}, @code{defimage} and
4664 @code{find-image} provide convenient ways to create image descriptors.
4666 @defun create-image file-or-data &optional type data-p &rest props
4667 This function creates and returns an image descriptor which uses the
4668 data in @var{file-or-data}.  @var{file-or-data} can be a file name or
4669 a string containing the image data; @var{data-p} should be @code{nil}
4670 for the former case, non-@code{nil} for the latter case.
4672 The optional argument @var{type} is a symbol specifying the image type.
4673 If @var{type} is omitted or @code{nil}, @code{create-image} tries to
4674 determine the image type from the file's first few bytes, or else
4675 from the file's name.
4677 The remaining arguments, @var{props}, specify additional image
4678 properties---for example,
4680 @example
4681 (create-image "foo.xpm" 'xpm nil :heuristic-mask t)
4682 @end example
4684 The function returns @code{nil} if images of this type are not
4685 supported.  Otherwise it returns an image descriptor.
4686 @end defun
4688 @defmac defimage symbol specs &optional doc
4689 This macro defines @var{symbol} as an image name.  The arguments
4690 @var{specs} is a list which specifies how to display the image.
4691 The third argument, @var{doc}, is an optional documentation string.
4693 Each argument in @var{specs} has the form of a property list, and each
4694 one should specify at least the @code{:type} property and either the
4695 @code{:file} or the @code{:data} property.  The value of @code{:type}
4696 should be a symbol specifying the image type, the value of
4697 @code{:file} is the file to load the image from, and the value of
4698 @code{:data} is a string containing the actual image data.  Here is an
4699 example:
4701 @example
4702 (defimage test-image
4703   ((:type xpm :file "~/test1.xpm")
4704    (:type xbm :file "~/test1.xbm")))
4705 @end example
4707 @code{defimage} tests each argument, one by one, to see if it is
4708 usable---that is, if the type is supported and the file exists.  The
4709 first usable argument is used to make an image descriptor which is
4710 stored in @var{symbol}.
4712 If none of the alternatives will work, then @var{symbol} is defined
4713 as @code{nil}.
4714 @end defmac
4716 @defun find-image specs
4717 This function provides a convenient way to find an image satisfying one
4718 of a list of image specifications @var{specs}.
4720 Each specification in @var{specs} is a property list with contents
4721 depending on image type.  All specifications must at least contain the
4722 properties @code{:type @var{type}} and either @w{@code{:file @var{file}}}
4723 or @w{@code{:data @var{DATA}}}, where @var{type} is a symbol specifying
4724 the image type, e.g.@: @code{xbm}, @var{file} is the file to load the
4725 image from, and @var{data} is a string containing the actual image data.
4726 The first specification in the list whose @var{type} is supported, and
4727 @var{file} exists, is used to construct the image specification to be
4728 returned.  If no specification is satisfied, @code{nil} is returned.
4730 The image is looked for in @code{image-load-path}.
4731 @end defun
4733 @defvar image-load-path
4734 This variable's value is a list of locations in which to search for
4735 image files.  If an element is a string or a variable symbol whose
4736 value is a string, the string is taken to be the name of a directory
4737 to search.  If an element is a variable symbol whose value is a list,
4738 that is taken to be a list of directory names to search.
4740 The default is to search in the @file{images} subdirectory of the
4741 directory specified by @code{data-directory}, then the directory
4742 specified by @code{data-directory}, and finally in the directories in
4743 @code{load-path}.  Subdirectories are not automatically included in
4744 the search, so if you put an image file in a subdirectory, you have to
4745 supply the subdirectory name explicitly.  For example, to find the
4746 image @file{images/foo/bar.xpm} within @code{data-directory}, you
4747 should specify the image as follows:
4749 @example
4750 (defimage foo-image '((:type xpm :file "foo/bar.xpm")))
4751 @end example
4752 @end defvar
4754 @defun image-load-path-for-library library image &optional path no-error
4755 This function returns a suitable search path for images used by the
4756 Lisp package @var{library}.
4758 The function searches for @var{image} first using @code{image-load-path},
4759 excluding @file{@code{data-directory}/images}, and then in
4760 @code{load-path}, followed by a path suitable for @var{library}, which
4761 includes @file{../../etc/images} and @file{../etc/images} relative to
4762 the library file itself, and finally in
4763 @file{@code{data-directory}/images}.
4765 Then this function returns a list of directories which contains first
4766 the directory in which @var{image} was found, followed by the value of
4767 @code{load-path}.  If @var{path} is given, it is used instead of
4768 @code{load-path}.
4770 If @var{no-error} is non-@code{nil} and a suitable path can't be
4771 found, don't signal an error.  Instead, return a list of directories as
4772 before, except that @code{nil} appears in place of the image directory.
4774 Here is an example of using @code{image-load-path-for-library}:
4776 @example
4777 (defvar image-load-path) ; shush compiler
4778 (let* ((load-path (image-load-path-for-library
4779                     "mh-e" "mh-logo.xpm"))
4780        (image-load-path (cons (car load-path)
4781                               image-load-path)))
4782   (mh-tool-bar-folder-buttons-init))
4783 @end example
4784 @end defun
4786 @node Showing Images
4787 @subsection Showing Images
4789   You can use an image descriptor by setting up the @code{display}
4790 property yourself, but it is easier to use the functions in this
4791 section.
4793 @defun insert-image image &optional string area slice
4794 This function inserts @var{image} in the current buffer at point.  The
4795 value @var{image} should be an image descriptor; it could be a value
4796 returned by @code{create-image}, or the value of a symbol defined with
4797 @code{defimage}.  The argument @var{string} specifies the text to put
4798 in the buffer to hold the image.  If it is omitted or @code{nil},
4799 @code{insert-image} uses @code{" "} by default.
4801 The argument @var{area} specifies whether to put the image in a margin.
4802 If it is @code{left-margin}, the image appears in the left margin;
4803 @code{right-margin} specifies the right margin.  If @var{area} is
4804 @code{nil} or omitted, the image is displayed at point within the
4805 buffer's text.
4807 The argument @var{slice} specifies a slice of the image to insert.  If
4808 @var{slice} is @code{nil} or omitted the whole image is inserted.
4809 Otherwise, @var{slice} is a list @code{(@var{x} @var{y} @var{width}
4810 @var{height})} which specifies the @var{x} and @var{y} positions and
4811 @var{width} and @var{height} of the image area to insert.  Integer
4812 values are in units of pixels.  A floating point number in the range
4813 0.0--1.0 stands for that fraction of the width or height of the entire
4814 image.
4816 Internally, this function inserts @var{string} in the buffer, and gives
4817 it a @code{display} property which specifies @var{image}.  @xref{Display
4818 Property}.
4819 @end defun
4821 @cindex slice, image
4822 @cindex image slice
4823 @defun insert-sliced-image image &optional string area rows cols
4824 This function inserts @var{image} in the current buffer at point, like
4825 @code{insert-image}, but splits the image into @var{rows}x@var{cols}
4826 equally sized slices.
4828 If an image is inserted ``sliced'', then the Emacs display engine will
4829 treat each slice as a separate image, and allow more intuitive
4830 scrolling up/down, instead of jumping up/down the entire image when
4831 paging through a buffer that displays (large) images.
4832 @end defun
4834 @defun put-image image pos &optional string area
4835 This function puts image @var{image} in front of @var{pos} in the
4836 current buffer.  The argument @var{pos} should be an integer or a
4837 marker.  It specifies the buffer position where the image should appear.
4838 The argument @var{string} specifies the text that should hold the image
4839 as an alternative to the default.
4841 The argument @var{image} must be an image descriptor, perhaps returned
4842 by @code{create-image} or stored by @code{defimage}.
4844 The argument @var{area} specifies whether to put the image in a margin.
4845 If it is @code{left-margin}, the image appears in the left margin;
4846 @code{right-margin} specifies the right margin.  If @var{area} is
4847 @code{nil} or omitted, the image is displayed at point within the
4848 buffer's text.
4850 Internally, this function creates an overlay, and gives it a
4851 @code{before-string} property containing text that has a @code{display}
4852 property whose value is the image.  (Whew!)
4853 @end defun
4855 @defun remove-images start end &optional buffer
4856 This function removes images in @var{buffer} between positions
4857 @var{start} and @var{end}.  If @var{buffer} is omitted or @code{nil},
4858 images are removed from the current buffer.
4860 This removes only images that were put into @var{buffer} the way
4861 @code{put-image} does it, not images that were inserted with
4862 @code{insert-image} or in other ways.
4863 @end defun
4865 @defun image-size spec &optional pixels frame
4866 This function returns the size of an image as a pair
4867 @w{@code{(@var{width} . @var{height})}}.  @var{spec} is an image
4868 specification.  @var{pixels} non-@code{nil} means return sizes
4869 measured in pixels, otherwise return sizes measured in canonical
4870 character units (fractions of the width/height of the frame's default
4871 font).  @var{frame} is the frame on which the image will be displayed.
4872 @var{frame} null or omitted means use the selected frame (@pxref{Input
4873 Focus}).
4874 @end defun
4876 @defvar max-image-size
4877 This variable is used to define the maximum size of image that Emacs
4878 will load.  Emacs will refuse to load (and display) any image that is
4879 larger than this limit.
4881 If the value is an integer, it directly specifies the maximum
4882 image height and width, measured in pixels.  If it is a floating
4883 point number, it specifies the maximum image height and width
4884 as a ratio to the frame height and width.  If the value is
4885 non-numeric, there is no explicit limit on the size of images.
4887 The purpose of this variable is to prevent unreasonably large images
4888 from accidentally being loaded into Emacs.  It only takes effect the
4889 first time an image is loaded.  Once an image is placed in the image
4890 cache, it can always be displayed, even if the value of
4891 @var{max-image-size} is subsequently changed (@pxref{Image Cache}).
4892 @end defvar
4894 @node Animated Images
4895 @subsection Animated Images
4897 @cindex animation
4898 @cindex image animation
4899 Some image files can contain more than one image.  This can be used to
4900 create animation.  Currently, Emacs only supports animated GIF files.
4901 The following functions related to animated images are available.
4903 @defun image-animated-p image
4904 This function returns non-nil if @var{image} can be animated.
4905 The actual return value is a cons @code{(@var{nimages} . @var{delay})}, 
4906 where @var{nimages} is the number of frames and @var{delay} is the
4907 delay in seconds between them.
4908 @end defun
4910 @defun image-animate image &optional index limit
4911 This function animates @var{image}.  The optional integer @var{index}
4912 specifies the frame from which to start (default 0).  The optional
4913 argument @var{limit} controls the length of the animation.  If omitted
4914 or @code{nil}, the image animates once only; if @code{t} it loops
4915 forever; if a number animation stops after that many seconds.
4916 @end defun
4918 @noindent Animation operates by means of a timer.  Note that Emacs imposes a
4919 minimum frame delay of 0.01 seconds.
4921 @defun image-animate-timer image
4922 This function returns the timer responsible for animating @var{image},
4923 if there is one.
4924 @end defun
4927 @node Image Cache
4928 @subsection Image Cache
4929 @cindex image cache
4931   Emacs caches images so that it can display them again more
4932 efficiently.  When Emacs displays an image, it searches the image
4933 cache for an existing image specification @code{equal} to the desired
4934 specification.  If a match is found, the image is displayed from the
4935 cache.  Otherwise, Emacs loads the image normally.
4937 @defun image-flush spec &optional frame
4938 This function removes the image with specification @var{spec} from the
4939 image cache of frame @var{frame}.  Image specifications are compared
4940 using @code{equal}.  If @var{frame} is @code{nil}, it defaults to the
4941 selected frame.  If @var{frame} is @code{t}, the image is flushed on
4942 all existing frames.
4944 In Emacs's current implementation, each graphical terminal possesses an
4945 image cache, which is shared by all the frames on that terminal
4946 (@pxref{Multiple Terminals}).  Thus, refreshing an image in one frame
4947 also refreshes it in all other frames on the same terminal.
4948 @end defun
4950   One use for @code{image-flush} is to tell Emacs about a change in an
4951 image file.  If an image specification contains a @code{:file}
4952 property, the image is cached based on the file's contents when the
4953 image is first displayed.  Even if the file subsequently changes,
4954 Emacs continues displaying the old version of the image.  Calling
4955 @code{image-flush} flushes the image from the cache, forcing Emacs to
4956 re-read the file the next time it needs to display that image.
4958   Another use for @code{image-flush} is for memory conservation.  If
4959 your Lisp program creates a large number of temporary images over a
4960 period much shorter than @code{image-cache-eviction-delay} (see
4961 below), you can opt to flush unused images yourself, instead of
4962 waiting for Emacs to do it automatically.
4964 @defun clear-image-cache &optional filter
4965 This function clears an image cache, removing all the images stored in
4966 it.  If @var{filter} is omitted or @code{nil}, it clears the cache for
4967 the selected frame.  If @var{filter} is a frame, it clears the cache
4968 for that frame.  If @var{filter} is @code{t}, all image caches are
4969 cleared.  Otherwise, @var{filter} is taken to be a file name, and all
4970 images associated with that file name are removed from all image
4971 caches.
4972 @end defun
4974 If an image in the image cache has not been displayed for a specified
4975 period of time, Emacs removes it from the cache and frees the
4976 associated memory.
4978 @defvar image-cache-eviction-delay
4979 This variable specifies the number of seconds an image can remain in
4980 the cache without being displayed.  When an image is not displayed for
4981 this length of time, Emacs removes it from the image cache.
4983 Under some circumstances, if the number of images in the cache grows
4984 too large, the actual eviction delay may be shorter than this.
4986 If the value is @code{nil}, Emacs does not remove images from the cache
4987 except when you explicitly clear it.  This mode can be useful for
4988 debugging.
4989 @end defvar
4991 @node Buttons
4992 @section Buttons
4993 @cindex buttons in buffers
4994 @cindex clickable buttons in buffers
4996   The @emph{button} package defines functions for inserting and
4997 manipulating clickable (with the mouse, or via keyboard commands)
4998 buttons in Emacs buffers, such as might be used for help hyper-links,
4999 etc.  Emacs uses buttons for the hyper-links in help text and the like.
5001   A button is essentially a set of properties attached (via text
5002 properties or overlays) to a region of text in an Emacs buffer.  These
5003 properties are called @dfn{button properties}.
5005   One of these properties (@code{action}) is a function, which will
5006 be called when the user invokes it using the keyboard or the mouse.
5007 The invoked function may then examine the button and use its other
5008 properties as desired.
5010   In some ways the Emacs button package duplicates functionality offered
5011 by the widget package (@pxref{Top, , Introduction, widget, The Emacs
5012 Widget Library}), but the button package has the advantage that it is
5013 much faster, much smaller, and much simpler to use (for elisp
5014 programmers---for users, the result is about the same).  The extra
5015 speed and space savings are useful mainly if you need to create many
5016 buttons in a buffer (for instance an @code{*Apropos*} buffer uses
5017 buttons to make entries clickable, and may contain many thousands of
5018 entries).
5020 @menu
5021 * Button Properties::      Button properties with special meanings.
5022 * Button Types::           Defining common properties for classes of buttons.
5023 * Making Buttons::         Adding buttons to Emacs buffers.
5024 * Manipulating Buttons::   Getting and setting properties of buttons.
5025 * Button Buffer Commands:: Buffer-wide commands and bindings for buttons.
5026 @end menu
5028 @node Button Properties
5029 @subsection Button Properties
5030 @cindex button properties
5032   Buttons have an associated list of properties defining their
5033 appearance and behavior, and other arbitrary properties may be used
5034 for application specific purposes.  Some properties that have special
5035 meaning to the button package include:
5037 @table @code
5038 @item action
5039 @kindex action @r{(button property)}
5040 The function to call when the user invokes the button, which is passed
5041 the single argument @var{button}.  By default this is @code{ignore},
5042 which does nothing.
5044 @item mouse-action
5045 @kindex mouse-action @r{(button property)}
5046 This is similar to @code{action}, and when present, will be used
5047 instead of @code{action} for button invocations resulting from
5048 mouse-clicks (instead of the user hitting @key{RET}).  If not
5049 present, mouse-clicks use @code{action} instead.
5051 @item face
5052 @kindex face @r{(button property)}
5053 This is an Emacs face controlling how buttons of this type are
5054 displayed; by default this is the @code{button} face.
5056 @item mouse-face
5057 @kindex mouse-face @r{(button property)}
5058 This is an additional face which controls appearance during
5059 mouse-overs (merged with the usual button face); by default this is
5060 the usual Emacs @code{highlight} face.
5062 @item keymap
5063 @kindex keymap @r{(button property)}
5064 The button's keymap, defining bindings active within the button
5065 region.  By default this is the usual button region keymap, stored
5066 in the variable @code{button-map}, which defines @key{RET} and
5067 @key{mouse-2} to invoke the button.
5069 @item type
5070 @kindex type @r{(button property)}
5071 The button-type of the button.  When creating a button, this is
5072 usually specified using the @code{:type} keyword argument.
5073 @xref{Button Types}.
5075 @item help-echo
5076 @kindex help-index @r{(button property)}
5077 A string displayed by the Emacs tool-tip help system; by default,
5078 @code{"mouse-2, RET: Push this button"}.
5080 @item follow-link
5081 @kindex follow-link @r{(button property)}
5082 The follow-link property, defining how a @key{Mouse-1} click behaves
5083 on this button, @xref{Clickable Text}.
5085 @item button
5086 @kindex button @r{(button property)}
5087 All buttons have a non-@code{nil} @code{button} property, which may be useful
5088 in finding regions of text that comprise buttons (which is what the
5089 standard button functions do).
5090 @end table
5092   There are other properties defined for the regions of text in a
5093 button, but these are not generally interesting for typical uses.
5095 @node Button Types
5096 @subsection Button Types
5097 @cindex button types
5099   Every button has a button @emph{type}, which defines default values
5100 for the button's properties.  Button types are arranged in a
5101 hierarchy, with specialized types inheriting from more general types,
5102 so that it's easy to define special-purpose types of buttons for
5103 specific tasks.
5105 @defun define-button-type name &rest properties
5106 Define a `button type' called @var{name} (a symbol).
5107 The remaining arguments
5108 form a sequence of @var{property value} pairs, specifying default
5109 property values for buttons with this type (a button's type may be set
5110 by giving it a @code{type} property when creating the button, using
5111 the @code{:type} keyword argument).
5113 In addition, the keyword argument @code{:supertype} may be used to
5114 specify a button-type from which @var{name} inherits its default
5115 property values.  Note that this inheritance happens only when
5116 @var{name} is defined; subsequent changes to a supertype are not
5117 reflected in its subtypes.
5118 @end defun
5120   Using @code{define-button-type} to define default properties for
5121 buttons is not necessary---buttons without any specified type use the
5122 built-in button-type @code{button}---but it is encouraged, since
5123 doing so usually makes the resulting code clearer and more efficient.
5125 @node Making Buttons
5126 @subsection Making Buttons
5127 @cindex making buttons
5129   Buttons are associated with a region of text, using an overlay or
5130 text properties to hold button-specific information, all of which are
5131 initialized from the button's type (which defaults to the built-in
5132 button type @code{button}).  Like all Emacs text, the appearance of
5133 the button is governed by the @code{face} property; by default (via
5134 the @code{face} property inherited from the @code{button} button-type)
5135 this is a simple underline, like a typical web-page link.
5137   For convenience, there are two sorts of button-creation functions,
5138 those that add button properties to an existing region of a buffer,
5139 called @code{make-...button}, and those that also insert the button
5140 text, called @code{insert-...button}.
5142   The button-creation functions all take the @code{&rest} argument
5143 @var{properties}, which should be a sequence of @var{property value}
5144 pairs, specifying properties to add to the button; see @ref{Button
5145 Properties}.  In addition, the keyword argument @code{:type} may be
5146 used to specify a button-type from which to inherit other properties;
5147 see @ref{Button Types}.  Any properties not explicitly specified
5148 during creation will be inherited from the button's type (if the type
5149 defines such a property).
5151   The following functions add a button using an overlay
5152 (@pxref{Overlays}) to hold the button properties:
5154 @defun make-button beg end &rest properties
5155 This makes a button from @var{beg} to @var{end} in the
5156 current buffer, and returns it.
5157 @end defun
5159 @defun insert-button label &rest properties
5160 This insert a button with the label @var{label} at point,
5161 and returns it.
5162 @end defun
5164   The following functions are similar, but use Emacs text properties
5165 (@pxref{Text Properties}) to hold the button properties, making the
5166 button actually part of the text instead of being a property of the
5167 buffer.  Buttons using text properties do not create markers into the
5168 buffer, which is important for speed when you use extremely large
5169 numbers of buttons.  (However, if there is an existing face text
5170 property at the site of the button, the button face may not be visible.)
5171 Both functions return the position of the start of the new button:
5173 @defun make-text-button beg end &rest properties
5174 This makes a button from @var{beg} to @var{end} in the current buffer, using
5175 text properties.
5176 @end defun
5178 @defun insert-text-button label &rest properties
5179 This inserts a button with the label @var{label} at point, using text
5180 properties.
5181 @end defun
5183 @node Manipulating Buttons
5184 @subsection Manipulating Buttons
5185 @cindex manipulating buttons
5187 These are functions for getting and setting properties of buttons.
5188 Often these are used by a button's invocation function to determine
5189 what to do.
5191 Where a @var{button} parameter is specified, it means an object
5192 referring to a specific button, either an overlay (for overlay
5193 buttons), or a buffer-position or marker (for text property buttons).
5194 Such an object is passed as the first argument to a button's
5195 invocation function when it is invoked.
5197 @defun button-start button
5198 Return the position at which @var{button} starts.
5199 @end defun
5201 @defun button-end button
5202 Return the position at which @var{button} ends.
5203 @end defun
5205 @defun button-get button prop
5206 Get the property of button @var{button} named @var{prop}.
5207 @end defun
5209 @defun button-put button prop val
5210 Set @var{button}'s @var{prop} property to @var{val}.
5211 @end defun
5213 @defun button-activate button &optional use-mouse-action
5214 Call @var{button}'s @code{action} property (i.e., invoke it).  If
5215 @var{use-mouse-action} is non-@code{nil}, try to invoke the button's
5216 @code{mouse-action} property instead of @code{action}; if the button
5217 has no @code{mouse-action} property, use @code{action} as normal.
5218 @end defun
5220 @defun button-label button
5221 Return @var{button}'s text label.
5222 @end defun
5224 @defun button-type button
5225 Return @var{button}'s button-type.
5226 @end defun
5228 @defun button-has-type-p button type
5229 Return @code{t} if @var{button} has button-type @var{type}, or one of
5230 @var{type}'s subtypes.
5231 @end defun
5233 @defun button-at pos
5234 Return the button at position @var{pos} in the current buffer, or @code{nil}.
5235 @end defun
5237 @defun button-type-put type prop val
5238 Set the button-type @var{type}'s @var{prop} property to @var{val}.
5239 @end defun
5241 @defun button-type-get type prop
5242 Get the property of button-type @var{type} named @var{prop}.
5243 @end defun
5245 @defun button-type-subtype-p type supertype
5246 Return @code{t} if button-type @var{type} is a subtype of @var{supertype}.
5247 @end defun
5249 @node Button Buffer Commands
5250 @subsection Button Buffer Commands
5251 @cindex button buffer commands
5253 These are commands and functions for locating and operating on
5254 buttons in an Emacs buffer.
5256 @code{push-button} is the command that a user uses to actually `push'
5257 a button, and is bound by default in the button itself to @key{RET}
5258 and to @key{mouse-2} using a region-specific keymap.  Commands
5259 that are useful outside the buttons itself, such as
5260 @code{forward-button} and @code{backward-button} are additionally
5261 available in the keymap stored in @code{button-buffer-map}; a mode
5262 which uses buttons may want to use @code{button-buffer-map} as a
5263 parent keymap for its keymap.
5265 If the button has a non-@code{nil} @code{follow-link} property, and
5266 @var{mouse-1-click-follows-link} is set, a quick @key{Mouse-1} click
5267 will also activate the @code{push-button} command.
5268 @xref{Clickable Text}.
5270 @deffn Command push-button &optional pos use-mouse-action
5271 Perform the action specified by a button at location @var{pos}.
5272 @var{pos} may be either a buffer position or a mouse-event.  If
5273 @var{use-mouse-action} is non-@code{nil}, or @var{pos} is a
5274 mouse-event (@pxref{Mouse Events}), try to invoke the button's
5275 @code{mouse-action} property instead of @code{action}; if the button
5276 has no @code{mouse-action} property, use @code{action} as normal.
5277 @var{pos} defaults to point, except when @code{push-button} is invoked
5278 interactively as the result of a mouse-event, in which case, the mouse
5279 event's position is used.  If there's no button at @var{pos}, do
5280 nothing and return @code{nil}, otherwise return @code{t}.
5281 @end deffn
5283 @deffn Command forward-button n &optional wrap display-message
5284 Move to the @var{n}th next button, or @var{n}th previous button if
5285 @var{n} is negative.  If @var{n} is zero, move to the start of any
5286 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5287 end of the buffer continues from the other end.  If
5288 @var{display-message} is non-@code{nil}, the button's help-echo string
5289 is displayed.  Any button with a non-@code{nil} @code{skip} property
5290 is skipped over.  Returns the button found.
5291 @end deffn
5293 @deffn Command backward-button n &optional wrap display-message
5294 Move to the @var{n}th previous button, or @var{n}th next button if
5295 @var{n} is negative.  If @var{n} is zero, move to the start of any
5296 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5297 end of the buffer continues from the other end.  If
5298 @var{display-message} is non-@code{nil}, the button's help-echo string
5299 is displayed.  Any button with a non-@code{nil} @code{skip} property
5300 is skipped over.  Returns the button found.
5301 @end deffn
5303 @defun next-button pos &optional count-current
5304 @defunx previous-button pos &optional count-current
5305 Return the next button after (for @code{next-button} or before (for
5306 @code{previous-button}) position @var{pos} in the current buffer.  If
5307 @var{count-current} is non-@code{nil}, count any button at @var{pos}
5308 in the search, instead of starting at the next button.
5309 @end defun
5311 @node Abstract Display
5312 @section Abstract Display
5313 @cindex ewoc
5314 @cindex display, abstract
5315 @cindex display, arbitrary objects
5316 @cindex model/view/controller
5317 @cindex view part, model/view/controller
5319   The Ewoc package constructs buffer text that represents a structure
5320 of Lisp objects, and updates the text to follow changes in that
5321 structure.  This is like the ``view'' component in the
5322 ``model/view/controller'' design paradigm.
5324   An @dfn{ewoc} is a structure that organizes information required to
5325 construct buffer text that represents certain Lisp data.  The buffer
5326 text of the ewoc has three parts, in order: first, fixed @dfn{header}
5327 text; next, textual descriptions of a series of data elements (Lisp
5328 objects that you specify); and last, fixed @dfn{footer} text.
5329 Specifically, an ewoc contains information on:
5331 @itemize @bullet
5332 @item
5333 The buffer which its text is generated in.
5335 @item
5336 The text's start position in the buffer.
5338 @item
5339 The header and footer strings.
5341 @item
5342 A doubly-linked chain of @dfn{nodes}, each of which contains:
5344 @itemize
5345 @item
5346 A @dfn{data element}, a single Lisp object.
5348 @item
5349 Links to the preceding and following nodes in the chain.
5350 @end itemize
5352 @item
5353 A @dfn{pretty-printer} function which is responsible for
5354 inserting the textual representation of a data
5355 element value into the current buffer.
5356 @end itemize
5358   Typically, you define an ewoc with @code{ewoc-create}, and then pass
5359 the resulting ewoc structure to other functions in the Ewoc package to
5360 build nodes within it, and display it in the buffer.  Once it is
5361 displayed in the buffer, other functions determine the correspondence
5362 between buffer positions and nodes, move point from one node's textual
5363 representation to another, and so forth.  @xref{Abstract Display
5364 Functions}.
5366   A node @dfn{encapsulates} a data element much the way a variable
5367 holds a value.  Normally, encapsulation occurs as a part of adding a
5368 node to the ewoc.  You can retrieve the data element value and place a
5369 new value in its place, like so:
5371 @lisp
5372 (ewoc-data @var{node})
5373 @result{} value
5375 (ewoc-set-data @var{node} @var{new-value})
5376 @result{} @var{new-value}
5377 @end lisp
5379 @noindent
5380 You can also use, as the data element value, a Lisp object (list or
5381 vector) that is a container for the ``real'' value, or an index into
5382 some other structure.  The example (@pxref{Abstract Display Example})
5383 uses the latter approach.
5385   When the data changes, you will want to update the text in the
5386 buffer.  You can update all nodes by calling @code{ewoc-refresh}, or
5387 just specific nodes using @code{ewoc-invalidate}, or all nodes
5388 satisfying a predicate using @code{ewoc-map}.  Alternatively, you can
5389 delete invalid nodes using @code{ewoc-delete} or @code{ewoc-filter},
5390 and add new nodes in their place.  Deleting a node from an ewoc deletes
5391 its associated textual description from buffer, as well.
5393 @menu
5394 * Abstract Display Functions::  Functions in the Ewoc package.
5395 * Abstract Display Example::    Example of using Ewoc.
5396 @end menu
5398 @node Abstract Display Functions
5399 @subsection Abstract Display Functions
5401   In this subsection, @var{ewoc} and @var{node} stand for the
5402 structures described above (@pxref{Abstract Display}), while
5403 @var{data} stands for an arbitrary Lisp object used as a data element.
5405 @defun ewoc-create pretty-printer &optional header footer nosep
5406 This constructs and returns a new ewoc, with no nodes (and thus no data
5407 elements).  @var{pretty-printer} should be a function that takes one
5408 argument, a data element of the sort you plan to use in this ewoc, and
5409 inserts its textual description at point using @code{insert} (and never
5410 @code{insert-before-markers}, because that would interfere with the
5411 Ewoc package's internal mechanisms).
5413 Normally, a newline is automatically inserted after the header,
5414 the footer and every node's textual description.  If @var{nosep}
5415 is non-@code{nil}, no newline is inserted.  This may be useful for
5416 displaying an entire ewoc on a single line, for example, or for
5417 making nodes ``invisible'' by arranging for @var{pretty-printer}
5418 to do nothing for those nodes.
5420 An ewoc maintains its text in the buffer that is current when
5421 you create it, so switch to the intended buffer before calling
5422 @code{ewoc-create}.
5423 @end defun
5425 @defun ewoc-buffer ewoc
5426 This returns the buffer where @var{ewoc} maintains its text.
5427 @end defun
5429 @defun ewoc-get-hf ewoc
5430 This returns a cons cell @code{(@var{header} . @var{footer})}
5431 made from @var{ewoc}'s header and footer.
5432 @end defun
5434 @defun ewoc-set-hf ewoc header footer
5435 This sets the header and footer of @var{ewoc} to the strings
5436 @var{header} and @var{footer}, respectively.
5437 @end defun
5439 @defun ewoc-enter-first ewoc data
5440 @defunx ewoc-enter-last ewoc data
5441 These add a new node encapsulating @var{data}, putting it, respectively,
5442 at the beginning or end of @var{ewoc}'s chain of nodes.
5443 @end defun
5445 @defun ewoc-enter-before ewoc node data
5446 @defunx ewoc-enter-after ewoc node data
5447 These add a new node encapsulating @var{data}, adding it to
5448 @var{ewoc} before or after @var{node}, respectively.
5449 @end defun
5451 @defun ewoc-prev ewoc node
5452 @defunx ewoc-next ewoc node
5453 These return, respectively, the previous node and the next node of @var{node}
5454 in @var{ewoc}.
5455 @end defun
5457 @defun ewoc-nth ewoc n
5458 This returns the node in @var{ewoc} found at zero-based index @var{n}.
5459 A negative @var{n} means count from the end.  @code{ewoc-nth} returns
5460 @code{nil} if @var{n} is out of range.
5461 @end defun
5463 @defun ewoc-data node
5464 This extracts the data encapsulated by @var{node} and returns it.
5465 @end defun
5467 @defun ewoc-set-data node data
5468 This sets the data encapsulated by @var{node} to @var{data}.
5469 @end defun
5471 @defun ewoc-locate ewoc &optional pos guess
5472 This determines the node in @var{ewoc} which contains point (or
5473 @var{pos} if specified), and returns that node.  If @var{ewoc} has no
5474 nodes, it returns @code{nil}.  If @var{pos} is before the first node,
5475 it returns the first node; if @var{pos} is after the last node, it returns
5476 the last node.  The optional third arg @var{guess}
5477 should be a node that is likely to be near @var{pos}; this doesn't
5478 alter the result, but makes the function run faster.
5479 @end defun
5481 @defun ewoc-location node
5482 This returns the start position of @var{node}.
5483 @end defun
5485 @defun ewoc-goto-prev ewoc arg
5486 @defunx ewoc-goto-next ewoc arg
5487 These move point to the previous or next, respectively, @var{arg}th node
5488 in @var{ewoc}.  @code{ewoc-goto-prev} does not move if it is already at
5489 the first node or if @var{ewoc} is empty, whereas @code{ewoc-goto-next}
5490 moves past the last node, returning @code{nil}.  Excepting this special
5491 case, these functions return the node moved to.
5492 @end defun
5494 @defun ewoc-goto-node ewoc node
5495 This moves point to the start of @var{node} in @var{ewoc}.
5496 @end defun
5498 @defun ewoc-refresh ewoc
5499 This function regenerates the text of @var{ewoc}.  It works by
5500 deleting the text between the header and the footer, i.e., all the
5501 data elements' representations, and then calling the pretty-printer
5502 function for each node, one by one, in order.
5503 @end defun
5505 @defun ewoc-invalidate ewoc &rest nodes
5506 This is similar to @code{ewoc-refresh}, except that only @var{nodes} in
5507 @var{ewoc} are updated instead of the entire set.
5508 @end defun
5510 @defun ewoc-delete ewoc &rest nodes
5511 This deletes each node in @var{nodes} from @var{ewoc}.
5512 @end defun
5514 @defun ewoc-filter ewoc predicate &rest args
5515 This calls @var{predicate} for each data element in @var{ewoc} and
5516 deletes those nodes for which @var{predicate} returns @code{nil}.
5517 Any @var{args} are passed to @var{predicate}.
5518 @end defun
5520 @defun ewoc-collect ewoc predicate &rest args
5521 This calls @var{predicate} for each data element in @var{ewoc}
5522 and returns a list of those elements for which @var{predicate}
5523 returns non-@code{nil}.  The elements in the list are ordered
5524 as in the buffer.  Any @var{args} are passed to @var{predicate}.
5525 @end defun
5527 @defun ewoc-map map-function ewoc &rest args
5528 This calls @var{map-function} for each data element in @var{ewoc} and
5529 updates those nodes for which @var{map-function} returns non-@code{nil}.
5530 Any @var{args} are passed to @var{map-function}.
5531 @end defun
5533 @node Abstract Display Example
5534 @subsection Abstract Display Example
5536   Here is a simple example using functions of the ewoc package to
5537 implement a ``color components display,'' an area in a buffer that
5538 represents a vector of three integers (itself representing a 24-bit RGB
5539 value) in various ways.
5541 @example
5542 (setq colorcomp-ewoc nil
5543       colorcomp-data nil
5544       colorcomp-mode-map nil
5545       colorcomp-labels ["Red" "Green" "Blue"])
5547 (defun colorcomp-pp (data)
5548   (if data
5549       (let ((comp (aref colorcomp-data data)))
5550         (insert (aref colorcomp-labels data) "\t: #x"
5551                 (format "%02X" comp) " "
5552                 (make-string (ash comp -2) ?#) "\n"))
5553     (let ((cstr (format "#%02X%02X%02X"
5554                         (aref colorcomp-data 0)
5555                         (aref colorcomp-data 1)
5556                         (aref colorcomp-data 2)))
5557           (samp " (sample text) "))
5558       (insert "Color\t: "
5559               (propertize samp 'face
5560                           `(foreground-color . ,cstr))
5561               (propertize samp 'face
5562                           `(background-color . ,cstr))
5563               "\n"))))
5565 (defun colorcomp (color)
5566   "Allow fiddling with COLOR in a new buffer.
5567 The buffer is in Color Components mode."
5568   (interactive "sColor (name or #RGB or #RRGGBB): ")
5569   (when (string= "" color)
5570     (setq color "green"))
5571   (unless (color-values color)
5572     (error "No such color: %S" color))
5573   (switch-to-buffer
5574    (generate-new-buffer (format "originally: %s" color)))
5575   (kill-all-local-variables)
5576   (setq major-mode 'colorcomp-mode
5577         mode-name "Color Components")
5578   (use-local-map colorcomp-mode-map)
5579   (erase-buffer)
5580   (buffer-disable-undo)
5581   (let ((data (apply 'vector (mapcar (lambda (n) (ash n -8))
5582                                      (color-values color))))
5583         (ewoc (ewoc-create 'colorcomp-pp
5584                            "\nColor Components\n\n"
5585                            (substitute-command-keys
5586                             "\n\\@{colorcomp-mode-map@}"))))
5587     (set (make-local-variable 'colorcomp-data) data)
5588     (set (make-local-variable 'colorcomp-ewoc) ewoc)
5589     (ewoc-enter-last ewoc 0)
5590     (ewoc-enter-last ewoc 1)
5591     (ewoc-enter-last ewoc 2)
5592     (ewoc-enter-last ewoc nil)))
5593 @end example
5595 @cindex controller part, model/view/controller
5596   This example can be extended to be a ``color selection widget'' (in
5597 other words, the controller part of the ``model/view/controller''
5598 design paradigm) by defining commands to modify @code{colorcomp-data}
5599 and to ``finish'' the selection process, and a keymap to tie it all
5600 together conveniently.
5602 @smallexample
5603 (defun colorcomp-mod (index limit delta)
5604   (let ((cur (aref colorcomp-data index)))
5605     (unless (= limit cur)
5606       (aset colorcomp-data index (+ cur delta)))
5607     (ewoc-invalidate
5608      colorcomp-ewoc
5609      (ewoc-nth colorcomp-ewoc index)
5610      (ewoc-nth colorcomp-ewoc -1))))
5612 (defun colorcomp-R-more () (interactive) (colorcomp-mod 0 255 1))
5613 (defun colorcomp-G-more () (interactive) (colorcomp-mod 1 255 1))
5614 (defun colorcomp-B-more () (interactive) (colorcomp-mod 2 255 1))
5615 (defun colorcomp-R-less () (interactive) (colorcomp-mod 0 0 -1))
5616 (defun colorcomp-G-less () (interactive) (colorcomp-mod 1 0 -1))
5617 (defun colorcomp-B-less () (interactive) (colorcomp-mod 2 0 -1))
5619 (defun colorcomp-copy-as-kill-and-exit ()
5620   "Copy the color components into the kill ring and kill the buffer.
5621 The string is formatted #RRGGBB (hash followed by six hex digits)."
5622   (interactive)
5623   (kill-new (format "#%02X%02X%02X"
5624                     (aref colorcomp-data 0)
5625                     (aref colorcomp-data 1)
5626                     (aref colorcomp-data 2)))
5627   (kill-buffer nil))
5629 (setq colorcomp-mode-map
5630       (let ((m (make-sparse-keymap)))
5631         (suppress-keymap m)
5632         (define-key m "i" 'colorcomp-R-less)
5633         (define-key m "o" 'colorcomp-R-more)
5634         (define-key m "k" 'colorcomp-G-less)
5635         (define-key m "l" 'colorcomp-G-more)
5636         (define-key m "," 'colorcomp-B-less)
5637         (define-key m "." 'colorcomp-B-more)
5638         (define-key m " " 'colorcomp-copy-as-kill-and-exit)
5639         m))
5640 @end smallexample
5642 Note that we never modify the data in each node, which is fixed when the
5643 ewoc is created to be either @code{nil} or an index into the vector
5644 @code{colorcomp-data}, the actual color components.
5646 @node Blinking
5647 @section Blinking Parentheses
5648 @cindex parenthesis matching
5649 @cindex blinking parentheses
5650 @cindex balancing parentheses
5652   This section describes the mechanism by which Emacs shows a matching
5653 open parenthesis when the user inserts a close parenthesis.
5655 @defvar blink-paren-function
5656 The value of this variable should be a function (of no arguments) to
5657 be called whenever a character with close parenthesis syntax is inserted.
5658 The value of @code{blink-paren-function} may be @code{nil}, in which
5659 case nothing is done.
5660 @end defvar
5662 @defopt blink-matching-paren
5663 If this variable is @code{nil}, then @code{blink-matching-open} does
5664 nothing.
5665 @end defopt
5667 @defopt blink-matching-paren-distance
5668 This variable specifies the maximum distance to scan for a matching
5669 parenthesis before giving up.
5670 @end defopt
5672 @defopt blink-matching-delay
5673 This variable specifies the number of seconds for the cursor to remain
5674 at the matching parenthesis.  A fraction of a second often gives
5675 good results, but the default is 1, which works on all systems.
5676 @end defopt
5678 @deffn Command blink-matching-open
5679 This function is the default value of @code{blink-paren-function}.  It
5680 assumes that point follows a character with close parenthesis syntax and
5681 moves the cursor momentarily to the matching opening character.  If that
5682 character is not already on the screen, it displays the character's
5683 context in the echo area.  To avoid long delays, this function does not
5684 search farther than @code{blink-matching-paren-distance} characters.
5686 Here is an example of calling this function explicitly.
5688 @smallexample
5689 @group
5690 (defun interactive-blink-matching-open ()
5691 @c Do not break this line! -- rms.
5692 @c The first line of a doc string
5693 @c must stand alone.
5694   "Indicate momentarily the start of sexp before point."
5695   (interactive)
5696 @end group
5697 @group
5698   (let ((blink-matching-paren-distance
5699          (buffer-size))
5700         (blink-matching-paren t))
5701     (blink-matching-open)))
5702 @end group
5703 @end smallexample
5704 @end deffn
5706 @node Usual Display
5707 @section Usual Display Conventions
5709   The usual display conventions define how to display each character
5710 code.  You can override these conventions by setting up a display table
5711 (@pxref{Display Tables}).  Here are the usual display conventions:
5713 @itemize @bullet
5714 @item
5715 Character codes 32 through 126 map to glyph codes 32 through 126.
5716 Normally this means they display as themselves, but a display table
5717 can change that.
5719 @item
5720 Character code 9 is a horizontal tab.  It displays as whitespace
5721 up to a position determined by @code{tab-width}.
5723 @item
5724 Character code 10 is a newline.  It is normally invisible on display,
5725 and has the effect of ending the preceding line and starting a new
5726 line.
5728 @item
5729 All other codes in the range 0 through 31 display in one of two ways
5730 according to the value of @code{ctl-arrow}.  If it is non-@code{nil},
5731 these codes map to sequences of two glyphs, where the first glyph is
5732 the @acronym{ASCII} code for @samp{^}.  (A display table can specify a
5733 glyph to use instead of @samp{^}.)  Otherwise, these codes map just
5734 like the raw bytes in the range 128 to 255 (described below).
5736 @cindex octal escapes
5737 @item
5738 Raw bytes (@pxref{Text Representations}) with codes 128 through 255,
5739 and the @acronym{ASCII} control character with code 127, display as
5740 sequences of four glyphs, where the first glyph is the @acronym{ASCII}
5741 code for @samp{\}, and the others are digit characters representing
5742 the character code in octal.  (A display table can specify a glyph to
5743 use instead of @samp{\}.)  This is known as the @dfn{octal escape}
5744 display.
5746 @item
5747 Non-@acronym{ASCII} character codes above 127 are displayed as
5748 themselves, if the terminal and the available fonts support them.
5749 Characters that are not supported by the terminal, or (on window
5750 systems) have no fonts available for them, are displayed as a question
5751 mark or a hex code or an empty box.  @xref{Glyphless Chars}, for how
5752 to control display of the characters not supported by the terminal or
5753 fonts.  Display tables can change how a character is displayed, even
5754 if it is supported.
5755 @end itemize
5757   The usual display conventions apply even when there is a display
5758 table, for any character whose entry in the active display table is
5759 @code{nil}.  Thus, when you set up a display table, you need only
5760 specify the characters for which you want special behavior.
5762   These display rules apply to carriage return (character code 13), when
5763 it appears in the buffer.  But that character may not appear in the
5764 buffer where you expect it, if it was eliminated as part of end-of-line
5765 conversion (@pxref{Coding System Basics}).
5767   These variables affect the way certain characters are displayed on the
5768 screen.  Since they change the number of columns the characters occupy,
5769 they also affect the indentation functions.  These variables also affect
5770 how the mode line is displayed; if you want to force redisplay of the
5771 mode line using the new values, call the function
5772 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5774 @defopt ctl-arrow
5775 @cindex control characters in display
5776 This buffer-local variable controls how control characters are
5777 displayed.  If it is non-@code{nil}, they are displayed as a caret
5778 followed by the character: @samp{^A}.  If it is @code{nil}, they are
5779 displayed as octal escapes: a backslash followed by three octal
5780 digits, as in @samp{\001}.
5781 @end defopt
5783 @defopt tab-width
5784 The value of this buffer-local variable is the spacing between tab
5785 stops used for displaying tab characters in Emacs buffers.  The value
5786 is in units of columns, and the default is 8.  Note that this feature
5787 is completely independent of the user-settable tab stops used by the
5788 command @code{tab-to-tab-stop}.  @xref{Indent Tabs}.
5789 @end defopt
5791 @node Display Tables
5792 @section Display Tables
5794 @cindex display table
5795 You can use the @dfn{display table} feature to control how all possible
5796 character codes display on the screen.  This is useful for displaying
5797 European languages that have letters not in the @acronym{ASCII} character
5798 set.
5800 The display table maps each character code into a sequence of
5801 @dfn{glyphs}, each glyph being a graphic that takes up one character
5802 position on the screen.  You can also define how to display each glyph
5803 on your terminal, using the @dfn{glyph table}.
5805 Display tables affect how the mode line is displayed; if you want to
5806 force redisplay of the mode line using a new display table, call
5807 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5809 @menu
5810 * Display Table Format::  What a display table consists of.
5811 * Active Display Table::  How Emacs selects a display table to use.
5812 * Glyphs::              How to define a glyph, and what glyphs mean.
5813 @end menu
5815 @node Display Table Format
5816 @subsection Display Table Format
5818   A display table is actually a char-table (@pxref{Char-Tables}) with
5819 @code{display-table} as its subtype.
5821 @defun make-display-table
5822 This creates and returns a display table.  The table initially has
5823 @code{nil} in all elements.
5824 @end defun
5826   The ordinary elements of the display table are indexed by character
5827 codes; the element at index @var{c} says how to display the character
5828 code @var{c}.  The value should be @code{nil} or a vector of the
5829 glyphs to be output (@pxref{Glyphs}).  @code{nil} says to display the
5830 character @var{c} according to the usual display conventions
5831 (@pxref{Usual Display}).
5833   @strong{Warning:} if you use the display table to change the display
5834 of newline characters, the whole buffer will be displayed as one long
5835 ``line.''
5837   The display table also has six ``extra slots'' which serve special
5838 purposes.  Here is a table of their meanings; @code{nil} in any slot
5839 means to use the default for that slot, as stated below.
5841 @table @asis
5842 @item 0
5843 The glyph for the end of a truncated screen line (the default for this
5844 is @samp{$}).  @xref{Glyphs}.  On graphical terminals, Emacs uses
5845 arrows in the fringes to indicate truncation, so the display table has
5846 no effect.
5848 @item 1
5849 The glyph for the end of a continued line (the default is @samp{\}).
5850 On graphical terminals, Emacs uses curved arrows in the fringes to
5851 indicate continuation, so the display table has no effect.
5853 @item 2
5854 The glyph for indicating a character displayed as an octal character
5855 code (the default is @samp{\}).
5857 @item 3
5858 The glyph for indicating a control character (the default is @samp{^}).
5860 @item 4
5861 A vector of glyphs for indicating the presence of invisible lines (the
5862 default is @samp{...}).  @xref{Selective Display}.
5864 @item 5
5865 The glyph used to draw the border between side-by-side windows (the
5866 default is @samp{|}).  @xref{Splitting Windows}.  This takes effect only
5867 when there are no scroll bars; if scroll bars are supported and in use,
5868 a scroll bar separates the two windows.
5869 @end table
5871   For example, here is how to construct a display table that mimics the
5872 effect of setting @code{ctl-arrow} to a non-@code{nil} value:
5874 @example
5875 (setq disptab (make-display-table))
5876 (let ((i 0))
5877   (while (< i 32)
5878     (or (= i ?\t) (= i ?\n)
5879         (aset disptab i (vector ?^ (+ i 64))))
5880     (setq i (1+ i)))
5881   (aset disptab 127 (vector ?^ ??)))
5882 @end example
5884 @defun display-table-slot display-table slot
5885 This function returns the value of the extra slot @var{slot} of
5886 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5887 5 inclusive, or a slot name (symbol).  Valid symbols are
5888 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5889 @code{selective-display}, and @code{vertical-border}.
5890 @end defun
5892 @defun set-display-table-slot display-table slot value
5893 This function stores @var{value} in the extra slot @var{slot} of
5894 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5895 5 inclusive, or a slot name (symbol).  Valid symbols are
5896 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5897 @code{selective-display}, and @code{vertical-border}.
5898 @end defun
5900 @defun describe-display-table display-table
5901 This function displays a description of the display table
5902 @var{display-table} in a help buffer.
5903 @end defun
5905 @deffn Command describe-current-display-table
5906 This command displays a description of the current display table in a
5907 help buffer.
5908 @end deffn
5910 @node Active Display Table
5911 @subsection Active Display Table
5912 @cindex active display table
5914   Each window can specify a display table, and so can each buffer.  When
5915 a buffer @var{b} is displayed in window @var{w}, display uses the
5916 display table for window @var{w} if it has one; otherwise, the display
5917 table for buffer @var{b} if it has one; otherwise, the standard display
5918 table if any.  The display table chosen is called the @dfn{active}
5919 display table.
5921 @defun window-display-table &optional window
5922 This function returns @var{window}'s display table, or @code{nil}
5923 if @var{window} does not have an assigned display table.  The default
5924 for @var{window} is the selected window.
5925 @end defun
5927 @defun set-window-display-table window table
5928 This function sets the display table of @var{window} to @var{table}.
5929 The argument @var{table} should be either a display table or
5930 @code{nil}.
5931 @end defun
5933 @defvar buffer-display-table
5934 This variable is automatically buffer-local in all buffers; its value in
5935 a particular buffer specifies the display table for that buffer.  If it
5936 is @code{nil}, that means the buffer does not have an assigned display
5937 table.
5938 @end defvar
5940 @defvar standard-display-table
5941 This variable's value is the default display table, used whenever a
5942 window has no display table and neither does the buffer displayed in
5943 that window.  This variable is @code{nil} by default.
5944 @end defvar
5946   If there is no display table to use for a particular window---that is,
5947 if the window specifies none, its buffer specifies none, and
5948 @code{standard-display-table} is @code{nil}---then Emacs uses the usual
5949 display conventions for all character codes in that window.  @xref{Usual
5950 Display}.
5952 A number of functions for changing the standard display table
5953 are defined in the library @file{disp-table}.
5955 @node Glyphs
5956 @subsection Glyphs
5958 @cindex glyph
5959   A @dfn{glyph} is a generalization of a character; it stands for an
5960 image that takes up a single character position on the screen.  Normally
5961 glyphs come from vectors in the display table (@pxref{Display Tables}).
5963   A glyph is represented in Lisp as a @dfn{glyph code}.  A glyph code
5964 can be @dfn{simple} or it can be defined by the @dfn{glyph table}.  A
5965 simple glyph code is just a way of specifying a character and a face
5966 to output it in.  @xref{Faces}.
5968   The following functions are used to manipulate simple glyph codes:
5970 @defun make-glyph-code char &optional face
5971 This function returns a simple glyph code representing char @var{char}
5972 with face @var{face}.
5973 @end defun
5975 @defun glyph-char glyph
5976 This function returns the character of simple glyph code @var{glyph}.
5977 @end defun
5979 @defun glyph-face glyph
5980 This function returns face of simple glyph code @var{glyph}, or
5981 @code{nil} if @var{glyph} has the default face (face-id 0).
5982 @xref{Face Functions}.
5983 @end defun
5985   On character terminals, you can set up a @dfn{glyph table} to define
5986 the meaning of glyph codes (represented as small integers).
5988 @defvar glyph-table
5989 The value of this variable is the current glyph table.  It should be
5990 @code{nil} or a vector whose @var{g}th element defines glyph code
5991 @var{g}.
5993 If a glyph code is greater than or equal to the length of the glyph
5994 table, that code is automatically simple.  If @code{glyph-table} is
5995 @code{nil} then all glyph codes are simple.
5997 The glyph table is used only on character terminals.  On graphical
5998 displays, all glyph codes are simple.
5999 @end defvar
6001   Here are the meaningful types of elements in the glyph table:
6003 @table @asis
6004 @item @var{string}
6005 Send the characters in @var{string} to the terminal to output
6006 this glyph code.
6008 @item @var{code}
6009 Define this glyph code as an alias for glyph code @var{code} created
6010 by @code{make-glyph-code}.  You can use such an alias to define a
6011 small-numbered glyph code which specifies a character with a face.
6013 @item @code{nil}
6014 This glyph code is simple.
6015 @end table
6017 @defun create-glyph string
6018 This function returns a newly-allocated glyph code which is set up to
6019 display by sending @var{string} to the terminal.
6020 @end defun
6022 @node Beeping
6023 @section Beeping
6024 @c  @cindex beeping   "beep" is adjacent
6025 @cindex bell
6027   This section describes how to make Emacs ring the bell (or blink the
6028 screen) to attract the user's attention.  Be conservative about how
6029 often you do this; frequent bells can become irritating.  Also be
6030 careful not to use just beeping when signaling an error is more
6031 appropriate.  (@xref{Errors}.)
6033 @defun ding &optional do-not-terminate
6034 @cindex keyboard macro termination
6035 This function beeps, or flashes the screen (see @code{visible-bell} below).
6036 It also terminates any keyboard macro currently executing unless
6037 @var{do-not-terminate} is non-@code{nil}.
6038 @end defun
6040 @defun beep &optional do-not-terminate
6041 This is a synonym for @code{ding}.
6042 @end defun
6044 @defopt visible-bell
6045 This variable determines whether Emacs should flash the screen to
6046 represent a bell.  Non-@code{nil} means yes, @code{nil} means no.
6047 This is effective on graphical displays, and on text terminals
6048 provided the terminal's Termcap entry defines the visible bell
6049 capability (@samp{vb}).
6050 @end defopt
6052 @defvar ring-bell-function
6053 If this is non-@code{nil}, it specifies how Emacs should ``ring the
6054 bell.''  Its value should be a function of no arguments.  If this is
6055 non-@code{nil}, it takes precedence over the @code{visible-bell}
6056 variable.
6057 @end defvar
6059 @node Window Systems
6060 @section Window Systems
6062   Emacs works with several window systems, most notably the X Window
6063 System.  Both Emacs and X use the term ``window,'' but use it
6064 differently.  An Emacs frame is a single window as far as X is
6065 concerned; the individual Emacs windows are not known to X at all.
6067 @defvar window-system
6068 This terminal-local variable tells Lisp programs what window system
6069 Emacs is using for displaying the frame.  The possible values are
6071 @table @code
6072 @item x
6073 @cindex X Window System
6074 Emacs is displaying the frame using X.
6075 @item w32
6076 Emacs is displaying the frame using native MS-Windows GUI.
6077 @item ns
6078 Emacs is displaying the frame using the Nextstep interface (used on
6079 GNUstep and Mac OS X).
6080 @item pc
6081 Emacs is displaying the frame using MS-DOS direct screen writes.
6082 @item nil
6083 Emacs is displaying the frame on a character-based terminal.
6084 @end table
6085 @end defvar
6087 @defvar initial-window-system
6088 This variable holds the value of @code{window-system} used for the
6089 first frame created by Emacs during startup.  (When Emacs is invoked
6090 with the @option{--daemon} option, it does not create any initial
6091 frames, so @code{initial-window-system} is @code{nil}.  @xref{Initial
6092 Options, daemon,, emacs, The GNU Emacs Manual}.)
6093 @end defvar
6095 @defun window-system &optional frame
6096 This function returns a symbol whose name tells what window system is
6097 used for displaying @var{frame} (which defaults to the currently
6098 selected frame).  The list of possible symbols it returns is the same
6099 one documented for the variable @code{window-system} above.
6100 @end defun
6102   Do @emph{not} use @code{window-system} and
6103 @code{initial-window-system} as predicates or boolean flag variables,
6104 if you want to write code that works differently on text terminals and
6105 graphic displays.  That is because @code{window-system} is not a good
6106 indicator of Emacs capabilities on a given display type.  Instead, use
6107 @code{display-graphic-p} or any of the other @code{display-*-p}
6108 predicates described in @ref{Display Feature Testing}.
6110 @defvar window-setup-hook
6111 This variable is a normal hook which Emacs runs after handling the
6112 initialization files.  Emacs runs this hook after it has completed
6113 loading your init file, the default initialization file (if
6114 any), and the terminal-specific Lisp code, and running the hook
6115 @code{term-setup-hook}.
6117 This hook is used for internal purposes: setting up communication with
6118 the window system, and creating the initial window.  Users should not
6119 interfere with it.
6120 @end defvar
6122 @node Bidirectional Display
6123 @section Bidirectional Display
6124 @cindex bidirectional display
6125 @cindex right-to-left text
6127   Emacs can display text written in scripts, such as Arabic, Farsi,
6128 and Hebrew, whose natural ordering of horizontal text for display is
6129 from right to left.  However, digits and Latin text embedded in these
6130 scripts are still displayed left to right.  It is also not uncommon to
6131 have small portions of text in Arabic or Hebrew embedded in otherwise
6132 Latin document, e.g., as comments and strings in a program source
6133 file.  Likewise, small portions of Latin text can be embedded in an
6134 Arabic or Farsi document.  For these reasons, text that uses these
6135 scripts is actually @dfn{bidirectional}: a mixture of runs of
6136 left-to-right and right-to-left characters.
6138   This section describes the facilities and options provided by Emacs
6139 for editing and displaying bidirectional text.
6141 @cindex logical order
6142 @cindex reading order
6143 @cindex visual order
6144 @cindex unicode bidirectional algorithm
6145   Emacs stores right-to-left and bidirectional text in the so-called
6146 @dfn{logical} (or @dfn{reading}) order: the buffer or string position
6147 of the first character you read precedes that of the next character.
6148 Reordering of bidirectional text into the @dfn{visual} order happens
6149 at display time.  As result, character positions no longer increase
6150 monotonically with their positions on display.  Emacs implements the
6151 Unicode Bidirectional Algorithm (a.k.a.@: @acronym{UBA}) described in
6152 the Unicode Standard Annex #9, for reordering of bidirectional text
6153 for display.  Reordering of bidirectional text for display in Emacs is
6154 a ``Full bidirectionality'' class implementation of the @acronym{UBA}.
6156 @defvar bidi-display-reordering
6157   This buffer-local variable controls whether text in the buffer is
6158 reordered for display.  If its value is non-@code{nil}, Emacs reorders
6159 characters that have right-to-left directionality when they are
6160 displayed.  The default value is @code{t}.  Text in overlay strings
6161 (@pxref{Overlay Properties,,before-string}), display strings
6162 (@pxref{Overlay Properties,,display}), and @code{display} text
6163 properties (@pxref{Display Property}) is also reordered for display if
6164 the buffer whose text includes these strings is reordered.  Turning
6165 off @code{bidi-display-reordering} for a buffer turns off reordering
6166 of all the overlay and display strings in that buffer.
6168   Reordering of strings that are unrelated to any buffer, such as text
6169 displayed on the mode line (@pxref{Mode Line Format}) or header line
6170 (@pxref{Header Lines}), is controlled by the default value of
6171 @code{bidi-display-reordering}.
6172 @end defvar
6174 @cindex unibyte buffers, and bidi reordering
6175   Emacs does not reorder text in unibyte buffers, even if
6176 @code{bidi-display-reordering} is non-@code{nil} in such a buffer.
6177 This is because unibyte buffers contain raw bytes, not characters, and
6178 thus don't have bidirectional properties defined for them which are
6179 required for correct reordering.  Therefore, to test whether text in a
6180 buffer will be reordered for display, it is not enough to test the
6181 value of @code{bidi-display-reordering} alone.  The correct test is
6182 this:
6184 @example
6185  (if (and enable-multibyte-characters
6186           bidi-display-reordering)
6187      ;; Buffer is being reordered for display
6188    )
6189 @end example
6191   In contrast to unibyte buffers, unibyte display and overlay strings
6192 @emph{are} reordered, if their parent buffer is reordered.  This is
6193 because plain-@sc{ascii} strings are stored by Emacs as unibyte
6194 strings.  If a unibyte display or overlay string includes
6195 non-@sc{ascii} characters, these characters are assumed to have
6196 left-to-right direction.
6198 @cindex display properties, and bidi reordering of text
6199   Text covered by @code{display} text properties, by overlays with
6200 @code{display} properties whose value is a string, and by any other
6201 properties that replace buffer text, is treated as a single unit when
6202 it is reordered for display.  That is, the entire chunk of text
6203 covered by these properties is reordered together.  Moreover, the
6204 bidirectional properties of the characters in this chunk of text are
6205 ignored, and Emacs reorders them as if they were replaced with a
6206 single character @code{U+FFFC}, known as the @dfn{Object Replacement
6207 Character}.  This means that placing a display property over a portion
6208 of text may change the way that the surrounding text is reordered for
6209 display.  To prevent this unexpected effect, always place such
6210 properties on text whose directionality is identical with text that
6211 surrounds it.
6213 @cindex base direction of a paragraph
6214   Each paragraph of bidirectional text can have its own @dfn{base
6215 direction}, either right-to-left or left-to-right.  Text in
6216 left-to-right paragraphs is displayed beginning at the left margin of
6217 the window and is truncated or continued when it reaches the right
6218 margin.  By contrast, display of text in right-to-left paragraphs
6219 begins at the right margin and is continued or truncated at the left
6220 margin.
6222 @defvar bidi-paragraph-direction
6223   By default, Emacs determines the base direction of each paragraph
6224 dynamically, based on the text at the beginning of the paragraph.  The
6225 precise method of determining the base direction is specified by the
6226 @acronym{UBA}; in a nutshell, the first character in a paragraph that
6227 has an explicit directionality determines the base direction of the
6228 paragraph.  However, sometimes a buffer may need to force a certain
6229 base direction for its paragraphs.  For example, a buffer that visits
6230 a source code of a program should force all its paragraphs to be
6231 displayed left to right.  The variable
6232 @code{bidi-paragraph-direction}, if non-@code{nil}, disables the
6233 dynamic determination of the base direction, and instead forces all
6234 paragraphs in the buffer to have the direction specified by its
6235 buffer-local value.  The value can be either @code{right-to-left} or
6236 @code{left-to-right}.  Any other value is interpreted as @code{nil}.
6237 The default is @code{nil}.
6239 @cindex @code{prog-mode}, and @code{bidi-paragraph-direction}
6240 Modes that are meant to display program source code should force a
6241 @code{left-to-right} paragraph direction.  The easiest way of doing so
6242 is to derive the mode from Prog Mode, which already sets
6243 @code{bidi-paragraph-direction} to that value.
6244 @end defvar
6246 @defun current-bidi-paragraph-direction &optional buffer
6247 This function returns the paragraph direction at point in the named
6248 @var{buffer}.  The returned value is a symbol, either
6249 @code{left-to-right} or @code{right-to-left}.  If @var{buffer} is
6250 omitted or @code{nil}, it defaults to the current buffer.  If the
6251 buffer-local value of the variable @code{bidi-paragraph-direction} is
6252 non-@code{nil}, the returned value will be identical to that value;
6253 otherwise, the returned value reflects the paragraph direction
6254 determined dynamically by Emacs.  For buffers whose value of
6255 @code{bidi-display-reordering} is @code{nil} as well as unibyte
6256 buffers, this function always returns @code{left-to-right}.
6257 @end defun
6259 @cindex layout on display, and bidirectional text
6260 @cindex jumbled display of bidirectional text
6261 @cindex concatenating bidirectional strings
6262   Reordering of bidirectional text for display can have surprising and
6263 unpleasant effects when two strings with bidirectional content are
6264 juxtaposed in a buffer, or otherwise programmatically concatenated
6265 into a string of text.  A typical example is a buffer whose lines are
6266 actually sequences of items, or fields, separated by whitespace or
6267 punctuation characters.  This is used in specialized modes such as
6268 Buffer-menu Mode or various email summary modes, like Rmail Summary
6269 Mode.  Because these separator characters are @dfn{weak}, i.e.@: have
6270 no strong directionality, they take on the directionality of
6271 surrounding text.  As result, a numeric field that follows a field
6272 with bidirectional content can be displayed @emph{to the left} of the
6273 preceding field, producing a jumbled display and messing up the
6274 expected layout.
6276   To countermand this, we recommend that you use one of the following
6277 techniques for forcing correct order of fields on display:
6279 @itemize @minus
6280 @item
6281 Append the special character @code{U+200E}, LEFT-TO-RIGHT MARK, or
6282 @acronym{LRM}, to the end of each field that may have bidirectional
6283 content, or prepend it to the beginning of the following field.  The
6284 function @code{bidi-string-mark-left-to-right}, described below, comes
6285 in handy for this purpose.  (In a right-to-left paragraph, use
6286 @code{U+200F}, RIGHT-TO-LEFT MARK, or @acronym{RLM}, instead.)  This
6287 is one of the solutions recommended by
6288 @uref{http://www.unicode.org/reports/tr9/#Separators, the
6289 @acronym{UBA}}.
6291 @item
6292 Include the tab character in the field separator.  The tab character
6293 plays the role of @dfn{segment separator} in the @acronym{UBA}
6294 reordering, whose effect is to make each field a separate segment, and
6295 thus reorder them separately.
6297 @cindex @code{space} display spec, and bidirectional text
6298 @item
6299 Separate fields with a @code{display} property or overlay with the
6300 property value of the form @code{(space . PROPS)} (@pxref{Specified
6301 Space}).  This display specification is treated by Emacs as a
6302 @dfn{paragraph separator}; the text before and after the separator is
6303 reordered separately, which avoids the influence of any field on its
6304 neighboring fields.
6305 @end itemize
6307 @defun bidi-string-mark-left-to-right string
6308 This subroutine returns its argument @var{string}, possibly modified,
6309 such that the result can be safely concatenated with another string,
6310 or juxtaposed with another string in a buffer, without disrupting the
6311 relative layout of this string and the next one on display.  If the
6312 string returned by this function is displayed as part of a
6313 left-to-right paragraph, it will always appear on display to the left
6314 of the text that follows it.  The function works by examining the
6315 characters of its argument, and if any of those characters could cause
6316 reordering on display, the function appends the @acronym{LRM}
6317 character to the string.  The appended @acronym{LRM} character is made
6318 @emph{invisible} (@pxref{Invisible Text}), to hide it on display.
6319 @end defun
6321   The reordering algorithm uses the bidirectional properties of the
6322 characters stored as their @code{bidi-class} property
6323 (@pxref{Character Properties}).  Lisp programs can change these
6324 properties by calling the @code{put-char-code-property} function.
6325 However, doing this requires a thorough understanding of the
6326 @acronym{UBA}, and is therefore not recommended.  Any changes to the
6327 bidirectional properties of a character have global effect: they
6328 affect all Emacs frames and windows.
6330   Similarly, the @code{mirroring} property is used to display the
6331 appropriate mirrored character in the reordered text.  Lisp programs
6332 can affect the mirrored display by changing this property.  Again, any
6333 such changes affect all of Emacs display.
6335 @node Glyphless Chars
6336 @section Glyphless Character Display
6337 @cindex glyphless characters
6339   @dfn{Glyphless characters} are not displayed in the usual way when
6340 they appear in a buffer, but in some special way (e.g. as a box
6341 containing a hexadecimal code).  These include characters that cannot
6342 be displayed with any available font (on a graphical display), or that
6343 cannot be encoded by the terminal's coding system (on a text
6344 terminal).  Specific characters can also be defined to be glyphless.
6346 @defvar glyphless-char-display
6347 The value of this variable is a char-table that defines glyphless
6348 characters and how they are displayed.  If an entry is @code{nil}, the
6349 corresponding character is displayed in its usual way.  Otherwise, an
6350 entry should be one of the following display methods:
6352 @table @asis
6353 @item @code{zero-width}
6354 Don't display the character.
6356 @item @code{thin-space}
6357 Display a thin space, 1-pixel wide on graphical displays, or
6358 1-character wide on text terminals.
6360 @item @code{empty-box}
6361 Display an empty box.
6363 @item @code{hex-code}
6364 Display a box containing the Unicode codepoint of the character, in
6365 hexadecimal notation.
6367 @item an @acronym{ASCII} string
6368 Display a box containing that string.
6369 @end table
6371 @noindent
6372 Except for @code{zero-width}, these methods display using the
6373 @code{glyphless-char} face.
6375 An entry can also be a cons cell @code{(@var{graphical}
6376 . @var{text})}, where @var{graphical} and @var{text} are the display
6377 methods on graphical displays and text terminals respectively.
6379 The char-table has one extra slot, which determines how to display any
6380 character that cannot be displayed with any available font, or cannot
6381 be encoded by the terminal's coding system.  Its value should be one
6382 of the above display methods, except @code{zero-width} or a cons cell.
6383 @end defvar
6385 @defopt glyphless-char-display-control
6386 This user option provides a convenient way to set
6387 @code{glyphless-char-display} for groups of similar characters.  It
6388 takes effect via a custom @code{:set} function (@pxref{Variable
6389 Definitions}), which update @code{glyphless-char-display}.
6391 Its value should be an alist of elements @code{(@var{group}
6392 . @var{method})}, where @var{group} is a symbol specifying a group of
6393 characters, and @var{method} is a symbol specifying how to display
6394 them.
6396 @var{group} should be one of the following:
6398 @table @code
6399 @item c0-control
6400 @acronym{ASCII} control characters @code{U+0000} to @code{U+001F},
6401 excluding the newline and tab characters (normally displayed as escape
6402 sequences like @samp{^A}; @pxref{Text Display,, How Text Is Displayed,
6403 emacs, The GNU Emacs Manual}).
6405 @item c1-control
6406 Non-@acronym{ASCII}, non-printing characters @code{U+0080} to
6407 @code{U+009F} (normally displayed as octal escape sequences like
6408 @samp{\230}).
6410 @item format-control
6411 Characters of Unicode General Category `Cf', such as @samp{U+200E}
6412 (Left-to-Right Mark), but excluding characters that have graphic
6413 images, such as @samp{U+00AD} (Soft Hyphen).
6415 @item no-font
6416 Characters for there is no suitable font, or which cannot be encoded
6417 by the terminal's coding system.
6418 @end table
6420 @c FIXME: this can also be `acronym', but that's not currently
6421 @c completely implemented; it applies only to the format-control
6422 @c group, and only works if the acronym is in `char-acronym-table'.
6423 The @var{method} symbol should be one of @code{zero-width},
6424 @code{thin-space}, @code{empty-box}, or @code{hex-code}.  These have
6425 the same meanings as in @code{glyphless-char-display}, above.
6426 @end defopt