*** empty log message ***
[bpt/emacs.git] / lisp / descr-text.el
CommitLineData
dcb90b5f 1;;; descr-text.el --- describe text mode
2a1e884e 2
0d30b337 3;; Copyright (C) 1994, 1995, 1996, 2001, 2002, 2003, 2004,
d7a0267c 4;; 2005, 2006, 2007 Free Software Foundation, Inc.
2a1e884e
RS
5
6;; Author: Boris Goldowsky <boris@gnu.org>
57d79b99 7;; Maintainer: FSF
2d65673f 8;; Keywords: faces, i18n, Unicode, multilingual
2a1e884e
RS
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
2a1e884e
RS
26
27;;; Commentary:
28
29;;; Describe-Text Mode.
30
31;;; Code:
32
e5a5c80c
NR
33(eval-when-compile (require 'quail))
34(require 'help-fns)
831ccfa6 35
2a1e884e
RS
36;;; Describe-Text Utilities.
37
38(defun describe-text-widget (widget)
39 "Insert text to describe WIDGET in the current buffer."
57d79b99
NR
40 (insert-text-button
41 (symbol-name (if (symbolp widget) widget (car widget)))
42 'action `(lambda (&rest ignore)
e5a5c80c
NR
43 (widget-browse ',widget))
44 'help-echo "mouse-2, RET: browse this widget")
57d79b99 45 (insert " ")
e5a5c80c
NR
46 (insert-text-button
47 "(widget)Top" 'type 'help-info 'help-args '("(widget)Top")))
2a1e884e
RS
48
49(defun describe-text-sexp (sexp)
50 "Insert a short description of SEXP in the current buffer."
51 (let ((pp (condition-case signal
52 (pp-to-string sexp)
53 (error (prin1-to-string signal)))))
54 (when (string-match "\n\\'" pp)
55 (setq pp (substring pp 0 (1- (length pp)))))
56 (if (cond ((string-match "\n" pp)
57 nil)
58 ((> (length pp) (- (window-width) (current-column)))
59 nil)
60 (t t))
57d79b99
NR
61 (insert pp)
62 (insert-text-button
2fd54bf8 63 "[Show]" 'action `(lambda (&rest ignore)
57d79b99
NR
64 (with-output-to-temp-buffer
65 "*Pp Eval Output*"
66 (princ ',pp)))
67 'help-echo "mouse-2, RET: pretty print value in another buffer"))))
2a1e884e 68
4adb7c09 69(defun describe-property-list (properties)
2a1e884e
RS
70 "Insert a description of PROPERTIES in the current buffer.
71PROPERTIES should be a list of overlay or text properties.
4eb59450 72The `category', `face' and `font-lock-face' properties are made
57d79b99 73into help buttons that call `describe-text-category' or
4eb59450 74`describe-face' when pushed."
e2fa2f6e 75 ;; Sort the properties by the size of their value.
8b18fb8f 76 (dolist (elt (sort (let (ret)
e2fa2f6e 77 (while properties
8b18fb8f 78 (push (list (pop properties) (pop properties)) ret))
e2fa2f6e 79 ret)
d502fc06
RS
80 (lambda (a b) (string< (prin1-to-string (nth 0 a) t)
81 (prin1-to-string (nth 0 b) t)))))
e2fa2f6e
CW
82 (let ((key (nth 0 elt))
83 (value (nth 1 elt)))
57d79b99 84 (insert (propertize (format " %-20s " key)
e5a5c80c 85 'face 'help-argument-name))
2a1e884e 86 (cond ((eq key 'category)
e5a5c80c
NR
87 (insert-text-button
88 (symbol-name value)
89 'action `(lambda (&rest ignore)
90 (describe-text-category ',value))
91 'help-echo "mouse-2, RET: describe this category"))
8b18fb8f 92 ((memq key '(face font-lock-face mouse-face))
2fd54bf8
JL
93 (insert-text-button
94 (format "%S" value)
95 'type 'help-face 'help-args (list value)))
f13cc97d 96 ((widgetp value)
2a1e884e
RS
97 (describe-text-widget value))
98 (t
8b18fb8f 99 (describe-text-sexp value))))
57d79b99 100 (insert "\n")))
2a1e884e
RS
101\f
102;;; Describe-Text Commands.
103
104(defun describe-text-category (category)
105 "Describe a text property category."
e5a5c80c
NR
106 (interactive "SCategory: ")
107 (help-setup-xref (list #'describe-text-category category) (interactive-p))
2a1e884e 108 (save-excursion
ca9088e7
SM
109 (with-output-to-temp-buffer "*Help*"
110 (set-buffer standard-output)
57d79b99 111 (insert "Category " (format "%S" category) ":\n\n")
4adb7c09 112 (describe-property-list (symbol-plist category))
2a1e884e
RS
113 (goto-char (point-min)))))
114
115;;;###autoload
4adb7c09
RS
116(defun describe-text-properties (pos &optional output-buffer)
117 "Describe widgets, buttons, overlays and text properties at POS.
118Interactively, describe them for the character after point.
119If optional second argument OUTPUT-BUFFER is non-nil,
120insert the output into that buffer, and don't initialize or clear it
121otherwise."
2a1e884e 122 (interactive "d")
4adb7c09
RS
123 (if (>= pos (point-max))
124 (error "No character follows specified position"))
125 (if output-buffer
126 (describe-text-properties-1 pos output-buffer)
127 (if (not (or (text-properties-at pos) (overlays-at pos)))
128 (message "This is plain text.")
0911ac26
KS
129 (let ((buffer (current-buffer))
130 (target-buffer "*Help*"))
131 (when (eq buffer (get-buffer target-buffer))
e217c04e 132 (setq target-buffer "*Help*<2>"))
4adb7c09 133 (save-excursion
0911ac26 134 (with-output-to-temp-buffer target-buffer
ca9088e7 135 (set-buffer standard-output)
4adb7c09 136 (setq output-buffer (current-buffer))
57d79b99 137 (insert "Text content at position " (format "%d" pos) ":\n\n")
4adb7c09
RS
138 (with-current-buffer buffer
139 (describe-text-properties-1 pos output-buffer))
4adb7c09
RS
140 (goto-char (point-min))))))))
141
142(defun describe-text-properties-1 (pos output-buffer)
2a1e884e
RS
143 (let* ((properties (text-properties-at pos))
144 (overlays (overlays-at pos))
2a1e884e
RS
145 (wid-field (get-char-property pos 'field))
146 (wid-button (get-char-property pos 'button))
147 (wid-doc (get-char-property pos 'widget-doc))
148 ;; If button.el is not loaded, we have no buttons in the text.
149 (button (and (fboundp 'button-at) (button-at pos)))
150 (button-type (and button (button-type button)))
151 (button-label (and button (button-label button)))
152 (widget (or wid-field wid-button wid-doc)))
4adb7c09
RS
153 (with-current-buffer output-buffer
154 ;; Widgets
155 (when (widgetp widget)
156 (newline)
57d79b99
NR
157 (insert (cond (wid-field "This is an editable text area")
158 (wid-button "This is an active area")
159 (wid-doc "This is documentation text")))
160 (insert " of a ")
4adb7c09 161 (describe-text-widget widget)
57d79b99 162 (insert ".\n\n"))
4adb7c09
RS
163 ;; Buttons
164 (when (and button (not (widgetp wid-button)))
165 (newline)
2fd54bf8
JL
166 (insert "Here is a `" (format "%S" button-type)
167 "' button labeled `" button-label "'.\n\n"))
4adb7c09
RS
168 ;; Overlays
169 (when overlays
170 (newline)
171 (if (eq (length overlays) 1)
57d79b99
NR
172 (insert "There is an overlay here:\n")
173 (insert "There are " (format "%d" (length overlays))
4adb7c09
RS
174 " overlays here:\n"))
175 (dolist (overlay overlays)
57d79b99 176 (insert " From " (format "%d" (overlay-start overlay))
4adb7c09
RS
177 " to " (format "%d" (overlay-end overlay)) "\n")
178 (describe-property-list (overlay-properties overlay)))
57d79b99 179 (insert "\n"))
4adb7c09
RS
180 ;; Text properties
181 (when properties
182 (newline)
57d79b99 183 (insert "There are text properties here:\n")
4adb7c09 184 (describe-property-list properties)))))
d6c135fb 185\f
49c2a2dc
SM
186(defcustom describe-char-unicodedata-file nil
187 "Location of Unicode data file.
2acb13b1 188This is the UnicodeData.txt file from the Unicode Consortium, used for
2a4960f9 189diagnostics. If it is non-nil `describe-char' will print data
49c2a2dc
SM
190looked up from it. This facility is mostly of use to people doing
191multilingual development.
4adb7c09 192
2acb13b1
JB
193This is a fairly large file, not typically present on GNU systems.
194At the time of writing it is at the URL
57d79b99 195`http://www.unicode.org/Public/UNIDATA/UnicodeData.txt'."
49c2a2dc 196 :group 'mule
bf247b6e 197 :version "22.1"
49c2a2dc
SM
198 :type '(choice (const :tag "None" nil)
199 file))
831ccfa6 200
49c2a2dc
SM
201;; We could convert the unidata file into a Lispy form once-for-all
202;; and distribute it for loading on demand. It might be made more
203;; space-efficient by splitting strings word-wise and replacing them
204;; with lists of symbols interned in a private obarray, e.g.
205;; "LATIN SMALL LETTER A" => '(LATIN SMALL LETTER A).
831ccfa6 206
49c2a2dc
SM
207;; Fixme: Check whether this needs updating for Unicode 4.
208(defun describe-char-unicode-data (char)
209 "Return a list of Unicode data for unicode CHAR.
210Each element is a list of a property description and the property value.
211The list is null if CHAR isn't found in `describe-char-unicodedata-file'."
212 (when describe-char-unicodedata-file
213 (unless (file-exists-p describe-char-unicodedata-file)
214 (error "`unicodedata-file' %s not found" describe-char-unicodedata-file))
def7167b
JB
215 (with-current-buffer (get-buffer-create " *Unicode Data*")
216 (when (zerop (buffer-size))
217 ;; Don't use -literally in case of DOS line endings.
218 (insert-file-contents describe-char-unicodedata-file))
49c2a2dc
SM
219 (goto-char (point-min))
220 (let ((hex (format "%04X" char))
221 found first last)
222 (if (re-search-forward (concat "^" hex) nil t)
223 (setq found t)
224 ;; It's not listed explicitly. Look for ranges, e.g. CJK
225 ;; ideographs, and check whether it's in one of them.
226 (while (and (re-search-forward "^\\([^;]+\\);[^;]+First>;" nil t)
227 (>= char (setq first
228 (string-to-number (match-string 1) 16)))
229 (progn
230 (forward-line 1)
231 (looking-at "^\\([^;]+\\);[^;]+Last>;")
232 (> char
233 (setq last
234 (string-to-number (match-string 1) 16))))))
235 (if (and (>= char first)
236 (<= char last))
237 (setq found t)))
238 (if found
239 (let ((fields (mapcar (lambda (elt)
240 (if (> (length elt) 0)
241 elt))
242 (cdr (split-string
243 (buffer-substring
244 (line-beginning-position)
245 (line-end-position))
246 ";")))))
247 ;; The length depends on whether the last field was empty.
248 (unless (or (= 13 (length fields))
249 (= 14 (length fields)))
250 (error "Invalid contents in %s" describe-char-unicodedata-file))
251 ;; The field names and values lists are slightly
252 ;; modified from Mule-UCS unidata.el.
253 (list
254 (list "Name" (let ((name (nth 0 fields)))
255 ;; Check for <..., First>, <..., Last>
256 (if (string-match "\\`\\(<[^,]+\\)," name)
257 (concat (match-string 1 name) ">")
258 name)))
259 (list "Category"
260 (cdr (assoc
261 (nth 1 fields)
262 '(("Lu" . "uppercase letter")
263 ("Ll" . "lowercase letter")
264 ("Lt" . "titlecase letter")
265 ("Mn" . "non-spacing mark")
266 ("Mc" . "spacing-combining mark")
267 ("Me" . "enclosing mark")
268 ("Nd" . "decimal digit")
269 ("Nl" . "letter number")
270 ("No" . "other number")
271 ("Zs" . "space separator")
272 ("Zl" . "line separator")
273 ("Zp" . "paragraph separator")
274 ("Cc" . "other control")
275 ("Cf" . "other format")
276 ("Cs" . "surrogate")
277 ("Co" . "private use")
278 ("Cn" . "not assigned")
279 ("Lm" . "modifier letter")
280 ("Lo" . "other letter")
281 ("Pc" . "connector punctuation")
282 ("Pd" . "dash punctuation")
283 ("Ps" . "open punctuation")
284 ("Pe" . "close punctuation")
285 ("Pi" . "initial-quotation punctuation")
286 ("Pf" . "final-quotation punctuation")
287 ("Po" . "other punctuation")
288 ("Sm" . "math symbol")
289 ("Sc" . "currency symbol")
290 ("Sk" . "modifier symbol")
291 ("So" . "other symbol")))))
292 (list "Combining class"
293 (cdr (assoc
294 (string-to-number (nth 2 fields))
295 '((0 . "Spacing")
296 (1 . "Overlays and interior")
297 (7 . "Nuktas")
298 (8 . "Hiragana/Katakana voicing marks")
299 (9 . "Viramas")
300 (10 . "Start of fixed position classes")
301 (199 . "End of fixed position classes")
302 (200 . "Below left attached")
303 (202 . "Below attached")
304 (204 . "Below right attached")
305 (208 . "Left attached (reordrant around \
306single base character)")
307 (210 . "Right attached")
308 (212 . "Above left attached")
309 (214 . "Above attached")
310 (216 . "Above right attached")
311 (218 . "Below left")
312 (220 . "Below")
313 (222 . "Below right")
314 (224 . "Left (reordrant around single base \
315character)")
316 (226 . "Right")
317 (228 . "Above left")
318 (230 . "Above")
319 (232 . "Above right")
320 (233 . "Double below")
321 (234 . "Double above")
322 (240 . "Below (iota subscript)")))))
323 (list "Bidi category"
324 (cdr (assoc
325 (nth 3 fields)
326 '(("L" . "Left-to-Right")
327 ("LRE" . "Left-to-Right Embedding")
328 ("LRO" . "Left-to-Right Override")
329 ("R" . "Right-to-Left")
330 ("AL" . "Right-to-Left Arabic")
331 ("RLE" . "Right-to-Left Embedding")
332 ("RLO" . "Right-to-Left Override")
333 ("PDF" . "Pop Directional Format")
334 ("EN" . "European Number")
335 ("ES" . "European Number Separator")
336 ("ET" . "European Number Terminator")
337 ("AN" . "Arabic Number")
338 ("CS" . "Common Number Separator")
339 ("NSM" . "Non-Spacing Mark")
340 ("BN" . "Boundary Neutral")
341 ("B" . "Paragraph Separator")
342 ("S" . "Segment Separator")
343 ("WS" . "Whitespace")
344 ("ON" . "Other Neutrals")))))
345 (list
346 "Decomposition"
347 (if (nth 4 fields)
348 (let* ((parts (split-string (nth 4 fields)))
349 (info (car parts)))
350 (if (string-match "\\`<\\(.+\\)>\\'" info)
351 (setq info (match-string 1 info))
352 (setq info nil))
353 (if info (setq parts (cdr parts)))
354 ;; Maybe printing ? for unrepresentable unicodes
355 ;; here and below should be changed?
356 (setq parts (mapconcat
357 (lambda (arg)
358 (string (or (decode-char
359 'ucs
360 (string-to-number arg 16))
361 ??)))
362 parts " "))
363 (concat info parts))))
364 (list "Decimal digit value"
365 (nth 5 fields))
366 (list "Digit value"
367 (nth 6 fields))
368 (list "Numeric value"
369 (nth 7 fields))
370 (list "Mirrored"
371 (if (equal "Y" (nth 8 fields))
372 "yes"))
373 (list "Old name" (nth 9 fields))
374 (list "ISO 10646 comment" (nth 10 fields))
375 (list "Uppercase" (and (nth 11 fields)
376 (string (or (decode-char
377 'ucs
378 (string-to-number
379 (nth 11 fields) 16))
380 ??))))
381 (list "Lowercase" (and (nth 12 fields)
382 (string (or (decode-char
383 'ucs
384 (string-to-number
385 (nth 12 fields) 16))
386 ??))))
387 (list "Titlecase" (and (nth 13 fields)
388 (string (or (decode-char
389 'ucs
390 (string-to-number
391 (nth 13 fields) 16))
392 ??)))))))))))
f15078e2
KH
393
394;; Return information about how CHAR is displayed at the buffer
395;; position POS. If the selected frame is on a graphic display,
396;; return a cons (FONTNAME . GLYPH-CODE). Otherwise, return a string
397;; describing the terminal codes for the character.
398(defun describe-char-display (pos char)
399 (if (display-graphic-p (selected-frame))
400 (internal-char-font pos char)
401 (let* ((coding (terminal-coding-system))
402 (encoded (encode-coding-char char coding)))
403 (if encoded
404 (encoded-string-description encoded coding)))))
405
d6c135fb 406\f
4adb7c09 407;;;###autoload
bfd94110 408(defun describe-char (pos)
4adb7c09
RS
409 "Describe the character after POS (interactively, the character after point).
410The information includes character code, charset and code points in it,
411syntax, category, how the character is encoded in a file,
412character composition information (if relevant),
413as well as widgets, buttons, overlays, and text properties."
414 (interactive "d")
4adb7c09
RS
415 (if (>= pos (point-max))
416 (error "No character follows specified position"))
417 (let* ((char (char-after pos))
418 (charset (char-charset char))
ca9088e7 419 (composition (find-composition pos nil nil t))
f15078e2
KH
420 (component-chars nil)
421 (display-table (or (window-display-table)
422 buffer-display-table
423 standard-display-table))
424 (disp-vector (and display-table (aref display-table char)))
4adb7c09 425 (multibyte-p enable-multibyte-characters)
6482d093
KH
426 (overlays (mapcar #'(lambda (o) (overlay-properties o))
427 (overlays-at pos)))
6398b88f
AS
428 (char-description (if (not multibyte-p)
429 (single-key-description char)
430 (if (< char 128)
431 (single-key-description char)
432 (string-to-multibyte
433 (char-to-string char)))))
e5a5c80c
NR
434 (text-props-desc
435 (let ((tmp-buf (generate-new-buffer " *text-props*")))
436 (unwind-protect
437 (progn
438 (describe-text-properties pos tmp-buf)
439 (with-current-buffer tmp-buf (buffer-string)))
440 (kill-buffer tmp-buf))))
831ccfa6 441 item-list max-width unicode)
831ccfa6 442
ed441285
KH
443 (if (or (< char 256)
444 (memq 'mule-utf-8 (find-coding-systems-region pos (1+ pos)))
445 (get-char-property pos 'untranslated-utf-8))
446 (setq unicode (or (get-char-property pos 'untranslated-utf-8)
447 (encode-char char 'ucs))))
448 (setq item-list
449 `(("character"
e5a5c80c
NR
450 ,(format "%s (%d, #o%o, #x%x%s)"
451 (apply 'propertize char-description
452 (text-properties-at pos))
453 char char char
454 (if unicode
455 (format ", U+%04X" unicode)
456 "")))
ed441285 457 ("charset"
57d79b99 458 ,`(insert-text-button
e5a5c80c
NR
459 ,(symbol-name charset)
460 'type 'help-character-set 'help-args '(,charset))
ed441285
KH
461 ,(format "(%s)" (charset-description charset)))
462 ("code point"
463 ,(let ((split (split-char char)))
e5a5c80c
NR
464 `(insert-text-button
465 ,(if (= (charset-dimension charset) 1)
2fd54bf8
JL
466 (format "#x%02X" (nth 1 split))
467 (format "#x%02X #x%02X" (nth 1 split)
e5a5c80c
NR
468 (nth 2 split)))
469 'action (lambda (&rest ignore)
470 (list-charset-chars ',charset)
471 (with-selected-window
472 (get-buffer-window "*Character List*" 0)
473 (goto-char (point-min))
474 (forward-line 2) ;Skip the header.
475 (let ((case-fold-search nil))
476 (search-forward ,(char-to-string char)
477 nil t))))
478 'help-echo
479 "mouse-2, RET: show this character in its character set")))
ed441285 480 ("syntax"
d8ac3d27 481 ,(let ((syntax (syntax-after pos)))
ed441285
KH
482 (with-temp-buffer
483 (internal-describe-syntax-value syntax)
484 (buffer-string))))
485 ("category"
486 ,@(let ((category-set (char-category-set char)))
487 (if (not category-set)
488 '("-- none --")
9f40939d 489 (mapcar #'(lambda (x) (format "%c:%s"
ed441285
KH
490 x (category-docstring x)))
491 (category-set-mnemonics category-set)))))
492 ,@(let ((props (aref char-code-property-table char))
493 ps)
494 (when props
495 (while props
496 (push (format "%s:" (pop props)) ps)
497 (push (format "%s;" (pop props)) ps))
498 (list (cons "Properties" (nreverse ps)))))
309473d0 499 ("to input"
22259c93
KH
500 ,@(let ((key-list (and (eq input-method-function
501 'quail-input-method)
309473d0
KH
502 (quail-find-key char))))
503 (if (consp key-list)
504 (list "type"
505 (mapconcat #'(lambda (x) (concat "\"" x "\""))
fedbc8e5
JL
506 key-list " or ")
507 "with"
57d79b99 508 `(insert-text-button
2fd54bf8 509 ,current-input-method
e5a5c80c
NR
510 'type 'help-input-method
511 'help-args '(,current-input-method))))))
ed441285
KH
512 ("buffer code"
513 ,(encoded-string-description
514 (string-as-unibyte (char-to-string char)) nil))
515 ("file code"
516 ,@(let* ((coding buffer-file-coding-system)
517 (encoded (encode-coding-char char coding)))
518 (if encoded
519 (list (encoded-string-description encoded coding)
520 (format "(encoded by coding system %S)" coding))
521 (list "not encodable by coding system"
522 (symbol-name coding)))))
523 ("display"
524 ,(cond
525 (disp-vector
526 (setq disp-vector (copy-sequence disp-vector))
527 (dotimes (i (length disp-vector))
528 (setq char (aref disp-vector i))
529 (aset disp-vector i
8b18fb8f
JL
530 (cons char (describe-char-display
531 pos (logand char #x7ffff)))))
ed441285 532 (format "by display table entry [%s] (see below)"
8b18fb8f
JL
533 (mapconcat
534 #'(lambda (x)
fedbc8e5 535 (format "?%c" (logand (car x) #x7ffff)))
8b18fb8f 536 disp-vector " ")))
ed441285
KH
537 (composition
538 (let ((from (car composition))
539 (to (nth 1 composition))
540 (next (1+ pos))
541 (components (nth 2 composition))
542 ch)
543 (setcar composition
544 (and (< from pos) (buffer-substring from pos)))
545 (setcar (cdr composition)
546 (and (< next to) (buffer-substring next to)))
547 (dotimes (i (length components))
548 (if (integerp (setq ch (aref components i)))
549 (push (cons ch (describe-char-display pos ch))
550 component-chars)))
551 (setq component-chars (nreverse component-chars))
552 (format "composed to form \"%s\" (see below)"
553 (buffer-substring from to))))
554 (t
555 (let ((display (describe-char-display pos char)))
556 (if (display-graphic-p (selected-frame))
f15078e2 557 (if display
ed441285
KH
558 (concat
559 "by this font (glyph code)\n"
9f40939d 560 (format " %s (#x%02X)"
ed441285
KH
561 (car display) (cdr display)))
562 "no font available")
563 (if display
564 (format "terminal code %s" display)
565 "not encodable for terminal"))))))
fedbc8e5
JL
566 ,@(let ((face
567 (if (not (or disp-vector composition))
568 (cond
569 ((and show-trailing-whitespace
570 (save-excursion (goto-char pos)
571 (looking-at "[ \t]+$")))
572 'trailing-whitespace)
573 ((and nobreak-char-display unicode (eq unicode '#xa0))
574 'nobreak-space)
575 ((and nobreak-char-display unicode (eq unicode '#xad))
576 'escape-glyph)
577 ((and (< char 32) (not (memq char '(9 10))))
578 'escape-glyph)))))
579 (if face (list (list "hardcoded face"
2fd54bf8
JL
580 `(insert-text-button
581 ,(symbol-name face)
582 'type 'help-face 'help-args '(,face))))))
ed441285
KH
583 ,@(let ((unicodedata (and unicode
584 (describe-char-unicode-data unicode))))
585 (if unicodedata
586 (cons (list "Unicode data" " ") unicodedata)))))
fedbc8e5
JL
587 (setq max-width (apply #'max (mapcar #'(lambda (x)
588 (if (cadr x) (length (car x)) 0))
4adb7c09 589 item-list)))
bfd94110
NR
590 (help-setup-xref nil (interactive-p))
591 (with-output-to-temp-buffer (help-buffer)
ca9088e7 592 (with-current-buffer standard-output
4adb7c09
RS
593 (set-buffer-multibyte multibyte-p)
594 (let ((formatter (format "%%%ds:" max-width)))
595 (dolist (elt item-list)
831ccfa6
DL
596 (when (cadr elt)
597 (insert (format formatter (car elt)))
598 (dolist (clm (cdr elt))
57d79b99 599 (if (eq (car-safe clm) 'insert-text-button)
fedbc8e5
JL
600 (progn (insert " ") (eval clm))
601 (when (>= (+ (current-column)
602 (or (string-match "\n" clm)
603 (string-width clm))
604 1)
605 (window-width))
606 (insert "\n")
607 (indent-to (1+ max-width)))
608 (insert " " clm)))
831ccfa6 609 (insert "\n"))))
f15078e2 610
086c5b2b
KH
611 (when overlays
612 (save-excursion
613 (goto-char (point-min))
614 (re-search-forward "character:[ \t\n]+")
615 (let* ((end (+ (point) (length char-description))))
6398b88f 616 (mapc #'(lambda (props)
086c5b2b 617 (let ((o (make-overlay (point) end)))
6398b88f
AS
618 (while props
619 (overlay-put o (car props) (nth 1 props))
620 (setq props (cddr props)))))
086c5b2b 621 overlays))))
ed441285 622
f15078e2
KH
623 (when disp-vector
624 (insert
625 "\nThe display table entry is displayed by ")
626 (if (display-graphic-p (selected-frame))
627 (progn
628 (insert "these fonts (glyph codes):\n")
629 (dotimes (i (length disp-vector))
8b18fb8f 630 (insert (logand (car (aref disp-vector i)) #x7ffff) ?:
f15078e2
KH
631 (propertize " " 'display '(space :align-to 5))
632 (if (cdr (aref disp-vector i))
9f40939d 633 (format "%s (#x%02X)" (cadr (aref disp-vector i))
f15078e2
KH
634 (cddr (aref disp-vector i)))
635 "-- no font --")
fedbc8e5
JL
636 "\n")
637 (when (> (car (aref disp-vector i)) #x7ffff)
638 (let* ((face-id (lsh (car (aref disp-vector i)) -19))
57d79b99
NR
639 (face (car (delq nil (mapcar
640 (lambda (face)
641 (and (eq (face-id face)
642 face-id) face))
643 (face-list))))))
fedbc8e5
JL
644 (when face
645 (insert (propertize " " 'display '(space :align-to 5))
646 "face: ")
57d79b99 647 (insert (concat "`" (symbol-name face) "'"))
fedbc8e5 648 (insert "\n"))))))
f15078e2
KH
649 (insert "these terminal codes:\n")
650 (dotimes (i (length disp-vector))
544cb6b0 651 (insert (car (aref disp-vector i))
f15078e2
KH
652 (propertize " " 'display '(space :align-to 5))
653 (or (cdr (aref disp-vector i)) "-- not encodable --")
654 "\n"))))
655
4adb7c09 656 (when composition
f15078e2
KH
657 (insert "\nComposed")
658 (if (car composition)
659 (if (cadr composition)
660 (insert " with the surrounding characters \""
661 (car composition) "\" and \""
662 (cadr composition) "\"")
663 (insert " with the preceding character(s) \""
664 (car composition) "\""))
665 (if (cadr composition)
666 (insert " with the following character(s) \""
667 (cadr composition) "\"")))
668 (insert " by the rule:\n\t("
669 (mapconcat (lambda (x)
670 (format (if (consp x) "%S" "?%c") x))
671 (nth 2 composition)
672 " ")
673 ")")
674 (insert "\nThe component character(s) are displayed by ")
675 (if (display-graphic-p (selected-frame))
676 (progn
677 (insert "these fonts (glyph codes):")
678 (dolist (elt component-chars)
679 (insert "\n " (car elt) ?:
680 (propertize " " 'display '(space :align-to 5))
681 (if (cdr elt)
9f40939d 682 (format "%s (#x%02X)" (cadr elt) (cddr elt))
f15078e2
KH
683 "-- no font --"))))
684 (insert "these terminal codes:")
685 (dolist (elt component-chars)
686 (insert "\n " (car elt) ":"
687 (propertize " " 'display '(space :align-to 5))
688 (or (cdr elt) "-- not encodable --"))))
689 (insert "\nSee the variable `reference-point-alist' for "
690 "the meaning of the rule.\n"))
4adb7c09 691
25a3c9d1 692 (if text-props-desc (insert text-props-desc))
2fd54bf8 693 (setq help-xref-stack-item (list 'help-insert-string (buffer-string)))
e217c04e 694 (toggle-read-only 1)
bfd94110 695 (print-help-return-message)))))
2a1e884e 696
831ccfa6 697(defalias 'describe-char-after 'describe-char)
fedbc8e5 698(make-obsolete 'describe-char-after 'describe-char "22.1")
831ccfa6 699
288395a7
CW
700(provide 'descr-text)
701
d8ac3d27 702;; arch-tag: fc55a498-f3e9-4312-b5bd-98cc02480af1
2a1e884e 703;;; descr-text.el ends here