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