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