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