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