aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2013-04-06 15:39:48 +0800
committerChong Yidong2013-04-06 15:39:48 +0800
commitcd542620197df6fefe2c2bebca1967ec84e8fa7c (patch)
tree566cb415c07f5a61db53d079fae5027b1591a7f3
parent8ead390103b65c93977dd4dee419f66316a79b96 (diff)
downloademacs-cd542620197df6fefe2c2bebca1967ec84e8fa7c.tar.gz
emacs-cd542620197df6fefe2c2bebca1967ec84e8fa7c.zip
Improve Lisp manual documentation on setting faces.
* display.texi (Faces): Minor clarifications. (Defining Faces): Clarify default vs custom face specs. Document face-spec-set. * display.texi (Overlay Properties): * text.texi (Special Properties): Use the "anonymous face" terminology. Describe foreground-color and background-color forms as compatibility-only.
-rw-r--r--doc/lispref/ChangeLog11
-rw-r--r--doc/lispref/display.texi297
-rw-r--r--doc/lispref/text.texi28
3 files changed, 192 insertions, 144 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index dc6ebb4f35c..0bc2b0880b0 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,14 @@
12013-04-06 Chong Yidong <cyd@gnu.org>
2
3 * display.texi (Faces): Minor clarifications.
4 (Defining Faces): Clarify default vs custom face specs. Document
5 face-spec-set.
6
7 * display.texi (Overlay Properties):
8 * text.texi (Special Properties): Use the "anonymous face"
9 terminology. Describe foreground-color and background-color forms
10 as compatibility-only.
11
12013-03-24 Eli Zaretskii <eliz@gnu.org> 122013-03-24 Eli Zaretskii <eliz@gnu.org>
2 13
3 * compile.texi (Byte-Code Objects): Add index entry. 14 * compile.texi (Byte-Code Objects): Add index entry.
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index eae6af9969d..4adcfdf8f4f 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1510,31 +1510,31 @@ of the symbol serve as defaults for the properties of the overlay.
1510 1510
1511@item face 1511@item face
1512@kindex face @r{(overlay property)} 1512@kindex face @r{(overlay property)}
1513This property controls the way text is displayed---for example, which 1513This property controls the appearance of the text (@pxref{Faces}).
1514font and which colors. @xref{Faces}, for more information. 1514The value of the property can be the following:
1515
1516In the simplest case, the value is a face name. It can also be a list;
1517then each element can be any of these possibilities:
1518 1515
1519@itemize @bullet 1516@itemize @bullet
1520@item 1517@item
1521A face name (a symbol or string). 1518A face name (a symbol or string).
1522 1519
1523@item 1520@item
1524A property list of face attributes. This has the form (@var{keyword} 1521An anonymous face: a property list of the form @code{(@var{keyword}
1525@var{value} @dots{}), where each @var{keyword} is a face attribute 1522@var{value} @dots{})}, where each @var{keyword} is a face attribute
1526name and @var{value} is a meaningful value for that attribute. With 1523name and @var{value} is a value for that attribute.
1527this feature, you do not need to create a face each time you want to
1528specify a particular attribute for certain text. @xref{Face
1529Attributes}.
1530 1524
1531@item 1525@item
1532A cons cell, of the form @code{(foreground-color . @var{color-name})} 1526A list of faces. Each list element should be either a face name or an
1533or @code{(background-color . @var{color-name})}. These elements 1527anonymous face. This specifies a face which is an aggregate of the
1534specify just the foreground color or just the background color. 1528attributes of each of the listed faces. Faces occurring earlier in
1529the list have higher priority.
1535 1530
1536@code{(foreground-color . @var{color-name})} has the same effect as 1531@item
1537@code{(:foreground @var{color-name})}; likewise for the background. 1532A cons cell of the form @code{(foreground-color . @var{color-name})}
1533or @code{(background-color . @var{color-name})}. This specifies the
1534foreground or background color, similar to @code{(:foreground
1535@var{color-name})} or @code{(:background @var{color-name})}. This
1536form is supported for backward compatibility only, and should be
1537avoided.
1538@end itemize 1538@end itemize
1539 1539
1540@item mouse-face 1540@item mouse-face
@@ -1901,44 +1901,39 @@ height.
1901@section Faces 1901@section Faces
1902@cindex faces 1902@cindex faces
1903 1903
1904 A @dfn{face} is a collection of graphical @dfn{attributes} for 1904 A @dfn{face} is a collection of graphical attributes for displaying
1905displaying text: font, foreground color, background color, optional 1905text: font, foreground color, background color, optional underlining,
1906underlining, etc. Faces control how Emacs displays text in buffers, 1906etc. Faces control how Emacs displays text in buffers, as well as
1907as well as other parts of the frame such as the mode line. 1907other parts of the frame such as the mode line.
1908 1908
1909@cindex anonymous face 1909@cindex anonymous face
1910 One way to represent a face is as a property list of attributes, 1910 One way to represent a face is as a property list of attributes,
1911like @code{(:foreground "red" :weight bold)}. For example, you can 1911like @code{(:foreground "red" :weight bold)}. Such a list is called
1912assign such an @dfn{anonymous face} as the value of the @code{face} 1912an @dfn{anonymous face}. For example, you can assign an anonymous
1913text property; this causes Emacs to display the underlying text with 1913face as the value of the @code{face} text property, and Emacs will
1914the specified attributes. @xref{Special Properties}. 1914display the underlying text with the specified attributes.
1915@xref{Special Properties}.
1915 1916
1916@cindex face name 1917@cindex face name
1917 More commonly, a face is referred to via a @dfn{face name}: a Lisp 1918 More commonly, a face is referred to via a @dfn{face name}: a Lisp
1918symbol which is associated with a set of face attributes. Named faces 1919symbol associated with a set of face attributes@footnote{For backward
1919are defined using the @code{defface} macro (@pxref{Defining Faces}). 1920compatibility, you can also use a string to specify a face name; that
1920Emacs defines several standard named faces; @xref{Standard Faces,,, 1921is equivalent to a Lisp symbol with the same name.}. Named faces are
1921emacs, The GNU Emacs Manual}. 1922defined using the @code{defface} macro (@pxref{Defining Faces}).
1922 1923Emacs comes with several standard named faces (@pxref{Basic Faces}).
1923 Many parts of Emacs require named faces, and do not accept anonymous 1924
1924faces. These include the functions documented in @ref{Attribute 1925 Many parts of Emacs required named faces, and do not accept
1925Functions}, and the variable @code{font-lock-keywords} 1926anonymous faces. These include the functions documented in
1927@ref{Attribute Functions}, and the variable @code{font-lock-keywords}
1926(@pxref{Search-based Fontification}). Unless otherwise stated, we 1928(@pxref{Search-based Fontification}). Unless otherwise stated, we
1927will use the term @dfn{face} to refer only to named faces. 1929will use the term @dfn{face} to refer only to named faces.
1928 1930
1929 For backward compatibility, you can also use a string to specify a
1930face name; that is equivalent to a Lisp symbol with the same name.
1931
1932@defun facep object 1931@defun facep object
1933This function returns a non-@code{nil} value if @var{object} is a 1932This function returns a non-@code{nil} value if @var{object} is a
1934named face: a Lisp symbol or string which serves as a face name. 1933named face: a Lisp symbol or string which serves as a face name.
1935Otherwise, it returns @code{nil}. 1934Otherwise, it returns @code{nil}.
1936@end defun 1935@end defun
1937 1936
1938 By default, each face name corresponds to the same set of attributes
1939in all frames. But you can also assign a face name a special set of
1940attributes in one frame (@pxref{Attribute Functions}).
1941
1942@menu 1937@menu
1943* Face Attributes:: What is in a face? 1938* Face Attributes:: What is in a face?
1944* Defining Faces:: How to define a face. 1939* Defining Faces:: How to define a face.
@@ -2178,32 +2173,47 @@ suitable for use with @code{:stipple} (see above). It returns
2178@node Defining Faces 2173@node Defining Faces
2179@subsection Defining Faces 2174@subsection Defining Faces
2180 2175
2176@cindex face spec
2181 The usual way to define a face is through the @code{defface} macro. 2177 The usual way to define a face is through the @code{defface} macro.
2182This macro defines a face name, and associates that name with a set of 2178This macro associates a face name (a symbol) with a default @dfn{face
2183face attributes. It also sets up the face so that the user can 2179spec}. A face spec is a construct which specifies what attributes a
2184customize it via the Customize interface (@pxref{Customization}). 2180face should have on any given terminal; for example, a face spec might
2181specify one foreground color on high-color terminals, and a different
2182foreground color on low-color terminals.
2183
2184 People are sometimes tempted to create a variable whose value is a
2185face name. In the vast majority of cases, this is not necessary; the
2186usual procedure is to define a face with @code{defface}, and then use
2187its name directly.
2185 2188
2186@defmac defface face spec doc [keyword value]@dots{} 2189@defmac defface face spec doc [keyword value]@dots{}
2187This macro declares @var{face} as a customizable face whose default 2190This macro declares @var{face} as a named face whose default face spec
2188attributes are given by @var{spec}. You should not quote the symbol 2191is given by @var{spec}. You should not quote the symbol @var{face},
2189@var{face}, and it should not end in @samp{-face} (that would be 2192and it should not end in @samp{-face} (that would be redundant). The
2190redundant). The argument @var{doc} is a documentation string for the 2193argument @var{doc} is a documentation string for the face. The
2191face. The additional @var{keyword} arguments have the same meanings 2194additional @var{keyword} arguments have the same meanings as in
2192as in @code{defgroup} and @code{defcustom} (@pxref{Common Keywords}). 2195@code{defgroup} and @code{defcustom} (@pxref{Common Keywords}).
2193 2196
2194When @code{defface} executes, it defines the face according to 2197If @var{face} already has a default face spec, this macro does
2195@var{spec}, then uses any customizations that were read from the 2198nothing.
2196init file (@pxref{Init File}) to override that specification. 2199
2197 2200The default face spec determines @var{face}'s appearance when no
2198When you evaluate a @code{defface} form with @kbd{C-M-x} in Emacs 2201customizations are in effect (@pxref{Customization}). If @var{face}
2199Lisp mode (@code{eval-defun}), a special feature of @code{eval-defun} 2202has already been customized (via Custom themes or via customizations
2200overrides any customizations of the face. This way, the face reflects 2203read from the init file), its appearance is determined by the custom
2201exactly what the @code{defface} says. 2204face spec(s), which override the default face spec @var{spec}.
2202 2205However, if the customizations are subsequently removed, the
2203@cindex face specification 2206appearance of @var{face} will again be determined by its default face
2204The @var{spec} argument is a @dfn{face specification}, which states 2207spec.
2205how the face should appear on different kinds of terminals. It should 2208
2206be an alist whose elements each have the form 2209As an exception, if you evaluate a @code{defface} form with
2210@kbd{C-M-x} in Emacs Lisp mode (@code{eval-defun}), a special feature
2211of @code{eval-defun} overrides any custom face specs on the face,
2212causing the face to reflect exactly what the @code{defface} says.
2213
2214The @var{spec} argument is a @dfn{face spec}, which states how the
2215face should appear on different kinds of terminals. It should be an
2216alist whose elements each have the form
2207 2217
2208@example 2218@example
2209(@var{display} . @var{plist}) 2219(@var{display} . @var{plist})
@@ -2275,7 +2285,8 @@ terminal must match one of the @var{value}s specified for it in
2275@end table 2285@end table
2276@end defmac 2286@end defmac
2277 2287
2278 Here's how the standard face @code{highlight} is defined: 2288 For example, here's the definition of the standard face
2289@code{highlight}:
2279 2290
2280@example 2291@example
2281(defface highlight 2292(defface highlight
@@ -2294,65 +2305,56 @@ terminal must match one of the @var{value}s specified for it in
2294 :group 'basic-faces) 2305 :group 'basic-faces)
2295@end example 2306@end example
2296 2307
2297 Internally, Emacs stores the face's default specification in its 2308 Internally, Emacs stores each face's default spec in its
2298@code{face-defface-spec} symbol property (@pxref{Symbol Properties}). 2309@code{face-defface-spec} symbol property (@pxref{Symbol Properties}).
2299The @code{saved-face} property stores the face specification saved by 2310The @code{saved-face} property stores any face spec saved by the user
2300the user, using the customization buffer; the @code{customized-face} 2311using the customization buffer; the @code{customized-face} property
2301property stores the face specification customized for the current 2312stores the face spec customized for the current session, but not
2302session, but not saved; and the @code{theme-face} property stores an 2313saved; and the @code{theme-face} property stores an alist associating
2303alist associating the active customization settings and Custom themes 2314the active customization settings and Custom themes with the face
2304with their specifications for that face. The face's documentation 2315specs for that face. The face's documentation string is stored in the
2305string is stored in the @code{face-documentation} property. But 2316@code{face-documentation} property.
2306normally you should not try to set any of these properties directly. 2317
2307@xref{Applying Customizations}, for the @code{custom-set-faces} 2318 Normally, a face is declared just once, using @code{defface}, and
2308function, which is used to apply customized face settings. 2319any further changes to its appearance are applied using the Customize
2309 2320framework (e.g., via the Customize user interface or via the
2310 People are sometimes tempted to create variables whose values 2321@code{custom-set-faces} function; @pxref{Applying Customizations}), or
2311specify a face to use. In the vast majority of cases, this is not 2322by face remapping (@pxref{Face Remapping}). In the rare event that
2312necessary; it is preferable to simply use faces directly. 2323you need to change a face spec directly from Lisp, you can use the
2324@code{face-spec-set} function.
2325
2326@defun face-spec-set face spec &optional spec-type
2327This function applies @var{spec} as a face spec for @code{face}.
2328@var{spec} should be a face spec, as described in the above
2329documentation for @code{defface}.
2330
2331@cindex override spec @r{(for a face)}
2332The argument @var{spec-type} determines which spec to set. If it is
2333@code{nil} or @code{face-override-spec}, this function sets the
2334@dfn{override spec}, which overrides over all other face specs on
2335@var{face}. If it is @code{face-defface-spec}, this function sets the
2336default face spec (the same one set by @code{defface}). If it is
2337@code{reset}, this function clears out all customization specs and
2338override specs from @var{face} (in this case, the value of @var{spec}
2339is ignored). Any other value of @var{spec-type} is reserved for
2340internal use.
2341@end defun
2313 2342
2314@node Attribute Functions 2343@node Attribute Functions
2315@subsection Face Attribute Functions 2344@subsection Face Attribute Functions
2316 2345
2317 This section describes the functions for accessing and modifying the 2346 This section describes functions for directly accessing and
2318attributes of an existing named face. 2347modifying the attributes of a named face.
2319
2320@defun set-face-attribute face frame &rest arguments
2321This function sets one or more attributes of @var{face} for
2322@var{frame}. The attributes you specify this way override whatever
2323the @code{defface} says.
2324
2325The extra arguments @var{arguments} specify the attributes to set, and
2326the values for them. They should consist of alternating attribute
2327names (such as @code{:family} or @code{:underline}) and values. Thus,
2328
2329@example
2330(set-face-attribute 'foo nil
2331 :width 'extended
2332 :weight 'bold)
2333@end example
2334
2335@noindent
2336sets the attribute @code{:width} to @code{extended} and the attribute
2337@code{:weight} to @code{bold}.
2338
2339If @var{frame} is @code{t}, this function sets the default attributes
2340for new frames. Default attribute values specified this way override
2341the @code{defface} for newly created frames.
2342
2343If @var{frame} is @code{nil}, this function sets the attributes for
2344all existing frames, and the default for new frames.
2345@end defun
2346 2348
2347@defun face-attribute face attribute &optional frame inherit 2349@defun face-attribute face attribute &optional frame inherit
2348This returns the value of the @var{attribute} attribute of @var{face} 2350This function returns the value of the @var{attribute} attribute for
2349on @var{frame}. If @var{frame} is @code{nil}, that means the selected 2351@var{face} on @var{frame}.
2350frame (@pxref{Input Focus}).
2351 2352
2352If @var{frame} is @code{t}, this returns whatever new-frames default 2353If @var{frame} is @code{nil}, that means the selected frame
2353value you previously specified with @code{set-face-attribute} for the 2354(@pxref{Input Focus}). If @var{frame} is @code{t}, this function
2354@var{attribute} attribute of @var{face}. If you have not specified 2355returns the value of the specified attribute for newly-created frames
2355one, it returns @code{nil}. 2356(this is normally @code{unspecified}, unless you have specified some
2357value using @code{set-face-attribute}; see below).
2356 2358
2357If @var{inherit} is @code{nil}, only attributes directly defined by 2359If @var{inherit} is @code{nil}, only attributes directly defined by
2358@var{face} are considered, so the return value may be 2360@var{face} are considered, so the return value may be
@@ -2411,6 +2413,36 @@ If @var{value1} is a relative value for the face attribute
2411face attribute @var{attribute}, returns @var{value1} unchanged. 2413face attribute @var{attribute}, returns @var{value1} unchanged.
2412@end defun 2414@end defun
2413 2415
2416 Normally, Emacs uses the face specs of each face to automatically
2417calculate its attributes on each frame (@pxref{Defining Faces}). The
2418function @code{set-face-attribute} can override this calculation by
2419directly assigning attributes to a face, either on a specific frame or
2420for all frames. This function is mostly intended for internal usage.
2421
2422@defun set-face-attribute face frame &rest arguments
2423This function sets one or more attributes of @var{face} for
2424@var{frame}. The attributes specifies in this way override the face
2425spec(s) belonging to @var{face}.
2426
2427The extra arguments @var{arguments} specify the attributes to set, and
2428the values for them. They should consist of alternating attribute
2429names (such as @code{:family} or @code{:underline}) and values. Thus,
2430
2431@example
2432(set-face-attribute 'foo nil :weight 'bold :slant 'italic)
2433@end example
2434
2435@noindent
2436sets the attribute @code{:weight} to @code{bold} and the attribute
2437@code{:slant} to @code{italic}.
2438
2439
2440If @var{frame} is @code{t}, this function sets the default attributes
2441for newly created frames. If @var{frame} is @code{nil}, this function
2442sets the attributes for all existing frames, as well as for newly
2443created frames.
2444@end defun
2445
2414 The following commands and functions mostly provide compatibility 2446 The following commands and functions mostly provide compatibility
2415with old versions of Emacs. They work by calling 2447with old versions of Emacs. They work by calling
2416@code{set-face-attribute}. Values of @code{t} and @code{nil} for 2448@code{set-face-attribute}. Values of @code{t} and @code{nil} for
@@ -2457,16 +2489,17 @@ This sets the @code{:inverse-video} attribute of @var{face} to
2457This swaps the foreground and background colors of face @var{face}. 2489This swaps the foreground and background colors of face @var{face}.
2458@end deffn 2490@end deffn
2459 2491
2460 The following functions examine the attributes of a face. If you 2492 The following functions examine the attributes of a face. They
2461don't specify @var{frame}, they refer to the selected frame; @code{t} 2493mostly provide compatibility with old versions of Emacs. If you don't
2462refers to the default data for new frames. They return the symbol 2494specify @var{frame}, they refer to the selected frame; @code{t} refers
2463@code{unspecified} if the face doesn't define any value for that 2495to the default data for new frames. They return @code{unspecified} if
2464attribute. If @var{inherit} is @code{nil}, only an attribute directly 2496the face doesn't define any value for that attribute. If
2465defined by the face is returned. If @var{inherit} is non-@code{nil}, 2497@var{inherit} is @code{nil}, only an attribute directly defined by the
2466any faces specified by its @code{:inherit} attribute are considered as 2498face is returned. If @var{inherit} is non-@code{nil}, any faces
2467well, and if @var{inherit} is a face or a list of faces, then they are 2499specified by its @code{:inherit} attribute are considered as well, and
2468also considered, until a specified attribute is found. To ensure that 2500if @var{inherit} is a face or a list of faces, then they are also
2469the return value is always specified, use a value of @code{default} for 2501considered, until a specified attribute is found. To ensure that the
2502return value is always specified, use a value of @code{default} for
2470@var{inherit}. 2503@var{inherit}.
2471 2504
2472@defun face-font face &optional frame 2505@defun face-font face &optional frame
@@ -2576,13 +2609,13 @@ The value of this variable is an alist whose elements have the form
2576any text having the face @var{face} with @var{remapping}, rather than 2609any text having the face @var{face} with @var{remapping}, rather than
2577the ordinary definition of @var{face}. 2610the ordinary definition of @var{face}.
2578 2611
2579@var{remapping} may be any face specification suitable for a 2612@var{remapping} may be any face spec suitable for a @code{face} text
2580@code{face} text property: either a face (i.e., a face name or a 2613property: either a face (i.e., a face name or a property list of
2581property list of attribute/value pairs), or a list of faces. For 2614attribute/value pairs), or a list of faces. For details, see the
2582details, see the description of the @code{face} text property in 2615description of the @code{face} text property in @ref{Special
2583@ref{Special Properties}. @var{remapping} serves as the complete 2616Properties}. @var{remapping} serves as the complete specification for
2584specification for the remapped face---it replaces the normal 2617the remapped face---it replaces the normal definition of @var{face},
2585definition of @var{face}, instead of modifying it. 2618instead of modifying it.
2586 2619
2587If @code{face-remapping-alist} is buffer-local, its local value takes 2620If @code{face-remapping-alist} is buffer-local, its local value takes
2588effect only within that buffer. 2621effect only within that buffer.
@@ -2629,7 +2662,7 @@ and @code{face-remap-reset-base} functions; it is intended for major
2629modes to remap faces in the buffers they control. 2662modes to remap faces in the buffers they control.
2630 2663
2631@defun face-remap-add-relative face &rest specs 2664@defun face-remap-add-relative face &rest specs
2632This functions adds the face specifications in @var{specs} as relative 2665This functions adds the face spec in @var{specs} as relative
2633remappings for face @var{face} in the current buffer. The remaining 2666remappings for face @var{face} in the current buffer. The remaining
2634arguments, @var{specs}, should form either a list of face names, or a 2667arguments, @var{specs}, should form either a list of face names, or a
2635property list of attribute/value pairs. 2668property list of attribute/value pairs.
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index c6cbfa5b3f8..6d5a39d887a 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -3008,27 +3008,31 @@ character.
3008@item face 3008@item face
3009@cindex face codes of text 3009@cindex face codes of text
3010@kindex face @r{(text property)} 3010@kindex face @r{(text property)}
3011The @code{face} property controls the appearance of the character, 3011The @code{face} property controls the appearance of the character
3012such as its font and color. @xref{Faces}. The value of the property 3012(@pxref{Faces}). The value of the property can be the following:
3013can be the following:
3014 3013
3015@itemize @bullet 3014@itemize @bullet
3016@item 3015@item
3017A face name (a symbol or string). 3016A face name (a symbol or string).
3018 3017
3019@item 3018@item
3020A property list of face attributes. This has the form (@var{keyword} 3019An anonymous face: a property list of the form @code{(@var{keyword}
3021@var{value} @dots{}), where each @var{keyword} is a face attribute 3020@var{value} @dots{})}, where each @var{keyword} is a face attribute
3022name and @var{value} is a meaningful value for that attribute. With 3021name and @var{value} is a value for that attribute.
3023this feature, you do not need to create a face each time you want to
3024specify a particular attribute for certain text.
3025 3022
3026@item 3023@item
3027A list of faces. This specifies a face which is an aggregate of the 3024A list of faces. Each list element should be either a face name or an
3025anonymous face. This specifies a face which is an aggregate of the
3028attributes of each of the listed faces. Faces occurring earlier in 3026attributes of each of the listed faces. Faces occurring earlier in
3029the list have higher priority. Each list element must have one of the 3027the list have higher priority.
3030two above forms (i.e., either a face name or a property list of face 3028
3031attributes). 3029@item
3030A cons cell of the form @code{(foreground-color . @var{color-name})}
3031or @code{(background-color . @var{color-name})}. This specifies the
3032foreground or background color, similar to @code{(:foreground
3033@var{color-name})} or @code{(:background @var{color-name})}. This
3034form is supported for backward compatibility only, and should be
3035avoided.
3032@end itemize 3036@end itemize
3033 3037
3034Font Lock mode (@pxref{Font Lock Mode}) works in most buffers by 3038Font Lock mode (@pxref{Font Lock Mode}) works in most buffers by