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