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