Update doc to reflect new non-nil value of redisplay-dont-pause.
[emacs.git] / doc / lispref / display.texi
blobb68b0697936d954dcc0e6356e4ed75ae96fc42ba
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.  The optional argument
90 @var{force}, if non-@code{nil}, forces the redisplay to be performed,
91 instead of being preempted, even if input is pending and the variable
92 @code{redisplay-dont-pause} is @code{nil} (see below).  If
93 @code{redisplay-dont-pause} is non-@code{nil} (the default), this
94 function redisplays in any case, i.e.@: @var{force} does nothing.
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 preempted by
99 newly arriving input.
100 @end defun
102 @defvar redisplay-dont-pause
103 If this variable is @code{nil}, arriving input events preempt
104 redisplay; Emacs avoids starting a redisplay, and stops any redisplay
105 that is in progress, until the input has been processed.  In
106 particular, @code{(redisplay)} returns @code{nil} without actually
107 redisplaying, if there is pending input.
109 The default value is @code{t}, which means that pending input does not
110 preempt redisplay.
111 @end defvar
113 @defvar redisplay-preemption-period
114 If @code{redisplay-dont-pause} is @code{nil}, this variable specifies
115 how many seconds Emacs waits between checks for new input during
116 redisplay; if input arrives during this interval, redisplay stops and
117 the input is processed.  The default value is 0.1; if the value is
118 @code{nil}, Emacs does not check for input during redisplay.
120 This variable has no effect when @code{redisplay-dont-pause} is
121 non-@code{nil} (the default).
122 @end defvar
124   Although @code{redisplay} tries immediately to redisplay, it does
125 not change how Emacs decides which parts of its frame(s) to redisplay.
126 By contrast, the following function adds certain windows to the
127 pending redisplay work (as if their contents had completely changed),
128 but does not immediately try to perform redisplay.
130 @defun force-window-update &optional object
131 This function forces some or all windows to be updated the next time
132 Emacs does a redisplay.  If @var{object} is a window, that window is
133 to be updated.  If @var{object} is a buffer or buffer name, all
134 windows displaying that buffer are to be updated.  If @var{object} is
135 @code{nil} (or omitted), all windows are to be updated.
137 This function does not do a redisplay immediately; Emacs does that as
138 it waits for input, or when the function @code{redisplay} is called.
139 @end defun
141 @node Truncation
142 @section Truncation
143 @cindex line wrapping
144 @cindex line truncation
145 @cindex continuation lines
146 @cindex @samp{$} in display
147 @cindex @samp{\} in display
149   When a line of text extends beyond the right edge of a window, Emacs
150 can @dfn{continue} the line (make it ``wrap'' to the next screen
151 line), or @dfn{truncate} the line (limit it to one screen line).  The
152 additional screen lines used to display a long text line are called
153 @dfn{continuation} lines.  Continuation is not the same as filling;
154 continuation happens on the screen only, not in the buffer contents,
155 and it breaks a line precisely at the right margin, not at a word
156 boundary.  @xref{Filling}.
158    On a graphical display, tiny arrow images in the window fringes
159 indicate truncated and continued lines (@pxref{Fringes}).  On a text
160 terminal, a @samp{$} in the rightmost column of the window indicates
161 truncation; a @samp{\} on the rightmost column indicates a line that
162 ``wraps.''  (The display table can specify alternate characters to use
163 for this; @pxref{Display Tables}).
165 @defopt truncate-lines
166 If this buffer-local variable is non-@code{nil}, lines that extend
167 beyond the right edge of the window are truncated; otherwise, they are
168 continued.  As a special exception, the variable
169 @code{truncate-partial-width-windows} takes precedence in
170 @dfn{partial-width} windows (i.e.@: windows that do not occupy the
171 entire frame width).
172 @end defopt
174 @defopt truncate-partial-width-windows
175 This variable controls line truncation in @dfn{partial-width} windows.
176 A partial-width window is one that does not occupy the entire frame
177 width (@pxref{Splitting Windows}).  If the value is @code{nil}, line
178 truncation is determined by the variable @code{truncate-lines} (see
179 above).  If the value is an integer @var{n}, lines are truncated if
180 the partial-width window has fewer than @var{n} columns, regardless of
181 the value of @code{truncate-lines}; if the partial-width window has
182 @var{n} or more columns, line truncation is determined by
183 @code{truncate-lines}.  For any other non-@code{nil} value, lines are
184 truncated in every partial-width window, regardless of the value of
185 @code{truncate-lines}.
186 @end defopt
188   When horizontal scrolling (@pxref{Horizontal Scrolling}) is in use in
189 a window, that forces truncation.
191 @defvar wrap-prefix
192 If this buffer-local variable is non-@code{nil}, it defines a
193 @dfn{wrap prefix} which Emacs displays at the start of every
194 continuation line.  (If lines are truncated, @code{wrap-prefix} is
195 never used.)  Its value may be a string or an image (@pxref{Other
196 Display Specs}), or a stretch of whitespace such as specified by the
197 @code{:width} or @code{:align-to} display properties (@pxref{Specified
198 Space}).  The value is interpreted in the same way as a @code{display}
199 text property.  @xref{Display Property}.
201 A wrap prefix may also be specified for regions of text, using the
202 @code{wrap-prefix} text or overlay property.  This takes precedence
203 over the @code{wrap-prefix} variable.  @xref{Special Properties}.
204 @end defvar
206 @defvar line-prefix
207 If this buffer-local variable is non-@code{nil}, it defines a
208 @dfn{line prefix} which Emacs displays at the start of every
209 non-continuation line.  Its value may be a string or an image
210 (@pxref{Other Display Specs}), or a stretch of whitespace such as
211 specified by the @code{:width} or @code{:align-to} display properties
212 (@pxref{Specified Space}).  The value is interpreted in the same way
213 as a @code{display} text property.  @xref{Display Property}.
215 A line prefix may also be specified for regions of text using the
216 @code{line-prefix} text or overlay property.  This takes precedence
217 over the @code{line-prefix} variable.  @xref{Special Properties}.
218 @end defvar
220   If your buffer contains @emph{very} long lines, and you use
221 continuation to display them, computing the continuation lines can
222 make redisplay slow.  The column computation and indentation functions
223 also become slow.  Then you might find it advisable to set
224 @code{cache-long-line-scans} to @code{t}.
226 @defvar cache-long-line-scans
227 If this variable is non-@code{nil}, various indentation and motion
228 functions, and Emacs redisplay, cache the results of scanning the
229 buffer, and consult the cache to avoid rescanning regions of the buffer
230 unless they are modified.
232 Turning on the cache slows down processing of short lines somewhat.
234 This variable is automatically buffer-local in every buffer.
235 @end defvar
237 @node The Echo Area
238 @section The Echo Area
239 @cindex error display
240 @cindex echo area
242   The @dfn{echo area} is used for displaying error messages
243 (@pxref{Errors}), for messages made with the @code{message} primitive,
244 and for echoing keystrokes.  It is not the same as the minibuffer,
245 despite the fact that the minibuffer appears (when active) in the same
246 place on the screen as the echo area.  The @cite{GNU Emacs Manual}
247 specifies the rules for resolving conflicts between the echo area and
248 the minibuffer for use of that screen space (@pxref{Minibuffer,, The
249 Minibuffer, emacs, The GNU Emacs Manual}).
251   You can write output in the echo area by using the Lisp printing
252 functions with @code{t} as the stream (@pxref{Output Functions}), or
253 explicitly.
255 @menu
256 * Displaying Messages:: Explicitly displaying text in the echo area.
257 * Progress::            Informing user about progress of a long operation.
258 * Logging Messages::    Echo area messages are logged for the user.
259 * Echo Area Customization:: Controlling the echo area.
260 @end menu
262 @node Displaying Messages
263 @subsection Displaying Messages in the Echo Area
264 @cindex display message in echo area
266   This section describes the functions for explicitly producing echo
267 area messages.  Many other Emacs features display messages there, too.
269 @defun message format-string &rest arguments
270 This function displays a message in the echo area.  The argument
271 @var{format-string} is similar to a C language @code{printf} format
272 string.  See @code{format} in @ref{Formatting Strings}, for the details
273 on the conversion specifications.  @code{message} returns the
274 constructed string.
276 In batch mode, @code{message} prints the message text on the standard
277 error stream, followed by a newline.
279 If @var{format-string}, or strings among the @var{arguments}, have
280 @code{face} text properties, these affect the way the message is displayed.
282 @c Emacs 19 feature
283 If @var{format-string} is @code{nil} or the empty string,
284 @code{message} clears the echo area; if the echo area has been
285 expanded automatically, this brings it back to its normal size.
286 If the minibuffer is active, this brings the minibuffer contents back
287 onto the screen immediately.
289 @example
290 @group
291 (message "Minibuffer depth is %d."
292          (minibuffer-depth))
293  @print{} Minibuffer depth is 0.
294 @result{} "Minibuffer depth is 0."
295 @end group
297 @group
298 ---------- Echo Area ----------
299 Minibuffer depth is 0.
300 ---------- Echo Area ----------
301 @end group
302 @end example
304 To automatically display a message in the echo area or in a pop-buffer,
305 depending on its size, use @code{display-message-or-buffer} (see below).
306 @end defun
308 @defmac with-temp-message message &rest body
309 This construct displays a message in the echo area temporarily, during
310 the execution of @var{body}.  It displays @var{message}, executes
311 @var{body}, then returns the value of the last body form while restoring
312 the previous echo area contents.
313 @end defmac
315 @defun message-or-box format-string &rest arguments
316 This function displays a message like @code{message}, but may display it
317 in a dialog box instead of the echo area.  If this function is called in
318 a command that was invoked using the mouse---more precisely, if
319 @code{last-nonmenu-event} (@pxref{Command Loop Info}) is either
320 @code{nil} or a list---then it uses a dialog box or pop-up menu to
321 display the message.  Otherwise, it uses the echo area.  (This is the
322 same criterion that @code{y-or-n-p} uses to make a similar decision; see
323 @ref{Yes-or-No Queries}.)
325 You can force use of the mouse or of the echo area by binding
326 @code{last-nonmenu-event} to a suitable value around the call.
327 @end defun
329 @defun message-box format-string &rest arguments
330 @anchor{message-box}
331 This function displays a message like @code{message}, but uses a dialog
332 box (or a pop-up menu) whenever that is possible.  If it is impossible
333 to use a dialog box or pop-up menu, because the terminal does not
334 support them, then @code{message-box} uses the echo area, like
335 @code{message}.
336 @end defun
338 @defun display-message-or-buffer message &optional buffer-name not-this-window frame
339 This function displays the message @var{message}, which may be either a
340 string or a buffer.  If it is shorter than the maximum height of the
341 echo area, as defined by @code{max-mini-window-height}, it is displayed
342 in the echo area, using @code{message}.  Otherwise,
343 @code{display-buffer} is used to show it in a pop-up buffer.
345 Returns either the string shown in the echo area, or when a pop-up
346 buffer is used, the window used to display it.
348 If @var{message} is a string, then the optional argument
349 @var{buffer-name} is the name of the buffer used to display it when a
350 pop-up buffer is used, defaulting to @samp{*Message*}.  In the case
351 where @var{message} is a string and displayed in the echo area, it is
352 not specified whether the contents are inserted into the buffer anyway.
354 The optional arguments @var{not-this-window} and @var{frame} are as for
355 @code{display-buffer}, and only used if a buffer is displayed.
356 @end defun
358 @defun current-message
359 This function returns the message currently being displayed in the
360 echo area, or @code{nil} if there is none.
361 @end defun
363 @node Progress
364 @subsection Reporting Operation Progress
365 @cindex progress reporting
367   When an operation can take a while to finish, you should inform the
368 user about the progress it makes.  This way the user can estimate
369 remaining time and clearly see that Emacs is busy working, not hung.
370 A convenient way to do this is to use a @dfn{progress reporter}.
372   Here is a working example that does nothing useful:
374 @smallexample
375 (let ((progress-reporter
376        (make-progress-reporter "Collecting mana for Emacs..."
377                                0  500)))
378   (dotimes (k 500)
379     (sit-for 0.01)
380     (progress-reporter-update progress-reporter k))
381   (progress-reporter-done progress-reporter))
382 @end smallexample
384 @defun make-progress-reporter message &optional min-value max-value current-value min-change min-time
385 This function creates and returns a progress reporter object, which
386 you will use as an argument for the other functions listed below.  The
387 idea is to precompute as much data as possible to make progress
388 reporting very fast.
390 When this progress reporter is subsequently used, it will display
391 @var{message} in the echo area, followed by progress percentage.
392 @var{message} is treated as a simple string.  If you need it to depend
393 on a filename, for instance, use @code{format} before calling this
394 function.
396 The arguments @var{min-value} and @var{max-value} should be numbers
397 standing for the starting and final states of the operation.  For
398 instance, an operation that ``scans'' a buffer should set these to the
399 results of @code{point-min} and @code{point-max} correspondingly.
400 @var{max-value} should be greater than @var{min-value}.
402 Alternatively, you can set @var{min-value} and @var{max-value} to
403 @code{nil}.  In that case, the progress reporter does not report
404 process percentages; it instead displays a ``spinner'' that rotates a
405 notch each time you update the progress reporter.
407 If @var{min-value} and @var{max-value} are numbers, you can give the
408 argument @var{current-value} a numerical value specifying the initial
409 progress; if omitted, this defaults to @var{min-value}.
411 The remaining arguments control the rate of echo area updates.  The
412 progress reporter will wait for at least @var{min-change} more
413 percents of the operation to be completed before printing next
414 message; the default is one percent.  @var{min-time} specifies the
415 minimum time in seconds to pass between successive prints; the default
416 is 0.2 seconds.  (On some operating systems, the progress reporter may
417 handle fractions of seconds with varying precision).
419 This function calls @code{progress-reporter-update}, so the first
420 message is printed immediately.
421 @end defun
423 @defun progress-reporter-update reporter value
424 This function does the main work of reporting progress of your
425 operation.  It displays the message of @var{reporter}, followed by
426 progress percentage determined by @var{value}.  If percentage is zero,
427 or close enough according to the @var{min-change} and @var{min-time}
428 arguments, then it is omitted from the output.
430 @var{reporter} must be the result of a call to
431 @code{make-progress-reporter}.  @var{value} specifies the current
432 state of your operation and must be between @var{min-value} and
433 @var{max-value} (inclusive) as passed to
434 @code{make-progress-reporter}.  For instance, if you scan a buffer,
435 then @var{value} should be the result of a call to @code{point}.
437 This function respects @var{min-change} and @var{min-time} as passed
438 to @code{make-progress-reporter} and so does not output new messages
439 on every invocation.  It is thus very fast and normally you should not
440 try to reduce the number of calls to it: resulting overhead will most
441 likely negate your effort.
442 @end defun
444 @defun progress-reporter-force-update reporter value &optional new-message
445 This function is similar to @code{progress-reporter-update} except
446 that it prints a message in the echo area unconditionally.
448 The first two arguments have the same meaning as for
449 @code{progress-reporter-update}.  Optional @var{new-message} allows
450 you to change the message of the @var{reporter}.  Since this functions
451 always updates the echo area, such a change will be immediately
452 presented to the user.
453 @end defun
455 @defun progress-reporter-done reporter
456 This function should be called when the operation is finished.  It
457 prints the message of @var{reporter} followed by word ``done'' in the
458 echo area.
460 You should always call this function and not hope for
461 @code{progress-reporter-update} to print ``100%.''  Firstly, it may
462 never print it, there are many good reasons for this not to happen.
463 Secondly, ``done'' is more explicit.
464 @end defun
466 @defmac dotimes-with-progress-reporter (var count [result]) message body@dots{}
467 This is a convenience macro that works the same way as @code{dotimes}
468 does, but also reports loop progress using the functions described
469 above.  It allows you to save some typing.
471 You can rewrite the example in the beginning of this node using
472 this macro this way:
474 @example
475 (dotimes-with-progress-reporter
476     (k 500)
477     "Collecting some mana for Emacs..."
478   (sit-for 0.01))
479 @end example
480 @end defmac
482 @node Logging Messages
483 @subsection Logging Messages in @samp{*Messages*}
484 @cindex logging echo-area messages
486   Almost all the messages displayed in the echo area are also recorded
487 in the @samp{*Messages*} buffer so that the user can refer back to
488 them.  This includes all the messages that are output with
489 @code{message}.
491 @defopt message-log-max
492 This variable specifies how many lines to keep in the @samp{*Messages*}
493 buffer.  The value @code{t} means there is no limit on how many lines to
494 keep.  The value @code{nil} disables message logging entirely.  Here's
495 how to display a message and prevent it from being logged:
497 @example
498 (let (message-log-max)
499   (message @dots{}))
500 @end example
501 @end defopt
503   To make @samp{*Messages*} more convenient for the user, the logging
504 facility combines successive identical messages.  It also combines
505 successive related messages for the sake of two cases: question
506 followed by answer, and a series of progress messages.
508   A ``question followed by an answer'' means two messages like the
509 ones produced by @code{y-or-n-p}: the first is @samp{@var{question}},
510 and the second is @samp{@var{question}...@var{answer}}.  The first
511 message conveys no additional information beyond what's in the second,
512 so logging the second message discards the first from the log.
514   A ``series of progress messages'' means successive messages like
515 those produced by @code{make-progress-reporter}.  They have the form
516 @samp{@var{base}...@var{how-far}}, where @var{base} is the same each
517 time, while @var{how-far} varies.  Logging each message in the series
518 discards the previous one, provided they are consecutive.
520   The functions @code{make-progress-reporter} and @code{y-or-n-p}
521 don't have to do anything special to activate the message log
522 combination feature.  It operates whenever two consecutive messages
523 are logged that share a common prefix ending in @samp{...}.
525 @node Echo Area Customization
526 @subsection Echo Area Customization
528   These variables control details of how the echo area works.
530 @defvar cursor-in-echo-area
531 This variable controls where the cursor appears when a message is
532 displayed in the echo area.  If it is non-@code{nil}, then the cursor
533 appears at the end of the message.  Otherwise, the cursor appears at
534 point---not in the echo area at all.
536 The value is normally @code{nil}; Lisp programs bind it to @code{t}
537 for brief periods of time.
538 @end defvar
540 @defvar echo-area-clear-hook
541 This normal hook is run whenever the echo area is cleared---either by
542 @code{(message nil)} or for any other reason.
543 @end defvar
545 @defopt echo-keystrokes
546 This variable determines how much time should elapse before command
547 characters echo.  Its value must be an integer or floating point number,
548 which specifies the
549 number of seconds to wait before echoing.  If the user types a prefix
550 key (such as @kbd{C-x}) and then delays this many seconds before
551 continuing, the prefix key is echoed in the echo area.  (Once echoing
552 begins in a key sequence, all subsequent characters in the same key
553 sequence are echoed immediately.)
555 If the value is zero, then command input is not echoed.
556 @end defopt
558 @defvar message-truncate-lines
559 Normally, displaying a long message resizes the echo area to display
560 the entire message.  But if the variable @code{message-truncate-lines}
561 is non-@code{nil}, the echo area does not resize, and the message is
562 truncated to fit it, as in Emacs 20 and before.
563 @end defvar
565   The variable @code{max-mini-window-height}, which specifies the
566 maximum height for resizing minibuffer windows, also applies to the
567 echo area (which is really a special use of the minibuffer window.
568 @xref{Minibuffer Misc}.).
570 @node Warnings
571 @section Reporting Warnings
572 @cindex warnings
574   @dfn{Warnings} are a facility for a program to inform the user of a
575 possible problem, but continue running.
577 @menu
578 * Warning Basics::      Warnings concepts and functions to report them.
579 * Warning Variables::   Variables programs bind to customize their warnings.
580 * Warning Options::     Variables users set to control display of warnings.
581 @end menu
583 @node Warning Basics
584 @subsection Warning Basics
585 @cindex severity level
587   Every warning has a textual message, which explains the problem for
588 the user, and a @dfn{severity level} which is a symbol.  Here are the
589 possible severity levels, in order of decreasing severity, and their
590 meanings:
592 @table @code
593 @item :emergency
594 A problem that will seriously impair Emacs operation soon
595 if you do not attend to it promptly.
596 @item :error
597 A report of data or circumstances that are inherently wrong.
598 @item :warning
599 A report of data or circumstances that are not inherently wrong, but
600 raise suspicion of a possible problem.
601 @item :debug
602 A report of information that may be useful if you are debugging.
603 @end table
605   When your program encounters invalid input data, it can either
606 signal a Lisp error by calling @code{error} or @code{signal} or report
607 a warning with severity @code{:error}.  Signaling a Lisp error is the
608 easiest thing to do, but it means the program cannot continue
609 processing.  If you want to take the trouble to implement a way to
610 continue processing despite the bad data, then reporting a warning of
611 severity @code{:error} is the right way to inform the user of the
612 problem.  For instance, the Emacs Lisp byte compiler can report an
613 error that way and continue compiling other functions.  (If the
614 program signals a Lisp error and then handles it with
615 @code{condition-case}, the user won't see the error message; it could
616 show the message to the user by reporting it as a warning.)
618 @cindex warning type
619   Each warning has a @dfn{warning type} to classify it.  The type is a
620 list of symbols.  The first symbol should be the custom group that you
621 use for the program's user options.  For example, byte compiler
622 warnings use the warning type @code{(bytecomp)}.  You can also
623 subcategorize the warnings, if you wish, by using more symbols in the
624 list.
626 @defun display-warning type message &optional level buffer-name
627 This function reports a warning, using @var{message} as the message
628 and @var{type} as the warning type.  @var{level} should be the
629 severity level, with @code{:warning} being the default.
631 @var{buffer-name}, if non-@code{nil}, specifies the name of the buffer
632 for logging the warning.  By default, it is @samp{*Warnings*}.
633 @end defun
635 @defun lwarn type level message &rest args
636 This function reports a warning using the value of @code{(format
637 @var{message} @var{args}...)} as the message.  In other respects it is
638 equivalent to @code{display-warning}.
639 @end defun
641 @defun warn message &rest args
642 This function reports a warning using the value of @code{(format
643 @var{message} @var{args}...)} as the message, @code{(emacs)} as the
644 type, and @code{:warning} as the severity level.  It exists for
645 compatibility only; we recommend not using it, because you should
646 specify a specific warning type.
647 @end defun
649 @node Warning Variables
650 @subsection Warning Variables
652   Programs can customize how their warnings appear by binding
653 the variables described in this section.
655 @defvar warning-levels
656 This list defines the meaning and severity order of the warning
657 severity levels.  Each element defines one severity level,
658 and they are arranged in order of decreasing severity.
660 Each element has the form @code{(@var{level} @var{string}
661 @var{function})}, where @var{level} is the severity level it defines.
662 @var{string} specifies the textual description of this level.
663 @var{string} should use @samp{%s} to specify where to put the warning
664 type information, or it can omit the @samp{%s} so as not to include
665 that information.
667 The optional @var{function}, if non-@code{nil}, is a function to call
668 with no arguments, to get the user's attention.
670 Normally you should not change the value of this variable.
671 @end defvar
673 @defvar warning-prefix-function
674 If non-@code{nil}, the value is a function to generate prefix text for
675 warnings.  Programs can bind the variable to a suitable function.
676 @code{display-warning} calls this function with the warnings buffer
677 current, and the function can insert text in it.  That text becomes
678 the beginning of the warning message.
680 The function is called with two arguments, the severity level and its
681 entry in @code{warning-levels}.  It should return a list to use as the
682 entry (this value need not be an actual member of
683 @code{warning-levels}).  By constructing this value, the function can
684 change the severity of the warning, or specify different handling for
685 a given severity level.
687 If the variable's value is @code{nil} then there is no function
688 to call.
689 @end defvar
691 @defvar warning-series
692 Programs can bind this variable to @code{t} to say that the next
693 warning should begin a series.  When several warnings form a series,
694 that means to leave point on the first warning of the series, rather
695 than keep moving it for each warning so that it appears on the last one.
696 The series ends when the local binding is unbound and
697 @code{warning-series} becomes @code{nil} again.
699 The value can also be a symbol with a function definition.  That is
700 equivalent to @code{t}, except that the next warning will also call
701 the function with no arguments with the warnings buffer current.  The
702 function can insert text which will serve as a header for the series
703 of warnings.
705 Once a series has begun, the value is a marker which points to the
706 buffer position in the warnings buffer of the start of the series.
708 The variable's normal value is @code{nil}, which means to handle
709 each warning separately.
710 @end defvar
712 @defvar warning-fill-prefix
713 When this variable is non-@code{nil}, it specifies a fill prefix to
714 use for filling each warning's text.
715 @end defvar
717 @defvar warning-type-format
718 This variable specifies the format for displaying the warning type
719 in the warning message.  The result of formatting the type this way
720 gets included in the message under the control of the string in the
721 entry in @code{warning-levels}.  The default value is @code{" (%s)"}.
722 If you bind it to @code{""} then the warning type won't appear at
723 all.
724 @end defvar
726 @node Warning Options
727 @subsection Warning Options
729   These variables are used by users to control what happens
730 when a Lisp program reports a warning.
732 @defopt warning-minimum-level
733 This user option specifies the minimum severity level that should be
734 shown immediately to the user.  The default is @code{:warning}, which
735 means to immediately display all warnings except @code{:debug}
736 warnings.
737 @end defopt
739 @defopt warning-minimum-log-level
740 This user option specifies the minimum severity level that should be
741 logged in the warnings buffer.  The default is @code{:warning}, which
742 means to log all warnings except @code{:debug} warnings.
743 @end defopt
745 @defopt warning-suppress-types
746 This list specifies which warning types should not be displayed
747 immediately for the user.  Each element of the list should be a list
748 of symbols.  If its elements match the first elements in a warning
749 type, then that warning is not displayed immediately.
750 @end defopt
752 @defopt warning-suppress-log-types
753 This list specifies which warning types should not be logged in the
754 warnings buffer.  Each element of the list should be a list of
755 symbols.  If it matches the first few elements in a warning type, then
756 that warning is not logged.
757 @end defopt
759 @node Invisible Text
760 @section Invisible Text
762 @cindex invisible text
763 You can make characters @dfn{invisible}, so that they do not appear on
764 the screen, with the @code{invisible} property.  This can be either a
765 text property (@pxref{Text Properties}) or a property of an overlay
766 (@pxref{Overlays}).  Cursor motion also partly ignores these
767 characters; if the command loop finds point within them, it moves
768 point to the other side of them.
770 In the simplest case, any non-@code{nil} @code{invisible} property makes
771 a character invisible.  This is the default case---if you don't alter
772 the default value of @code{buffer-invisibility-spec}, this is how the
773 @code{invisible} property works.  You should normally use @code{t}
774 as the value of the @code{invisible} property if you don't plan
775 to set @code{buffer-invisibility-spec} yourself.
777 More generally, you can use the variable @code{buffer-invisibility-spec}
778 to control which values of the @code{invisible} property make text
779 invisible.  This permits you to classify the text into different subsets
780 in advance, by giving them different @code{invisible} values, and
781 subsequently make various subsets visible or invisible by changing the
782 value of @code{buffer-invisibility-spec}.
784 Controlling visibility with @code{buffer-invisibility-spec} is
785 especially useful in a program to display the list of entries in a
786 database.  It permits the implementation of convenient filtering
787 commands to view just a part of the entries in the database.  Setting
788 this variable is very fast, much faster than scanning all the text in
789 the buffer looking for properties to change.
791 @defvar buffer-invisibility-spec
792 This variable specifies which kinds of @code{invisible} properties
793 actually make a character invisible.  Setting this variable makes it
794 buffer-local.
796 @table @asis
797 @item @code{t}
798 A character is invisible if its @code{invisible} property is
799 non-@code{nil}.  This is the default.
801 @item a list
802 Each element of the list specifies a criterion for invisibility; if a
803 character's @code{invisible} property fits any one of these criteria,
804 the character is invisible.  The list can have two kinds of elements:
806 @table @code
807 @item @var{atom}
808 A character is invisible if its @code{invisible} property value
809 is @var{atom} or if it is a list with @var{atom} as a member.
811 @item (@var{atom} . t)
812 A character is invisible if its @code{invisible} property value is
813 @var{atom} or if it is a list with @var{atom} as a member.  Moreover,
814 a sequence of such characters displays as an ellipsis.
815 @end table
816 @end table
817 @end defvar
819   Two functions are specifically provided for adding elements to
820 @code{buffer-invisibility-spec} and removing elements from it.
822 @defun add-to-invisibility-spec element
823 This function adds the element @var{element} to
824 @code{buffer-invisibility-spec}.  If @code{buffer-invisibility-spec}
825 was @code{t}, it changes to a list, @code{(t)}, so that text whose
826 @code{invisible} property is @code{t} remains invisible.
827 @end defun
829 @defun remove-from-invisibility-spec element
830 This removes the element @var{element} from
831 @code{buffer-invisibility-spec}.  This does nothing if @var{element}
832 is not in the list.
833 @end defun
835   A convention for use of @code{buffer-invisibility-spec} is that a
836 major mode should use the mode's own name as an element of
837 @code{buffer-invisibility-spec} and as the value of the
838 @code{invisible} property:
840 @example
841 ;; @r{If you want to display an ellipsis:}
842 (add-to-invisibility-spec '(my-symbol . t))
843 ;; @r{If you don't want ellipsis:}
844 (add-to-invisibility-spec 'my-symbol)
846 (overlay-put (make-overlay beginning end)
847              'invisible 'my-symbol)
849 ;; @r{When done with the overlays:}
850 (remove-from-invisibility-spec '(my-symbol . t))
851 ;; @r{Or respectively:}
852 (remove-from-invisibility-spec 'my-symbol)
853 @end example
855   You can check for invisibility using the following function:
857 @defun invisible-p pos-or-prop
858 If @var{pos-or-prop} is a marker or number, this function returns a
859 non-@code{nil} value if the text at that position is invisible.
861 If @var{pos-or-prop} is any other kind of Lisp object, that is taken
862 to mean a possible value of the @code{invisible} text or overlay
863 property.  In that case, this function returns a non-@code{nil} value
864 if that value would cause text to become invisible, based on the
865 current value of @code{buffer-invisibility-spec}.
866 @end defun
868 @vindex line-move-ignore-invisible
869   Ordinarily, functions that operate on text or move point do not care
870 whether the text is invisible.  The user-level line motion commands
871 ignore invisible newlines if @code{line-move-ignore-invisible} is
872 non-@code{nil} (the default), but only because they are explicitly
873 programmed to do so.
875   However, if a command ends with point inside or at the boundary of invisible
876 text, the main editing loop moves point to one of the two ends of the invisible
877 text.  Which end to move to is chosen based on the following factors: make sure
878 that the overall movement of the command is still in the same direction, and
879 prefer a position where an inserted char would not inherit the @code{invisible}
880 property.  Additionally, if the text is not replaced by an ellipsis and the
881 command only moved within the invisible text, then point is moved one extra
882 character so as to try and reflect the command's movement by a visible movement
883 of the cursor.
885   Thus, if the command moved point back to an invisible range (with the usual
886 stickiness), Emacs moves point back to the beginning of that range.  If the
887 command moved point forward into an invisible range, Emacs moves point forward
888 to the first visible character that follows the invisible text and then forward
889 one more character.
891   Incremental search can make invisible overlays visible temporarily
892 and/or permanently when a match includes invisible text.  To enable
893 this, the overlay should have a non-@code{nil}
894 @code{isearch-open-invisible} property.  The property value should be a
895 function to be called with the overlay as an argument.  This function
896 should make the overlay visible permanently; it is used when the match
897 overlaps the overlay on exit from the search.
899   During the search, such overlays are made temporarily visible by
900 temporarily modifying their invisible and intangible properties.  If you
901 want this to be done differently for a certain overlay, give it an
902 @code{isearch-open-invisible-temporary} property which is a function.
903 The function is called with two arguments: the first is the overlay, and
904 the second is @code{nil} to make the overlay visible, or @code{t} to
905 make it invisible again.
907 @node Selective Display
908 @section Selective Display
909 @c @cindex selective display   Duplicates selective-display
911   @dfn{Selective display} refers to a pair of related features for
912 hiding certain lines on the screen.
914   The first variant, explicit selective display, is designed for use
915 in a Lisp program: it controls which lines are hidden by altering the
916 text.  This kind of hiding in some ways resembles the effect of the
917 @code{invisible} property (@pxref{Invisible Text}), but the two
918 features are different and do not work the same way.
920   In the second variant, the choice of lines to hide is made
921 automatically based on indentation.  This variant is designed to be a
922 user-level feature.
924   The way you control explicit selective display is by replacing a
925 newline (control-j) with a carriage return (control-m).  The text that
926 was formerly a line following that newline is now hidden.  Strictly
927 speaking, it is temporarily no longer a line at all, since only
928 newlines can separate lines; it is now part of the previous line.
930   Selective display does not directly affect editing commands.  For
931 example, @kbd{C-f} (@code{forward-char}) moves point unhesitatingly
932 into hidden text.  However, the replacement of newline characters with
933 carriage return characters affects some editing commands.  For
934 example, @code{next-line} skips hidden lines, since it searches only
935 for newlines.  Modes that use selective display can also define
936 commands that take account of the newlines, or that control which
937 parts of the text are hidden.
939   When you write a selectively displayed buffer into a file, all the
940 control-m's are output as newlines.  This means that when you next read
941 in the file, it looks OK, with nothing hidden.  The selective display
942 effect is seen only within Emacs.
944 @defvar selective-display
945 This buffer-local variable enables selective display.  This means that
946 lines, or portions of lines, may be made hidden.
948 @itemize @bullet
949 @item
950 If the value of @code{selective-display} is @code{t}, then the character
951 control-m marks the start of hidden text; the control-m, and the rest
952 of the line following it, are not displayed.  This is explicit selective
953 display.
955 @item
956 If the value of @code{selective-display} is a positive integer, then
957 lines that start with more than that many columns of indentation are not
958 displayed.
959 @end itemize
961 When some portion of a buffer is hidden, the vertical movement
962 commands operate as if that portion did not exist, allowing a single
963 @code{next-line} command to skip any number of hidden lines.
964 However, character movement commands (such as @code{forward-char}) do
965 not skip the hidden portion, and it is possible (if tricky) to insert
966 or delete text in an hidden portion.
968 In the examples below, we show the @emph{display appearance} of the
969 buffer @code{foo}, which changes with the value of
970 @code{selective-display}.  The @emph{contents} of the buffer do not
971 change.
973 @example
974 @group
975 (setq selective-display nil)
976      @result{} nil
978 ---------- Buffer: foo ----------
979 1 on this column
980  2on this column
981   3n this column
982   3n this column
983  2on this column
984 1 on this column
985 ---------- Buffer: foo ----------
986 @end group
988 @group
989 (setq selective-display 2)
990      @result{} 2
992 ---------- Buffer: foo ----------
993 1 on this column
994  2on this column
995  2on this column
996 1 on this column
997 ---------- Buffer: foo ----------
998 @end group
999 @end example
1000 @end defvar
1002 @defopt selective-display-ellipses
1003 If this buffer-local variable is non-@code{nil}, then Emacs displays
1004 @samp{@dots{}} at the end of a line that is followed by hidden text.
1005 This example is a continuation of the previous one.
1007 @example
1008 @group
1009 (setq selective-display-ellipses t)
1010      @result{} t
1012 ---------- Buffer: foo ----------
1013 1 on this column
1014  2on this column ...
1015  2on this column
1016 1 on this column
1017 ---------- Buffer: foo ----------
1018 @end group
1019 @end example
1021 You can use a display table to substitute other text for the ellipsis
1022 (@samp{@dots{}}).  @xref{Display Tables}.
1023 @end defopt
1025 @node Temporary Displays
1026 @section Temporary Displays
1028   Temporary displays are used by Lisp programs to put output into a
1029 buffer and then present it to the user for perusal rather than for
1030 editing.  Many help commands use this feature.
1032 @defmac with-output-to-temp-buffer buffer-name forms@dots{}
1033 This function executes @var{forms} while arranging to insert any output
1034 they print into the buffer named @var{buffer-name}, which is first
1035 created if necessary, and put into Help mode.  Finally, the buffer is
1036 displayed in some window, but not selected.
1038 If the @var{forms} do not change the major mode in the output buffer,
1039 so that it is still Help mode at the end of their execution, then
1040 @code{with-output-to-temp-buffer} makes this buffer read-only at the
1041 end, and also scans it for function and variable names to make them
1042 into clickable cross-references.  @xref{Docstring hyperlinks, , Tips
1043 for Documentation Strings}, in particular the item on hyperlinks in
1044 documentation strings, for more details.
1046 The string @var{buffer-name} specifies the temporary buffer, which
1047 need not already exist.  The argument must be a string, not a buffer.
1048 The buffer is erased initially (with no questions asked), and it is
1049 marked as unmodified after @code{with-output-to-temp-buffer} exits.
1051 @code{with-output-to-temp-buffer} binds @code{standard-output} to the
1052 temporary buffer, then it evaluates the forms in @var{forms}.  Output
1053 using the Lisp output functions within @var{forms} goes by default to
1054 that buffer (but screen display and messages in the echo area, although
1055 they are ``output'' in the general sense of the word, are not affected).
1056 @xref{Output Functions}.
1058 Several hooks are available for customizing the behavior
1059 of this construct; they are listed below.
1061 The value of the last form in @var{forms} is returned.
1063 @example
1064 @group
1065 ---------- Buffer: foo ----------
1066  This is the contents of foo.
1067 ---------- Buffer: foo ----------
1068 @end group
1070 @group
1071 (with-output-to-temp-buffer "foo"
1072     (print 20)
1073     (print standard-output))
1074 @result{} #<buffer foo>
1076 ---------- Buffer: foo ----------
1079 #<buffer foo>
1081 ---------- Buffer: foo ----------
1082 @end group
1083 @end example
1084 @end defmac
1086 @defopt temp-buffer-show-function
1087 If this variable is non-@code{nil}, @code{with-output-to-temp-buffer}
1088 calls it as a function to do the job of displaying a help buffer.  The
1089 function gets one argument, which is the buffer it should display.
1091 It is a good idea for this function to run @code{temp-buffer-show-hook}
1092 just as @code{with-output-to-temp-buffer} normally would, inside of
1093 @code{save-selected-window} and with the chosen window and buffer
1094 selected.
1095 @end defopt
1097 @defvar temp-buffer-setup-hook
1098 This normal hook is run by @code{with-output-to-temp-buffer} before
1099 evaluating @var{body}.  When the hook runs, the temporary buffer is
1100 current.  This hook is normally set up with a function to put the
1101 buffer in Help mode.
1102 @end defvar
1104 @defvar temp-buffer-show-hook
1105 This normal hook is run by @code{with-output-to-temp-buffer} after
1106 displaying the temporary buffer.  When the hook runs, the temporary buffer
1107 is current, and the window it was displayed in is selected.
1108 @end defvar
1110 @defun momentary-string-display string position &optional char message
1111 This function momentarily displays @var{string} in the current buffer at
1112 @var{position}.  It has no effect on the undo list or on the buffer's
1113 modification status.
1115 The momentary display remains until the next input event.  If the next
1116 input event is @var{char}, @code{momentary-string-display} ignores it
1117 and returns.  Otherwise, that event remains buffered for subsequent use
1118 as input.  Thus, typing @var{char} will simply remove the string from
1119 the display, while typing (say) @kbd{C-f} will remove the string from
1120 the display and later (presumably) move point forward.  The argument
1121 @var{char} is a space by default.
1123 The return value of @code{momentary-string-display} is not meaningful.
1125 If the string @var{string} does not contain control characters, you can
1126 do the same job in a more general way by creating (and then subsequently
1127 deleting) an overlay with a @code{before-string} property.
1128 @xref{Overlay Properties}.
1130 If @var{message} is non-@code{nil}, it is displayed in the echo area
1131 while @var{string} is displayed in the buffer.  If it is @code{nil}, a
1132 default message says to type @var{char} to continue.
1134 In this example, point is initially located at the beginning of the
1135 second line:
1137 @example
1138 @group
1139 ---------- Buffer: foo ----------
1140 This is the contents of foo.
1141 @point{}Second line.
1142 ---------- Buffer: foo ----------
1143 @end group
1145 @group
1146 (momentary-string-display
1147   "**** Important Message! ****"
1148   (point) ?\r
1149   "Type RET when done reading")
1150 @result{} t
1151 @end group
1153 @group
1154 ---------- Buffer: foo ----------
1155 This is the contents of foo.
1156 **** Important Message! ****Second line.
1157 ---------- Buffer: foo ----------
1159 ---------- Echo Area ----------
1160 Type RET when done reading
1161 ---------- Echo Area ----------
1162 @end group
1163 @end example
1164 @end defun
1166 @node Overlays
1167 @section Overlays
1168 @cindex overlays
1170 You can use @dfn{overlays} to alter the appearance of a buffer's text on
1171 the screen, for the sake of presentation features.  An overlay is an
1172 object that belongs to a particular buffer, and has a specified
1173 beginning and end.  It also has properties that you can examine and set;
1174 these affect the display of the text within the overlay.
1176 @cindex scalability of overlays
1177 The visual effect of an overlay is the same as of the corresponding
1178 text property (@pxref{Text Properties}).  However, due to a different
1179 implementation, overlays generally don't scale well (many operations
1180 take a time that is proportional to the number of overlays in the
1181 buffer).  If you need to affect the visual appearance of many portions
1182 in the buffer, we recommend using text properties.
1184 An overlay uses markers to record its beginning and end; thus,
1185 editing the text of the buffer adjusts the beginning and end of each
1186 overlay so that it stays with the text.  When you create the overlay,
1187 you can specify whether text inserted at the beginning should be
1188 inside the overlay or outside, and likewise for the end of the overlay.
1190 @menu
1191 * Managing Overlays::   Creating and moving overlays.
1192 * Overlay Properties::  How to read and set properties.
1193                           What properties do to the screen display.
1194 * Finding Overlays::    Searching for overlays.
1195 @end menu
1197 @node Managing Overlays
1198 @subsection Managing Overlays
1200   This section describes the functions to create, delete and move
1201 overlays, and to examine their contents.  Overlay changes are not
1202 recorded in the buffer's undo list, since the overlays are not
1203 part of the buffer's contents.
1205 @defun overlayp object
1206 This function returns @code{t} if @var{object} is an overlay.
1207 @end defun
1209 @defun make-overlay start end &optional buffer front-advance rear-advance
1210 This function creates and returns an overlay that belongs to
1211 @var{buffer} and ranges from @var{start} to @var{end}.  Both @var{start}
1212 and @var{end} must specify buffer positions; they may be integers or
1213 markers.  If @var{buffer} is omitted, the overlay is created in the
1214 current buffer.
1216 The arguments @var{front-advance} and @var{rear-advance} specify the
1217 marker insertion type for the start of the overlay and for the end of
1218 the overlay, respectively.  @xref{Marker Insertion Types}.  If they
1219 are both @code{nil}, the default, then the overlay extends to include
1220 any text inserted at the beginning, but not text inserted at the end.
1221 If @var{front-advance} is non-@code{nil}, text inserted at the
1222 beginning of the overlay is excluded from the overlay.  If
1223 @var{rear-advance} is non-@code{nil}, text inserted at the end of the
1224 overlay is included in the overlay.
1225 @end defun
1227 @defun overlay-start overlay
1228 This function returns the position at which @var{overlay} starts,
1229 as an integer.
1230 @end defun
1232 @defun overlay-end overlay
1233 This function returns the position at which @var{overlay} ends,
1234 as an integer.
1235 @end defun
1237 @defun overlay-buffer overlay
1238 This function returns the buffer that @var{overlay} belongs to.  It
1239 returns @code{nil} if @var{overlay} has been deleted.
1240 @end defun
1242 @defun delete-overlay overlay
1243 This function deletes @var{overlay}.  The overlay continues to exist as
1244 a Lisp object, and its property list is unchanged, but it ceases to be
1245 attached to the buffer it belonged to, and ceases to have any effect on
1246 display.
1248 A deleted overlay is not permanently disconnected.  You can give it a
1249 position in a buffer again by calling @code{move-overlay}.
1250 @end defun
1252 @defun move-overlay overlay start end &optional buffer
1253 This function moves @var{overlay} to @var{buffer}, and places its bounds
1254 at @var{start} and @var{end}.  Both arguments @var{start} and @var{end}
1255 must specify buffer positions; they may be integers or markers.
1257 If @var{buffer} is omitted, @var{overlay} stays in the same buffer it
1258 was already associated with; if @var{overlay} was deleted, it goes into
1259 the current buffer.
1261 The return value is @var{overlay}.
1263 This is the only valid way to change the endpoints of an overlay.  Do
1264 not try modifying the markers in the overlay by hand, as that fails to
1265 update other vital data structures and can cause some overlays to be
1266 ``lost.''
1267 @end defun
1269 @defun remove-overlays &optional start end name value
1270 This function removes all the overlays between @var{start} and
1271 @var{end} whose property @var{name} has the value @var{value}.  It can
1272 move the endpoints of the overlays in the region, or split them.
1274 If @var{name} is omitted or @code{nil}, it means to delete all overlays in
1275 the specified region.  If @var{start} and/or @var{end} are omitted or
1276 @code{nil}, that means the beginning and end of the buffer respectively.
1277 Therefore, @code{(remove-overlays)} removes all the overlays in the
1278 current buffer.
1279 @end defun
1281 @defun copy-overlay overlay
1282 This function returns a copy of @var{overlay}.  The copy has the same
1283 endpoints and properties as @var{overlay}.  However, the marker
1284 insertion type for the start of the overlay and for the end of the
1285 overlay are set to their default values (@pxref{Marker Insertion
1286 Types}).
1287 @end defun
1289   Here are some examples:
1291 @example
1292 ;; @r{Create an overlay.}
1293 (setq foo (make-overlay 1 10))
1294      @result{} #<overlay from 1 to 10 in display.texi>
1295 (overlay-start foo)
1296      @result{} 1
1297 (overlay-end foo)
1298      @result{} 10
1299 (overlay-buffer foo)
1300      @result{} #<buffer display.texi>
1301 ;; @r{Give it a property we can check later.}
1302 (overlay-put foo 'happy t)
1303      @result{} t
1304 ;; @r{Verify the property is present.}
1305 (overlay-get foo 'happy)
1306      @result{} t
1307 ;; @r{Move the overlay.}
1308 (move-overlay foo 5 20)
1309      @result{} #<overlay from 5 to 20 in display.texi>
1310 (overlay-start foo)
1311      @result{} 5
1312 (overlay-end foo)
1313      @result{} 20
1314 ;; @r{Delete the overlay.}
1315 (delete-overlay foo)
1316      @result{} nil
1317 ;; @r{Verify it is deleted.}
1319      @result{} #<overlay in no buffer>
1320 ;; @r{A deleted overlay has no position.}
1321 (overlay-start foo)
1322      @result{} nil
1323 (overlay-end foo)
1324      @result{} nil
1325 (overlay-buffer foo)
1326      @result{} nil
1327 ;; @r{Undelete the overlay.}
1328 (move-overlay foo 1 20)
1329      @result{} #<overlay from 1 to 20 in display.texi>
1330 ;; @r{Verify the results.}
1331 (overlay-start foo)
1332      @result{} 1
1333 (overlay-end foo)
1334      @result{} 20
1335 (overlay-buffer foo)
1336      @result{} #<buffer display.texi>
1337 ;; @r{Moving and deleting the overlay does not change its properties.}
1338 (overlay-get foo 'happy)
1339      @result{} t
1340 @end example
1342   Emacs stores the overlays of each buffer in two lists, divided
1343 around an arbitrary ``center position.''  One list extends backwards
1344 through the buffer from that center position, and the other extends
1345 forwards from that center position.  The center position can be anywhere
1346 in the buffer.
1348 @defun overlay-recenter pos
1349 This function recenters the overlays of the current buffer around
1350 position @var{pos}.  That makes overlay lookup faster for positions
1351 near @var{pos}, but slower for positions far away from @var{pos}.
1352 @end defun
1354   A loop that scans the buffer forwards, creating overlays, can run
1355 faster if you do @code{(overlay-recenter (point-max))} first.
1357 @node Overlay Properties
1358 @subsection Overlay Properties
1360   Overlay properties are like text properties in that the properties that
1361 alter how a character is displayed can come from either source.  But in
1362 most respects they are different.  @xref{Text Properties}, for comparison.
1364   Text properties are considered a part of the text; overlays and
1365 their properties are specifically considered not to be part of the
1366 text.  Thus, copying text between various buffers and strings
1367 preserves text properties, but does not try to preserve overlays.
1368 Changing a buffer's text properties marks the buffer as modified,
1369 while moving an overlay or changing its properties does not.  Unlike
1370 text property changes, overlay property changes are not recorded in
1371 the buffer's undo list.
1373   Since more than one overlay can specify a property value for the
1374 same character, Emacs lets you specify a priority value of each
1375 overlay.  You should not make assumptions about which overlay will
1376 prevail when there is a conflict and they have the same priority.
1378   These functions read and set the properties of an overlay:
1380 @defun overlay-get overlay prop
1381 This function returns the value of property @var{prop} recorded in
1382 @var{overlay}, if any.  If @var{overlay} does not record any value for
1383 that property, but it does have a @code{category} property which is a
1384 symbol, that symbol's @var{prop} property is used.  Otherwise, the value
1385 is @code{nil}.
1386 @end defun
1388 @defun overlay-put overlay prop value
1389 This function sets the value of property @var{prop} recorded in
1390 @var{overlay} to @var{value}.  It returns @var{value}.
1391 @end defun
1393 @defun overlay-properties overlay
1394 This returns a copy of the property list of @var{overlay}.
1395 @end defun
1397   See also the function @code{get-char-property} which checks both
1398 overlay properties and text properties for a given character.
1399 @xref{Examining Properties}.
1401   Many overlay properties have special meanings; here is a table
1402 of them:
1404 @table @code
1405 @item priority
1406 @kindex priority @r{(overlay property)}
1407 This property's value (which should be a nonnegative integer number)
1408 determines the priority of the overlay.  No priority, or @code{nil},
1409 means zero.
1411 The priority matters when two or more overlays cover the same
1412 character and both specify the same property; the one whose
1413 @code{priority} value is larger overrides the other.  For the
1414 @code{face} property, the higher priority overlay's value does not
1415 completely override the other value; instead, its face attributes
1416 override the face attributes of the lower priority @code{face}
1417 property.
1419 Currently, all overlays take priority over text properties.  Please
1420 avoid using negative priority values, as we have not yet decided just
1421 what they should mean.
1423 @item window
1424 @kindex window @r{(overlay property)}
1425 If the @code{window} property is non-@code{nil}, then the overlay
1426 applies only on that window.
1428 @item category
1429 @kindex category @r{(overlay property)}
1430 If an overlay has a @code{category} property, we call it the
1431 @dfn{category} of the overlay.  It should be a symbol.  The properties
1432 of the symbol serve as defaults for the properties of the overlay.
1434 @item face
1435 @kindex face @r{(overlay property)}
1436 This property controls the way text is displayed---for example, which
1437 font and which colors.  @xref{Faces}, for more information.
1439 In the simplest case, the value is a face name.  It can also be a list;
1440 then each element can be any of these possibilities:
1442 @itemize @bullet
1443 @item
1444 A face name (a symbol or string).
1446 @item
1447 A property list of face attributes.  This has the form (@var{keyword}
1448 @var{value} @dots{}), where each @var{keyword} is a face attribute
1449 name and @var{value} is a meaningful value for that attribute.  With
1450 this feature, you do not need to create a face each time you want to
1451 specify a particular attribute for certain text.  @xref{Face
1452 Attributes}.
1454 @item
1455 A cons cell, of the form @code{(foreground-color . @var{color-name})}
1456 or @code{(background-color . @var{color-name})}.  These elements
1457 specify just the foreground color or just the background color.
1459 @code{(foreground-color . @var{color-name})} has the same effect as
1460 @code{(:foreground @var{color-name})}; likewise for the background.
1461 @end itemize
1463 @item mouse-face
1464 @kindex mouse-face @r{(overlay property)}
1465 This property is used instead of @code{face} when the mouse is within
1466 the range of the overlay.  However, Emacs ignores all face attributes
1467 from this property that alter the text size (e.g.  @code{:height},
1468 @code{:weight}, and @code{:slant}).  Those attributes are always the
1469 same as in the unhighlighted text.
1471 @item display
1472 @kindex display @r{(overlay property)}
1473 This property activates various features that change the
1474 way text is displayed.  For example, it can make text appear taller
1475 or shorter, higher or lower, wider or narrower, or replaced with an image.
1476 @xref{Display Property}.
1478 @item help-echo
1479 @kindex help-echo @r{(overlay property)}
1480 If an overlay has a @code{help-echo} property, then when you move the
1481 mouse onto the text in the overlay, Emacs displays a help string in the
1482 echo area, or in the tooltip window.  For details see @ref{Text
1483 help-echo}.
1485 @item modification-hooks
1486 @kindex modification-hooks @r{(overlay property)}
1487 This property's value is a list of functions to be called if any
1488 character within the overlay is changed or if text is inserted strictly
1489 within the overlay.
1491 The hook functions are called both before and after each change.
1492 If the functions save the information they receive, and compare notes
1493 between calls, they can determine exactly what change has been made
1494 in the buffer text.
1496 When called before a change, each function receives four arguments: the
1497 overlay, @code{nil}, and the beginning and end of the text range to be
1498 modified.
1500 When called after a change, each function receives five arguments: the
1501 overlay, @code{t}, the beginning and end of the text range just
1502 modified, and the length of the pre-change text replaced by that range.
1503 (For an insertion, the pre-change length is zero; for a deletion, that
1504 length is the number of characters deleted, and the post-change
1505 beginning and end are equal.)
1507 If these functions modify the buffer, they should bind
1508 @code{inhibit-modification-hooks} to @code{t} around doing so, to
1509 avoid confusing the internal mechanism that calls these hooks.
1511 Text properties also support the @code{modification-hooks} property,
1512 but the details are somewhat different (@pxref{Special Properties}).
1514 @item insert-in-front-hooks
1515 @kindex insert-in-front-hooks @r{(overlay property)}
1516 This property's value is a list of functions to be called before and
1517 after inserting text right at the beginning of the overlay.  The calling
1518 conventions are the same as for the @code{modification-hooks} functions.
1520 @item insert-behind-hooks
1521 @kindex insert-behind-hooks @r{(overlay property)}
1522 This property's value is a list of functions to be called before and
1523 after inserting text right at the end of the overlay.  The calling
1524 conventions are the same as for the @code{modification-hooks} functions.
1526 @item invisible
1527 @kindex invisible @r{(overlay property)}
1528 The @code{invisible} property can make the text in the overlay
1529 invisible, which means that it does not appear on the screen.
1530 @xref{Invisible Text}, for details.
1532 @item intangible
1533 @kindex intangible @r{(overlay property)}
1534 The @code{intangible} property on an overlay works just like the
1535 @code{intangible} text property.  @xref{Special Properties}, for details.
1537 @item isearch-open-invisible
1538 This property tells incremental search how to make an invisible overlay
1539 visible, permanently, if the final match overlaps it.  @xref{Invisible
1540 Text}.
1542 @item isearch-open-invisible-temporary
1543 This property tells incremental search how to make an invisible overlay
1544 visible, temporarily, during the search.  @xref{Invisible Text}.
1546 @item before-string
1547 @kindex before-string @r{(overlay property)}
1548 This property's value is a string to add to the display at the beginning
1549 of the overlay.  The string does not appear in the buffer in any
1550 sense---only on the screen.
1552 @item after-string
1553 @kindex after-string @r{(overlay property)}
1554 This property's value is a string to add to the display at the end of
1555 the overlay.  The string does not appear in the buffer in any
1556 sense---only on the screen.
1558 @item line-prefix
1559 This property specifies a display spec to prepend to each
1560 non-continuation line at display-time.  @xref{Truncation}.
1562 @itemx wrap-prefix
1563 This property specifies a display spec to prepend to each continuation
1564 line at display-time.  @xref{Truncation}.
1566 @item evaporate
1567 @kindex evaporate @r{(overlay property)}
1568 If this property is non-@code{nil}, the overlay is deleted automatically
1569 if it becomes empty (i.e., if its length becomes zero).  If you give
1570 an empty overlay a non-@code{nil} @code{evaporate} property, that deletes
1571 it immediately.
1573 @item local-map
1574 @cindex keymap of character (and overlays)
1575 @kindex local-map @r{(overlay property)}
1576 If this property is non-@code{nil}, it specifies a keymap for a portion
1577 of the text.  The property's value replaces the buffer's local map, when
1578 the character after point is within the overlay.  @xref{Active Keymaps}.
1580 @item keymap
1581 @kindex keymap @r{(overlay property)}
1582 The @code{keymap} property is similar to @code{local-map} but overrides the
1583 buffer's local map (and the map specified by the @code{local-map}
1584 property) rather than replacing it.
1585 @end table
1587 The @code{local-map} and @code{keymap} properties do not affect a
1588 string displayed by the @code{before-string}, @code{after-string}, or
1589 @code{display} properties.  This is only relevant for mouse clicks and
1590 other mouse events that fall on the string, since point is never on
1591 the string.  To bind special mouse events for the string, assign it a
1592 @code{local-map} or @code{keymap} text property.  @xref{Special
1593 Properties}.
1595 @node Finding Overlays
1596 @subsection Searching for Overlays
1598 @defun overlays-at pos
1599 This function returns a list of all the overlays that cover the
1600 character at position @var{pos} in the current buffer.  The list is in
1601 no particular order.  An overlay contains position @var{pos} if it
1602 begins at or before @var{pos}, and ends after @var{pos}.
1604 To illustrate usage, here is a Lisp function that returns a list of the
1605 overlays that specify property @var{prop} for the character at point:
1607 @smallexample
1608 (defun find-overlays-specifying (prop)
1609   (let ((overlays (overlays-at (point)))
1610         found)
1611     (while overlays
1612       (let ((overlay (car overlays)))
1613         (if (overlay-get overlay prop)
1614             (setq found (cons overlay found))))
1615       (setq overlays (cdr overlays)))
1616     found))
1617 @end smallexample
1618 @end defun
1620 @defun overlays-in beg end
1621 This function returns a list of the overlays that overlap the region
1622 @var{beg} through @var{end}.  ``Overlap'' means that at least one
1623 character is contained within the overlay and also contained within the
1624 specified region; however, empty overlays are included in the result if
1625 they are located at @var{beg}, strictly between @var{beg} and @var{end},
1626 or at @var{end} when @var{end} denotes the position at the end of the
1627 buffer.
1628 @end defun
1630 @defun next-overlay-change pos
1631 This function returns the buffer position of the next beginning or end
1632 of an overlay, after @var{pos}.  If there is none, it returns
1633 @code{(point-max)}.
1634 @end defun
1636 @defun previous-overlay-change pos
1637 This function returns the buffer position of the previous beginning or
1638 end of an overlay, before @var{pos}.  If there is none, it returns
1639 @code{(point-min)}.
1640 @end defun
1642   As an example, here's a simplified (and inefficient) version of the
1643 primitive function @code{next-single-char-property-change}
1644 (@pxref{Property Search}).  It searches forward from position
1645 @var{pos} for the next position where the value of a given property
1646 @code{prop}, as obtained from either overlays or text properties,
1647 changes.
1649 @smallexample
1650 (defun next-single-char-property-change (position prop)
1651   (save-excursion
1652     (goto-char position)
1653     (let ((propval (get-char-property (point) prop)))
1654       (while (and (not (eobp))
1655                   (eq (get-char-property (point) prop) propval))
1656         (goto-char (min (next-overlay-change (point))
1657                         (next-single-property-change (point) prop)))))
1658     (point)))
1659 @end smallexample
1661 @node Width
1662 @section Width
1664 Since not all characters have the same width, these functions let you
1665 check the width of a character.  @xref{Primitive Indent}, and
1666 @ref{Screen Lines}, for related functions.
1668 @defun char-width char
1669 This function returns the width in columns of the character @var{char},
1670 if it were displayed in the current buffer and the selected window.
1671 @end defun
1673 @defun string-width string
1674 This function returns the width in columns of the string @var{string},
1675 if it were displayed in the current buffer and the selected window.
1676 @end defun
1678 @defun truncate-string-to-width string width &optional start-column padding ellipsis
1679 This function returns the part of @var{string} that fits within
1680 @var{width} columns, as a new string.
1682 If @var{string} does not reach @var{width}, then the result ends where
1683 @var{string} ends.  If one multi-column character in @var{string}
1684 extends across the column @var{width}, that character is not included in
1685 the result.  Thus, the result can fall short of @var{width} but cannot
1686 go beyond it.
1688 The optional argument @var{start-column} specifies the starting column.
1689 If this is non-@code{nil}, then the first @var{start-column} columns of
1690 the string are omitted from the value.  If one multi-column character in
1691 @var{string} extends across the column @var{start-column}, that
1692 character is not included.
1694 The optional argument @var{padding}, if non-@code{nil}, is a padding
1695 character added at the beginning and end of the result string, to extend
1696 it to exactly @var{width} columns.  The padding character is used at the
1697 end of the result if it falls short of @var{width}.  It is also used at
1698 the beginning of the result if one multi-column character in
1699 @var{string} extends across the column @var{start-column}.
1701 If @var{ellipsis} is non-@code{nil}, it should be a string which will
1702 replace the end of @var{str} (including any padding) if it extends
1703 beyond @var{end-column}, unless the display width of @var{str} is
1704 equal to or less than the display width of @var{ellipsis}.  If
1705 @var{ellipsis} is non-@code{nil} and not a string, it stands for
1706 @code{"..."}.
1708 @example
1709 (truncate-string-to-width "\tab\t" 12 4)
1710      @result{} "ab"
1711 (truncate-string-to-width "\tab\t" 12 4 ?\s)
1712      @result{} "    ab  "
1713 @end example
1714 @end defun
1716 @node Line Height
1717 @section Line Height
1718 @cindex line height
1720   The total height of each display line consists of the height of the
1721 contents of the line, plus optional additional vertical line spacing
1722 above or below the display line.
1724   The height of the line contents is the maximum height of any
1725 character or image on that display line, including the final newline
1726 if there is one.  (A display line that is continued doesn't include a
1727 final newline.)  That is the default line height, if you do nothing to
1728 specify a greater height.  (In the most common case, this equals the
1729 height of the default frame font.)
1731   There are several ways to explicitly specify a larger line height,
1732 either by specifying an absolute height for the display line, or by
1733 specifying vertical space.  However, no matter what you specify, the
1734 actual line height can never be less than the default.
1736 @kindex line-height @r{(text property)}
1737   A newline can have a @code{line-height} text or overlay property
1738 that controls the total height of the display line ending in that
1739 newline.
1741   If the property value is @code{t}, the newline character has no
1742 effect on the displayed height of the line---the visible contents
1743 alone determine the height.  This is useful for tiling small images
1744 (or image slices) without adding blank areas between the images.
1746   If the property value is a list of the form @code{(@var{height}
1747 @var{total})}, that adds extra space @emph{below} the display line.
1748 First Emacs uses @var{height} as a height spec to control extra space
1749 @emph{above} the line; then it adds enough space @emph{below} the line
1750 to bring the total line height up to @var{total}.  In this case, the
1751 other ways to specify the line spacing are ignored.
1753   Any other kind of property value is a height spec, which translates
1754 into a number---the specified line height.  There are several ways to
1755 write a height spec; here's how each of them translates into a number:
1757 @table @code
1758 @item @var{integer}
1759 If the height spec is a positive integer, the height value is that integer.
1760 @item @var{float}
1761 If the height spec is a float, @var{float}, the numeric height value
1762 is @var{float} times the frame's default line height.
1763 @item (@var{face} . @var{ratio})
1764 If the height spec is a cons of the format shown, the numeric height
1765 is @var{ratio} times the height of face @var{face}.  @var{ratio} can
1766 be any type of number, or @code{nil} which means a ratio of 1.
1767 If @var{face} is @code{t}, it refers to the current face.
1768 @item (nil . @var{ratio})
1769 If the height spec is a cons of the format shown, the numeric height
1770 is @var{ratio} times the height of the contents of the line.
1771 @end table
1773   Thus, any valid height spec determines the height in pixels, one way
1774 or another.  If the line contents' height is less than that, Emacs
1775 adds extra vertical space above the line to achieve the specified
1776 total height.
1778   If you don't specify the @code{line-height} property, the line's
1779 height consists of the contents' height plus the line spacing.
1780 There are several ways to specify the line spacing for different
1781 parts of Emacs text.
1783   On graphical terminals, you can specify the line spacing for all
1784 lines in a frame, using the @code{line-spacing} frame parameter
1785 (@pxref{Layout Parameters}).  However, if the default value of
1786 @code{line-spacing} is non-@code{nil}, it overrides the
1787 frame's @code{line-spacing} parameter.  An integer value specifies the
1788 number of pixels put below lines.  A floating point number specifies
1789 the spacing relative to the frame's default line height.
1791 @vindex line-spacing
1792   You can specify the line spacing for all lines in a buffer via the
1793 buffer-local @code{line-spacing} variable.  An integer value specifies
1794 the number of pixels put below lines.  A floating point number
1795 specifies the spacing relative to the default frame line height.  This
1796 overrides line spacings specified for the frame.
1798 @kindex line-spacing @r{(text property)}
1799   Finally, a newline can have a @code{line-spacing} text or overlay
1800 property that overrides the default frame line spacing and the buffer
1801 local @code{line-spacing} variable, for the display line ending in
1802 that newline.
1804   One way or another, these mechanisms specify a Lisp value for the
1805 spacing of each line.  The value is a height spec, and it translates
1806 into a Lisp value as described above.  However, in this case the
1807 numeric height value specifies the line spacing, rather than the line
1808 height.
1810   On text terminals, the line spacing cannot be altered.
1812 @node Faces
1813 @section Faces
1814 @cindex faces
1816   A @dfn{face} is a collection of graphical attributes for displaying
1817 text: font, foreground color, background color, optional underlining,
1818 and so on.  Faces control how buffer text is displayed, and how some
1819 parts of the frame, such as the mode-line, are displayed.
1820 @xref{Standard Faces,,, emacs, The GNU Emacs Manual}, for the list of
1821 faces Emacs normally comes with.
1823 @cindex face id
1824   For most purposes, you refer to a face in Lisp programs using its
1825 @dfn{face name}.  This is either a string or (equivalently) a Lisp
1826 symbol whose name is equal to that string.
1828 @defun facep object
1829 This function returns a non-@code{nil} value if @var{object} is a Lisp
1830 symbol or string that names a face.  Otherwise, it returns @code{nil}.
1831 @end defun
1833   Each face name is meaningful for all frames, and by default it has
1834 the same meaning in all frames.  But you can arrange to give a
1835 particular face name a special meaning in one frame if you wish.
1837 @menu
1838 * Defining Faces::      How to define a face with @code{defface}.
1839 * Face Attributes::     What is in a face?
1840 * Attribute Functions::  Functions to examine and set face attributes.
1841 * Displaying Faces::     How Emacs combines the faces specified for a character.
1842 * Face Remapping::      Remapping faces to alternative definitions.
1843 * Face Functions::      How to define and examine faces.
1844 * Auto Faces::          Hook for automatic face assignment.
1845 * Basic Faces::         Faces that are defined by default.
1846 * Font Selection::      Finding the best available font for a face.
1847 * Font Lookup::         Looking up the names of available fonts
1848                           and information about them.
1849 * Fontsets::            A fontset is a collection of fonts
1850                           that handle a range of character sets.
1851 * Low-Level Font::      Lisp representation for character display fonts.
1852 @end menu
1854 @node Defining Faces
1855 @subsection Defining Faces
1857   The way to define a new face is with @code{defface}.  This creates a
1858 kind of customization item (@pxref{Customization}) which the user can
1859 customize using the Customization buffer (@pxref{Easy Customization,,,
1860 emacs, The GNU Emacs Manual}).
1862   People are sometimes tempted to create variables whose values specify
1863 which faces to use (for example, Font-Lock does this).  In the vast
1864 majority of cases, this is not necessary, and simply using faces
1865 directly is preferable.
1867 @defmac defface face spec doc [keyword value]@dots{}
1868 This declares @var{face} as a customizable face whose default
1869 attributes are given by @var{spec}.  You should not quote the symbol
1870 @var{face}, and it should not end in @samp{-face} (that would be
1871 redundant).  The argument @var{doc} specifies the face documentation.
1872 The keywords you can use in @code{defface} are the same as in
1873 @code{defgroup} and @code{defcustom} (@pxref{Common Keywords}).
1875 When @code{defface} executes, it defines the face according to
1876 @var{spec}, then uses any customizations that were read from the
1877 init file (@pxref{Init File}) to override that specification.
1879 When you evaluate a @code{defface} form with @kbd{C-M-x} in Emacs
1880 Lisp mode (@code{eval-defun}), a special feature of @code{eval-defun}
1881 overrides any customizations of the face.  This way, the face reflects
1882 exactly what the @code{defface} says.
1884 The purpose of @var{spec} is to specify how the face should appear on
1885 different kinds of terminals.  It should be an alist whose elements
1886 have the form @code{(@var{display} @var{atts})}.  Each element's
1887 @sc{car}, @var{display}, specifies a class of terminals.  (The first
1888 element, if its @sc{car} is @code{default}, is special---it specifies
1889 defaults for the remaining elements).  The element's @sc{cadr},
1890 @var{atts}, is a list of face attributes and their values; it
1891 specifies what the face should look like on that kind of terminal.
1892 The possible attributes are defined in the value of
1893 @code{custom-face-attributes}.
1895 The @var{display} part of an element of @var{spec} determines which
1896 frames the element matches.  If more than one element of @var{spec}
1897 matches a given frame, the first element that matches is the one used
1898 for that frame.  There are three possibilities for @var{display}:
1900 @table @asis
1901 @item @code{default}
1902 This element of @var{spec} doesn't match any frames; instead, it
1903 specifies defaults that apply to all frames.  This kind of element, if
1904 used, must be the first element of @var{spec}.  Each of the following
1905 elements can override any or all of these defaults.
1907 @item @code{t}
1908 This element of @var{spec} matches all frames.  Therefore, any
1909 subsequent elements of @var{spec} are never used.  Normally
1910 @code{t} is used in the last (or only) element of @var{spec}.
1912 @item a list
1913 If @var{display} is a list, each element should have the form
1914 @code{(@var{characteristic} @var{value}@dots{})}.  Here
1915 @var{characteristic} specifies a way of classifying frames, and the
1916 @var{value}s are possible classifications which @var{display} should
1917 apply to.  Here are the possible values of @var{characteristic}:
1919 @table @code
1920 @item type
1921 The kind of window system the frame uses---either @code{graphic} (any
1922 graphics-capable display), @code{x}, @code{pc} (for the MS-DOS console),
1923 @code{w32} (for MS Windows 9X/NT/2K/XP), or @code{tty} 
1924 (a non-graphics-capable display).
1925 @xref{Window Systems, window-system}.
1927 @item class
1928 What kinds of colors the frame supports---either @code{color},
1929 @code{grayscale}, or @code{mono}.
1931 @item background
1932 The kind of background---either @code{light} or @code{dark}.
1934 @item min-colors
1935 An integer that represents the minimum number of colors the frame
1936 should support.  This matches a frame if its
1937 @code{display-color-cells} value is at least the specified integer.
1939 @item supports
1940 Whether or not the frame can display the face attributes given in
1941 @var{value}@dots{} (@pxref{Face Attributes}).  @xref{Display Face
1942 Attribute Testing}, for more information on exactly how this testing
1943 is done.
1944 @end table
1946 If an element of @var{display} specifies more than one @var{value} for a
1947 given @var{characteristic}, any of those values is acceptable.  If
1948 @var{display} has more than one element, each element should specify a
1949 different @var{characteristic}; then @emph{each} characteristic of the
1950 frame must match one of the @var{value}s specified for it in
1951 @var{display}.
1952 @end table
1953 @end defmac
1955   Here's how the standard face @code{region} is defined:
1957 @example
1958 @group
1959 (defface region
1960   '((((class color) (min-colors 88) (background dark))
1961      :background "blue3")
1962 @end group
1963     (((class color) (min-colors 88) (background light))
1964      :background "lightgoldenrod2")
1965     (((class color) (min-colors 16) (background dark))
1966      :background "blue3")
1967     (((class color) (min-colors 16) (background light))
1968      :background "lightgoldenrod2")
1969     (((class color) (min-colors 8))
1970      :background "blue" :foreground "white")
1971     (((type tty) (class mono))
1972      :inverse-video t)
1973     (t :background "gray"))
1974 @group
1975   "Basic face for highlighting the region."
1976   :group 'basic-faces)
1977 @end group
1978 @end example
1980   Internally, @code{defface} uses the symbol property
1981 @code{face-defface-spec} to record the specified face attributes.  The
1982 attributes saved by the user with the customization buffer are
1983 recorded in the symbol property @code{saved-face}; the attributes
1984 customized by the user for the current session, but not saved, are
1985 recorded in the symbol property @code{customized-face}.  The
1986 documentation string is recorded in the symbol property
1987 @code{face-documentation}.
1989 @defopt frame-background-mode
1990 This option, if non-@code{nil}, specifies the background type to use for
1991 interpreting face definitions.  If it is @code{dark}, then Emacs treats
1992 all frames as if they had a dark background, regardless of their actual
1993 background colors.  If it is @code{light}, then Emacs treats all frames
1994 as if they had a light background.
1995 @end defopt
1997 @node Face Attributes
1998 @subsection Face Attributes
1999 @cindex face attributes
2001   The effect of using a face is determined by a fixed set of @dfn{face
2002 attributes}.  This table lists all the face attributes, their possible
2003 values, and their effects.  You can specify more than one face for a
2004 given piece of text; Emacs merges the attributes of all the faces to
2005 determine how to display the text.  @xref{Displaying Faces}.
2007   In addition to the values given below, each face attribute can also
2008 have the value @code{unspecified}.  This special value means the face
2009 doesn't specify that attribute.  In face merging, when the first face
2010 fails to specify a particular attribute, the next face gets a chance.
2011 However, the @code{default} face must specify all attributes.
2013   Some of these font attributes are meaningful only on certain kinds
2014 of displays.  If your display cannot handle a certain attribute, the
2015 attribute is ignored.
2017 @table @code
2018 @item :family
2019 Font family or fontset (a string).  @xref{Fonts,,, emacs, The GNU
2020 Emacs Manual}.  If you specify a font family name, the wild-card
2021 characters @samp{*} and @samp{?} are allowed.  The function
2022 @code{font-family-list}, described below, returns a list of available
2023 family names.  @xref{Fontsets}, for information about fontsets.
2025 @item :foundry
2026 The name of the @dfn{font foundry} for the font family specified by
2027 the @code{:family} attribute (a string).  The wild-card characters
2028 @samp{*} and @samp{?} are allowed.  @xref{Fonts,,, emacs, The GNU
2029 Emacs Manual}.
2031 @item :width
2032 Relative proportionate character width, also known as the character
2033 set width.  This should be one of the symbols @code{ultra-condensed},
2034 @code{extra-condensed}, @code{condensed}, @code{semi-condensed},
2035 @code{normal}, @code{semi-expanded}, @code{expanded},
2036 @code{extra-expanded}, or @code{ultra-expanded}.
2038 @item :height
2039 The height of the font.  In the simplest case, this is an integer in
2040 units of 1/10 point.
2042 The value can also be a floating point number or a function, which
2043 specifies the height relative to an @dfn{underlying face} (i.e., a
2044 face that has a lower priority in the list described in
2045 @ref{Displaying Faces}).  If the value is a floating point number,
2046 that specifies the amount by which to scale the height of the
2047 underlying face.  If the value is a function, that function is called
2048 with one argument, the height of the underlying face, and returns the
2049 height of the new face.  If the function is passed an integer
2050 argument, it must return an integer.
2052 The height of the default face must be specified using an integer;
2053 floating point and function values are not allowed.
2055 @item :weight
2056 Font weight---one of the symbols (from densest to faintest)
2057 @code{ultra-bold}, @code{extra-bold}, @code{bold}, @code{semi-bold},
2058 @code{normal}, @code{semi-light}, @code{light}, @code{extra-light}, or
2059 @code{ultra-light}.  On text terminals which support
2060 variable-brightness text, any weight greater than normal is displayed
2061 as extra bright, and any weight less than normal is displayed as
2062 half-bright.
2064 @item :slant
2065 Font slant---one of the symbols @code{italic}, @code{oblique},
2066 @code{normal}, @code{reverse-italic}, or @code{reverse-oblique}.  On
2067 text terminals that support variable-brightness text, slanted text is
2068 displayed as half-bright.
2070 @item :foreground
2071 Foreground color, a string.  The value can be a system-defined color
2072 name, or a hexadecimal color specification.  @xref{Color Names}.  On
2073 black-and-white displays, certain shades of gray are implemented by
2074 stipple patterns.
2076 @item :background
2077 Background color, a string.  The value can be a system-defined color
2078 name, or a hexadecimal color specification.  @xref{Color Names}.
2080 @item :underline
2081 Whether or not characters should be underlined, and in what color.  If
2082 the value is @code{t}, underlining uses the foreground color of the
2083 face.  If the value is a string, underlining uses that color.  The
2084 value @code{nil} means do not underline.
2086 @item :overline
2087 Whether or not characters should be overlined, and in what color.
2088 The value is used like that of @code{:underline}.
2090 @item :strike-through
2091 Whether or not characters should be strike-through, and in what
2092 color.  The value is used like that of @code{:underline}.
2094 @item :box
2095 Whether or not a box should be drawn around characters, its color, the
2096 width of the box lines, and 3D appearance.  Here are the possible
2097 values of the @code{:box} attribute, and what they mean:
2099 @table @asis
2100 @item @code{nil}
2101 Don't draw a box.
2103 @item @code{t}
2104 Draw a box with lines of width 1, in the foreground color.
2106 @item @var{color}
2107 Draw a box with lines of width 1, in color @var{color}.
2109 @item @code{(:line-width @var{width} :color @var{color} :style @var{style})}
2110 This way you can explicitly specify all aspects of the box.  The value
2111 @var{width} specifies the width of the lines to draw; it defaults to
2112 1.  A negative width @var{-n} means to draw a line of width @var{n}
2113 that occupies the space of the underlying text, thus avoiding any
2114 increase in the character height or width.
2116 The value @var{color} specifies the color to draw with.  The default is
2117 the foreground color of the face for simple boxes, and the background
2118 color of the face for 3D boxes.
2120 The value @var{style} specifies whether to draw a 3D box.  If it is
2121 @code{released-button}, the box looks like a 3D button that is not being
2122 pressed.  If it is @code{pressed-button}, the box looks like a 3D button
2123 that is being pressed.  If it is @code{nil} or omitted, a plain 2D box
2124 is used.
2125 @end table
2127 @item :inverse-video
2128 Whether or not characters should be displayed in inverse video.  The
2129 value should be @code{t} (yes) or @code{nil} (no).
2131 @item :stipple
2132 The background stipple, a bitmap.
2134 The value can be a string; that should be the name of a file containing
2135 external-format X bitmap data.  The file is found in the directories
2136 listed in the variable @code{x-bitmap-file-path}.
2138 Alternatively, the value can specify the bitmap directly, with a list
2139 of the form @code{(@var{width} @var{height} @var{data})}.  Here,
2140 @var{width} and @var{height} specify the size in pixels, and
2141 @var{data} is a string containing the raw bits of the bitmap, row by
2142 row.  Each row occupies @math{(@var{width} + 7) / 8} consecutive bytes
2143 in the string (which should be a unibyte string for best results).
2144 This means that each row always occupies at least one whole byte.
2146 If the value is @code{nil}, that means use no stipple pattern.
2148 Normally you do not need to set the stipple attribute, because it is
2149 used automatically to handle certain shades of gray.
2151 @item :font
2152 The font used to display the face.  Its value should be a font object.
2153 @xref{Font Selection}, for information about font objects.
2155 When specifying this attribute using @code{set-face-attribute}
2156 (@pxref{Attribute Functions}), you may also supply a font spec, a font
2157 entity, or a string.  Emacs converts such values to an appropriate
2158 font object, and stores that font object as the actual attribute
2159 value.  If you specify a string, the contents of the string should be
2160 a font name (@pxref{Fonts,,, emacs, The GNU Emacs Manual}); if the
2161 font name is an XLFD containing wildcards, Emacs chooses the first
2162 font matching those wildcards.  Specifying this attribute also changes
2163 the values of the @code{:family}, @code{:foundry}, @code{:width},
2164 @code{:height}, @code{:weight}, and @code{:slant} attributes.
2166 @item :inherit
2167 The name of a face from which to inherit attributes, or a list of face
2168 names.  Attributes from inherited faces are merged into the face like
2169 an underlying face would be, with higher priority than underlying
2170 faces (@pxref{Displaying Faces}).  If a list of faces is used,
2171 attributes from faces earlier in the list override those from later
2172 faces.
2173 @end table
2175 For compatibility with Emacs 20, you can also specify values for two
2176 ``fake'' face attributes: @code{:bold} and @code{:italic}.  Their
2177 values must be either @code{t} or @code{nil}; a value of
2178 @code{unspecified} is not allowed.  Setting @code{:bold} to @code{t}
2179 is equivalent to setting the @code{:weight} attribute to @code{bold},
2180 and setting it to @code{nil} is equivalent to setting @code{:weight}
2181 to @code{normal}.  Setting @code{:italic} to @code{t} is equivalent to
2182 setting the @code{:slant} attribute to @code{italic}, and setting it
2183 to @code{nil} is equivalent to setting @code{:slant} to @code{normal}.
2185 @defun font-family-list &optional frame
2186 This function returns a list of available font family names.  The
2187 optional argument @var{frame} specifies the frame on which the text is
2188 to be displayed; if it is @code{nil}, the selected frame is used.
2189 @end defun
2191 @defopt underline-minimum-offset
2192 This variable specifies the minimum distance between the baseline and
2193 the underline, in pixels, when displaying underlined text.
2194 @end defopt
2196 @defopt x-bitmap-file-path
2197 This variable specifies a list of directories for searching
2198 for bitmap files, for the @code{:stipple} attribute.
2199 @end defopt
2201 @defun bitmap-spec-p object
2202 This returns @code{t} if @var{object} is a valid bitmap specification,
2203 suitable for use with @code{:stipple} (see above).  It returns
2204 @code{nil} otherwise.
2205 @end defun
2207 @node Attribute Functions
2208 @subsection Face Attribute Functions
2210   This section describes the functions for accessing and modifying the
2211 attributes of an existing face.
2213 @defun set-face-attribute face frame &rest arguments
2214 This function sets one or more attributes of @var{face} for
2215 @var{frame}.  The attributes you specify this way override whatever
2216 the @code{defface} says.
2218 The extra arguments @var{arguments} specify the attributes to set, and
2219 the values for them.  They should consist of alternating attribute names
2220 (such as @code{:family} or @code{:underline}) and corresponding values.
2221 Thus,
2223 @example
2224 (set-face-attribute 'foo nil
2225                     :width 'extended
2226                     :weight 'bold
2227                     :underline "red")
2228 @end example
2230 @noindent
2231 sets the attributes @code{:width}, @code{:weight} and @code{:underline}
2232 to the corresponding values.
2234 If @var{frame} is @code{t}, this function sets the default attributes
2235 for new frames.  Default attribute values specified this way override
2236 the @code{defface} for newly created frames.
2238 If @var{frame} is @code{nil}, this function sets the attributes for
2239 all existing frames, and the default for new frames.
2240 @end defun
2242 @defun face-attribute face attribute &optional frame inherit
2243 This returns the value of the @var{attribute} attribute of @var{face}
2244 on @var{frame}.  If @var{frame} is @code{nil}, that means the selected
2245 frame (@pxref{Input Focus}).
2247 If @var{frame} is @code{t}, this returns whatever new-frames default
2248 value you previously specified with @code{set-face-attribute} for the
2249 @var{attribute} attribute of @var{face}.  If you have not specified
2250 one, it returns @code{nil}.
2252 If @var{inherit} is @code{nil}, only attributes directly defined by
2253 @var{face} are considered, so the return value may be
2254 @code{unspecified}, or a relative value.  If @var{inherit} is
2255 non-@code{nil}, @var{face}'s definition of @var{attribute} is merged
2256 with the faces specified by its @code{:inherit} attribute; however the
2257 return value may still be @code{unspecified} or relative.  If
2258 @var{inherit} is a face or a list of faces, then the result is further
2259 merged with that face (or faces), until it becomes specified and
2260 absolute.
2262 To ensure that the return value is always specified and absolute, use
2263 a value of @code{default} for @var{inherit}; this will resolve any
2264 unspecified or relative values by merging with the @code{default} face
2265 (which is always completely specified).
2267 For example,
2269 @example
2270 (face-attribute 'bold :weight)
2271      @result{} bold
2272 @end example
2273 @end defun
2275 @defun face-attribute-relative-p attribute value
2276 This function returns non-@code{nil} if @var{value}, when used as the
2277 value of the face attribute @var{attribute}, is relative.  This means
2278 it would modify, rather than completely override, any value that comes
2279 from a subsequent face in the face list or that is inherited from
2280 another face.
2282 @code{unspecified} is a relative value for all attributes.  For
2283 @code{:height}, floating point and function values are also relative.
2285 For example:
2287 @example
2288 (face-attribute-relative-p :height 2.0)
2289      @result{} t
2290 @end example
2291 @end defun
2293 @defun face-all-attributes face &optional frame
2294 This function returns an alist of attributes of @var{face}.  The
2295 elements of the result are name-value pairs of the form
2296 @w{@code{(@var{attr-name} . @var{attr-value})}}.  Optional argument
2297 @var{frame} specifies the frame whose definition of @var{face} to
2298 return; if omitted or @code{nil}, the returned value describes the
2299 default attributes of @var{face} for newly created frames.
2300 @end defun
2302 @defun merge-face-attribute attribute value1 value2
2303 If @var{value1} is a relative value for the face attribute
2304 @var{attribute}, returns it merged with the underlying value
2305 @var{value2}; otherwise, if @var{value1} is an absolute value for the
2306 face attribute @var{attribute}, returns @var{value1} unchanged.
2307 @end defun
2309   The following functions provide compatibility with Emacs 20 and
2310 below.  They work by calling @code{set-face-attribute}.  Values of
2311 @code{t} and @code{nil} for their @var{frame} argument are handled
2312 just like @code{set-face-attribute} and @code{face-attribute}.
2314 @defun set-face-foreground face color &optional frame
2315 @defunx set-face-background face color &optional frame
2316 These functions set the @code{:foreground} attribute (or
2317 @code{:background} attribute, respectively) of @var{face} to
2318 @var{color}.
2319 @end defun
2321 @defun set-face-stipple face pattern &optional frame
2322 This function sets the @code{:stipple} attribute of @var{face} to
2323 @var{pattern}.
2324 @end defun
2326 @defun set-face-font face font &optional frame
2327 This function sets the @code{:font} attribute of @var{face} to
2328 @var{font}.
2329 @end defun
2331 @defun set-face-bold-p face bold-p &optional frame
2332 This function sets the @code{:weight} attribute of @var{face} to
2333 @var{normal} if @var{bold-p} is @code{nil}, and to @var{bold}
2334 otherwise.
2335 @end defun
2337 @defun set-face-italic-p face italic-p &optional frame
2338 This function sets the @code{:slant} attribute of @var{face} to
2339 @var{normal} if @var{italic-p} is @code{nil}, and to @var{italic}
2340 otherwise.
2341 @end defun
2343 @defun set-face-underline-p face underline &optional frame
2344 This function sets the @code{:underline} attribute of @var{face} to
2345 @var{underline}.
2346 @end defun
2348 @defun set-face-inverse-video-p face inverse-video-p &optional frame
2349 This function sets the @code{:inverse-video} attribute of @var{face}
2350 to @var{inverse-video-p}.
2351 @end defun
2353 @defun invert-face face &optional frame
2354 This function swaps the foreground and background colors of face
2355 @var{face}.
2356 @end defun
2358   The following functions examine the attributes of a face.  If you
2359 don't specify @var{frame}, they refer to the selected frame; @code{t}
2360 refers to the default data for new frames.  They return the symbol
2361 @code{unspecified} if the face doesn't define any value for that
2362 attribute.
2364 @defun face-foreground face &optional frame inherit
2365 @defunx face-background face &optional frame inherit
2366 These functions return the foreground color (or background color,
2367 respectively) of face @var{face}, as a string.
2369 If @var{inherit} is @code{nil}, only a color directly defined by the face is
2370 returned.  If @var{inherit} is non-@code{nil}, any faces specified by its
2371 @code{:inherit} attribute are considered as well, and if @var{inherit}
2372 is a face or a list of faces, then they are also considered, until a
2373 specified color is found.  To ensure that the return value is always
2374 specified, use a value of @code{default} for @var{inherit}.
2375 @end defun
2377 @defun face-stipple face &optional frame inherit
2378 This function returns the name of the background stipple pattern of face
2379 @var{face}, or @code{nil} if it doesn't have one.
2381 If @var{inherit} is @code{nil}, only a stipple directly defined by the
2382 face is returned.  If @var{inherit} is non-@code{nil}, any faces
2383 specified by its @code{:inherit} attribute are considered as well, and
2384 if @var{inherit} is a face or a list of faces, then they are also
2385 considered, until a specified stipple is found.  To ensure that the
2386 return value is always specified, use a value of @code{default} for
2387 @var{inherit}.
2388 @end defun
2390 @defun face-font face &optional frame
2391 This function returns the name of the font of face @var{face}.
2392 @end defun
2394 @defun face-bold-p face &optional frame
2395 This function returns a non-@code{nil} value if the @code{:weight}
2396 attribute of @var{face} is bolder than normal (i.e., one of
2397 @code{semi-bold}, @code{bold}, @code{extra-bold}, or
2398 @code{ultra-bold}).  Otherwise, it returns @code{nil}.
2399 @end defun
2401 @defun face-italic-p face &optional frame
2402 This function returns a non-@code{nil} value if the @code{:slant}
2403 attribute of @var{face} is @code{italic} or @code{oblique}, and
2404 @code{nil} otherwise.
2405 @end defun
2407 @defun face-underline-p face &optional frame
2408 This function returns the @code{:underline} attribute of face @var{face}.
2409 @end defun
2411 @defun face-inverse-video-p face &optional frame
2412 This function returns the @code{:inverse-video} attribute of face @var{face}.
2413 @end defun
2415 @node Displaying Faces
2416 @subsection Displaying Faces
2418   Here is how Emacs determines the face to use for displaying any
2419 given piece of text:
2421 @itemize @bullet
2422 @item
2423 If the text consists of a special glyph, the glyph can specify a
2424 particular face.  @xref{Glyphs}.
2426 @item
2427 If the text lies within an active region, Emacs highlights it using
2428 the @code{region} face.  @xref{Standard Faces,,, emacs, The GNU Emacs
2429 Manual}.
2431 @item
2432 If the text lies within an overlay with a non-@code{nil} @code{face}
2433 property, Emacs applies the face or face attributes specified by that
2434 property.  If the overlay has a @code{mouse-face} property and the
2435 mouse is ``near enough'' to the overlay, Emacs applies the face or
2436 face attributes specified by the @code{mouse-face} property instead.
2437 @xref{Overlay Properties}.
2439 When multiple overlays cover one character, an overlay with higher
2440 priority overrides those with lower priority.  @xref{Overlays}.
2442 @item
2443 If the text contains a @code{face} or @code{mouse-face} property,
2444 Emacs applies the specified faces and face attributes.  @xref{Special
2445 Properties}.  (This is how Font Lock mode faces are applied.
2446 @xref{Font Lock Mode}.)
2448 @item
2449 If the text lies within the mode line of the selected window, Emacs
2450 applies the @code{mode-line} face.  For the mode line of a
2451 non-selected window, Emacs applies the @code{mode-line-inactive} face.
2452 For a header line, Emacs applies the @code{header-line} face.
2454 @item
2455 If any given attribute has not been specified during the preceding
2456 steps, Emacs applies the attribute of the @code{default} face.
2457 @end itemize
2459   If these various sources together specify more than one face for a
2460 particular character, Emacs merges the attributes of the various faces
2461 specified.  For each attribute, Emacs tries using the above order
2462 (i.e., first the face of any special glyph; then the face for region
2463 highlighting, if appropriate; then faces specified by overlays, then
2464 faces specified by text properties, then the @code{mode-line} or
2465 @code{mode-line-inactive} or @code{header-line} face, if appropriate,
2466 and finally the @code{default} face).
2468 @node Face Remapping
2469 @subsection Face Remapping
2471   The variable @code{face-remapping-alist} is used for buffer-local or
2472 global changes in the appearance of a face.  For instance, it can be
2473 used to make the @code{default} face a variable-pitch face within a
2474 particular buffer.
2476 @defvar face-remapping-alist
2477 An alist whose elements have the form @code{(@var{face}
2478 @var{remapping...})}.  This causes Emacs to display text using the
2479 face @var{face} using @var{remapping...} instead of @var{face}'s
2480 ordinary definition.  @var{remapping...} may be any face specification
2481 suitable for a @code{face} text property: either a face name, or a
2482 property list of attribute/value pairs.  @xref{Special Properties}.
2484 If @code{face-remapping-alist} is buffer-local, its local value takes
2485 effect only within that buffer.
2487 Two points bear emphasizing:
2489 @enumerate
2490 @item
2491 The new definition @var{remapping...} is the complete
2492 specification of how to display @var{face}---it entirely replaces,
2493 rather than augmenting or modifying, the normal definition of that
2494 face.
2496 @item
2497 If @var{remapping...} recursively references the same face name
2498 @var{face}, either directly remapping entry, or via the
2499 @code{:inherit} attribute of some other face in @var{remapping...},
2500 then that reference uses the normal definition of @var{face} in the
2501 selected frame, instead of the ``remapped'' definition.
2503 For instance, if the @code{mode-line} face is remapped using this
2504 entry in @code{face-remapping-alist}:
2505 @example
2506 (mode-line italic mode-line)
2507 @end example
2508 @noindent
2509 then the new definition of the @code{mode-line} face inherits from the
2510 @code{italic} face, and the @emph{normal} (non-remapped) definition of
2511 @code{mode-line} face.
2512 @end enumerate
2513 @end defvar
2515   A typical use of the @code{face-remapping-alist} is to change a
2516 buffer's @code{default} face; for example, the following changes a
2517 buffer's @code{default} face to use the @code{variable-pitch} face,
2518 with the height doubled:
2520 @example
2521 (set (make-local-variable 'face-remapping-alist)
2522      '((default variable-pitch :height 2.0)))
2523 @end example
2525   The following functions implement a higher-level interface to
2526 @code{face-remapping-alist}, making it easier to use
2527 ``cooperatively''.  They are mainly intended for buffer-local use, and
2528 so all make @code{face-remapping-alist} variable buffer-local as a
2529 side-effect.  They use entries in @code{face-remapping-alist} which
2530 have the general form:
2532 @example
2533   (@var{face} @var{relative_specs_1} @var{relative_specs_2} @var{...} @var{base_specs})
2534 @end example
2536 Everything except @var{face} is a ``face spec'': a list of face names
2537 or face attribute-value pairs.  All face specs are merged together,
2538 with earlier values taking precedence.
2540 The @var{relative_specs_}n values are ``relative specs'', and are
2541 added by @code{face-remap-add-relative} (and removed by
2542 @code{face-remap-remove-relative}.  These are intended for face
2543 modifications (such as increasing the size).  Typical users of these
2544 relative specs would be minor modes.
2546 @var{base_specs} is the lowest-priority value, and by default is just the
2547 face name, which causes the global definition of that face to be used.
2549 A non-default value of @var{base_specs} may also be set using
2550 @code{face-remap-set-base}.  Because this @emph{overwrites} the
2551 default base-spec value (which inherits the global face definition),
2552 it is up to the caller of @code{face-remap-set-base} to add such
2553 inheritance if it is desired.  A typical use of
2554 @code{face-remap-set-base} would be a major mode adding a face
2555 remappings, e.g., of the default face.
2558 @defun face-remap-add-relative face &rest specs
2559 This functions adds a face remapping entry of @var{face} to @var{specs}
2560 in the current buffer.
2562 It returns a ``cookie'' which can be used to later delete the remapping with
2563 @code{face-remap-remove-relative}.
2565 @var{specs} can be any value suitable for the @code{face} text
2566 property, including a face name, a list of face names, or a
2567 face-attribute property list.  The attributes given by @var{specs}
2568 will be merged with any other currently active face remappings of
2569 @var{face}, and with the global definition of @var{face} (by default;
2570 this may be changed using @code{face-remap-set-base}), with the most
2571 recently added relative remapping taking precedence.
2572 @end defun
2574 @defun face-remap-remove-relative cookie
2575 This function removes a face remapping previously added by
2576 @code{face-remap-add-relative}.  @var{cookie} should be a return value
2577 from that function.
2578 @end defun
2580 @defun face-remap-set-base face &rest specs
2581 This function sets the ``base remapping'' of @var{face} in the current
2582 buffer to @var{specs}.  If @var{specs} is empty, the default base
2583 remapping is restored, which inherits from the global definition of
2584 @var{face}; note that this is different from @var{specs} containing a
2585 single value @code{nil}, which has the opposite result (the global
2586 definition of @var{face} is ignored).
2587 @end defun
2589 @defun face-remap-reset-base face
2590 This function sets the ``base remapping'' of @var{face} to its default
2591 value, which inherits from @var{face}'s global definition.
2592 @end defun
2594 @node Face Functions
2595 @subsection Functions for Working with Faces
2597   Here are additional functions for creating and working with faces.
2599 @defun make-face name
2600 This function defines a new face named @var{name}, initially with all
2601 attributes @code{nil}.  It does nothing if there is already a face named
2602 @var{name}.
2603 @end defun
2605 @defun face-list
2606 This function returns a list of all defined faces.
2607 @end defun
2609 @defun copy-face old-face new-name &optional frame new-frame
2610 This function defines a face named @var{new-name} as a copy of the existing
2611 face named @var{old-face}.  It creates the face @var{new-name} if that
2612 doesn't already exist.
2614 If the optional argument @var{frame} is given, this function applies
2615 only to that frame.  Otherwise it applies to each frame individually,
2616 copying attributes from @var{old-face} in each frame to @var{new-face}
2617 in the same frame.
2619 If the optional argument @var{new-frame} is given, then @code{copy-face}
2620 copies the attributes of @var{old-face} in @var{frame} to @var{new-name}
2621 in @var{new-frame}.
2622 @end defun
2624 @defun face-id face
2625 This function returns the @dfn{face number} of face @var{face}.  This
2626 is a number that uniquely identifies a face at low levels within
2627 Emacs.  It is seldom necessary to refer to a face by its face number.
2628 @end defun
2630 @defun face-documentation face
2631 This function returns the documentation string of face @var{face}, or
2632 @code{nil} if none was specified for it.
2633 @end defun
2635 @defun face-equal face1 face2 &optional frame
2636 This returns @code{t} if the faces @var{face1} and @var{face2} have the
2637 same attributes for display.
2638 @end defun
2640 @defun face-differs-from-default-p face &optional frame
2641 This returns non-@code{nil} if the face @var{face} displays
2642 differently from the default face.
2643 @end defun
2645 @cindex face alias
2646 A @dfn{face alias} provides an equivalent name for a face.  You can
2647 define a face alias by giving the alias symbol the @code{face-alias}
2648 property, with a value of the target face name.  The following example
2649 makes @code{modeline} an alias for the @code{mode-line} face.
2651 @example
2652 (put 'modeline 'face-alias 'mode-line)
2653 @end example
2655 @defun define-obsolete-face-alias obsolete-face current-face &optional when
2656 This function defines a face alias and marks it as obsolete, indicating
2657 that it may be removed in future.  The optional string @var{when}
2658 indicates when the face was made obsolete (for example, a release number).
2659 @end defun
2661 @node Auto Faces
2662 @subsection Automatic Face Assignment
2663 @cindex automatic face assignment
2664 @cindex faces, automatic choice
2666   This hook is used for automatically assigning faces to text in the
2667 buffer.  It is part of the implementation of Jit-Lock mode, used by
2668 Font-Lock.
2670 @defvar fontification-functions
2671 This variable holds a list of functions that are called by Emacs
2672 redisplay as needed, just before doing redisplay.  They are called even
2673 when Font Lock Mode isn't enabled.  When Font Lock Mode is enabled, this
2674 variable usually holds just one function, @code{jit-lock-function}.
2676 The functions are called in the order listed, with one argument, a
2677 buffer position @var{pos}.  Collectively they should attempt to assign
2678 faces to the text in the current buffer starting at @var{pos}.
2680 The functions should record the faces they assign by setting the
2681 @code{face} property.  They should also add a non-@code{nil}
2682 @code{fontified} property to all the text they have assigned faces to.
2683 That property tells redisplay that faces have been assigned to that text
2684 already.
2686 It is probably a good idea for the functions to do nothing if the
2687 character after @var{pos} already has a non-@code{nil} @code{fontified}
2688 property, but this is not required.  If one function overrides the
2689 assignments made by a previous one, the properties after the last
2690 function finishes are the ones that really matter.
2692 For efficiency, we recommend writing these functions so that they
2693 usually assign faces to around 400 to 600 characters at each call.
2694 @end defvar
2696 @node Basic Faces
2697 @subsection Basic Faces
2699 If your Emacs Lisp program needs to assign some faces to text, it is
2700 often a good idea to use certain existing faces or inherit from them,
2701 rather than defining entirely new faces.  This way, if other users
2702 have customized the basic faces to give Emacs a certain look, your
2703 program will ``fit in'' without additional customization.
2705   Some of the basic faces defined in Emacs are listed below.  In
2706 addition to these, you might want to make use of the Font Lock faces
2707 for syntactic highlighting, if highlighting is not already handled by
2708 Font Lock mode, or if some Font Lock faces are not in use.
2709 @xref{Faces for Font Lock}.
2711 @table @code
2712 @item default
2713 The default face, whose attributes are all specified.  All other faces
2714 implicitly inherit from it: any unspecified attribute defaults to the
2715 attribute on this face (@pxref{Face Attributes}).
2717 @item bold
2718 @itemx italic
2719 @itemx bold-italic
2720 @itemx underline
2721 @itemx fixed-pitch
2722 @itemx variable-pitch
2723 These have the attributes indicated by their names (e.g. @code{bold}
2724 has a bold @code{:weight} attribute), with all other attributes
2725 unspecified (and so given by @code{default}).
2727 @item shadow
2728 For ``dimmed out'' text.  For example, it is used for the ignored
2729 part of a filename in the minibuffer (@pxref{Minibuffer File,,
2730 Minibuffers for File Names, emacs, The GNU Emacs Manual}).
2732 @item link
2733 @itemx link-visited
2734 For clickable text buttons that send the user to a different
2735 buffer or ``location''.
2737 @item highlight
2738 For stretches of text that should temporarily stand out.  For example,
2739 it is commonly assigned to the @code{mouse-face} property for cursor
2740 highlighting (@pxref{Special Properties}).
2742 @item match
2743 For text matching a search command.
2745 @item error
2746 @itemx warning
2747 @itemx success
2748 For text concerning errors, warnings, or successes.  For example,
2749 these are used for messages in @samp{*Compilation*} buffers.
2750 @end table
2752 @node Font Selection
2753 @subsection Font Selection
2755   Before Emacs can draw a character on a particular display, it must
2756 select a @dfn{font} for that character@footnote{In this context, the
2757 term @dfn{font} has nothing to do with Font Lock (@pxref{Font Lock
2758 Mode}).}.  @xref{Fonts,,, emacs, The GNU Emacs Manual}.  Normally,
2759 Emacs automatically chooses a font based on the faces assigned to that
2760 character---specifically, the face attributes @code{:family},
2761 @code{:weight}, @code{:slant}, and @code{:width} (@pxref{Face
2762 Attributes}).  The choice of font also depends on the character to be
2763 displayed; some fonts can only display a limited set of characters.
2764 If no available font exactly fits the requirements, Emacs looks for
2765 the @dfn{closest matching font}.  The variables in this section
2766 control how Emacs makes this selection.
2768 @defopt face-font-family-alternatives
2769 If a given family is specified but does not exist, this variable
2770 specifies alternative font families to try.  Each element should have
2771 this form:
2773 @example
2774 (@var{family} @var{alternate-families}@dots{})
2775 @end example
2777 If @var{family} is specified but not available, Emacs will try the other
2778 families given in @var{alternate-families}, one by one, until it finds a
2779 family that does exist.
2780 @end defopt
2782 @defopt face-font-selection-order
2783 If there is no font that exactly matches all desired face attributes
2784 (@code{:width}, @code{:height}, @code{:weight}, and @code{:slant}),
2785 this variable specifies the order in which these attributes should be
2786 considered when selecting the closest matching font.  The value should
2787 be a list containing those four attribute symbols, in order of
2788 decreasing importance.  The default is @code{(:width :height :weight
2789 :slant)}.
2791 Font selection first finds the best available matches for the first
2792 attribute in the list; then, among the fonts which are best in that
2793 way, it searches for the best matches in the second attribute, and so
2796 The attributes @code{:weight} and @code{:width} have symbolic values in
2797 a range centered around @code{normal}.  Matches that are more extreme
2798 (farther from @code{normal}) are somewhat preferred to matches that are
2799 less extreme (closer to @code{normal}); this is designed to ensure that
2800 non-normal faces contrast with normal ones, whenever possible.
2802 One example of a case where this variable makes a difference is when the
2803 default font has no italic equivalent.  With the default ordering, the
2804 @code{italic} face will use a non-italic font that is similar to the
2805 default one.  But if you put @code{:slant} before @code{:height}, the
2806 @code{italic} face will use an italic font, even if its height is not
2807 quite right.
2808 @end defopt
2810 @defopt face-font-registry-alternatives
2811 This variable lets you specify alternative font registries to try, if a
2812 given registry is specified and doesn't exist.  Each element should have
2813 this form:
2815 @example
2816 (@var{registry} @var{alternate-registries}@dots{})
2817 @end example
2819 If @var{registry} is specified but not available, Emacs will try the
2820 other registries given in @var{alternate-registries}, one by one,
2821 until it finds a registry that does exist.
2822 @end defopt
2824   Emacs can make use of scalable fonts, but by default it does not use
2825 them.
2827 @defopt scalable-fonts-allowed
2828 This variable controls which scalable fonts to use.  A value of
2829 @code{nil}, the default, means do not use scalable fonts.  @code{t}
2830 means to use any scalable font that seems appropriate for the text.
2832 Otherwise, the value must be a list of regular expressions.  Then a
2833 scalable font is enabled for use if its name matches any regular
2834 expression in the list.  For example,
2836 @example
2837 (setq scalable-fonts-allowed '("muleindian-2$"))
2838 @end example
2840 @noindent
2841 allows the use of scalable fonts with registry @code{muleindian-2}.
2842 @end defopt
2844 @defvar face-font-rescale-alist
2845 This variable specifies scaling for certain faces.  Its value should
2846 be a list of elements of the form
2848 @example
2849 (@var{fontname-regexp} . @var{scale-factor})
2850 @end example
2852 If @var{fontname-regexp} matches the font name that is about to be
2853 used, this says to choose a larger similar font according to the
2854 factor @var{scale-factor}.  You would use this feature to normalize
2855 the font size if certain fonts are bigger or smaller than their
2856 nominal heights and widths would suggest.
2857 @end defvar
2859 @node Font Lookup
2860 @subsection Looking Up Fonts
2862 @defun x-list-fonts name &optional reference-face frame maximum width
2863 This function returns a list of available font names that match
2864 @var{name}.  @var{name} should be a string containing a font name in
2865 either the Fontconfig, GTK, or XLFD format (@pxref{Fonts,,, emacs, The
2866 GNU Emacs Manual}).  Within an XLFD string, wildcard characters may be
2867 used: the @samp{*} character matches any substring, and the @samp{?}
2868 character matches any single character.  Case is ignored when matching
2869 font names.
2871 If the optional arguments @var{reference-face} and @var{frame} are
2872 specified, the returned list includes only fonts that are the same
2873 size as @var{reference-face} (a face name) currently is on the frame
2874 @var{frame}.
2876 The optional argument @var{maximum} sets a limit on how many fonts to
2877 return.  If it is non-@code{nil}, then the return value is truncated
2878 after the first @var{maximum} matching fonts.  Specifying a small
2879 value for @var{maximum} can make this function much faster, in cases
2880 where many fonts match the pattern.
2882 The optional argument @var{width} specifies a desired font width.  If
2883 it is non-@code{nil}, the function only returns those fonts whose
2884 characters are (on average) @var{width} times as wide as
2885 @var{reference-face}.
2886 @end defun
2888 @defun x-family-fonts &optional family frame
2889 This function returns a list describing the available fonts for family
2890 @var{family} on @var{frame}.  If @var{family} is omitted or @code{nil},
2891 this list applies to all families, and therefore, it contains all
2892 available fonts.  Otherwise, @var{family} must be a string; it may
2893 contain the wildcards @samp{?} and @samp{*}.
2895 The list describes the display that @var{frame} is on; if @var{frame} is
2896 omitted or @code{nil}, it applies to the selected frame's display
2897 (@pxref{Input Focus}).
2899 Each element in the list is a vector of the following form:
2901 @example
2902 [@var{family} @var{width} @var{point-size} @var{weight} @var{slant}
2903  @var{fixed-p} @var{full} @var{registry-and-encoding}]
2904 @end example
2906 The first five elements correspond to face attributes; if you
2907 specify these attributes for a face, it will use this font.
2909 The last three elements give additional information about the font.
2910 @var{fixed-p} is non-@code{nil} if the font is fixed-pitch.
2911 @var{full} is the full name of the font, and
2912 @var{registry-and-encoding} is a string giving the registry and
2913 encoding of the font.
2914 @end defun
2916 @defvar font-list-limit
2917 This variable specifies maximum number of fonts to consider in font
2918 matching.  The function @code{x-family-fonts} will not return more than
2919 that many fonts, and font selection will consider only that many fonts
2920 when searching a matching font for face attributes.  The default is
2921 currently 100.
2922 @end defvar
2924 @node Fontsets
2925 @subsection Fontsets
2927   A @dfn{fontset} is a list of fonts, each assigned to a range of
2928 character codes.  An individual font cannot display the whole range of
2929 characters that Emacs supports, but a fontset can.  Fontsets have names,
2930 just as fonts do, and you can use a fontset name in place of a font name
2931 when you specify the ``font'' for a frame or a face.  Here is
2932 information about defining a fontset under Lisp program control.
2934 @defun create-fontset-from-fontset-spec fontset-spec &optional style-variant-p noerror
2935 This function defines a new fontset according to the specification
2936 string @var{fontset-spec}.  The string should have this format:
2938 @smallexample
2939 @var{fontpattern}, @r{[}@var{charset}:@var{font}@r{]@dots{}}
2940 @end smallexample
2942 @noindent
2943 Whitespace characters before and after the commas are ignored.
2945 The first part of the string, @var{fontpattern}, should have the form of
2946 a standard X font name, except that the last two fields should be
2947 @samp{fontset-@var{alias}}.
2949 The new fontset has two names, one long and one short.  The long name is
2950 @var{fontpattern} in its entirety.  The short name is
2951 @samp{fontset-@var{alias}}.  You can refer to the fontset by either
2952 name.  If a fontset with the same name already exists, an error is
2953 signaled, unless @var{noerror} is non-@code{nil}, in which case this
2954 function does nothing.
2956 If optional argument @var{style-variant-p} is non-@code{nil}, that says
2957 to create bold, italic and bold-italic variants of the fontset as well.
2958 These variant fontsets do not have a short name, only a long one, which
2959 is made by altering @var{fontpattern} to indicate the bold or italic
2960 status.
2962 The specification string also says which fonts to use in the fontset.
2963 See below for the details.
2964 @end defun
2966   The construct @samp{@var{charset}:@var{font}} specifies which font to
2967 use (in this fontset) for one particular character set.  Here,
2968 @var{charset} is the name of a character set, and @var{font} is the font
2969 to use for that character set.  You can use this construct any number of
2970 times in the specification string.
2972   For the remaining character sets, those that you don't specify
2973 explicitly, Emacs chooses a font based on @var{fontpattern}: it replaces
2974 @samp{fontset-@var{alias}} with a value that names one character set.
2975 For the @acronym{ASCII} character set, @samp{fontset-@var{alias}} is replaced
2976 with @samp{ISO8859-1}.
2978   In addition, when several consecutive fields are wildcards, Emacs
2979 collapses them into a single wildcard.  This is to prevent use of
2980 auto-scaled fonts.  Fonts made by scaling larger fonts are not usable
2981 for editing, and scaling a smaller font is not useful because it is
2982 better to use the smaller font in its own size, which Emacs does.
2984   Thus if @var{fontpattern} is this,
2986 @example
2987 -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24
2988 @end example
2990 @noindent
2991 the font specification for @acronym{ASCII} characters would be this:
2993 @example
2994 -*-fixed-medium-r-normal-*-24-*-ISO8859-1
2995 @end example
2997 @noindent
2998 and the font specification for Chinese GB2312 characters would be this:
3000 @example
3001 -*-fixed-medium-r-normal-*-24-*-gb2312*-*
3002 @end example
3004   You may not have any Chinese font matching the above font
3005 specification.  Most X distributions include only Chinese fonts that
3006 have @samp{song ti} or @samp{fangsong ti} in the @var{family} field.  In
3007 such a case, @samp{Fontset-@var{n}} can be specified as below:
3009 @smallexample
3010 Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
3011         chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*
3012 @end smallexample
3014 @noindent
3015 Then, the font specifications for all but Chinese GB2312 characters have
3016 @samp{fixed} in the @var{family} field, and the font specification for
3017 Chinese GB2312 characters has a wild card @samp{*} in the @var{family}
3018 field.
3020 @defun set-fontset-font name character font-spec &optional frame add
3021 This function modifies the existing fontset @var{name} to use the font
3022 matching with @var{font-spec} for the character @var{character}.
3024 If @var{name} is @code{nil}, this function modifies the fontset of the
3025 selected frame or that of @var{frame} if @var{frame} is not
3026 @code{nil}.
3028 If @var{name} is @code{t}, this function modifies the default
3029 fontset, whose short name is @samp{fontset-default}.
3031 @var{character} may be a cons; @code{(@var{from} . @var{to})}, where
3032 @var{from} and @var{to} are character codepoints.  In that case, use
3033 @var{font-spec} for all characters in the range @var{from} and @var{to}
3034 (inclusive).
3036 @var{character} may be a charset.  In that case, use
3037 @var{font-spec} for all character in the charsets.
3039 @var{character} may be a script name.  In that case, use
3040 @var{font-spec} for all character in the charsets.
3042 @var{font-spec} may be a cons; @code{(@var{family} . @var{registry})},
3043 where @var{family} is a family name of a font (possibly including a
3044 foundry name at the head), @var{registry} is a registry name of a font
3045 (possibly including an encoding name at the tail).
3047 @var{font-spec} may be a font name string.
3049 The optional argument @var{add}, if non-@code{nil}, specifies how to
3050 add @var{font-spec} to the font specifications previously set.  If it
3051 is @code{prepend}, @var{font-spec} is prepended.  If it is
3052 @code{append}, @var{font-spec} is appended.  By default,
3053 @var{font-spec} overrides the previous settings.
3055 For instance, this changes the default fontset to use a font of which
3056 family name is @samp{Kochi Gothic} for all characters belonging to
3057 the charset @code{japanese-jisx0208}.
3059 @smallexample
3060 (set-fontset-font t 'japanese-jisx0208
3061                   (font-spec :family "Kochi Gothic"))
3062 @end smallexample
3063 @end defun
3065 @defun char-displayable-p char
3066 This function returns @code{t} if Emacs ought to be able to display
3067 @var{char}.  More precisely, if the selected frame's fontset has a
3068 font to display the character set that @var{char} belongs to.
3070 Fontsets can specify a font on a per-character basis; when the fontset
3071 does that, this function's value may not be accurate.
3072 @end defun
3074 @node Low-Level Font
3075 @subsection Low-Level Font Representation
3077   Normally, it is not necessary to manipulate fonts directly.  In case
3078 you need to do so, this section explains how.
3080   In Emacs Lisp, fonts are represented using three different Lisp
3081 object types: @dfn{font objects}, @dfn{font specs}, and @dfn{font
3082 entities}.
3084 @defun fontp object &optional type
3085 Return @code{t} if @var{object} is a font object, font spec, or font
3086 entity.  Otherwise, return @code{nil}.
3088 The optional argument @var{type}, if non-@code{nil}, determines the
3089 exact type of Lisp object to check for.  In that case, @var{type}
3090 should be one of @code{font-object}, @code{font-spec}, or
3091 @code{font-entity}.
3092 @end defun
3094   A font object is a Lisp object that represents a font that Emacs has
3095 @dfn{opened}.  Font objects cannot be modified in Lisp, but they can
3096 be inspected.
3098 @defun font-at position &optional window string
3099 Return the font object that is being used to display the character at
3100 position @var{position} in the window @var{window}.  If @var{window}
3101 is @code{nil}, it defaults to the selected window.  If @var{string} is
3102 @code{nil}, @var{position} specifies a position in the current buffer;
3103 otherwise, @var{string} should be a string, and @var{position}
3104 specifies a position in that string.
3105 @end defun
3107   A font spec is a Lisp object that contains a set of specifications
3108 that can be used to find a font.  More than one font may match the
3109 specifications in a font spec.
3111 @defun font-spec &rest arguments
3112 Return a new font spec using the specifications in @var{arguments},
3113 which should come in @code{property}-@code{value} pairs.  The possible
3114 specifications are as follows:
3116 @table @code
3117 @item :name
3118 The font name (a string), in either XLFD, Fontconfig, or GTK format.
3119 @xref{Fonts,,, emacs, The GNU Emacs Manual}.
3121 @item :family
3122 @itemx :foundry
3123 @itemx :weight
3124 @itemx :slant
3125 @itemx :width
3126 These have the same meanings as the face attributes of the same name.
3127 @xref{Face Attributes}.
3129 @item :size
3130 The font size---either a non-negative integer that specifies the pixel
3131 size, or a floating point number that specifies the point size.
3133 @item :adstyle
3134 Additional typographic style information for the font, such as
3135 @samp{sans}.  The value should be a string or a symbol.
3137 @item :registry
3138 The charset registry and encoding of the font, such as
3139 @samp{iso8859-1}.  The value should be a string or a symbol.
3141 @item :script
3142 The script that the font must support (a symbol).
3144 @item :otf
3145 The font must be an OpenType font that supports these OpenType
3146 features, provided Emacs is compiled with support for @samp{libotf} (a
3147 library for performing complex text layout in certain scripts).  The
3148 value must be a list of the form
3150 @smallexample
3151 @code{(@var{script-tag} @var{langsys-tag} @var{gsub} @var{gpos})}
3152 @end smallexample
3154 where @var{script-tag} is the OpenType script tag symbol;
3155 @var{langsys-tag} is the OpenType language system tag symbol, or
3156 @code{nil} to use the default language system; @code{gsub} is a list
3157 of OpenType GSUB feature tag symbols, or @code{nil} if none is
3158 required; and @code{gpos} is a list of OpenType GPOS feature tag
3159 symbols, or @code{nil} if none is required.  If @code{gsub} or
3160 @code{gpos} is a list, a @code{nil} element in that list means that
3161 the font must not match any of the remaining tag symbols.  The
3162 @code{gpos} element may be omitted.
3163 @end table
3164 @end defun
3166 @defun font-put font-spec property value
3167 Set the font property @var{property} in the font-spec @var{font-spec}
3168 to @var{value}.
3169 @end defun
3171   A font entity is a reference to a font that need not be open.  Its
3172 properties are intermediate between a font object and a font spec:
3173 like a font object, and unlike a font spec, it refers to a single,
3174 specific font.  Unlike a font object, creating a font entity does not
3175 load the contents of that font into computer memory.
3177 @defun find-font font-spec &optional frame
3178 This function returns a font entity that best matches the font spec
3179 @var{font-spec} on frame @var{frame}.  If @var{frame} is @code{nil},
3180 it defaults to the selected frame.
3181 @end defun
3183 @defun list-fonts font-spec &optional frame num prefer
3184 This function returns a list of all font entities that match the font
3185 spec @var{font-spec}.
3187 The optional argument @var{frame}, if non-@code{nil}, specifies the
3188 frame on which the fonts are to be displayed.  The optional argument
3189 @var{num}, if non-@code{nil}, should be an integer that specifies the
3190 maximum length of the returned list.  The optional argument
3191 @var{prefer}, if non-@code{nil}, should be another font spec, which is
3192 used to control the order of the returned list; the returned font
3193 entities are sorted in order of decreasing ``closeness'' to that font
3194 spec.
3195 @end defun
3197   If you call @code{set-face-attribute} and pass a font spec, font
3198 entity, or font name string as the value of the @code{:font}
3199 attribute, Emacs opens the best ``matching'' font that is available
3200 for display.  It then stores the corresponding font object as the
3201 actual value of the @code{:font} attribute for that face.
3203   The following functions can be used to obtain information about a
3204 font.  For these functions, the @var{font} argument can be a font
3205 object, a font entity, or a font spec.
3207 @defun font-get font property
3208 This function returns the value of the font property @var{property}
3209 for @var{font}.
3211 If @var{font} is a font spec and the font spec does not specify
3212 @var{property}, the return value is @code{nil}.  If @var{font} is a
3213 font object or font entity, the value for the @var{:script} property
3214 may be a list of scripts supported by the font.
3215 @end defun
3217 @defun font-face-attributes font &optional frame
3218 This function returns a list of face attributes corresponding to
3219 @var{font}.  The optional argument @var{frame} specifies the frame on
3220 which the font is to be displayed.  If it is @code{nil}, the selected
3221 frame is used.  The return value has the form
3223 @smallexample
3224 (:family @var{family} :height @var{height} :weight @var{weight}
3225    :slant @var{slant} :width @var{width})
3226 @end smallexample
3228 where the values of @var{family}, @var{height}, @var{weight},
3229 @var{slant}, and @var{width} are face attribute values.  Some of these
3230 key-attribute pairs may be omitted from the list if they are not
3231 specified by @var{font}.
3232 @end defun
3234 @defun font-xlfd-name font &optional fold-wildcards
3235 This function returns the XLFD (X Logical Font Descriptor), a string,
3236 matching @var{font}.  @xref{Fonts,,, emacs, The GNU Emacs Manual}, for
3237 information about XLFDs.  If the name is too long for an XLFD (which
3238 can contain at most 255 characters), the function returns @code{nil}.
3240 If the optional argument @var{fold-wildcards} is non-@code{nil},
3241 consecutive wildcards in the XLFD are folded into one.
3242 @end defun
3244 @node Fringes
3245 @section Fringes
3246 @cindex fringes
3248   The @dfn{fringes} of a window are thin vertical strips down the
3249 sides that are used for displaying bitmaps that indicate truncation,
3250 continuation, horizontal scrolling, and the overlay arrow.
3252 @menu
3253 * Fringe Size/Pos::     Specifying where to put the window fringes.
3254 * Fringe Indicators::   Displaying indicator icons in the window fringes.
3255 * Fringe Cursors::      Displaying cursors in the right fringe.
3256 * Fringe Bitmaps::      Specifying bitmaps for fringe indicators.
3257 * Customizing Bitmaps:: Specifying your own bitmaps to use in the fringes.
3258 * Overlay Arrow::       Display of an arrow to indicate position.
3259 @end menu
3261 @node Fringe Size/Pos
3262 @subsection Fringe Size and Position
3264   The following buffer-local variables control the position and width
3265 of the window fringes.
3267 @defvar fringes-outside-margins
3268 The fringes normally appear between the display margins and the window
3269 text.  If the value is non-@code{nil}, they appear outside the display
3270 margins.  @xref{Display Margins}.
3271 @end defvar
3273 @defvar left-fringe-width
3274 This variable, if non-@code{nil}, specifies the width of the left
3275 fringe in pixels.  A value of @code{nil} means to use the left fringe
3276 width from the window's frame.
3277 @end defvar
3279 @defvar right-fringe-width
3280 This variable, if non-@code{nil}, specifies the width of the right
3281 fringe in pixels.  A value of @code{nil} means to use the right fringe
3282 width from the window's frame.
3283 @end defvar
3285   The values of these variables take effect when you display the
3286 buffer in a window.  If you change them while the buffer is visible,
3287 you can call @code{set-window-buffer} to display it once again in the
3288 same window, to make the changes take effect.  A buffer that does not
3289 specify values for these variables will use the default values
3290 specified for the frame; see @ref{Layout Parameters}.
3292 @defun set-window-fringes window left &optional right outside-margins
3293 This function sets the fringe widths of window @var{window}.
3294 If @var{window} is @code{nil}, the selected window is used.
3296 The argument @var{left} specifies the width in pixels of the left
3297 fringe, and likewise @var{right} for the right fringe.  A value of
3298 @code{nil} for either one stands for the default width.  If
3299 @var{outside-margins} is non-@code{nil}, that specifies that fringes
3300 should appear outside of the display margins.
3301 @end defun
3303 @defun window-fringes &optional window
3304 This function returns information about the fringes of a window
3305 @var{window}.  If @var{window} is omitted or @code{nil}, the selected
3306 window is used.  The value has the form @code{(@var{left-width}
3307 @var{right-width} @var{outside-margins})}.
3308 @end defun
3311 @node Fringe Indicators
3312 @subsection Fringe Indicators
3313 @cindex fringe indicators
3314 @cindex indicators, fringe
3316   The @dfn{fringe indicators} are tiny icons Emacs displays in the
3317 window fringe (on a graphic display) to indicate truncated or
3318 continued lines, buffer boundaries, overlay arrow, etc.
3320 @defopt indicate-empty-lines
3321 @cindex fringes, and empty line indication
3322 When this is non-@code{nil}, Emacs displays a special glyph in the
3323 fringe of each empty line at the end of the buffer, on graphical
3324 displays.  @xref{Fringes}.  This variable is automatically
3325 buffer-local in every buffer.
3326 @end defopt
3328 @defopt indicate-buffer-boundaries
3329 This buffer-local variable controls how the buffer boundaries and
3330 window scrolling are indicated in the window fringes.
3332 Emacs can indicate the buffer boundaries---that is, the first and last
3333 line in the buffer---with angle icons when they appear on the screen.
3334 In addition, Emacs can display an up-arrow in the fringe to show
3335 that there is text above the screen, and a down-arrow to show
3336 there is text below the screen.
3338 There are three kinds of basic values:
3340 @table @asis
3341 @item @code{nil}
3342 Don't display any of these fringe icons.
3343 @item @code{left}
3344 Display the angle icons and arrows in the left fringe.
3345 @item @code{right}
3346 Display the angle icons and arrows in the right fringe.
3347 @item any non-alist
3348 Display the angle icons in the left fringe
3349 and don't display the arrows.
3350 @end table
3352 Otherwise the value should be an alist that specifies which fringe
3353 indicators to display and where.  Each element of the alist should
3354 have the form @code{(@var{indicator} . @var{position})}.  Here,
3355 @var{indicator} is one of @code{top}, @code{bottom}, @code{up},
3356 @code{down}, and @code{t} (which covers all the icons not yet
3357 specified), while @var{position} is one of @code{left}, @code{right}
3358 and @code{nil}.
3360 For example, @code{((top . left) (t . right))} places the top angle
3361 bitmap in left fringe, and the bottom angle bitmap as well as both
3362 arrow bitmaps in right fringe.  To show the angle bitmaps in the left
3363 fringe, and no arrow bitmaps, use @code{((top .  left) (bottom . left))}.
3364 @end defopt
3366 @defvar fringe-indicator-alist
3367 This buffer-local variable specifies the mapping from logical fringe
3368 indicators to the actual bitmaps displayed in the window fringes.  The
3369 value is an alist of elements @code{(@var{indicator}
3370 . @var{bitmaps})}, where @var{indicator} specifies a logical indicator
3371 type and @var{bitmaps} specifies the fringe bitmaps to use for that
3372 indicator.
3374   Each @var{indicator} should be one of the following symbols:
3376 @table @asis
3377 @item @code{truncation}, @code{continuation}.
3378 Used for truncation and continuation lines.
3380 @item @code{up}, @code{down}, @code{top}, @code{bottom}, @code{top-bottom}
3381 Used when @code{indicate-buffer-boundaries} is non-@code{nil}:
3382 @code{up} and @code{down} indicate a buffer boundary lying above or
3383 below the window edge; @code{top} and @code{bottom} indicate the
3384 topmost and bottommost buffer text line; and @code{top-bottom}
3385 indicates where there is just one line of text in the buffer.
3387 @item @code{empty-line}
3388 Used to indicate empty lines when @code{indicate-empty-lines} is
3389 non-@code{nil}.
3391 @item @code{overlay-arrow}
3392 Used for overlay arrows (@pxref{Overlay Arrow}).
3393 @c Is this used anywhere?
3394 @c @item Unknown bitmap indicator:
3395 @c @code{unknown}.
3396 @end table
3398   Each @var{bitmaps} value may be a list of symbols @code{(@var{left}
3399 @var{right} [@var{left1} @var{right1}])}.  The @var{left} and
3400 @var{right} symbols specify the bitmaps shown in the left and/or right
3401 fringe, for the specific indicator.  @var{left1} and @var{right1} are
3402 specific to the @code{bottom} and @code{top-bottom} indicators, and
3403 are used to indicate that the last text line has no final newline.
3404 Alternatively, @var{bitmaps} may be a single symbol which is used in
3405 both left and right fringes.
3407   @xref{Fringe Bitmaps}, for a list of standard bitmap symbols and how
3408 to define your own.  In addition, @code{nil} represents the empty
3409 bitmap (i.e.@: an indicator that is not shown).
3411   When @code{fringe-indicator-alist} has a buffer-local value, and
3412 there is no bitmap defined for a logical indicator, or the bitmap is
3413 @code{t}, the corresponding value from the default value of
3414 @code{fringe-indicator-alist} is used.
3415 @end defvar
3417 @node Fringe Cursors
3418 @subsection Fringe Cursors
3419 @cindex fringe cursors
3420 @cindex cursor, fringe
3422   When a line is exactly as wide as the window, Emacs displays the
3423 cursor in the right fringe instead of using two lines.  Different
3424 bitmaps are used to represent the cursor in the fringe depending on
3425 the current buffer's cursor type.
3427 @defopt overflow-newline-into-fringe
3428 If this is non-@code{nil}, lines exactly as wide as the window (not
3429 counting the final newline character) are not continued.  Instead,
3430 when point is at the end of the line, the cursor appears in the right
3431 fringe.
3432 @end defopt
3434 @defvar fringe-cursor-alist
3435 This variable specifies the mapping from logical cursor type to the
3436 actual fringe bitmaps displayed in the right fringe.  The value is an
3437 alist where each element has the form @code{(@var{cursor-type}
3438 . @var{bitmap})}, which means to use the fringe bitmap @var{bitmap} to
3439 display cursors of type @var{cursor-type}.
3441 Each @var{cursor-type} should be one of @code{box}, @code{hollow},
3442 @code{bar}, @code{hbar}, or @code{hollow-small}.  The first four have
3443 the same meanings as in the @code{cursor-type} frame parameter
3444 (@pxref{Cursor Parameters}).  The @code{hollow-small} type is used
3445 instead of @code{hollow} when the normal @code{hollow-rectangle}
3446 bitmap is too tall to fit on a specific display line.
3448 Each @var{bitmap} should be a symbol specifying the fringe bitmap to
3449 be displayed for that logical cursor type.
3450 @iftex
3451 See the next subsection for details.
3452 @end iftex
3453 @ifnottex
3454 @xref{Fringe Bitmaps}.
3455 @end ifnottex
3457 When @code{fringe-cursor-alist} has a buffer-local value, and there is
3458 no bitmap defined for a cursor type, the corresponding value from the
3459 default value of @code{fringes-indicator-alist} is used.
3460 @end defvar
3462 @node Fringe Bitmaps
3463 @subsection Fringe Bitmaps
3464 @cindex fringe bitmaps
3465 @cindex bitmaps, fringe
3467   The @dfn{fringe bitmaps} are the actual bitmaps which represent the
3468 logical fringe indicators for truncated or continued lines, buffer
3469 boundaries, overlay arrows, etc.  Each bitmap is represented by a
3470 symbol.
3471 @iftex
3472 These symbols are referred to by the variables
3473 @code{fringe-indicator-alist} and @code{fringe-cursor-alist},
3474 described in the previous subsections.
3475 @end iftex
3476 @ifnottex
3477 These symbols are referred to by the variable
3478 @code{fringe-indicator-alist}, which maps fringe indicators to bitmaps
3479 (@pxref{Fringe Indicators}), and the variable
3480 @code{fringe-cursor-alist}, which maps fringe cursors to bitmaps
3481 (@pxref{Fringe Cursors}).
3482 @end ifnottex
3484   Lisp programs can also directly display a bitmap in the left or
3485 right fringe, by using a @code{display} property for one of the
3486 characters appearing in the line (@pxref{Other Display Specs}).  Such
3487 a display specification has the form
3489 @example
3490 (left-fringe @var{bitmap} [@var{face}])
3491 @end example
3493 @noindent
3496 @example
3497 (right-fringe @var{bitmap} [@var{face}])
3498 @end example
3500 @noindent
3501 The symbol @var{bitmap} identifies the bitmap to display.  The
3502 optional @var{face} names a face whose foreground color is used to
3503 display the bitmap; this face is automatically merged with the
3504 @code{fringe} face.
3506   Here is a list of the standard fringe bitmaps defined in Emacs, and
3507 how they are currently used in Emacs (via
3508 @code{fringe-indicator-alist} and @code{fringe-cursor-alist}):
3510 @table @asis
3511 @item @code{left-arrow}, @code{right-arrow}
3512 Used to indicate truncated lines.
3514 @item @code{left-curly-arrow}, @code{right-curly-arrow}
3515 Used to indicate continued lines.
3517 @item @code{right-triangle}, @code{left-triangle}
3518 The former is used by overlay arrows.  The latter is unused.
3520 @item @code{up-arrow}, @code{down-arrow}, @code{top-left-angle} @code{top-right-angle}
3521 @itemx @code{bottom-left-angle}, @code{bottom-right-angle}
3522 @itemx @code{top-right-angle}, @code{top-left-angle}
3523 @itemx @code{left-bracket}, @code{right-bracket}, @code{top-right-angle}, @code{top-left-angle}
3524 Used to indicate buffer boundaries.
3526 @item @code{filled-rectangle}, @code{hollow-rectangle}
3527 @itemx @code{filled-square}, @code{hollow-square}
3528 @itemx @code{vertical-bar}, @code{horizontal-bar}
3529 Used for different types of fringe cursors.
3531 @item @code{empty-line}, @code{question-mark}
3532 Unused.
3533 @end table
3535 @noindent
3536 The next subsection describes how to define your own fringe bitmaps.
3538 @defun fringe-bitmaps-at-pos &optional pos window
3539 This function returns the fringe bitmaps of the display line
3540 containing position @var{pos} in window @var{window}.  The return
3541 value has the form @code{(@var{left} @var{right} @var{ov})}, where @var{left}
3542 is the symbol for the fringe bitmap in the left fringe (or @code{nil}
3543 if no bitmap), @var{right} is similar for the right fringe, and @var{ov}
3544 is non-@code{nil} if there is an overlay arrow in the left fringe.
3546 The value is @code{nil} if @var{pos} is not visible in @var{window}.
3547 If @var{window} is @code{nil}, that stands for the selected window.
3548 If @var{pos} is @code{nil}, that stands for the value of point in
3549 @var{window}.
3550 @end defun
3552 @node Customizing Bitmaps
3553 @subsection Customizing Fringe Bitmaps
3555 @defun define-fringe-bitmap bitmap bits &optional height width align
3556 This function defines the symbol @var{bitmap} as a new fringe bitmap,
3557 or replaces an existing bitmap with that name.
3559 The argument @var{bits} specifies the image to use.  It should be
3560 either a string or a vector of integers, where each element (an
3561 integer) corresponds to one row of the bitmap.  Each bit of an integer
3562 corresponds to one pixel of the bitmap, where the low bit corresponds
3563 to the rightmost pixel of the bitmap.
3565 The height is normally the length of @var{bits}.  However, you
3566 can specify a different height with non-@code{nil} @var{height}.  The width
3567 is normally 8, but you can specify a different width with non-@code{nil}
3568 @var{width}.  The width must be an integer between 1 and 16.
3570 The argument @var{align} specifies the positioning of the bitmap
3571 relative to the range of rows where it is used; the default is to
3572 center the bitmap.  The allowed values are @code{top}, @code{center},
3573 or @code{bottom}.
3575 The @var{align} argument may also be a list @code{(@var{align}
3576 @var{periodic})} where @var{align} is interpreted as described above.
3577 If @var{periodic} is non-@code{nil}, it specifies that the rows in
3578 @code{bits} should be repeated enough times to reach the specified
3579 height.
3580 @end defun
3582 @defun destroy-fringe-bitmap bitmap
3583 This function destroy the fringe bitmap identified by @var{bitmap}.
3584 If @var{bitmap} identifies a standard fringe bitmap, it actually
3585 restores the standard definition of that bitmap, instead of
3586 eliminating it entirely.
3587 @end defun
3589 @defun set-fringe-bitmap-face bitmap &optional face
3590 This sets the face for the fringe bitmap @var{bitmap} to @var{face}.
3591 If @var{face} is @code{nil}, it selects the @code{fringe} face.  The
3592 bitmap's face controls the color to draw it in.
3594 @var{face} is merged with the @code{fringe} face, so normally
3595 @var{face} should specify only the foreground color.
3596 @end defun
3598 @node Overlay Arrow
3599 @subsection The Overlay Arrow
3600 @c @cindex overlay arrow  Duplicates variable names
3602   The @dfn{overlay arrow} is useful for directing the user's attention
3603 to a particular line in a buffer.  For example, in the modes used for
3604 interface to debuggers, the overlay arrow indicates the line of code
3605 about to be executed.  This feature has nothing to do with
3606 @dfn{overlays} (@pxref{Overlays}).
3608 @defvar overlay-arrow-string
3609 This variable holds the string to display to call attention to a
3610 particular line, or @code{nil} if the arrow feature is not in use.
3611 On a graphical display the contents of the string are ignored; instead a
3612 glyph is displayed in the fringe area to the left of the display area.
3613 @end defvar
3615 @defvar overlay-arrow-position
3616 This variable holds a marker that indicates where to display the overlay
3617 arrow.  It should point at the beginning of a line.  On a non-graphical
3618 display the arrow text
3619 appears at the beginning of that line, overlaying any text that would
3620 otherwise appear.  Since the arrow is usually short, and the line
3621 usually begins with indentation, normally nothing significant is
3622 overwritten.
3624 The overlay-arrow string is displayed in any given buffer if the value
3625 of @code{overlay-arrow-position} in that buffer points into that
3626 buffer.  Thus, it is possible to display multiple overlay arrow strings
3627 by creating buffer-local bindings of @code{overlay-arrow-position}.
3628 However, it is usually cleaner to use
3629 @code{overlay-arrow-variable-list} to achieve this result.
3630 @c !!! overlay-arrow-position: but the overlay string may remain in the display
3631 @c of some other buffer until an update is required.  This should be fixed
3632 @c now.  Is it?
3633 @end defvar
3635   You can do a similar job by creating an overlay with a
3636 @code{before-string} property.  @xref{Overlay Properties}.
3638   You can define multiple overlay arrows via the variable
3639 @code{overlay-arrow-variable-list}.
3641 @defvar overlay-arrow-variable-list
3642 This variable's value is a list of variables, each of which specifies
3643 the position of an overlay arrow.  The variable
3644 @code{overlay-arrow-position} has its normal meaning because it is on
3645 this list.
3646 @end defvar
3648 Each variable on this list can have properties
3649 @code{overlay-arrow-string} and @code{overlay-arrow-bitmap} that
3650 specify an overlay arrow string (for text terminals) or fringe bitmap
3651 (for graphical terminals) to display at the corresponding overlay
3652 arrow position.  If either property is not set, the default
3653 @code{overlay-arrow-string} or @code{overlay-arrow} fringe indicator
3654 is used.
3656 @node Scroll Bars
3657 @section Scroll Bars
3658 @cindex scroll bars
3660 Normally the frame parameter @code{vertical-scroll-bars} controls
3661 whether the windows in the frame have vertical scroll bars, and
3662 whether they are on the left or right.  The frame parameter
3663 @code{scroll-bar-width} specifies how wide they are (@code{nil}
3664 meaning the default).  @xref{Layout Parameters}.
3666 @defun frame-current-scroll-bars &optional frame
3667 This function reports the scroll bar type settings for frame
3668 @var{frame}.  The value is a cons cell
3669 @code{(@var{vertical-type} .@: @var{horizontal-type})}, where
3670 @var{vertical-type} is either @code{left}, @code{right}, or @code{nil}
3671 (which means no scroll bar.)  @var{horizontal-type} is meant to
3672 specify the horizontal scroll bar type, but since they are not
3673 implemented, it is always @code{nil}.
3674 @end defun
3676 @vindex vertical-scroll-bar
3677   You can enable or disable scroll bars for a particular buffer,
3678 by setting the variable @code{vertical-scroll-bar}.  This variable
3679 automatically becomes buffer-local when set.  The possible values are
3680 @code{left}, @code{right}, @code{t}, which means to use the
3681 frame's default, and @code{nil} for no scroll bar.
3683   You can also control this for individual windows.  Call the function
3684 @code{set-window-scroll-bars} to specify what to do for a specific window:
3686 @defun set-window-scroll-bars window width &optional vertical-type horizontal-type
3687 This function sets the width and type of scroll bars for window
3688 @var{window}.
3690 @var{width} specifies the scroll bar width in pixels (@code{nil} means
3691 use the width specified for the frame).  @var{vertical-type} specifies
3692 whether to have a vertical scroll bar and, if so, where.  The possible
3693 values are @code{left}, @code{right} and @code{nil}, just like the
3694 values of the @code{vertical-scroll-bars} frame parameter.
3696 The argument @var{horizontal-type} is meant to specify whether and
3697 where to have horizontal scroll bars, but since they are not
3698 implemented, it has no effect.  If @var{window} is @code{nil}, the
3699 selected window is used.
3700 @end defun
3702 @defun window-scroll-bars &optional window
3703 Report the width and type of scroll bars specified for @var{window}.
3704 If @var{window} is omitted or @code{nil}, the selected window is used.
3705 The value is a list of the form @code{(@var{width}
3706 @var{cols} @var{vertical-type} @var{horizontal-type})}.  The value
3707 @var{width} is the value that was specified for the width (which may
3708 be @code{nil}); @var{cols} is the number of columns that the scroll
3709 bar actually occupies.
3711 @var{horizontal-type} is not actually meaningful.
3712 @end defun
3714 If you don't specify these values for a window with
3715 @code{set-window-scroll-bars}, the buffer-local variables
3716 @code{scroll-bar-mode} and @code{scroll-bar-width} in the buffer being
3717 displayed control the window's vertical scroll bars.  The function
3718 @code{set-window-buffer} examines these variables.  If you change them
3719 in a buffer that is already visible in a window, you can make the
3720 window take note of the new values by calling @code{set-window-buffer}
3721 specifying the same buffer that is already displayed.
3723 @defopt scroll-bar-mode
3724 This variable, always local in all buffers, controls whether and where
3725 to put scroll bars in windows displaying the buffer.  The possible values
3726 are @code{nil} for no scroll bar, @code{left} to put a scroll bar on
3727 the left, and @code{right} to put a scroll bar on the right.
3728 @end defopt
3730 @defun window-current-scroll-bars &optional window
3731 This function reports the scroll bar type for window @var{window}.
3732 If @var{window} is omitted or @code{nil}, the selected window is used.
3733 The value is a cons cell
3734 @code{(@var{vertical-type} .@: @var{horizontal-type})}.  Unlike
3735 @code{window-scroll-bars}, this reports the scroll bar type actually
3736 used, once frame defaults and @code{scroll-bar-mode} are taken into
3737 account.
3738 @end defun
3740 @defvar scroll-bar-width
3741 This variable, always local in all buffers, specifies the width of the
3742 buffer's scroll bars, measured in pixels.  A value of @code{nil} means
3743 to use the value specified by the frame.
3744 @end defvar
3746 @node Display Property
3747 @section The @code{display} Property
3748 @cindex display specification
3749 @kindex display @r{(text property)}
3751   The @code{display} text property (or overlay property) is used to
3752 insert images into text, and also control other aspects of how text
3753 displays.  The value of the @code{display} property should be a
3754 display specification, or a list or vector containing several display
3755 specifications.  Display specifications in the same @code{display}
3756 property value generally apply in parallel to the text they cover.
3758   If several sources (overlays and/or a text property) specify values
3759 for the @code{display} property, only one of the values takes effect,
3760 following the rules of @code{get-char-property}.  @xref{Examining
3761 Properties}.
3763   The rest of this section describes several kinds of
3764 display specifications and what they mean.
3766 @menu
3767 * Replacing Specs::      Display specs that replace the text.
3768 * Specified Space::      Displaying one space with a specified width.
3769 * Pixel Specification::  Specifying space width or height in pixels.
3770 * Other Display Specs::     Displaying an image; adjusting the height,
3771                               spacing, and other properties of text.
3772 * Display Margins::     Displaying text or images to the side of the main text.
3773 @end menu
3775 @node Replacing Specs
3776 @subsection Display Specs That Replace The Text
3778   Some kinds of @code{display} specifications specify something to
3779 display instead of the text that has the property.  These are called
3780 @dfn{replacing} display specifications.  Emacs does not allow the user
3781 to interactively move point into the middle of buffer text that is
3782 replaced in this way.
3784   If a list of display specifications includes more than one replacing
3785 display specification, the first overrides the rest.  Replacing
3786 display specifications make most other display specifications
3787 irrelevant, since those don't apply to the replacement.
3789   For replacing display specifications, ``the text that has the
3790 property'' means all the consecutive characters that have the same
3791 Lisp object as their @code{display} property; these characters are
3792 replaced as a single unit.  By contrast, characters that have similar
3793 but distinct Lisp objects as their @code{display} properties are
3794 handled separately.  Here's a function that illustrates this point:
3796 @smallexample
3797 (defun foo ()
3798   (goto-char (point-min))
3799   (dotimes (i 5)
3800     (let ((string (concat "A")))
3801       (put-text-property (point) (1+ (point)) 'display string)
3802       (forward-char 1)
3803       (put-text-property (point) (1+ (point)) 'display string)
3804       (forward-char 1))))
3805 @end smallexample
3807 @noindent
3808 It gives each of the first ten characters in the buffer string
3809 @code{"A"} as the @code{display} property, but they don't all get the
3810 same string.  The first two characters get the same string, so they
3811 together are replaced with one @samp{A}.  The next two characters get
3812 a second string, so they together are replaced with one @samp{A}.
3813 Likewise for each following pair of characters.  Thus, the ten
3814 characters appear as five A's.  This function would have the same
3815 results:
3817 @smallexample
3818 (defun foo ()
3819   (goto-char (point-min))
3820   (dotimes (i 5)
3821     (let ((string (concat "A")))
3822       (put-text-property (point) (+ 2 (point)) 'display string)
3823       (put-text-property (point) (1+ (point)) 'display string)
3824       (forward-char 2))))
3825 @end smallexample
3827 @noindent
3828 This illustrates that what matters is the property value for
3829 each character.  If two consecutive characters have the same
3830 object as the @code{display} property value, it's irrelevant
3831 whether they got this property from a single call to
3832 @code{put-text-property} or from two different calls.
3834 @node Specified Space
3835 @subsection Specified Spaces
3836 @cindex spaces, specified height or width
3837 @cindex variable-width spaces
3839   To display a space of specified width and/or height, use a display
3840 specification of the form @code{(space . @var{props})}, where
3841 @var{props} is a property list (a list of alternating properties and
3842 values).  You can put this property on one or more consecutive
3843 characters; a space of the specified height and width is displayed in
3844 place of @emph{all} of those characters.  These are the properties you
3845 can use in @var{props} to specify the weight of the space:
3847 @table @code
3848 @item :width @var{width}
3849 If @var{width} is an integer or floating point number, it specifies
3850 that the space width should be @var{width} times the normal character
3851 width.  @var{width} can also be a @dfn{pixel width} specification
3852 (@pxref{Pixel Specification}).
3854 @item :relative-width @var{factor}
3855 Specifies that the width of the stretch should be computed from the
3856 first character in the group of consecutive characters that have the
3857 same @code{display} property.  The space width is the width of that
3858 character, multiplied by @var{factor}.
3860 @item :align-to @var{hpos}
3861 Specifies that the space should be wide enough to reach @var{hpos}.
3862 If @var{hpos} is a number, it is measured in units of the normal
3863 character width.  @var{hpos} can also be a @dfn{pixel width}
3864 specification (@pxref{Pixel Specification}).
3865 @end table
3867   You should use one and only one of the above properties.  You can
3868 also specify the height of the space, with these properties:
3870 @table @code
3871 @item :height @var{height}
3872 Specifies the height of the space.
3873 If @var{height} is an integer or floating point number, it specifies
3874 that the space height should be @var{height} times the normal character
3875 height.  The @var{height} may also be a @dfn{pixel height} specification
3876 (@pxref{Pixel Specification}).
3878 @item :relative-height @var{factor}
3879 Specifies the height of the space, multiplying the ordinary height
3880 of the text having this display specification by @var{factor}.
3882 @item :ascent @var{ascent}
3883 If the value of @var{ascent} is a non-negative number no greater than
3884 100, it specifies that @var{ascent} percent of the height of the space
3885 should be considered as the ascent of the space---that is, the part
3886 above the baseline.  The ascent may also be specified in pixel units
3887 with a @dfn{pixel ascent} specification (@pxref{Pixel Specification}).
3889 @end table
3891   Don't use both @code{:height} and @code{:relative-height} together.
3893   The @code{:width} and @code{:align-to} properties are supported on
3894 non-graphic terminals, but the other space properties in this section
3895 are not.
3897   Note that space properties are treated as paragraph separators for
3898 the purposes of reordering bidirectional text for display.
3899 @xref{Bidirectional Display}, for the details.
3901 @node Pixel Specification
3902 @subsection Pixel Specification for Spaces
3903 @cindex spaces, pixel specification
3905   The value of the @code{:width}, @code{:align-to}, @code{:height},
3906 and @code{:ascent} properties can be a special kind of expression that
3907 is evaluated during redisplay.  The result of the evaluation is used
3908 as an absolute number of pixels.
3910   The following expressions are supported:
3912 @smallexample
3913 @group
3914   @var{expr} ::= @var{num} | (@var{num}) | @var{unit} | @var{elem} | @var{pos} | @var{image} | @var{form}
3915   @var{num}  ::= @var{integer} | @var{float} | @var{symbol}
3916   @var{unit} ::= in | mm | cm | width | height
3917 @end group
3918 @group
3919   @var{elem} ::= left-fringe | right-fringe | left-margin | right-margin
3920         |  scroll-bar | text
3921   @var{pos}  ::= left | center | right
3922   @var{form} ::= (@var{num} . @var{expr}) | (@var{op} @var{expr} ...)
3923   @var{op}   ::= + | -
3924 @end group
3925 @end smallexample
3927   The form @var{num} specifies a fraction of the default frame font
3928 height or width.  The form @code{(@var{num})} specifies an absolute
3929 number of pixels.  If @var{num} is a symbol, @var{symbol}, its
3930 buffer-local variable binding is used.
3932   The @code{in}, @code{mm}, and @code{cm} units specify the number of
3933 pixels per inch, millimeter, and centimeter, respectively.  The
3934 @code{width} and @code{height} units correspond to the default width
3935 and height of the current face.  An image specification @code{image}
3936 corresponds to the width or height of the image.
3938   The elements @code{left-fringe}, @code{right-fringe},
3939 @code{left-margin}, @code{right-margin}, @code{scroll-bar}, and
3940 @code{text} specify to the width of the corresponding area of the
3941 window.
3943   The @code{left}, @code{center}, and @code{right} positions can be
3944 used with @code{:align-to} to specify a position relative to the left
3945 edge, center, or right edge of the text area.
3947   Any of the above window elements (except @code{text}) can also be
3948 used with @code{:align-to} to specify that the position is relative to
3949 the left edge of the given area.  Once the base offset for a relative
3950 position has been set (by the first occurrence of one of these
3951 symbols), further occurrences of these symbols are interpreted as the
3952 width of the specified area.  For example, to align to the center of
3953 the left-margin, use
3955 @example
3956 :align-to (+ left-margin (0.5 . left-margin))
3957 @end example
3959   If no specific base offset is set for alignment, it is always relative
3960 to the left edge of the text area.  For example, @samp{:align-to 0} in a
3961 header-line aligns with the first text column in the text area.
3963   A value of the form @code{(@var{num} . @var{expr})} stands for the
3964 product of the values of @var{num} and @var{expr}.  For example,
3965 @code{(2 . in)} specifies a width of 2 inches, while @code{(0.5 .
3966 @var{image})} specifies half the width (or height) of the specified
3967 image.
3969   The form @code{(+ @var{expr} ...)} adds up the value of the
3970 expressions.  The form @code{(- @var{expr} ...)} negates or subtracts
3971 the value of the expressions.
3973 @node Other Display Specs
3974 @subsection Other Display Specifications
3976   Here are the other sorts of display specifications that you can use
3977 in the @code{display} text property.
3979 @table @code
3980 @item @var{string}
3981 Display @var{string} instead of the text that has this property.
3983 Recursive display specifications are not supported---@var{string}'s
3984 @code{display} properties, if any, are not used.
3986 @item (image . @var{image-props})
3987 This kind of display specification is an image descriptor (@pxref{Images}).
3988 When used as a display specification, it means to display the image
3989 instead of the text that has the display specification.
3991 @item (slice @var{x} @var{y} @var{width} @var{height})
3992 This specification together with @code{image} specifies a @dfn{slice}
3993 (a partial area) of the image to display.  The elements @var{y} and
3994 @var{x} specify the top left corner of the slice, within the image;
3995 @var{width} and @var{height} specify the width and height of the
3996 slice.  Integer values are numbers of pixels.  A floating point number
3997 in the range 0.0--1.0 stands for that fraction of the width or height
3998 of the entire image.
4000 @item ((margin nil) @var{string})
4001 A display specification of this form means to display @var{string}
4002 instead of the text that has the display specification, at the same
4003 position as that text.  It is equivalent to using just @var{string},
4004 but it is done as a special case of marginal display (@pxref{Display
4005 Margins}).
4007 @item (left-fringe @var{bitmap} @r{[}@var{face}@r{]})
4008 @itemx (right-fringe @var{bitmap} @r{[}@var{face}@r{]})
4009 This display specification on any character of a line of text causes
4010 the specified @var{bitmap} be displayed in the left or right fringes
4011 for that line, instead of the characters that have the display
4012 specification.  The optional @var{face} specifies the colors to be
4013 used for the bitmap.  @xref{Fringe Bitmaps}, for the details.
4015 @item (space-width @var{factor})
4016 This display specification affects all the space characters within the
4017 text that has the specification.  It displays all of these spaces
4018 @var{factor} times as wide as normal.  The element @var{factor} should
4019 be an integer or float.  Characters other than spaces are not affected
4020 at all; in particular, this has no effect on tab characters.
4022 @item (height @var{height})
4023 This display specification makes the text taller or shorter.
4024 Here are the possibilities for @var{height}:
4026 @table @asis
4027 @item @code{(+ @var{n})}
4028 This means to use a font that is @var{n} steps larger.  A ``step'' is
4029 defined by the set of available fonts---specifically, those that match
4030 what was otherwise specified for this text, in all attributes except
4031 height.  Each size for which a suitable font is available counts as
4032 another step.  @var{n} should be an integer.
4034 @item @code{(- @var{n})}
4035 This means to use a font that is @var{n} steps smaller.
4037 @item a number, @var{factor}
4038 A number, @var{factor}, means to use a font that is @var{factor} times
4039 as tall as the default font.
4041 @item a symbol, @var{function}
4042 A symbol is a function to compute the height.  It is called with the
4043 current height as argument, and should return the new height to use.
4045 @item anything else, @var{form}
4046 If the @var{height} value doesn't fit the previous possibilities, it is
4047 a form.  Emacs evaluates it to get the new height, with the symbol
4048 @code{height} bound to the current specified font height.
4049 @end table
4051 @item (raise @var{factor})
4052 This kind of display specification raises or lowers the text
4053 it applies to, relative to the baseline of the line.
4055 @var{factor} must be a number, which is interpreted as a multiple of the
4056 height of the affected text.  If it is positive, that means to display
4057 the characters raised.  If it is negative, that means to display them
4058 lower down.
4060 If the text also has a @code{height} display specification, that does
4061 not affect the amount of raising or lowering, which is based on the
4062 faces used for the text.
4063 @end table
4065 @c We put all the `@code{(when ...)}' on one line to encourage
4066 @c makeinfo's end-of-sentence heuristics to DTRT.  Previously, the dot
4067 @c was at eol; the info file ended up w/ two spaces rendered after it.
4068   You can make any display specification conditional.  To do that,
4069 package it in another list of the form
4070 @code{(when @var{condition} . @var{spec})}.
4071 Then the specification @var{spec} applies only when
4072 @var{condition} evaluates to a non-@code{nil} value.  During the
4073 evaluation, @code{object} is bound to the string or buffer having the
4074 conditional @code{display} property.  @code{position} and
4075 @code{buffer-position} are bound to the position within @code{object}
4076 and the buffer position where the @code{display} property was found,
4077 respectively.  Both positions can be different when @code{object} is a
4078 string.
4080 @node Display Margins
4081 @subsection Displaying in the Margins
4082 @cindex display margins
4083 @cindex margins, display
4085   A buffer can have blank areas called @dfn{display margins} on the
4086 left and on the right.  Ordinary text never appears in these areas,
4087 but you can put things into the display margins using the
4088 @code{display} property.  There is currently no way to make text or
4089 images in the margin mouse-sensitive.
4091   The way to display something in the margins is to specify it in a
4092 margin display specification in the @code{display} property of some
4093 text.  This is a replacing display specification, meaning that the
4094 text you put it on does not get displayed; the margin display appears,
4095 but that text does not.
4097   A margin display specification looks like @code{((margin
4098 right-margin) @var{spec})} or @code{((margin left-margin) @var{spec})}.
4099 Here, @var{spec} is another display specification that says what to
4100 display in the margin.  Typically it is a string of text to display,
4101 or an image descriptor.
4103   To display something in the margin @emph{in association with}
4104 certain buffer text, without altering or preventing the display of
4105 that text, put a @code{before-string} property on the text and put the
4106 margin display specification on the contents of the before-string.
4108   Before the display margins can display anything, you must give
4109 them a nonzero width.  The usual way to do that is to set these
4110 variables:
4112 @defvar left-margin-width
4113 This variable specifies the width of the left margin.
4114 It is buffer-local in all buffers.
4115 @end defvar
4117 @defvar right-margin-width
4118 This variable specifies the width of the right margin.
4119 It is buffer-local in all buffers.
4120 @end defvar
4122   Setting these variables does not immediately affect the window.  These
4123 variables are checked when a new buffer is displayed in the window.
4124 Thus, you can make changes take effect by calling
4125 @code{set-window-buffer}.
4127   You can also set the margin widths immediately.
4129 @defun set-window-margins window left &optional right
4130 This function specifies the margin widths for window @var{window}.
4131 The argument @var{left} controls the left margin and
4132 @var{right} controls the right margin (default @code{0}).
4133 @end defun
4135 @defun window-margins &optional window
4136 This function returns the left and right margins of @var{window}
4137 as a cons cell of the form @code{(@var{left} . @var{right})}.
4138 If @var{window} is @code{nil}, the selected window is used.
4139 @end defun
4141 @node Images
4142 @section Images
4143 @cindex images in buffers
4145   To display an image in an Emacs buffer, you must first create an image
4146 descriptor, then use it as a display specifier in the @code{display}
4147 property of text that is displayed (@pxref{Display Property}).
4149   Emacs is usually able to display images when it is run on a
4150 graphical terminal.  Images cannot be displayed in a text terminal, on
4151 certain graphical terminals that lack the support for this, or if
4152 Emacs is compiled without image support.  You can use the function
4153 @code{display-images-p} to determine if images can in principle be
4154 displayed (@pxref{Display Feature Testing}).
4156 @menu
4157 * Image Formats::       Supported image formats.
4158 * Image Descriptors::   How to specify an image for use in @code{:display}.
4159 * XBM Images::          Special features for XBM format.
4160 * XPM Images::          Special features for XPM format.
4161 * GIF Images::          Special features for GIF format.
4162 * TIFF Images::         Special features for TIFF format.
4163 * PostScript Images::   Special features for PostScript format.
4164 * ImageMagick Images::  Special features available through ImageMagick.
4165 * Other Image Types::   Various other formats are supported.
4166 * Defining Images::     Convenient ways to define an image for later use.
4167 * Showing Images::      Convenient ways to display an image once it is defined.
4168 * Animated Images::     Some image formats can be animated.
4169 * Image Cache::         Internal mechanisms of image display.
4170 @end menu
4172 @node Image Formats
4173 @subsection Image Formats
4174 @cindex image formats
4175 @cindex image types
4177   Emacs can display a number of different image formats; some of them
4178 are supported only if particular support libraries are installed on
4179 your machine.  In some environments, Emacs can load support libraries
4180 on demand; if so, the variable @code{dynamic-library-alist}
4181 (@pxref{Dynamic Libraries}) can be used to modify the set of known
4182 names for these dynamic libraries (though it is not possible to add
4183 new image formats).  Note that image types @code{pbm} and @code{xbm}
4184 do not depend on external libraries and are always available in Emacs.
4186   The supported image formats (and the necessary library files)
4187 include XBM, XPM (@code{libXpm} and @code{libz}), GIF (@code{libgif}
4188 or @code{libungif}), PostScript, PBM, JPEG (@code{libjpeg}), TIFF
4189 (@code{libtiff}), PNG (@code{libpng}), and SVG (@code{librsvg}).
4191   You specify one of these formats with an image type symbol.  The image
4192 type symbols are @code{xbm}, @code{xpm}, @code{gif}, @code{postscript},
4193 @code{pbm}, @code{jpeg}, @code{tiff}, @code{png}, and @code{svg}.
4195 @defvar image-types
4196 This variable contains a list of those image type symbols that are
4197 potentially supported in the current configuration.
4198 @emph{Potentially} here means that Emacs knows about the image types,
4199 not necessarily that they can be loaded (they could depend on
4200 unavailable dynamic libraries, for example).
4202 To know which image types are really available, use
4203 @code{image-type-available-p}.
4204 @end defvar
4206 @defun image-type-available-p type
4207 This function returns non-@code{nil} if image type @var{type} is
4208 available, i.e., if images of this type can be loaded and displayed in
4209 Emacs.  @var{type} should be one of the types contained in
4210 @code{image-types}.
4212 For image types whose support libraries are statically linked, this
4213 function always returns @code{t}; for other image types, it returns
4214 @code{t} if the dynamic library could be loaded, @code{nil} otherwise.
4215 @end defun
4217 @node Image Descriptors
4218 @subsection Image Descriptors
4219 @cindex image descriptor
4221   An image description is a list of the form @code{(image . @var{props})},
4222 where @var{props} is a property list containing alternating keyword
4223 symbols (symbols whose names start with a colon) and their values.
4224 You can use any Lisp object as a property, but the only properties
4225 that have any special meaning are certain symbols, all of them keywords.
4227   Every image descriptor must contain the property @code{:type
4228 @var{type}} to specify the format of the image.  The value of @var{type}
4229 should be an image type symbol; for example, @code{xpm} for an image in
4230 XPM format.
4232   Here is a list of other properties that are meaningful for all image
4233 types:
4235 @table @code
4236 @item :file @var{file}
4237 The @code{:file} property says to load the image from file
4238 @var{file}.  If @var{file} is not an absolute file name, it is expanded
4239 in @code{data-directory}.
4241 @item :data @var{data}
4242 The @code{:data} property says the actual contents of the image.
4243 Each image must use either @code{:data} or @code{:file}, but not both.
4244 For most image types, the value of the @code{:data} property should be a
4245 string containing the image data; we recommend using a unibyte string.
4247 Before using @code{:data}, look for further information in the section
4248 below describing the specific image format.  For some image types,
4249 @code{:data} may not be supported; for some, it allows other data types;
4250 for some, @code{:data} alone is not enough, so you need to use other
4251 image properties along with @code{:data}.
4253 @item :margin @var{margin}
4254 The @code{:margin} property specifies how many pixels to add as an
4255 extra margin around the image.  The value, @var{margin}, must be a
4256 non-negative number, or a pair @code{(@var{x} . @var{y})} of such
4257 numbers.  If it is a pair, @var{x} specifies how many pixels to add
4258 horizontally, and @var{y} specifies how many pixels to add vertically.
4259 If @code{:margin} is not specified, the default is zero.
4261 @item :ascent @var{ascent}
4262 The @code{:ascent} property specifies the amount of the image's
4263 height to use for its ascent---that is, the part above the baseline.
4264 The value, @var{ascent}, must be a number in the range 0 to 100, or
4265 the symbol @code{center}.
4267 If @var{ascent} is a number, that percentage of the image's height is
4268 used for its ascent.
4270 If @var{ascent} is @code{center}, the image is vertically centered
4271 around a centerline which would be the vertical centerline of text drawn
4272 at the position of the image, in the manner specified by the text
4273 properties and overlays that apply to the image.
4275 If this property is omitted, it defaults to 50.
4277 @item :relief @var{relief}
4278 The @code{:relief} property, if non-@code{nil}, adds a shadow rectangle
4279 around the image.  The value, @var{relief}, specifies the width of the
4280 shadow lines, in pixels.  If @var{relief} is negative, shadows are drawn
4281 so that the image appears as a pressed button; otherwise, it appears as
4282 an unpressed button.
4284 @item :conversion @var{algorithm}
4285 The @code{:conversion} property, if non-@code{nil}, specifies a
4286 conversion algorithm that should be applied to the image before it is
4287 displayed; the value, @var{algorithm}, specifies which algorithm.
4289 @table @code
4290 @item laplace
4291 @itemx emboss
4292 Specifies the Laplace edge detection algorithm, which blurs out small
4293 differences in color while highlighting larger differences.  People
4294 sometimes consider this useful for displaying the image for a
4295 ``disabled'' button.
4297 @item (edge-detection :matrix @var{matrix} :color-adjust @var{adjust})
4298 Specifies a general edge-detection algorithm.  @var{matrix} must be
4299 either a nine-element list or a nine-element vector of numbers.  A pixel
4300 at position @math{x/y} in the transformed image is computed from
4301 original pixels around that position.  @var{matrix} specifies, for each
4302 pixel in the neighborhood of @math{x/y}, a factor with which that pixel
4303 will influence the transformed pixel; element @math{0} specifies the
4304 factor for the pixel at @math{x-1/y-1}, element @math{1} the factor for
4305 the pixel at @math{x/y-1} etc., as shown below:
4306 @iftex
4307 @tex
4308 $$\pmatrix{x-1/y-1 & x/y-1  & x+1/y-1 \cr
4309    x-1/y  &   x/y &    x+1/y \cr
4310    x-1/y+1&   x/y+1 &  x+1/y+1 \cr}$$
4311 @end tex
4312 @end iftex
4313 @ifnottex
4314 @display
4315   (x-1/y-1  x/y-1  x+1/y-1
4316    x-1/y    x/y    x+1/y
4317    x-1/y+1  x/y+1  x+1/y+1)
4318 @end display
4319 @end ifnottex
4321 The resulting pixel is computed from the color intensity of the color
4322 resulting from summing up the RGB values of surrounding pixels,
4323 multiplied by the specified factors, and dividing that sum by the sum
4324 of the factors' absolute values.
4326 Laplace edge-detection currently uses a matrix of
4327 @iftex
4328 @tex
4329 $$\pmatrix{1 & 0 & 0 \cr
4330    0&  0 &  0 \cr
4331    0 & 0 & -1 \cr}$$
4332 @end tex
4333 @end iftex
4334 @ifnottex
4335 @display
4336   (1  0  0
4337    0  0  0
4338    0  0 -1)
4339 @end display
4340 @end ifnottex
4342 Emboss edge-detection uses a matrix of
4343 @iftex
4344 @tex
4345 $$\pmatrix{ 2 & -1 &  0 \cr
4346    -1 &  0 &  1 \cr
4347     0  & 1 & -2 \cr}$$
4348 @end tex
4349 @end iftex
4350 @ifnottex
4351 @display
4352   ( 2 -1  0
4353    -1  0  1
4354     0  1 -2)
4355 @end display
4356 @end ifnottex
4358 @item disabled
4359 Specifies transforming the image so that it looks ``disabled.''
4360 @end table
4362 @item :mask @var{mask}
4363 If @var{mask} is @code{heuristic} or @code{(heuristic @var{bg})}, build
4364 a clipping mask for the image, so that the background of a frame is
4365 visible behind the image.  If @var{bg} is not specified, or if @var{bg}
4366 is @code{t}, determine the background color of the image by looking at
4367 the four corners of the image, assuming the most frequently occurring
4368 color from the corners is the background color of the image.  Otherwise,
4369 @var{bg} must be a list @code{(@var{red} @var{green} @var{blue})}
4370 specifying the color to assume for the background of the image.
4372 If @var{mask} is @code{nil}, remove a mask from the image, if it has
4373 one.  Images in some formats include a mask which can be removed by
4374 specifying @code{:mask nil}.
4376 @item :pointer @var{shape}
4377 This specifies the pointer shape when the mouse pointer is over this
4378 image.  @xref{Pointer Shape}, for available pointer shapes.
4380 @item :map @var{map}
4381 This associates an image map of @dfn{hot spots} with this image.
4383 An image map is an alist where each element has the format
4384 @code{(@var{area} @var{id} @var{plist})}.  An @var{area} is specified
4385 as either a rectangle, a circle, or a polygon.
4387 A rectangle is a cons
4388 @code{(rect . ((@var{x0} . @var{y0}) . (@var{x1} . @var{y1})))}
4389 which specifies the pixel coordinates of the upper left and bottom right
4390 corners of the rectangle area.
4392 A circle is a cons
4393 @code{(circle . ((@var{x0} . @var{y0}) . @var{r}))}
4394 which specifies the center and the radius of the circle; @var{r} may
4395 be a float or integer.
4397 A polygon is a cons
4398 @code{(poly . [@var{x0} @var{y0} @var{x1} @var{y1} ...])}
4399 where each pair in the vector describes one corner in the polygon.
4401 When the mouse pointer lies on a hot-spot area of an image, the
4402 @var{plist} of that hot-spot is consulted; if it contains a @code{help-echo}
4403 property, that defines a tool-tip for the hot-spot, and if it contains
4404 a @code{pointer} property, that defines the shape of the mouse cursor when
4405 it is on the hot-spot.
4406 @xref{Pointer Shape}, for available pointer shapes.
4408 When you click the mouse when the mouse pointer is over a hot-spot, an
4409 event is composed by combining the @var{id} of the hot-spot with the
4410 mouse event; for instance, @code{[area4 mouse-1]} if the hot-spot's
4411 @var{id} is @code{area4}.
4412 @end table
4414 @defun image-mask-p spec &optional frame
4415 This function returns @code{t} if image @var{spec} has a mask bitmap.
4416 @var{frame} is the frame on which the image will be displayed.
4417 @var{frame} @code{nil} or omitted means to use the selected frame
4418 (@pxref{Input Focus}).
4419 @end defun
4421 @node XBM Images
4422 @subsection XBM Images
4423 @cindex XBM
4425   To use XBM format, specify @code{xbm} as the image type.  This image
4426 format doesn't require an external library, so images of this type are
4427 always supported.
4429   Additional image properties supported for the @code{xbm} image type are:
4431 @table @code
4432 @item :foreground @var{foreground}
4433 The value, @var{foreground}, should be a string specifying the image
4434 foreground color, or @code{nil} for the default color.  This color is
4435 used for each pixel in the XBM that is 1.  The default is the frame's
4436 foreground color.
4438 @item :background @var{background}
4439 The value, @var{background}, should be a string specifying the image
4440 background color, or @code{nil} for the default color.  This color is
4441 used for each pixel in the XBM that is 0.  The default is the frame's
4442 background color.
4443 @end table
4445   If you specify an XBM image using data within Emacs instead of an
4446 external file, use the following three properties:
4448 @table @code
4449 @item :data @var{data}
4450 The value, @var{data}, specifies the contents of the image.
4451 There are three formats you can use for @var{data}:
4453 @itemize @bullet
4454 @item
4455 A vector of strings or bool-vectors, each specifying one line of the
4456 image.  Do specify @code{:height} and @code{:width}.
4458 @item
4459 A string containing the same byte sequence as an XBM file would contain.
4460 You must not specify @code{:height} and @code{:width} in this case,
4461 because omitting them is what indicates the data has the format of an
4462 XBM file.  The file contents specify the height and width of the image.
4464 @item
4465 A string or a bool-vector containing the bits of the image (plus perhaps
4466 some extra bits at the end that will not be used).  It should contain at
4467 least @var{width} * @code{height} bits.  In this case, you must specify
4468 @code{:height} and @code{:width}, both to indicate that the string
4469 contains just the bits rather than a whole XBM file, and to specify the
4470 size of the image.
4471 @end itemize
4473 @item :width @var{width}
4474 The value, @var{width}, specifies the width of the image, in pixels.
4476 @item :height @var{height}
4477 The value, @var{height}, specifies the height of the image, in pixels.
4478 @end table
4480 @node XPM Images
4481 @subsection XPM Images
4482 @cindex XPM
4484   To use XPM format, specify @code{xpm} as the image type.  The
4485 additional image property @code{:color-symbols} is also meaningful with
4486 the @code{xpm} image type:
4488 @table @code
4489 @item :color-symbols @var{symbols}
4490 The value, @var{symbols}, should be an alist whose elements have the
4491 form @code{(@var{name} . @var{color})}.  In each element, @var{name} is
4492 the name of a color as it appears in the image file, and @var{color}
4493 specifies the actual color to use for displaying that name.
4494 @end table
4496 @node GIF Images
4497 @subsection GIF Images
4498 @cindex GIF
4500   For GIF images, specify image type @code{gif}.
4502 @table @code
4503 @item :index @var{index}
4504 You can use @code{:index} to specify image number @var{index} from a
4505 GIF file that contains more than one image.  If the GIF file doesn't
4506 contain an image with the specified index, the image displays as a
4507 hollow box.  GIF files with more than one image can be animated,
4508 @pxref{Animated Images}.
4509 @end table
4511 @node TIFF Images
4512 @subsection TIFF Images
4513 @cindex TIFF
4515   For TIFF images, specify image type @code{tiff}.
4517 @table @code
4518 @item :index @var{index}
4519 You can use @code{:index} to specify image number @var{index} from a
4520 TIFF file that contains more than one image.  If the TIFF file doesn't
4521 contain an image with the specified index, the image displays as a
4522 hollow box.
4523 @end table
4525 @node PostScript Images
4526 @subsection PostScript Images
4527 @cindex postscript images
4529   To use PostScript for an image, specify image type @code{postscript}.
4530 This works only if you have Ghostscript installed.  You must always use
4531 these three properties:
4533 @table @code
4534 @item :pt-width @var{width}
4535 The value, @var{width}, specifies the width of the image measured in
4536 points (1/72 inch).  @var{width} must be an integer.
4538 @item :pt-height @var{height}
4539 The value, @var{height}, specifies the height of the image in points
4540 (1/72 inch).  @var{height} must be an integer.
4542 @item :bounding-box @var{box}
4543 The value, @var{box}, must be a list or vector of four integers, which
4544 specifying the bounding box of the PostScript image, analogous to the
4545 @samp{BoundingBox} comment found in PostScript files.
4547 @example
4548 %%BoundingBox: 22 171 567 738
4549 @end example
4550 @end table
4552 @node ImageMagick Images
4553 @subsection ImageMagick Images
4554 @cindex ImageMagick images
4555 @cindex images, support for more formats
4557   If you build Emacs with ImageMagick (@url{http://www.imagemagick.org})
4558 support, you can use the ImageMagick library to load many image formats.
4560 @findex imagemagick-types
4561 @findex imagemagick-register-types
4562 The function @code{imagemagick-types} returns a list of image file
4563 extensions that your installation of ImageMagick supports.  To enable
4564 support, you must call the function @code{imagemagick-register-types}.
4565 This enables Emacs to visit these file types in @code{image-mode}
4566 (@pxref{File Conveniences,,, emacs, The GNU Emacs Manual}).
4567 If your Emacs was not compiled with ImageMagick support, then
4568 @code{imagemagick-types} will be undefined and
4569 @code{imagemagick-register-types} will do nothing.
4571 @vindex imagemagick-types-inhibit
4572 The variable @code{imagemagick-types-inhibit} specifies a list of
4573 image types that you do @emph{not} want ImageMagick to handle.  It is
4574 a list of symbols, each of which has the same name as one of the
4575 format tags used internally by ImageMagick (i.e., as
4576 @code{imagemagick-types} returns).  ImageMagick has a very broad
4577 definition of what an image is, for example it includes such file
4578 types as C files and HTML files.  It is not appropriate to treat these
4579 as images in Emacs.  You can add any other ImageMagick type that you
4580 wish to this list.
4581 @ignore
4582 @c I don't know what this means.  I suspect it means eg loading jpg
4583 @c images via libjpeg or ImageMagick.  But it doesn't work.
4584 @c If you don't have libjpeg support compiled in, you cannot
4585 @c view jpeg images, even if you have imagemagick support:
4586 @c http://debbugs.gnu.org/9045
4587 @c And if you have both compiled in, then you always get
4588 @c the libjpeg version:
4589 @c http://debbugs.gnu.org/10746
4590 There may be overlap between image loaders in your Emacs installation,
4591 and you may prefer to use a different one for a given image type
4592 (which loader will be used in practice depends on the priority of the
4593 loaders).  
4594 For example, if you never want to use the ImageMagick loader to view
4595 JPEG files, add @code{JPG} to this list.
4596 @end ignore
4597 Note that ImageMagick often distinguishes between several different
4598 types of a particular format (e.g., @code{JPG}, @code{JPEG},
4599 @code{PJPEG}, etc.), and you may need to add all versions to this
4600 list.
4602 @c Not sure this should even be in the manual at all.
4603 @vindex imagemagick-render-type
4604 If you wish to experiment with the performance of the ImageMagick
4605 loader, see the variable @code{imagemagick-render-type}.
4607 Images loaded with ImageMagick support a few new display specifications:
4609 @table @code
4610 @item :width, :height
4611 The @code{:width} and @code{:height} keywords are used for scaling the
4612 image.  If only one of them is specified, the other one will be
4613 calculated so as to preserve the aspect ratio.  If both are specified,
4614 aspect ratio may not be preserved.
4616 @item :rotation
4617 Specifies a rotation angle in degrees.
4619 @item :index
4620 @c Doesn't work: http://debbugs.gnu.org/7978
4621 This has the same meaning as it does for GIF images (@pxref{GIF Images}),
4622 i.e. it specifies which image to view inside an image bundle file format
4623 such as DJVM.  You can use the @code{image-metadata} function to
4624 retrieve the total number of images in an image bundle.
4625 @end table
4628 @node Other Image Types
4629 @subsection Other Image Types
4630 @cindex PBM
4632   For PBM images, specify image type @code{pbm}.  Color, gray-scale and
4633 monochromatic images are supported.   For mono PBM images, two additional
4634 image properties are supported.
4636 @table @code
4637 @item :foreground @var{foreground}
4638 The value, @var{foreground}, should be a string specifying the image
4639 foreground color, or @code{nil} for the default color.  This color is
4640 used for each pixel in the PBM that is 1.  The default is the frame's
4641 foreground color.
4643 @item :background @var{background}
4644 The value, @var{background}, should be a string specifying the image
4645 background color, or @code{nil} for the default color.  This color is
4646 used for each pixel in the PBM that is 0.  The default is the frame's
4647 background color.
4648 @end table
4650   For JPEG images, specify image type @code{jpeg}.
4652   For TIFF images, specify image type @code{tiff}.
4654   For PNG images, specify image type @code{png}.
4656   For SVG images, specify image type @code{svg}.
4658 @node Defining Images
4659 @subsection Defining Images
4661   The functions @code{create-image}, @code{defimage} and
4662 @code{find-image} provide convenient ways to create image descriptors.
4664 @defun create-image file-or-data &optional type data-p &rest props
4665 This function creates and returns an image descriptor which uses the
4666 data in @var{file-or-data}.  @var{file-or-data} can be a file name or
4667 a string containing the image data; @var{data-p} should be @code{nil}
4668 for the former case, non-@code{nil} for the latter case.
4670 The optional argument @var{type} is a symbol specifying the image type.
4671 If @var{type} is omitted or @code{nil}, @code{create-image} tries to
4672 determine the image type from the file's first few bytes, or else
4673 from the file's name.
4675 The remaining arguments, @var{props}, specify additional image
4676 properties---for example,
4678 @example
4679 (create-image "foo.xpm" 'xpm nil :heuristic-mask t)
4680 @end example
4682 The function returns @code{nil} if images of this type are not
4683 supported.  Otherwise it returns an image descriptor.
4684 @end defun
4686 @defmac defimage symbol specs &optional doc
4687 This macro defines @var{symbol} as an image name.  The arguments
4688 @var{specs} is a list which specifies how to display the image.
4689 The third argument, @var{doc}, is an optional documentation string.
4691 Each argument in @var{specs} has the form of a property list, and each
4692 one should specify at least the @code{:type} property and either the
4693 @code{:file} or the @code{:data} property.  The value of @code{:type}
4694 should be a symbol specifying the image type, the value of
4695 @code{:file} is the file to load the image from, and the value of
4696 @code{:data} is a string containing the actual image data.  Here is an
4697 example:
4699 @example
4700 (defimage test-image
4701   ((:type xpm :file "~/test1.xpm")
4702    (:type xbm :file "~/test1.xbm")))
4703 @end example
4705 @code{defimage} tests each argument, one by one, to see if it is
4706 usable---that is, if the type is supported and the file exists.  The
4707 first usable argument is used to make an image descriptor which is
4708 stored in @var{symbol}.
4710 If none of the alternatives will work, then @var{symbol} is defined
4711 as @code{nil}.
4712 @end defmac
4714 @defun find-image specs
4715 This function provides a convenient way to find an image satisfying one
4716 of a list of image specifications @var{specs}.
4718 Each specification in @var{specs} is a property list with contents
4719 depending on image type.  All specifications must at least contain the
4720 properties @code{:type @var{type}} and either @w{@code{:file @var{file}}}
4721 or @w{@code{:data @var{DATA}}}, where @var{type} is a symbol specifying
4722 the image type, e.g.@: @code{xbm}, @var{file} is the file to load the
4723 image from, and @var{data} is a string containing the actual image data.
4724 The first specification in the list whose @var{type} is supported, and
4725 @var{file} exists, is used to construct the image specification to be
4726 returned.  If no specification is satisfied, @code{nil} is returned.
4728 The image is looked for in @code{image-load-path}.
4729 @end defun
4731 @defvar image-load-path
4732 This variable's value is a list of locations in which to search for
4733 image files.  If an element is a string or a variable symbol whose
4734 value is a string, the string is taken to be the name of a directory
4735 to search.  If an element is a variable symbol whose value is a list,
4736 that is taken to be a list of directory names to search.
4738 The default is to search in the @file{images} subdirectory of the
4739 directory specified by @code{data-directory}, then the directory
4740 specified by @code{data-directory}, and finally in the directories in
4741 @code{load-path}.  Subdirectories are not automatically included in
4742 the search, so if you put an image file in a subdirectory, you have to
4743 supply the subdirectory name explicitly.  For example, to find the
4744 image @file{images/foo/bar.xpm} within @code{data-directory}, you
4745 should specify the image as follows:
4747 @example
4748 (defimage foo-image '((:type xpm :file "foo/bar.xpm")))
4749 @end example
4750 @end defvar
4752 @defun image-load-path-for-library library image &optional path no-error
4753 This function returns a suitable search path for images used by the
4754 Lisp package @var{library}.
4756 The function searches for @var{image} first using @code{image-load-path},
4757 excluding @file{@code{data-directory}/images}, and then in
4758 @code{load-path}, followed by a path suitable for @var{library}, which
4759 includes @file{../../etc/images} and @file{../etc/images} relative to
4760 the library file itself, and finally in
4761 @file{@code{data-directory}/images}.
4763 Then this function returns a list of directories which contains first
4764 the directory in which @var{image} was found, followed by the value of
4765 @code{load-path}.  If @var{path} is given, it is used instead of
4766 @code{load-path}.
4768 If @var{no-error} is non-@code{nil} and a suitable path can't be
4769 found, don't signal an error.  Instead, return a list of directories as
4770 before, except that @code{nil} appears in place of the image directory.
4772 Here is an example of using @code{image-load-path-for-library}:
4774 @example
4775 (defvar image-load-path) ; shush compiler
4776 (let* ((load-path (image-load-path-for-library
4777                     "mh-e" "mh-logo.xpm"))
4778        (image-load-path (cons (car load-path)
4779                               image-load-path)))
4780   (mh-tool-bar-folder-buttons-init))
4781 @end example
4782 @end defun
4784 @node Showing Images
4785 @subsection Showing Images
4787   You can use an image descriptor by setting up the @code{display}
4788 property yourself, but it is easier to use the functions in this
4789 section.
4791 @defun insert-image image &optional string area slice
4792 This function inserts @var{image} in the current buffer at point.  The
4793 value @var{image} should be an image descriptor; it could be a value
4794 returned by @code{create-image}, or the value of a symbol defined with
4795 @code{defimage}.  The argument @var{string} specifies the text to put
4796 in the buffer to hold the image.  If it is omitted or @code{nil},
4797 @code{insert-image} uses @code{" "} by default.
4799 The argument @var{area} specifies whether to put the image in a margin.
4800 If it is @code{left-margin}, the image appears in the left margin;
4801 @code{right-margin} specifies the right margin.  If @var{area} is
4802 @code{nil} or omitted, the image is displayed at point within the
4803 buffer's text.
4805 The argument @var{slice} specifies a slice of the image to insert.  If
4806 @var{slice} is @code{nil} or omitted the whole image is inserted.
4807 Otherwise, @var{slice} is a list @code{(@var{x} @var{y} @var{width}
4808 @var{height})} which specifies the @var{x} and @var{y} positions and
4809 @var{width} and @var{height} of the image area to insert.  Integer
4810 values are in units of pixels.  A floating point number in the range
4811 0.0--1.0 stands for that fraction of the width or height of the entire
4812 image.
4814 Internally, this function inserts @var{string} in the buffer, and gives
4815 it a @code{display} property which specifies @var{image}.  @xref{Display
4816 Property}.
4817 @end defun
4819 @cindex slice, image
4820 @cindex image slice
4821 @defun insert-sliced-image image &optional string area rows cols
4822 This function inserts @var{image} in the current buffer at point, like
4823 @code{insert-image}, but splits the image into @var{rows}x@var{cols}
4824 equally sized slices.
4826 If an image is inserted ``sliced'', then the Emacs display engine will
4827 treat each slice as a separate image, and allow more intuitive
4828 scrolling up/down, instead of jumping up/down the entire image when
4829 paging through a buffer that displays (large) images.
4830 @end defun
4832 @defun put-image image pos &optional string area
4833 This function puts image @var{image} in front of @var{pos} in the
4834 current buffer.  The argument @var{pos} should be an integer or a
4835 marker.  It specifies the buffer position where the image should appear.
4836 The argument @var{string} specifies the text that should hold the image
4837 as an alternative to the default.
4839 The argument @var{image} must be an image descriptor, perhaps returned
4840 by @code{create-image} or stored by @code{defimage}.
4842 The argument @var{area} specifies whether to put the image in a margin.
4843 If it is @code{left-margin}, the image appears in the left margin;
4844 @code{right-margin} specifies the right margin.  If @var{area} is
4845 @code{nil} or omitted, the image is displayed at point within the
4846 buffer's text.
4848 Internally, this function creates an overlay, and gives it a
4849 @code{before-string} property containing text that has a @code{display}
4850 property whose value is the image.  (Whew!)
4851 @end defun
4853 @defun remove-images start end &optional buffer
4854 This function removes images in @var{buffer} between positions
4855 @var{start} and @var{end}.  If @var{buffer} is omitted or @code{nil},
4856 images are removed from the current buffer.
4858 This removes only images that were put into @var{buffer} the way
4859 @code{put-image} does it, not images that were inserted with
4860 @code{insert-image} or in other ways.
4861 @end defun
4863 @defun image-size spec &optional pixels frame
4864 This function returns the size of an image as a pair
4865 @w{@code{(@var{width} . @var{height})}}.  @var{spec} is an image
4866 specification.  @var{pixels} non-@code{nil} means return sizes
4867 measured in pixels, otherwise return sizes measured in canonical
4868 character units (fractions of the width/height of the frame's default
4869 font).  @var{frame} is the frame on which the image will be displayed.
4870 @var{frame} null or omitted means use the selected frame (@pxref{Input
4871 Focus}).
4872 @end defun
4874 @defvar max-image-size
4875 This variable is used to define the maximum size of image that Emacs
4876 will load.  Emacs will refuse to load (and display) any image that is
4877 larger than this limit.
4879 If the value is an integer, it directly specifies the maximum
4880 image height and width, measured in pixels.  If it is a floating
4881 point number, it specifies the maximum image height and width
4882 as a ratio to the frame height and width.  If the value is
4883 non-numeric, there is no explicit limit on the size of images.
4885 The purpose of this variable is to prevent unreasonably large images
4886 from accidentally being loaded into Emacs.  It only takes effect the
4887 first time an image is loaded.  Once an image is placed in the image
4888 cache, it can always be displayed, even if the value of
4889 @var{max-image-size} is subsequently changed (@pxref{Image Cache}).
4890 @end defvar
4892 @node Animated Images
4893 @subsection Animated Images
4895 @cindex animation
4896 @cindex image animation
4897 Some image files can contain more than one image.  This can be used to
4898 create animation.  Currently, Emacs only supports animated GIF files.
4899 The following functions related to animated images are available.
4901 @defun image-animated-p image
4902 This function returns non-nil if @var{image} can be animated.
4903 The actual return value is a cons @code{(@var{nimages} . @var{delay})}, 
4904 where @var{nimages} is the number of frames and @var{delay} is the
4905 delay in seconds between them.
4906 @end defun
4908 @defun image-animate image &optional index limit
4909 This function animates @var{image}.  The optional integer @var{index}
4910 specifies the frame from which to start (default 0).  The optional
4911 argument @var{limit} controls the length of the animation.  If omitted
4912 or @code{nil}, the image animates once only; if @code{t} it loops
4913 forever; if a number animation stops after that many seconds.
4914 @end defun
4916 @noindent Animation operates by means of a timer.  Note that Emacs imposes a
4917 minimum frame delay of 0.01 seconds.
4919 @defun image-animate-timer image
4920 This function returns the timer responsible for animating @var{image},
4921 if there is one.
4922 @end defun
4925 @node Image Cache
4926 @subsection Image Cache
4927 @cindex image cache
4929   Emacs caches images so that it can display them again more
4930 efficiently.  When Emacs displays an image, it searches the image
4931 cache for an existing image specification @code{equal} to the desired
4932 specification.  If a match is found, the image is displayed from the
4933 cache.  Otherwise, Emacs loads the image normally.
4935 @defun image-flush spec &optional frame
4936 This function removes the image with specification @var{spec} from the
4937 image cache of frame @var{frame}.  Image specifications are compared
4938 using @code{equal}.  If @var{frame} is @code{nil}, it defaults to the
4939 selected frame.  If @var{frame} is @code{t}, the image is flushed on
4940 all existing frames.
4942 In Emacs's current implementation, each graphical terminal possesses an
4943 image cache, which is shared by all the frames on that terminal
4944 (@pxref{Multiple Terminals}).  Thus, refreshing an image in one frame
4945 also refreshes it in all other frames on the same terminal.
4946 @end defun
4948   One use for @code{image-flush} is to tell Emacs about a change in an
4949 image file.  If an image specification contains a @code{:file}
4950 property, the image is cached based on the file's contents when the
4951 image is first displayed.  Even if the file subsequently changes,
4952 Emacs continues displaying the old version of the image.  Calling
4953 @code{image-flush} flushes the image from the cache, forcing Emacs to
4954 re-read the file the next time it needs to display that image.
4956   Another use for @code{image-flush} is for memory conservation.  If
4957 your Lisp program creates a large number of temporary images over a
4958 period much shorter than @code{image-cache-eviction-delay} (see
4959 below), you can opt to flush unused images yourself, instead of
4960 waiting for Emacs to do it automatically.
4962 @defun clear-image-cache &optional filter
4963 This function clears an image cache, removing all the images stored in
4964 it.  If @var{filter} is omitted or @code{nil}, it clears the cache for
4965 the selected frame.  If @var{filter} is a frame, it clears the cache
4966 for that frame.  If @var{filter} is @code{t}, all image caches are
4967 cleared.  Otherwise, @var{filter} is taken to be a file name, and all
4968 images associated with that file name are removed from all image
4969 caches.
4970 @end defun
4972 If an image in the image cache has not been displayed for a specified
4973 period of time, Emacs removes it from the cache and frees the
4974 associated memory.
4976 @defvar image-cache-eviction-delay
4977 This variable specifies the number of seconds an image can remain in
4978 the cache without being displayed.  When an image is not displayed for
4979 this length of time, Emacs removes it from the image cache.
4981 Under some circumstances, if the number of images in the cache grows
4982 too large, the actual eviction delay may be shorter than this.
4984 If the value is @code{nil}, Emacs does not remove images from the cache
4985 except when you explicitly clear it.  This mode can be useful for
4986 debugging.
4987 @end defvar
4989 @node Buttons
4990 @section Buttons
4991 @cindex buttons in buffers
4992 @cindex clickable buttons in buffers
4994   The @emph{button} package defines functions for inserting and
4995 manipulating clickable (with the mouse, or via keyboard commands)
4996 buttons in Emacs buffers, such as might be used for help hyper-links,
4997 etc.  Emacs uses buttons for the hyper-links in help text and the like.
4999   A button is essentially a set of properties attached (via text
5000 properties or overlays) to a region of text in an Emacs buffer.  These
5001 properties are called @dfn{button properties}.
5003   One of these properties (@code{action}) is a function, which will
5004 be called when the user invokes it using the keyboard or the mouse.
5005 The invoked function may then examine the button and use its other
5006 properties as desired.
5008   In some ways the Emacs button package duplicates functionality offered
5009 by the widget package (@pxref{Top, , Introduction, widget, The Emacs
5010 Widget Library}), but the button package has the advantage that it is
5011 much faster, much smaller, and much simpler to use (for elisp
5012 programmers---for users, the result is about the same).  The extra
5013 speed and space savings are useful mainly if you need to create many
5014 buttons in a buffer (for instance an @code{*Apropos*} buffer uses
5015 buttons to make entries clickable, and may contain many thousands of
5016 entries).
5018 @menu
5019 * Button Properties::      Button properties with special meanings.
5020 * Button Types::           Defining common properties for classes of buttons.
5021 * Making Buttons::         Adding buttons to Emacs buffers.
5022 * Manipulating Buttons::   Getting and setting properties of buttons.
5023 * Button Buffer Commands:: Buffer-wide commands and bindings for buttons.
5024 @end menu
5026 @node Button Properties
5027 @subsection Button Properties
5028 @cindex button properties
5030   Buttons have an associated list of properties defining their
5031 appearance and behavior, and other arbitrary properties may be used
5032 for application specific purposes.  Some properties that have special
5033 meaning to the button package include:
5035 @table @code
5036 @item action
5037 @kindex action @r{(button property)}
5038 The function to call when the user invokes the button, which is passed
5039 the single argument @var{button}.  By default this is @code{ignore},
5040 which does nothing.
5042 @item mouse-action
5043 @kindex mouse-action @r{(button property)}
5044 This is similar to @code{action}, and when present, will be used
5045 instead of @code{action} for button invocations resulting from
5046 mouse-clicks (instead of the user hitting @key{RET}).  If not
5047 present, mouse-clicks use @code{action} instead.
5049 @item face
5050 @kindex face @r{(button property)}
5051 This is an Emacs face controlling how buttons of this type are
5052 displayed; by default this is the @code{button} face.
5054 @item mouse-face
5055 @kindex mouse-face @r{(button property)}
5056 This is an additional face which controls appearance during
5057 mouse-overs (merged with the usual button face); by default this is
5058 the usual Emacs @code{highlight} face.
5060 @item keymap
5061 @kindex keymap @r{(button property)}
5062 The button's keymap, defining bindings active within the button
5063 region.  By default this is the usual button region keymap, stored
5064 in the variable @code{button-map}, which defines @key{RET} and
5065 @key{mouse-2} to invoke the button.
5067 @item type
5068 @kindex type @r{(button property)}
5069 The button-type of the button.  When creating a button, this is
5070 usually specified using the @code{:type} keyword argument.
5071 @xref{Button Types}.
5073 @item help-echo
5074 @kindex help-index @r{(button property)}
5075 A string displayed by the Emacs tool-tip help system; by default,
5076 @code{"mouse-2, RET: Push this button"}.
5078 @item follow-link
5079 @kindex follow-link @r{(button property)}
5080 The follow-link property, defining how a @key{Mouse-1} click behaves
5081 on this button, @xref{Clickable Text}.
5083 @item button
5084 @kindex button @r{(button property)}
5085 All buttons have a non-@code{nil} @code{button} property, which may be useful
5086 in finding regions of text that comprise buttons (which is what the
5087 standard button functions do).
5088 @end table
5090   There are other properties defined for the regions of text in a
5091 button, but these are not generally interesting for typical uses.
5093 @node Button Types
5094 @subsection Button Types
5095 @cindex button types
5097   Every button has a button @emph{type}, which defines default values
5098 for the button's properties.  Button types are arranged in a
5099 hierarchy, with specialized types inheriting from more general types,
5100 so that it's easy to define special-purpose types of buttons for
5101 specific tasks.
5103 @defun define-button-type name &rest properties
5104 Define a `button type' called @var{name} (a symbol).
5105 The remaining arguments
5106 form a sequence of @var{property value} pairs, specifying default
5107 property values for buttons with this type (a button's type may be set
5108 by giving it a @code{type} property when creating the button, using
5109 the @code{:type} keyword argument).
5111 In addition, the keyword argument @code{:supertype} may be used to
5112 specify a button-type from which @var{name} inherits its default
5113 property values.  Note that this inheritance happens only when
5114 @var{name} is defined; subsequent changes to a supertype are not
5115 reflected in its subtypes.
5116 @end defun
5118   Using @code{define-button-type} to define default properties for
5119 buttons is not necessary---buttons without any specified type use the
5120 built-in button-type @code{button}---but it is encouraged, since
5121 doing so usually makes the resulting code clearer and more efficient.
5123 @node Making Buttons
5124 @subsection Making Buttons
5125 @cindex making buttons
5127   Buttons are associated with a region of text, using an overlay or
5128 text properties to hold button-specific information, all of which are
5129 initialized from the button's type (which defaults to the built-in
5130 button type @code{button}).  Like all Emacs text, the appearance of
5131 the button is governed by the @code{face} property; by default (via
5132 the @code{face} property inherited from the @code{button} button-type)
5133 this is a simple underline, like a typical web-page link.
5135   For convenience, there are two sorts of button-creation functions,
5136 those that add button properties to an existing region of a buffer,
5137 called @code{make-...button}, and those that also insert the button
5138 text, called @code{insert-...button}.
5140   The button-creation functions all take the @code{&rest} argument
5141 @var{properties}, which should be a sequence of @var{property value}
5142 pairs, specifying properties to add to the button; see @ref{Button
5143 Properties}.  In addition, the keyword argument @code{:type} may be
5144 used to specify a button-type from which to inherit other properties;
5145 see @ref{Button Types}.  Any properties not explicitly specified
5146 during creation will be inherited from the button's type (if the type
5147 defines such a property).
5149   The following functions add a button using an overlay
5150 (@pxref{Overlays}) to hold the button properties:
5152 @defun make-button beg end &rest properties
5153 This makes a button from @var{beg} to @var{end} in the
5154 current buffer, and returns it.
5155 @end defun
5157 @defun insert-button label &rest properties
5158 This insert a button with the label @var{label} at point,
5159 and returns it.
5160 @end defun
5162   The following functions are similar, but use Emacs text properties
5163 (@pxref{Text Properties}) to hold the button properties, making the
5164 button actually part of the text instead of being a property of the
5165 buffer.  Buttons using text properties do not create markers into the
5166 buffer, which is important for speed when you use extremely large
5167 numbers of buttons.  (However, if there is an existing face text
5168 property at the site of the button, the button face may not be visible.)
5169 Both functions return the position of the start of the new button:
5171 @defun make-text-button beg end &rest properties
5172 This makes a button from @var{beg} to @var{end} in the current buffer, using
5173 text properties.
5174 @end defun
5176 @defun insert-text-button label &rest properties
5177 This inserts a button with the label @var{label} at point, using text
5178 properties.
5179 @end defun
5181 @node Manipulating Buttons
5182 @subsection Manipulating Buttons
5183 @cindex manipulating buttons
5185 These are functions for getting and setting properties of buttons.
5186 Often these are used by a button's invocation function to determine
5187 what to do.
5189 Where a @var{button} parameter is specified, it means an object
5190 referring to a specific button, either an overlay (for overlay
5191 buttons), or a buffer-position or marker (for text property buttons).
5192 Such an object is passed as the first argument to a button's
5193 invocation function when it is invoked.
5195 @defun button-start button
5196 Return the position at which @var{button} starts.
5197 @end defun
5199 @defun button-end button
5200 Return the position at which @var{button} ends.
5201 @end defun
5203 @defun button-get button prop
5204 Get the property of button @var{button} named @var{prop}.
5205 @end defun
5207 @defun button-put button prop val
5208 Set @var{button}'s @var{prop} property to @var{val}.
5209 @end defun
5211 @defun button-activate button &optional use-mouse-action
5212 Call @var{button}'s @code{action} property (i.e., invoke it).  If
5213 @var{use-mouse-action} is non-@code{nil}, try to invoke the button's
5214 @code{mouse-action} property instead of @code{action}; if the button
5215 has no @code{mouse-action} property, use @code{action} as normal.
5216 @end defun
5218 @defun button-label button
5219 Return @var{button}'s text label.
5220 @end defun
5222 @defun button-type button
5223 Return @var{button}'s button-type.
5224 @end defun
5226 @defun button-has-type-p button type
5227 Return @code{t} if @var{button} has button-type @var{type}, or one of
5228 @var{type}'s subtypes.
5229 @end defun
5231 @defun button-at pos
5232 Return the button at position @var{pos} in the current buffer, or @code{nil}.
5233 @end defun
5235 @defun button-type-put type prop val
5236 Set the button-type @var{type}'s @var{prop} property to @var{val}.
5237 @end defun
5239 @defun button-type-get type prop
5240 Get the property of button-type @var{type} named @var{prop}.
5241 @end defun
5243 @defun button-type-subtype-p type supertype
5244 Return @code{t} if button-type @var{type} is a subtype of @var{supertype}.
5245 @end defun
5247 @node Button Buffer Commands
5248 @subsection Button Buffer Commands
5249 @cindex button buffer commands
5251 These are commands and functions for locating and operating on
5252 buttons in an Emacs buffer.
5254 @code{push-button} is the command that a user uses to actually `push'
5255 a button, and is bound by default in the button itself to @key{RET}
5256 and to @key{mouse-2} using a region-specific keymap.  Commands
5257 that are useful outside the buttons itself, such as
5258 @code{forward-button} and @code{backward-button} are additionally
5259 available in the keymap stored in @code{button-buffer-map}; a mode
5260 which uses buttons may want to use @code{button-buffer-map} as a
5261 parent keymap for its keymap.
5263 If the button has a non-@code{nil} @code{follow-link} property, and
5264 @var{mouse-1-click-follows-link} is set, a quick @key{Mouse-1} click
5265 will also activate the @code{push-button} command.
5266 @xref{Clickable Text}.
5268 @deffn Command push-button &optional pos use-mouse-action
5269 Perform the action specified by a button at location @var{pos}.
5270 @var{pos} may be either a buffer position or a mouse-event.  If
5271 @var{use-mouse-action} is non-@code{nil}, or @var{pos} is a
5272 mouse-event (@pxref{Mouse Events}), try to invoke the button's
5273 @code{mouse-action} property instead of @code{action}; if the button
5274 has no @code{mouse-action} property, use @code{action} as normal.
5275 @var{pos} defaults to point, except when @code{push-button} is invoked
5276 interactively as the result of a mouse-event, in which case, the mouse
5277 event's position is used.  If there's no button at @var{pos}, do
5278 nothing and return @code{nil}, otherwise return @code{t}.
5279 @end deffn
5281 @deffn Command forward-button n &optional wrap display-message
5282 Move to the @var{n}th next button, or @var{n}th previous button if
5283 @var{n} is negative.  If @var{n} is zero, move to the start of any
5284 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5285 end of the buffer continues from the other end.  If
5286 @var{display-message} is non-@code{nil}, the button's help-echo string
5287 is displayed.  Any button with a non-@code{nil} @code{skip} property
5288 is skipped over.  Returns the button found.
5289 @end deffn
5291 @deffn Command backward-button n &optional wrap display-message
5292 Move to the @var{n}th previous button, or @var{n}th next button if
5293 @var{n} is negative.  If @var{n} is zero, move to the start of any
5294 button at point.  If @var{wrap} is non-@code{nil}, moving past either
5295 end of the buffer continues from the other end.  If
5296 @var{display-message} is non-@code{nil}, the button's help-echo string
5297 is displayed.  Any button with a non-@code{nil} @code{skip} property
5298 is skipped over.  Returns the button found.
5299 @end deffn
5301 @defun next-button pos &optional count-current
5302 @defunx previous-button pos &optional count-current
5303 Return the next button after (for @code{next-button} or before (for
5304 @code{previous-button}) position @var{pos} in the current buffer.  If
5305 @var{count-current} is non-@code{nil}, count any button at @var{pos}
5306 in the search, instead of starting at the next button.
5307 @end defun
5309 @node Abstract Display
5310 @section Abstract Display
5311 @cindex ewoc
5312 @cindex display, abstract
5313 @cindex display, arbitrary objects
5314 @cindex model/view/controller
5315 @cindex view part, model/view/controller
5317   The Ewoc package constructs buffer text that represents a structure
5318 of Lisp objects, and updates the text to follow changes in that
5319 structure.  This is like the ``view'' component in the
5320 ``model/view/controller'' design paradigm.
5322   An @dfn{ewoc} is a structure that organizes information required to
5323 construct buffer text that represents certain Lisp data.  The buffer
5324 text of the ewoc has three parts, in order: first, fixed @dfn{header}
5325 text; next, textual descriptions of a series of data elements (Lisp
5326 objects that you specify); and last, fixed @dfn{footer} text.
5327 Specifically, an ewoc contains information on:
5329 @itemize @bullet
5330 @item
5331 The buffer which its text is generated in.
5333 @item
5334 The text's start position in the buffer.
5336 @item
5337 The header and footer strings.
5339 @item
5340 A doubly-linked chain of @dfn{nodes}, each of which contains:
5342 @itemize
5343 @item
5344 A @dfn{data element}, a single Lisp object.
5346 @item
5347 Links to the preceding and following nodes in the chain.
5348 @end itemize
5350 @item
5351 A @dfn{pretty-printer} function which is responsible for
5352 inserting the textual representation of a data
5353 element value into the current buffer.
5354 @end itemize
5356   Typically, you define an ewoc with @code{ewoc-create}, and then pass
5357 the resulting ewoc structure to other functions in the Ewoc package to
5358 build nodes within it, and display it in the buffer.  Once it is
5359 displayed in the buffer, other functions determine the correspondence
5360 between buffer positions and nodes, move point from one node's textual
5361 representation to another, and so forth.  @xref{Abstract Display
5362 Functions}.
5364   A node @dfn{encapsulates} a data element much the way a variable
5365 holds a value.  Normally, encapsulation occurs as a part of adding a
5366 node to the ewoc.  You can retrieve the data element value and place a
5367 new value in its place, like so:
5369 @lisp
5370 (ewoc-data @var{node})
5371 @result{} value
5373 (ewoc-set-data @var{node} @var{new-value})
5374 @result{} @var{new-value}
5375 @end lisp
5377 @noindent
5378 You can also use, as the data element value, a Lisp object (list or
5379 vector) that is a container for the ``real'' value, or an index into
5380 some other structure.  The example (@pxref{Abstract Display Example})
5381 uses the latter approach.
5383   When the data changes, you will want to update the text in the
5384 buffer.  You can update all nodes by calling @code{ewoc-refresh}, or
5385 just specific nodes using @code{ewoc-invalidate}, or all nodes
5386 satisfying a predicate using @code{ewoc-map}.  Alternatively, you can
5387 delete invalid nodes using @code{ewoc-delete} or @code{ewoc-filter},
5388 and add new nodes in their place.  Deleting a node from an ewoc deletes
5389 its associated textual description from buffer, as well.
5391 @menu
5392 * Abstract Display Functions::  Functions in the Ewoc package.
5393 * Abstract Display Example::    Example of using Ewoc.
5394 @end menu
5396 @node Abstract Display Functions
5397 @subsection Abstract Display Functions
5399   In this subsection, @var{ewoc} and @var{node} stand for the
5400 structures described above (@pxref{Abstract Display}), while
5401 @var{data} stands for an arbitrary Lisp object used as a data element.
5403 @defun ewoc-create pretty-printer &optional header footer nosep
5404 This constructs and returns a new ewoc, with no nodes (and thus no data
5405 elements).  @var{pretty-printer} should be a function that takes one
5406 argument, a data element of the sort you plan to use in this ewoc, and
5407 inserts its textual description at point using @code{insert} (and never
5408 @code{insert-before-markers}, because that would interfere with the
5409 Ewoc package's internal mechanisms).
5411 Normally, a newline is automatically inserted after the header,
5412 the footer and every node's textual description.  If @var{nosep}
5413 is non-@code{nil}, no newline is inserted.  This may be useful for
5414 displaying an entire ewoc on a single line, for example, or for
5415 making nodes ``invisible'' by arranging for @var{pretty-printer}
5416 to do nothing for those nodes.
5418 An ewoc maintains its text in the buffer that is current when
5419 you create it, so switch to the intended buffer before calling
5420 @code{ewoc-create}.
5421 @end defun
5423 @defun ewoc-buffer ewoc
5424 This returns the buffer where @var{ewoc} maintains its text.
5425 @end defun
5427 @defun ewoc-get-hf ewoc
5428 This returns a cons cell @code{(@var{header} . @var{footer})}
5429 made from @var{ewoc}'s header and footer.
5430 @end defun
5432 @defun ewoc-set-hf ewoc header footer
5433 This sets the header and footer of @var{ewoc} to the strings
5434 @var{header} and @var{footer}, respectively.
5435 @end defun
5437 @defun ewoc-enter-first ewoc data
5438 @defunx ewoc-enter-last ewoc data
5439 These add a new node encapsulating @var{data}, putting it, respectively,
5440 at the beginning or end of @var{ewoc}'s chain of nodes.
5441 @end defun
5443 @defun ewoc-enter-before ewoc node data
5444 @defunx ewoc-enter-after ewoc node data
5445 These add a new node encapsulating @var{data}, adding it to
5446 @var{ewoc} before or after @var{node}, respectively.
5447 @end defun
5449 @defun ewoc-prev ewoc node
5450 @defunx ewoc-next ewoc node
5451 These return, respectively, the previous node and the next node of @var{node}
5452 in @var{ewoc}.
5453 @end defun
5455 @defun ewoc-nth ewoc n
5456 This returns the node in @var{ewoc} found at zero-based index @var{n}.
5457 A negative @var{n} means count from the end.  @code{ewoc-nth} returns
5458 @code{nil} if @var{n} is out of range.
5459 @end defun
5461 @defun ewoc-data node
5462 This extracts the data encapsulated by @var{node} and returns it.
5463 @end defun
5465 @defun ewoc-set-data node data
5466 This sets the data encapsulated by @var{node} to @var{data}.
5467 @end defun
5469 @defun ewoc-locate ewoc &optional pos guess
5470 This determines the node in @var{ewoc} which contains point (or
5471 @var{pos} if specified), and returns that node.  If @var{ewoc} has no
5472 nodes, it returns @code{nil}.  If @var{pos} is before the first node,
5473 it returns the first node; if @var{pos} is after the last node, it returns
5474 the last node.  The optional third arg @var{guess}
5475 should be a node that is likely to be near @var{pos}; this doesn't
5476 alter the result, but makes the function run faster.
5477 @end defun
5479 @defun ewoc-location node
5480 This returns the start position of @var{node}.
5481 @end defun
5483 @defun ewoc-goto-prev ewoc arg
5484 @defunx ewoc-goto-next ewoc arg
5485 These move point to the previous or next, respectively, @var{arg}th node
5486 in @var{ewoc}.  @code{ewoc-goto-prev} does not move if it is already at
5487 the first node or if @var{ewoc} is empty, whereas @code{ewoc-goto-next}
5488 moves past the last node, returning @code{nil}.  Excepting this special
5489 case, these functions return the node moved to.
5490 @end defun
5492 @defun ewoc-goto-node ewoc node
5493 This moves point to the start of @var{node} in @var{ewoc}.
5494 @end defun
5496 @defun ewoc-refresh ewoc
5497 This function regenerates the text of @var{ewoc}.  It works by
5498 deleting the text between the header and the footer, i.e., all the
5499 data elements' representations, and then calling the pretty-printer
5500 function for each node, one by one, in order.
5501 @end defun
5503 @defun ewoc-invalidate ewoc &rest nodes
5504 This is similar to @code{ewoc-refresh}, except that only @var{nodes} in
5505 @var{ewoc} are updated instead of the entire set.
5506 @end defun
5508 @defun ewoc-delete ewoc &rest nodes
5509 This deletes each node in @var{nodes} from @var{ewoc}.
5510 @end defun
5512 @defun ewoc-filter ewoc predicate &rest args
5513 This calls @var{predicate} for each data element in @var{ewoc} and
5514 deletes those nodes for which @var{predicate} returns @code{nil}.
5515 Any @var{args} are passed to @var{predicate}.
5516 @end defun
5518 @defun ewoc-collect ewoc predicate &rest args
5519 This calls @var{predicate} for each data element in @var{ewoc}
5520 and returns a list of those elements for which @var{predicate}
5521 returns non-@code{nil}.  The elements in the list are ordered
5522 as in the buffer.  Any @var{args} are passed to @var{predicate}.
5523 @end defun
5525 @defun ewoc-map map-function ewoc &rest args
5526 This calls @var{map-function} for each data element in @var{ewoc} and
5527 updates those nodes for which @var{map-function} returns non-@code{nil}.
5528 Any @var{args} are passed to @var{map-function}.
5529 @end defun
5531 @node Abstract Display Example
5532 @subsection Abstract Display Example
5534   Here is a simple example using functions of the ewoc package to
5535 implement a ``color components display,'' an area in a buffer that
5536 represents a vector of three integers (itself representing a 24-bit RGB
5537 value) in various ways.
5539 @example
5540 (setq colorcomp-ewoc nil
5541       colorcomp-data nil
5542       colorcomp-mode-map nil
5543       colorcomp-labels ["Red" "Green" "Blue"])
5545 (defun colorcomp-pp (data)
5546   (if data
5547       (let ((comp (aref colorcomp-data data)))
5548         (insert (aref colorcomp-labels data) "\t: #x"
5549                 (format "%02X" comp) " "
5550                 (make-string (ash comp -2) ?#) "\n"))
5551     (let ((cstr (format "#%02X%02X%02X"
5552                         (aref colorcomp-data 0)
5553                         (aref colorcomp-data 1)
5554                         (aref colorcomp-data 2)))
5555           (samp " (sample text) "))
5556       (insert "Color\t: "
5557               (propertize samp 'face
5558                           `(foreground-color . ,cstr))
5559               (propertize samp 'face
5560                           `(background-color . ,cstr))
5561               "\n"))))
5563 (defun colorcomp (color)
5564   "Allow fiddling with COLOR in a new buffer.
5565 The buffer is in Color Components mode."
5566   (interactive "sColor (name or #RGB or #RRGGBB): ")
5567   (when (string= "" color)
5568     (setq color "green"))
5569   (unless (color-values color)
5570     (error "No such color: %S" color))
5571   (switch-to-buffer
5572    (generate-new-buffer (format "originally: %s" color)))
5573   (kill-all-local-variables)
5574   (setq major-mode 'colorcomp-mode
5575         mode-name "Color Components")
5576   (use-local-map colorcomp-mode-map)
5577   (erase-buffer)
5578   (buffer-disable-undo)
5579   (let ((data (apply 'vector (mapcar (lambda (n) (ash n -8))
5580                                      (color-values color))))
5581         (ewoc (ewoc-create 'colorcomp-pp
5582                            "\nColor Components\n\n"
5583                            (substitute-command-keys
5584                             "\n\\@{colorcomp-mode-map@}"))))
5585     (set (make-local-variable 'colorcomp-data) data)
5586     (set (make-local-variable 'colorcomp-ewoc) ewoc)
5587     (ewoc-enter-last ewoc 0)
5588     (ewoc-enter-last ewoc 1)
5589     (ewoc-enter-last ewoc 2)
5590     (ewoc-enter-last ewoc nil)))
5591 @end example
5593 @cindex controller part, model/view/controller
5594   This example can be extended to be a ``color selection widget'' (in
5595 other words, the controller part of the ``model/view/controller''
5596 design paradigm) by defining commands to modify @code{colorcomp-data}
5597 and to ``finish'' the selection process, and a keymap to tie it all
5598 together conveniently.
5600 @smallexample
5601 (defun colorcomp-mod (index limit delta)
5602   (let ((cur (aref colorcomp-data index)))
5603     (unless (= limit cur)
5604       (aset colorcomp-data index (+ cur delta)))
5605     (ewoc-invalidate
5606      colorcomp-ewoc
5607      (ewoc-nth colorcomp-ewoc index)
5608      (ewoc-nth colorcomp-ewoc -1))))
5610 (defun colorcomp-R-more () (interactive) (colorcomp-mod 0 255 1))
5611 (defun colorcomp-G-more () (interactive) (colorcomp-mod 1 255 1))
5612 (defun colorcomp-B-more () (interactive) (colorcomp-mod 2 255 1))
5613 (defun colorcomp-R-less () (interactive) (colorcomp-mod 0 0 -1))
5614 (defun colorcomp-G-less () (interactive) (colorcomp-mod 1 0 -1))
5615 (defun colorcomp-B-less () (interactive) (colorcomp-mod 2 0 -1))
5617 (defun colorcomp-copy-as-kill-and-exit ()
5618   "Copy the color components into the kill ring and kill the buffer.
5619 The string is formatted #RRGGBB (hash followed by six hex digits)."
5620   (interactive)
5621   (kill-new (format "#%02X%02X%02X"
5622                     (aref colorcomp-data 0)
5623                     (aref colorcomp-data 1)
5624                     (aref colorcomp-data 2)))
5625   (kill-buffer nil))
5627 (setq colorcomp-mode-map
5628       (let ((m (make-sparse-keymap)))
5629         (suppress-keymap m)
5630         (define-key m "i" 'colorcomp-R-less)
5631         (define-key m "o" 'colorcomp-R-more)
5632         (define-key m "k" 'colorcomp-G-less)
5633         (define-key m "l" 'colorcomp-G-more)
5634         (define-key m "," 'colorcomp-B-less)
5635         (define-key m "." 'colorcomp-B-more)
5636         (define-key m " " 'colorcomp-copy-as-kill-and-exit)
5637         m))
5638 @end smallexample
5640 Note that we never modify the data in each node, which is fixed when the
5641 ewoc is created to be either @code{nil} or an index into the vector
5642 @code{colorcomp-data}, the actual color components.
5644 @node Blinking
5645 @section Blinking Parentheses
5646 @cindex parenthesis matching
5647 @cindex blinking parentheses
5648 @cindex balancing parentheses
5650   This section describes the mechanism by which Emacs shows a matching
5651 open parenthesis when the user inserts a close parenthesis.
5653 @defvar blink-paren-function
5654 The value of this variable should be a function (of no arguments) to
5655 be called whenever a character with close parenthesis syntax is inserted.
5656 The value of @code{blink-paren-function} may be @code{nil}, in which
5657 case nothing is done.
5658 @end defvar
5660 @defopt blink-matching-paren
5661 If this variable is @code{nil}, then @code{blink-matching-open} does
5662 nothing.
5663 @end defopt
5665 @defopt blink-matching-paren-distance
5666 This variable specifies the maximum distance to scan for a matching
5667 parenthesis before giving up.
5668 @end defopt
5670 @defopt blink-matching-delay
5671 This variable specifies the number of seconds for the cursor to remain
5672 at the matching parenthesis.  A fraction of a second often gives
5673 good results, but the default is 1, which works on all systems.
5674 @end defopt
5676 @deffn Command blink-matching-open
5677 This function is the default value of @code{blink-paren-function}.  It
5678 assumes that point follows a character with close parenthesis syntax and
5679 moves the cursor momentarily to the matching opening character.  If that
5680 character is not already on the screen, it displays the character's
5681 context in the echo area.  To avoid long delays, this function does not
5682 search farther than @code{blink-matching-paren-distance} characters.
5684 Here is an example of calling this function explicitly.
5686 @smallexample
5687 @group
5688 (defun interactive-blink-matching-open ()
5689 @c Do not break this line! -- rms.
5690 @c The first line of a doc string
5691 @c must stand alone.
5692   "Indicate momentarily the start of sexp before point."
5693   (interactive)
5694 @end group
5695 @group
5696   (let ((blink-matching-paren-distance
5697          (buffer-size))
5698         (blink-matching-paren t))
5699     (blink-matching-open)))
5700 @end group
5701 @end smallexample
5702 @end deffn
5704 @node Usual Display
5705 @section Usual Display Conventions
5707   The usual display conventions define how to display each character
5708 code.  You can override these conventions by setting up a display table
5709 (@pxref{Display Tables}).  Here are the usual display conventions:
5711 @itemize @bullet
5712 @item
5713 Character codes 32 through 126 map to glyph codes 32 through 126.
5714 Normally this means they display as themselves, but a display table
5715 can change that.
5717 @item
5718 Character code 9 is a horizontal tab.  It displays as whitespace
5719 up to a position determined by @code{tab-width}.
5721 @item
5722 Character code 10 is a newline.  It is normally invisible on display,
5723 and has the effect of ending the preceding line and starting a new
5724 line.
5726 @item
5727 All other codes in the range 0 through 31 display in one of two ways
5728 according to the value of @code{ctl-arrow}.  If it is non-@code{nil},
5729 these codes map to sequences of two glyphs, where the first glyph is
5730 the @acronym{ASCII} code for @samp{^}.  (A display table can specify a
5731 glyph to use instead of @samp{^}.)  Otherwise, these codes map just
5732 like the raw bytes in the range 128 to 255 (described below).
5734 @cindex octal escapes
5735 @item
5736 Raw bytes (@pxref{Text Representations}) with codes 128 through 255,
5737 and the @acronym{ASCII} control character with code 127, display as
5738 sequences of four glyphs, where the first glyph is the @acronym{ASCII}
5739 code for @samp{\}, and the others are digit characters representing
5740 the character code in octal.  (A display table can specify a glyph to
5741 use instead of @samp{\}.)  This is known as the @dfn{octal escape}
5742 display.
5744 @item
5745 Non-@acronym{ASCII} character codes above 127 are displayed as
5746 themselves, if the terminal and the available fonts support them.
5747 Characters that are not supported by the terminal, or (on window
5748 systems) have no fonts available for them, are displayed as a question
5749 mark or a hex code or an empty box.  @xref{Glyphless Chars}, for how
5750 to control display of the characters not supported by the terminal or
5751 fonts.  Display tables can change how a character is displayed, even
5752 if it is supported.
5753 @end itemize
5755   The usual display conventions apply even when there is a display
5756 table, for any character whose entry in the active display table is
5757 @code{nil}.  Thus, when you set up a display table, you need only
5758 specify the characters for which you want special behavior.
5760   These display rules apply to carriage return (character code 13), when
5761 it appears in the buffer.  But that character may not appear in the
5762 buffer where you expect it, if it was eliminated as part of end-of-line
5763 conversion (@pxref{Coding System Basics}).
5765   These variables affect the way certain characters are displayed on the
5766 screen.  Since they change the number of columns the characters occupy,
5767 they also affect the indentation functions.  These variables also affect
5768 how the mode line is displayed; if you want to force redisplay of the
5769 mode line using the new values, call the function
5770 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5772 @defopt ctl-arrow
5773 @cindex control characters in display
5774 This buffer-local variable controls how control characters are
5775 displayed.  If it is non-@code{nil}, they are displayed as a caret
5776 followed by the character: @samp{^A}.  If it is @code{nil}, they are
5777 displayed as octal escapes: a backslash followed by three octal
5778 digits, as in @samp{\001}.
5779 @end defopt
5781 @defopt tab-width
5782 The value of this buffer-local variable is the spacing between tab
5783 stops used for displaying tab characters in Emacs buffers.  The value
5784 is in units of columns, and the default is 8.  Note that this feature
5785 is completely independent of the user-settable tab stops used by the
5786 command @code{tab-to-tab-stop}.  @xref{Indent Tabs}.
5787 @end defopt
5789 @node Display Tables
5790 @section Display Tables
5792 @cindex display table
5793 You can use the @dfn{display table} feature to control how all possible
5794 character codes display on the screen.  This is useful for displaying
5795 European languages that have letters not in the @acronym{ASCII} character
5796 set.
5798 The display table maps each character code into a sequence of
5799 @dfn{glyphs}, each glyph being a graphic that takes up one character
5800 position on the screen.  You can also define how to display each glyph
5801 on your terminal, using the @dfn{glyph table}.
5803 Display tables affect how the mode line is displayed; if you want to
5804 force redisplay of the mode line using a new display table, call
5805 @code{force-mode-line-update} (@pxref{Mode Line Format}).
5807 @menu
5808 * Display Table Format::  What a display table consists of.
5809 * Active Display Table::  How Emacs selects a display table to use.
5810 * Glyphs::              How to define a glyph, and what glyphs mean.
5811 @end menu
5813 @node Display Table Format
5814 @subsection Display Table Format
5816   A display table is actually a char-table (@pxref{Char-Tables}) with
5817 @code{display-table} as its subtype.
5819 @defun make-display-table
5820 This creates and returns a display table.  The table initially has
5821 @code{nil} in all elements.
5822 @end defun
5824   The ordinary elements of the display table are indexed by character
5825 codes; the element at index @var{c} says how to display the character
5826 code @var{c}.  The value should be @code{nil} or a vector of the
5827 glyphs to be output (@pxref{Glyphs}).  @code{nil} says to display the
5828 character @var{c} according to the usual display conventions
5829 (@pxref{Usual Display}).
5831   @strong{Warning:} if you use the display table to change the display
5832 of newline characters, the whole buffer will be displayed as one long
5833 ``line.''
5835   The display table also has six ``extra slots'' which serve special
5836 purposes.  Here is a table of their meanings; @code{nil} in any slot
5837 means to use the default for that slot, as stated below.
5839 @table @asis
5840 @item 0
5841 The glyph for the end of a truncated screen line (the default for this
5842 is @samp{$}).  @xref{Glyphs}.  On graphical terminals, Emacs uses
5843 arrows in the fringes to indicate truncation, so the display table has
5844 no effect.
5846 @item 1
5847 The glyph for the end of a continued line (the default is @samp{\}).
5848 On graphical terminals, Emacs uses curved arrows in the fringes to
5849 indicate continuation, so the display table has no effect.
5851 @item 2
5852 The glyph for indicating a character displayed as an octal character
5853 code (the default is @samp{\}).
5855 @item 3
5856 The glyph for indicating a control character (the default is @samp{^}).
5858 @item 4
5859 A vector of glyphs for indicating the presence of invisible lines (the
5860 default is @samp{...}).  @xref{Selective Display}.
5862 @item 5
5863 The glyph used to draw the border between side-by-side windows (the
5864 default is @samp{|}).  @xref{Splitting Windows}.  This takes effect only
5865 when there are no scroll bars; if scroll bars are supported and in use,
5866 a scroll bar separates the two windows.
5867 @end table
5869   For example, here is how to construct a display table that mimics the
5870 effect of setting @code{ctl-arrow} to a non-@code{nil} value:
5872 @example
5873 (setq disptab (make-display-table))
5874 (let ((i 0))
5875   (while (< i 32)
5876     (or (= i ?\t) (= i ?\n)
5877         (aset disptab i (vector ?^ (+ i 64))))
5878     (setq i (1+ i)))
5879   (aset disptab 127 (vector ?^ ??)))
5880 @end example
5882 @defun display-table-slot display-table slot
5883 This function returns the value of the extra slot @var{slot} of
5884 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5885 5 inclusive, or a slot name (symbol).  Valid symbols are
5886 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5887 @code{selective-display}, and @code{vertical-border}.
5888 @end defun
5890 @defun set-display-table-slot display-table slot value
5891 This function stores @var{value} in the extra slot @var{slot} of
5892 @var{display-table}.  The argument @var{slot} may be a number from 0 to
5893 5 inclusive, or a slot name (symbol).  Valid symbols are
5894 @code{truncation}, @code{wrap}, @code{escape}, @code{control},
5895 @code{selective-display}, and @code{vertical-border}.
5896 @end defun
5898 @defun describe-display-table display-table
5899 This function displays a description of the display table
5900 @var{display-table} in a help buffer.
5901 @end defun
5903 @deffn Command describe-current-display-table
5904 This command displays a description of the current display table in a
5905 help buffer.
5906 @end deffn
5908 @node Active Display Table
5909 @subsection Active Display Table
5910 @cindex active display table
5912   Each window can specify a display table, and so can each buffer.  When
5913 a buffer @var{b} is displayed in window @var{w}, display uses the
5914 display table for window @var{w} if it has one; otherwise, the display
5915 table for buffer @var{b} if it has one; otherwise, the standard display
5916 table if any.  The display table chosen is called the @dfn{active}
5917 display table.
5919 @defun window-display-table &optional window
5920 This function returns @var{window}'s display table, or @code{nil}
5921 if @var{window} does not have an assigned display table.  The default
5922 for @var{window} is the selected window.
5923 @end defun
5925 @defun set-window-display-table window table
5926 This function sets the display table of @var{window} to @var{table}.
5927 The argument @var{table} should be either a display table or
5928 @code{nil}.
5929 @end defun
5931 @defvar buffer-display-table
5932 This variable is automatically buffer-local in all buffers; its value in
5933 a particular buffer specifies the display table for that buffer.  If it
5934 is @code{nil}, that means the buffer does not have an assigned display
5935 table.
5936 @end defvar
5938 @defvar standard-display-table
5939 This variable's value is the default display table, used whenever a
5940 window has no display table and neither does the buffer displayed in
5941 that window.  This variable is @code{nil} by default.
5942 @end defvar
5944   If there is no display table to use for a particular window---that is,
5945 if the window specifies none, its buffer specifies none, and
5946 @code{standard-display-table} is @code{nil}---then Emacs uses the usual
5947 display conventions for all character codes in that window.  @xref{Usual
5948 Display}.
5950 A number of functions for changing the standard display table
5951 are defined in the library @file{disp-table}.
5953 @node Glyphs
5954 @subsection Glyphs
5956 @cindex glyph
5957   A @dfn{glyph} is a generalization of a character; it stands for an
5958 image that takes up a single character position on the screen.  Normally
5959 glyphs come from vectors in the display table (@pxref{Display Tables}).
5961   A glyph is represented in Lisp as a @dfn{glyph code}.  A glyph code
5962 can be @dfn{simple} or it can be defined by the @dfn{glyph table}.  A
5963 simple glyph code is just a way of specifying a character and a face
5964 to output it in.  @xref{Faces}.
5966   The following functions are used to manipulate simple glyph codes:
5968 @defun make-glyph-code char &optional face
5969 This function returns a simple glyph code representing char @var{char}
5970 with face @var{face}.
5971 @end defun
5973 @defun glyph-char glyph
5974 This function returns the character of simple glyph code @var{glyph}.
5975 @end defun
5977 @defun glyph-face glyph
5978 This function returns face of simple glyph code @var{glyph}, or
5979 @code{nil} if @var{glyph} has the default face (face-id 0).
5980 @xref{Face Functions}.
5981 @end defun
5983   On character terminals, you can set up a @dfn{glyph table} to define
5984 the meaning of glyph codes (represented as small integers).
5986 @defvar glyph-table
5987 The value of this variable is the current glyph table.  It should be
5988 @code{nil} or a vector whose @var{g}th element defines glyph code
5989 @var{g}.
5991 If a glyph code is greater than or equal to the length of the glyph
5992 table, that code is automatically simple.  If @code{glyph-table} is
5993 @code{nil} then all glyph codes are simple.
5995 The glyph table is used only on character terminals.  On graphical
5996 displays, all glyph codes are simple.
5997 @end defvar
5999   Here are the meaningful types of elements in the glyph table:
6001 @table @asis
6002 @item @var{string}
6003 Send the characters in @var{string} to the terminal to output
6004 this glyph code.
6006 @item @var{code}
6007 Define this glyph code as an alias for glyph code @var{code} created
6008 by @code{make-glyph-code}.  You can use such an alias to define a
6009 small-numbered glyph code which specifies a character with a face.
6011 @item @code{nil}
6012 This glyph code is simple.
6013 @end table
6015 @defun create-glyph string
6016 This function returns a newly-allocated glyph code which is set up to
6017 display by sending @var{string} to the terminal.
6018 @end defun
6020 @node Beeping
6021 @section Beeping
6022 @c  @cindex beeping   "beep" is adjacent
6023 @cindex bell
6025   This section describes how to make Emacs ring the bell (or blink the
6026 screen) to attract the user's attention.  Be conservative about how
6027 often you do this; frequent bells can become irritating.  Also be
6028 careful not to use just beeping when signaling an error is more
6029 appropriate.  (@xref{Errors}.)
6031 @defun ding &optional do-not-terminate
6032 @cindex keyboard macro termination
6033 This function beeps, or flashes the screen (see @code{visible-bell} below).
6034 It also terminates any keyboard macro currently executing unless
6035 @var{do-not-terminate} is non-@code{nil}.
6036 @end defun
6038 @defun beep &optional do-not-terminate
6039 This is a synonym for @code{ding}.
6040 @end defun
6042 @defopt visible-bell
6043 This variable determines whether Emacs should flash the screen to
6044 represent a bell.  Non-@code{nil} means yes, @code{nil} means no.
6045 This is effective on graphical displays, and on text terminals
6046 provided the terminal's Termcap entry defines the visible bell
6047 capability (@samp{vb}).
6048 @end defopt
6050 @defvar ring-bell-function
6051 If this is non-@code{nil}, it specifies how Emacs should ``ring the
6052 bell.''  Its value should be a function of no arguments.  If this is
6053 non-@code{nil}, it takes precedence over the @code{visible-bell}
6054 variable.
6055 @end defvar
6057 @node Window Systems
6058 @section Window Systems
6060   Emacs works with several window systems, most notably the X Window
6061 System.  Both Emacs and X use the term ``window,'' but use it
6062 differently.  An Emacs frame is a single window as far as X is
6063 concerned; the individual Emacs windows are not known to X at all.
6065 @defvar window-system
6066 This terminal-local variable tells Lisp programs what window system
6067 Emacs is using for displaying the frame.  The possible values are
6069 @table @code
6070 @item x
6071 @cindex X Window System
6072 Emacs is displaying the frame using X.
6073 @item w32
6074 Emacs is displaying the frame using native MS-Windows GUI.
6075 @item ns
6076 Emacs is displaying the frame using the Nextstep interface (used on
6077 GNUstep and Mac OS X).
6078 @item pc
6079 Emacs is displaying the frame using MS-DOS direct screen writes.
6080 @item nil
6081 Emacs is displaying the frame on a character-based terminal.
6082 @end table
6083 @end defvar
6085 @defvar initial-window-system
6086 This variable holds the value of @code{window-system} used for the
6087 first frame created by Emacs during startup.  (When Emacs is invoked
6088 with the @option{--daemon} option, it does not create any initial
6089 frames, so @code{initial-window-system} is @code{nil}.  @xref{Initial
6090 Options, daemon,, emacs, The GNU Emacs Manual}.)
6091 @end defvar
6093 @defun window-system &optional frame
6094 This function returns a symbol whose name tells what window system is
6095 used for displaying @var{frame} (which defaults to the currently
6096 selected frame).  The list of possible symbols it returns is the same
6097 one documented for the variable @code{window-system} above.
6098 @end defun
6100   Do @emph{not} use @code{window-system} and
6101 @code{initial-window-system} as predicates or boolean flag variables,
6102 if you want to write code that works differently on text terminals and
6103 graphic displays.  That is because @code{window-system} is not a good
6104 indicator of Emacs capabilities on a given display type.  Instead, use
6105 @code{display-graphic-p} or any of the other @code{display-*-p}
6106 predicates described in @ref{Display Feature Testing}.
6108 @defvar window-setup-hook
6109 This variable is a normal hook which Emacs runs after handling the
6110 initialization files.  Emacs runs this hook after it has completed
6111 loading your init file, the default initialization file (if
6112 any), and the terminal-specific Lisp code, and running the hook
6113 @code{term-setup-hook}.
6115 This hook is used for internal purposes: setting up communication with
6116 the window system, and creating the initial window.  Users should not
6117 interfere with it.
6118 @end defvar
6120 @node Bidirectional Display
6121 @section Bidirectional Display
6122 @cindex bidirectional display
6123 @cindex right-to-left text
6125   Emacs can display text written in scripts, such as Arabic, Farsi,
6126 and Hebrew, whose natural ordering of horizontal text for display is
6127 from right to left.  However, digits and Latin text embedded in these
6128 scripts are still displayed left to right.  It is also not uncommon to
6129 have small portions of text in Arabic or Hebrew embedded in otherwise
6130 Latin document, e.g., as comments and strings in a program source
6131 file.  Likewise, small portions of Latin text can be embedded in an
6132 Arabic or Farsi document.  For these reasons, text that uses these
6133 scripts is actually @dfn{bidirectional}: a mixture of runs of
6134 left-to-right and right-to-left characters.
6136   This section describes the facilities and options provided by Emacs
6137 for editing and displaying bidirectional text.
6139 @cindex logical order
6140 @cindex reading order
6141 @cindex visual order
6142 @cindex unicode bidirectional algorithm
6143   Emacs stores right-to-left and bidirectional text in the so-called
6144 @dfn{logical} (or @dfn{reading}) order: the buffer or string position
6145 of the first character you read precedes that of the next character.
6146 Reordering of bidirectional text into the @dfn{visual} order happens
6147 at display time.  As result, character positions no longer increase
6148 monotonically with their positions on display.  Emacs implements the
6149 Unicode Bidirectional Algorithm (a.k.a.@: @acronym{UBA}) described in
6150 the Unicode Standard Annex #9, for reordering of bidirectional text
6151 for display.  Reordering of bidirectional text for display in Emacs is
6152 a ``Full bidirectionality'' class implementation of the @acronym{UBA}.
6154 @defvar bidi-display-reordering
6155   This buffer-local variable controls whether text in the buffer is
6156 reordered for display.  If its value is non-@code{nil}, Emacs reorders
6157 characters that have right-to-left directionality when they are
6158 displayed.  The default value is @code{t}.  Text in overlay strings
6159 (@pxref{Overlay Properties,,before-string}), display strings
6160 (@pxref{Overlay Properties,,display}), and @code{display} text
6161 properties (@pxref{Display Property}) is also reordered for display if
6162 the buffer whose text includes these strings is reordered.  Turning
6163 off @code{bidi-display-reordering} for a buffer turns off reordering
6164 of all the overlay and display strings in that buffer.
6166   Reordering of strings that are unrelated to any buffer, such as text
6167 displayed on the mode line (@pxref{Mode Line Format}) or header line
6168 (@pxref{Header Lines}), is controlled by the default value of
6169 @code{bidi-display-reordering}.
6170 @end defvar
6172 @cindex unibyte buffers, and bidi reordering
6173   Emacs does not reorder text in unibyte buffers, even if
6174 @code{bidi-display-reordering} is non-@code{nil} in such a buffer.
6175 This is because unibyte buffers contain raw bytes, not characters, and
6176 thus don't have bidirectional properties defined for them which are
6177 required for correct reordering.  Therefore, to test whether text in a
6178 buffer will be reordered for display, it is not enough to test the
6179 value of @code{bidi-display-reordering} alone.  The correct test is
6180 this:
6182 @example
6183  (if (and enable-multibyte-characters
6184           bidi-display-reordering)
6185      ;; Buffer is being reordered for display
6186    )
6187 @end example
6189   In contrast to unibyte buffers, unibyte display and overlay strings
6190 @emph{are} reordered, if their parent buffer is reordered.  This is
6191 because plain-@sc{ascii} strings are stored by Emacs as unibyte
6192 strings.  If a unibyte display or overlay string includes
6193 non-@sc{ascii} characters, these characters are assumed to have
6194 left-to-right direction.
6196 @cindex display properties, and bidi reordering of text
6197   Text covered by @code{display} text properties, by overlays with
6198 @code{display} properties whose value is a string, and by any other
6199 properties that replace buffer text, is treated as a single unit when
6200 it is reordered for display.  That is, the entire chunk of text
6201 covered by these properties is reordered together.  Moreover, the
6202 bidirectional properties of the characters in this chunk of text are
6203 ignored, and Emacs reorders them as if they were replaced with a
6204 single character @code{U+FFFC}, known as the @dfn{Object Replacement
6205 Character}.  This means that placing a display property over a portion
6206 of text may change the way that the surrounding text is reordered for
6207 display.  To prevent this unexpected effect, always place such
6208 properties on text whose directionality is identical with text that
6209 surrounds it.
6211 @cindex base direction of a paragraph
6212   Each paragraph of bidirectional text can have its own @dfn{base
6213 direction}, either right-to-left or left-to-right.  Text in
6214 left-to-right paragraphs is displayed beginning at the left margin of
6215 the window and is truncated or continued when it reaches the right
6216 margin.  By contrast, display of text in right-to-left paragraphs
6217 begins at the right margin and is continued or truncated at the left
6218 margin.
6220 @defvar bidi-paragraph-direction
6221   By default, Emacs determines the base direction of each paragraph
6222 dynamically, based on the text at the beginning of the paragraph.  The
6223 precise method of determining the base direction is specified by the
6224 @acronym{UBA}; in a nutshell, the first character in a paragraph that
6225 has an explicit directionality determines the base direction of the
6226 paragraph.  However, sometimes a buffer may need to force a certain
6227 base direction for its paragraphs.  For example, a buffer that visits
6228 a source code of a program should force all its paragraphs to be
6229 displayed left to right.  The variable
6230 @code{bidi-paragraph-direction}, if non-@code{nil}, disables the
6231 dynamic determination of the base direction, and instead forces all
6232 paragraphs in the buffer to have the direction specified by its
6233 buffer-local value.  The value can be either @code{right-to-left} or
6234 @code{left-to-right}.  Any other value is interpreted as @code{nil}.
6235 The default is @code{nil}.
6237 @cindex @code{prog-mode}, and @code{bidi-paragraph-direction}
6238 Modes that are meant to display program source code should force a
6239 @code{left-to-right} paragraph direction.  The easiest way of doing so
6240 is to derive the mode from Prog Mode, which already sets
6241 @code{bidi-paragraph-direction} to that value.
6242 @end defvar
6244 @defun current-bidi-paragraph-direction &optional buffer
6245 This function returns the paragraph direction at point in the named
6246 @var{buffer}.  The returned value is a symbol, either
6247 @code{left-to-right} or @code{right-to-left}.  If @var{buffer} is
6248 omitted or @code{nil}, it defaults to the current buffer.  If the
6249 buffer-local value of the variable @code{bidi-paragraph-direction} is
6250 non-@code{nil}, the returned value will be identical to that value;
6251 otherwise, the returned value reflects the paragraph direction
6252 determined dynamically by Emacs.  For buffers whose value of
6253 @code{bidi-display-reordering} is @code{nil} as well as unibyte
6254 buffers, this function always returns @code{left-to-right}.
6255 @end defun
6257 @cindex layout on display, and bidirectional text
6258 @cindex jumbled display of bidirectional text
6259 @cindex concatenating bidirectional strings
6260   Reordering of bidirectional text for display can have surprising and
6261 unpleasant effects when two strings with bidirectional content are
6262 juxtaposed in a buffer, or otherwise programmatically concatenated
6263 into a string of text.  A typical example is a buffer whose lines are
6264 actually sequences of items, or fields, separated by whitespace or
6265 punctuation characters.  This is used in specialized modes such as
6266 Buffer-menu Mode or various email summary modes, like Rmail Summary
6267 Mode.  Because these separator characters are @dfn{weak}, i.e.@: have
6268 no strong directionality, they take on the directionality of
6269 surrounding text.  As result, a numeric field that follows a field
6270 with bidirectional content can be displayed @emph{to the left} of the
6271 preceding field, producing a jumbled display and messing up the
6272 expected layout.
6274   To countermand this, we recommend that you use one of the following
6275 techniques for forcing correct order of fields on display:
6277 @itemize @minus
6278 @item
6279 Append the special character @code{U+200E}, LEFT-TO-RIGHT MARK, or
6280 @acronym{LRM}, to the end of each field that may have bidirectional
6281 content, or prepend it to the beginning of the following field.  The
6282 function @code{bidi-string-mark-left-to-right}, described below, comes
6283 in handy for this purpose.  (In a right-to-left paragraph, use
6284 @code{U+200F}, RIGHT-TO-LEFT MARK, or @acronym{RLM}, instead.)  This
6285 is one of the solutions recommended by
6286 @uref{http://www.unicode.org/reports/tr9/#Separators, the
6287 @acronym{UBA}}.
6289 @item
6290 Include the tab character in the field separator.  The tab character
6291 plays the role of @dfn{segment separator} in the @acronym{UBA}
6292 reordering, whose effect is to make each field a separate segment, and
6293 thus reorder them separately.
6295 @cindex @code{space} display spec, and bidirectional text
6296 @item
6297 Separate fields with a @code{display} property or overlay with the
6298 property value of the form @code{(space . PROPS)} (@pxref{Specified
6299 Space}).  This display specification is treated by Emacs as a
6300 @dfn{paragraph separator}; the text before and after the separator is
6301 reordered separately, which avoids the influence of any field on its
6302 neighboring fields.
6303 @end itemize
6305 @defun bidi-string-mark-left-to-right string
6306 This subroutine returns its argument @var{string}, possibly modified,
6307 such that the result can be safely concatenated with another string,
6308 or juxtaposed with another string in a buffer, without disrupting the
6309 relative layout of this string and the next one on display.  If the
6310 string returned by this function is displayed as part of a
6311 left-to-right paragraph, it will always appear on display to the left
6312 of the text that follows it.  The function works by examining the
6313 characters of its argument, and if any of those characters could cause
6314 reordering on display, the function appends the @acronym{LRM}
6315 character to the string.  The appended @acronym{LRM} character is made
6316 @emph{invisible} (@pxref{Invisible Text}), to hide it on display.
6317 @end defun
6319   The reordering algorithm uses the bidirectional properties of the
6320 characters stored as their @code{bidi-class} property
6321 (@pxref{Character Properties}).  Lisp programs can change these
6322 properties by calling the @code{put-char-code-property} function.
6323 However, doing this requires a thorough understanding of the
6324 @acronym{UBA}, and is therefore not recommended.  Any changes to the
6325 bidirectional properties of a character have global effect: they
6326 affect all Emacs frames and windows.
6328   Similarly, the @code{mirroring} property is used to display the
6329 appropriate mirrored character in the reordered text.  Lisp programs
6330 can affect the mirrored display by changing this property.  Again, any
6331 such changes affect all of Emacs display.
6333 @node Glyphless Chars
6334 @section Glyphless Character Display
6335 @cindex glyphless characters
6337   @dfn{Glyphless characters} are not displayed in the usual way when
6338 they appear in a buffer, but in some special way (e.g. as a box
6339 containing a hexadecimal code).  These include characters that cannot
6340 be displayed with any available font (on a graphical display), or that
6341 cannot be encoded by the terminal's coding system (on a text
6342 terminal).  Specific characters can also be defined to be glyphless.
6344 @defvar glyphless-char-display
6345 The value of this variable is a char-table that defines glyphless
6346 characters and how they are displayed.  If an entry is @code{nil}, the
6347 corresponding character is displayed in its usual way.  Otherwise, an
6348 entry should be one of the following display methods:
6350 @table @asis
6351 @item @code{zero-width}
6352 Don't display the character.
6354 @item @code{thin-space}
6355 Display a thin space, 1-pixel wide on graphical displays, or
6356 1-character wide on text terminals.
6358 @item @code{empty-box}
6359 Display an empty box.
6361 @item @code{hex-code}
6362 Display a box containing the Unicode codepoint of the character, in
6363 hexadecimal notation.
6365 @item an @acronym{ASCII} string
6366 Display a box containing that string.
6367 @end table
6369 @noindent
6370 Except for @code{zero-width}, these methods display using the
6371 @code{glyphless-char} face.
6373 An entry can also be a cons cell @code{(@var{graphical}
6374 . @var{text})}, where @var{graphical} and @var{text} are the display
6375 methods on graphical displays and text terminals respectively.
6377 The char-table has one extra slot, which determines how to display any
6378 character that cannot be displayed with any available font, or cannot
6379 be encoded by the terminal's coding system.  Its value should be one
6380 of the above display methods, except @code{zero-width} or a cons cell.
6381 @end defvar
6383 @defopt glyphless-char-display-control
6384 This user option provides a convenient way to set
6385 @code{glyphless-char-display} for groups of similar characters.  It
6386 takes effect via a custom @code{:set} function (@pxref{Variable
6387 Definitions}), which update @code{glyphless-char-display}.
6389 Its value should be an alist of elements @code{(@var{group}
6390 . @var{method})}, where @var{group} is a symbol specifying a group of
6391 characters, and @var{method} is a symbol specifying how to display
6392 them.
6394 @var{group} should be one of the following:
6396 @table @code
6397 @item c0-control
6398 @acronym{ASCII} control characters @code{U+0000} to @code{U+001F},
6399 excluding the newline and tab characters (normally displayed as escape
6400 sequences like @samp{^A}; @pxref{Text Display,, How Text Is Displayed,
6401 emacs, The GNU Emacs Manual}).
6403 @item c1-control
6404 Non-@acronym{ASCII}, non-printing characters @code{U+0080} to
6405 @code{U+009F} (normally displayed as octal escape sequences like
6406 @samp{\230}).
6408 @item format-control
6409 Characters of Unicode General Category `Cf', such as @samp{U+200E}
6410 (Left-to-Right Mark), but excluding characters that have graphic
6411 images, such as @samp{U+00AD} (Soft Hyphen).
6413 @item no-font
6414 Characters for there is no suitable font, or which cannot be encoded
6415 by the terminal's coding system.
6416 @end table
6418 @c FIXME: this can also be `acronym', but that's not currently
6419 @c completely implemented; it applies only to the format-control
6420 @c group, and only works if the acronym is in `char-acronym-table'.
6421 The @var{method} symbol should be one of @code{zero-width},
6422 @code{thin-space}, @code{empty-box}, or @code{hex-code}.  These have
6423 the same meanings as in @code{glyphless-char-display}, above.
6424 @end defopt