[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: describe-face should show an example of text in the face.
From: |
Yoni Rabkin Katzenell |
Subject: |
Re: describe-face should show an example of text in the face. |
Date: |
Mon, 16 Oct 2006 22:01:53 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux) |
"Drew Adams" <address@hidden> writes:
> > Good idea. How about showing two samples: foreground and background?
>
> Like in `list-colors-display'? If that is not what you mean then I am
> misunderstanding you.
>
> Yes, that's what I was thinking.
>
> But I was mistakenly thinking of colors, not faces. Please ignore my
> suggestion.
Your reply got me thinking.
The following patch does exactly the same, except that it renders the
"sample" text to look just like the "sample" text in the `customize'
buffer. So that both are visually consistent examples.
The following screenshot shows how `describe-face' looks with the
attached patch, as compared with the `customize' buffer:
http://yrk.nfshost.com/images/faces-sample.png
Index: faces.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/faces.el,v
retrieving revision 1.354
diff -u -r1.354 faces.el
--- faces.el 14 Sep 2006 23:54:44 -0000 1.354
+++ faces.el 16 Oct 2006 19:52:28 -0000
@@ -32,6 +32,9 @@
;; Warning suppression -- can't require x-win in batch:
(autoload 'xw-defined-colors "x-win"))
+(defvar faces-sample-overlay nil
+ "Overlay for showing an example of a face.")
+
(defvar help-xref-stack-item)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1253,6 +1256,17 @@
(setq faces (cdr faces)))))))
+(defun faces-sample-overlay (face)
+ "Insert sample text with FACE.
+
+If FACE is not a face or nil, use the default face."
+ (let ((f (if (facep face) face 'default))
+ (start (+ (point) 2))) ;; +1 to skip leading space
+ (insert " (sample)")
+ (setq faces-sample-overlay (make-overlay start (1- (point))))
+ (overlay-put faces-sample-overlay 'face f)))
+
+
(defun describe-face (face &optional frame)
"Display the properties of face FACE on FRAME.
Interactively, FACE defaults to the faces of the character after point
@@ -1293,6 +1307,7 @@
(insert " undefined face.\n")
(let ((customize-label "customize this face")
file-name)
+ (faces-sample-overlay f)
(princ (concat " (" customize-label ")\n"))
(insert "Documentation: "
(or (face-documentation f)
--
"Cut your own wood and it will warm you twice"