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