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