1 ;;; facemenu.el --- create a face menu for interactively adding fonts to text
3 ;; Copyright (c) 1994, 1995, 1996, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: Boris Goldowsky <boris@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;;; Describe-Text Mode.
31 (defun describe-text-done ()
32 "Delete the current window or bury the current buffer."
34 (if (> (count-windows) 1)
38 (defvar describe-text-mode-map
39 (let ((map (make-sparse-keymap)))
40 (set-keymap-parent map widget-keymap
)
42 "Keymap for `describe-text-mode'.")
44 (defcustom describe-text-mode-hook nil
45 "List of hook functions ran by `describe-text-mode'."
48 (defun describe-text-mode ()
49 "Major mode for buffers created by `describe-text-at'.
51 \\{describe-text-mode-map}
52 Entry to this mode calls the value of `describe-text-mode-hook'
53 if that value is non-nil."
54 (kill-all-local-variables)
55 (setq major-mode
'describe-text-mode
56 mode-name
"Describe-Text")
57 (use-local-map describe-text-mode-map
)
59 (run-hooks 'describe-text-mode-hook
))
61 ;;; Describe-Text Utilities.
63 (defun describe-text-widget (widget)
64 "Insert text to describe WIDGET in the current buffer."
66 :notify
`(lambda (&rest ignore
)
67 (widget-browse ',widget
))
68 (format "%S" (if (symbolp widget
)
72 (widget-create 'info-link
:tag
"widget" "(widget)Top"))
74 (defun describe-text-sexp (sexp)
75 "Insert a short description of SEXP in the current buffer."
76 (let ((pp (condition-case signal
78 (error (prin1-to-string signal
)))))
79 (when (string-match "\n\\'" pp
)
80 (setq pp
(substring pp
0 (1- (length pp
)))))
81 (if (cond ((string-match "\n" pp
)
83 ((> (length pp
) (- (window-width) (current-column)))
87 (widget-create 'push-button
89 :action
(lambda (widget &optional event
)
90 (with-output-to-temp-buffer
92 (princ (widget-get widget
:value
))))
96 (defun describe-text-properties (properties)
97 "Insert a description of PROPERTIES in the current buffer.
98 PROPERTIES should be a list of overlay or text properties.
99 The `category' property is made into a widget button that call
100 `describe-text-category' when pushed."
102 (widget-insert (format " %-20s " (car properties
)))
103 (let ((key (nth 0 properties
))
104 (value (nth 1 properties
)))
105 (cond ((eq key
'category
)
107 :notify
`(lambda (&rest ignore
)
108 (describe-text-category ',value
))
109 (format "%S" value
)))
111 (describe-text-widget value
))
113 (describe-text-sexp value
))))
115 (setq properties
(cdr (cdr properties
)))))
117 ;;; Describe-Text Commands.
119 (defun describe-text-category (category)
120 "Describe a text property category."
122 (when (get-buffer "*Text Category*")
123 (kill-buffer "*Text Category*"))
125 (with-output-to-temp-buffer "*Text Category*"
126 (set-buffer "*Text Category*")
127 (widget-insert "Category " (format "%S" category
) ":\n\n")
128 (describe-text-properties (symbol-plist category
))
130 (goto-char (point-min)))))
133 (defun describe-text-at (pos)
134 "Describe widgets, buttons, overlays and text properties at POS."
136 (when (eq (current-buffer) (get-buffer "*Text Description*"))
137 (error "Can't do self inspection"))
138 (let* ((properties (text-properties-at pos
))
139 (overlays (overlays-at pos
))
141 (wid-field (get-char-property pos
'field
))
142 (wid-button (get-char-property pos
'button
))
143 (wid-doc (get-char-property pos
'widget-doc
))
144 ;; If button.el is not loaded, we have no buttons in the text.
145 (button (and (fboundp 'button-at
) (button-at pos
)))
146 (button-type (and button
(button-type button
)))
147 (button-label (and button
(button-label button
)))
148 (widget (or wid-field wid-button wid-doc
)))
149 (if (not (or properties overlays
))
150 (message "This is plain text.")
151 (when (get-buffer "*Text Description*")
152 (kill-buffer "*Text Description*"))
154 (with-output-to-temp-buffer "*Text Description*"
155 (set-buffer "*Text Description*")
156 (widget-insert "Text content at position " (format "%d" pos
) ":\n\n")
158 (when (widgetp widget
)
159 (widget-insert (cond (wid-field "This is an editable text area")
160 (wid-button "This is an active area")
161 (wid-doc "This is documentation text")))
162 (widget-insert " of a ")
163 (describe-text-widget widget
)
164 (widget-insert ".\n\n"))
166 (when (and button
(not (widgetp wid-button
)))
167 (widget-insert "Here is a " (format "%S" button-type
)
168 " button labeled `" button-label
"'.\n\n"))
171 (if (eq (length overlays
) 1)
172 (widget-insert "There is an overlay here:\n")
173 (widget-insert "There are " (format "%d" (length overlays
))
174 " overlays here:\n"))
175 (dolist (overlay overlays
)
176 (widget-insert " From " (format "%d" (overlay-start overlay
))
177 " to " (format "%d" (overlay-end overlay
)) "\n")
178 (describe-text-properties (overlay-properties overlay
)))
179 (widget-insert "\n"))
182 (widget-insert "There are text properties here:\n")
183 (describe-text-properties properties
))
185 (goto-char (point-min)))))))
187 ;;; descr-text.el ends here