Add optional "inherit" argument for face-bold-p and related functions

* lisp/faces.el (face-underline-p, face-inverse-video-p, face-bold-p)
(face-italic-p): Add optional argument "inherit".

* doc/lispref/display.texi (Attribute Functions):
Add new "inherit" argument for face-bold-p etc.
Move description of this argument to a common section, like "frame".
This commit is contained in:
Glenn Morris 2012-11-21 00:39:08 -08:00
parent 3ca2f1bf25
commit 1bf335cf43
4 changed files with 41 additions and 47 deletions

View file

@ -2,6 +2,8 @@
* display.texi (Attribute Functions):
Update for set-face-* name changes.
Add new "inherit" argument for face-bold-p etc.
Move description of this argument to a common section, like "frame".
* debugging.texi (Profiling): New section.
(Debugging): Mention profiling in the introduction.

View file

@ -2453,59 +2453,48 @@ This swaps the foreground and background colors of face @var{face}.
don't specify @var{frame}, they refer to the selected frame; @code{t}
refers to the default data for new frames. They return the symbol
@code{unspecified} if the face doesn't define any value for that
attribute.
@defun face-foreground face &optional frame inherit
@defunx face-background face &optional frame inherit
These functions return the foreground color (or background color,
respectively) of face @var{face}, as a string.
If @var{inherit} is @code{nil}, only a color directly defined by the face is
returned. If @var{inherit} is non-@code{nil}, any faces specified by its
@code{:inherit} attribute are considered as well, and if @var{inherit}
is a face or a list of faces, then they are also considered, until a
specified color is found. To ensure that the return value is always
specified, use a value of @code{default} for @var{inherit}.
@end defun
@defun face-stipple face &optional frame inherit
This function returns the name of the background stipple pattern of face
@var{face}, or @code{nil} if it doesn't have one.
If @var{inherit} is @code{nil}, only a stipple directly defined by the
face is returned. If @var{inherit} is non-@code{nil}, any faces
specified by its @code{:inherit} attribute are considered as well, and
if @var{inherit} is a face or a list of faces, then they are also
considered, until a specified stipple is found. To ensure that the
return value is always specified, use a value of @code{default} for
attribute. If @var{inherit} is @code{nil}, only an attribute directly
defined by the face is returned. If @var{inherit} is non-@code{nil},
any faces specified by its @code{:inherit} attribute are considered as
well, and if @var{inherit} is a face or a list of faces, then they are
also considered, until a specified attribute is found. To ensure that
the return value is always specified, use a value of @code{default} for
@var{inherit}.
@end defun
@defun face-font face &optional frame
This function returns the name of the font of face @var{face}.
@end defun
@defun face-bold-p face &optional frame
@defun face-foreground face &optional frame inherit
@defunx face-background face &optional frame inherit
These functions return the foreground color (or background color,
respectively) of face @var{face}, as a string.
@end defun
@defun face-stipple face &optional frame inherit
This function returns the name of the background stipple pattern of face
@var{face}, or @code{nil} if it doesn't have one.
@end defun
@defun face-bold-p face &optional frame inherit
This function returns a non-@code{nil} value if the @code{:weight}
attribute of @var{face} is bolder than normal (i.e., one of
@code{semi-bold}, @code{bold}, @code{extra-bold}, or
@code{ultra-bold}). Otherwise, it returns @code{nil}.
@end defun
@defun face-italic-p face &optional frame
@defun face-italic-p face &optional frame inherit
This function returns a non-@code{nil} value if the @code{:slant}
attribute of @var{face} is @code{italic} or @code{oblique}, and
@code{nil} otherwise.
@end defun
@c Note the weasel words. A face that inherits from an underlined
@c face but does not specify :underline will return nil.
@defun face-underline-p face &optional frame
@defun face-underline-p face &optional frame inherit
This function returns non-@code{nil} if face @var{face} specifies
a non-@code{nil} @code{:underline} attribute.
@end defun
@defun face-inverse-video-p face &optional frame
@defun face-inverse-video-p face &optional frame inherit
This function returns non-@code{nil} if face @var{face} specifies
a non-@code{nil} @code{:inverse-video} attribute.
@end defun

View file

@ -1,5 +1,8 @@
2012-11-21 Glenn Morris <rgm@gnu.org>
* faces.el (face-underline-p, face-inverse-video-p, face-bold-p)
(face-italic-p): Add optional argument "inherit".
* faces.el (set-face-inverse-video, set-face-bold, set-face-italic):
Remove -p suffix from names, for consistency with other set-face-*.
(set-face-inverse-video): Fix interactive spec.

View file

@ -487,44 +487,44 @@ with the `default' face (which is always completely specified)."
(defalias 'face-background-pixmap 'face-stipple)
;; FIXME all of these -p functions ignore inheritance (cf face-stipple).
;; Ie, a face that inherits from an underlined face but does not
;; specify :underline will return nil.
;; So these functions don't actually tell you anything about how the
;; face will _appear_. So not very useful IMO.
(defun face-underline-p (face &optional frame)
(defun face-underline-p (face &optional frame inherit)
"Return non-nil if FACE specifies a non-nil underlining.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame."
(face-attribute-specified-or (face-attribute face :underline frame) nil))
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'."
(face-attribute-specified-or
(face-attribute face :underline frame inherit) nil))
(defun face-inverse-video-p (face &optional frame)
(defun face-inverse-video-p (face &optional frame inherit)
"Return non-nil if FACE specifies a non-nil inverse-video.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame."
(eq (face-attribute face :inverse-video frame) t))
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'."
(eq (face-attribute face :inverse-video frame inherit) t))
(defun face-bold-p (face &optional frame)
(defun face-bold-p (face &optional frame inherit)
"Return non-nil if the font of FACE is bold on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'.
Use `face-attribute' for finer control."
(let ((bold (face-attribute face :weight frame)))
(let ((bold (face-attribute face :weight frame inherit)))
(memq bold '(semi-bold bold extra-bold ultra-bold))))
(defun face-italic-p (face &optional frame)
(defun face-italic-p (face &optional frame inherit)
"Return non-nil if the font of FACE is italic on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'.
Use `face-attribute' for finer control."
(let ((italic (face-attribute face :slant frame)))
(let ((italic (face-attribute face :slant frame inherit)))
(memq italic '(italic oblique))))