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