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