* image-mode.el (image-toggle-display):
[bpt/emacs.git] / lisp / descr-text.el
... / ...
CommitLineData
1;;; descr-text.el --- describe text mode
2
3;; Copyright (C) 1994, 1995, 1996, 2001, 2002, 2003, 2004,
4;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5
6;; Author: Boris Goldowsky <boris@gnu.org>
7;; Maintainer: FSF
8;; Keywords: faces, i18n, Unicode, multilingual
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 3 of the License, or
15;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26
27;;; Describe-Text Mode.
28
29;;; Code:
30
31(eval-when-compile (require 'quail))
32(require 'help-fns)
33
34;;; Describe-Text Utilities.
35
36(defun describe-text-widget (widget)
37 "Insert text to describe WIDGET in the current buffer."
38 (insert-text-button
39 (symbol-name (if (symbolp widget) widget (car widget)))
40 'action `(lambda (&rest ignore)
41 (widget-browse ',widget))
42 'help-echo "mouse-2, RET: browse this widget")
43 (insert " ")
44 (insert-text-button
45 "(widget)Top" 'type 'help-info 'help-args '("(widget)Top")))
46
47(defun describe-text-sexp (sexp)
48 "Insert a short description of SEXP in the current buffer."
49 (let ((pp (condition-case signal
50 (pp-to-string sexp)
51 (error (prin1-to-string signal)))))
52 (when (string-match-p "\n\\'" pp)
53 (setq pp (substring pp 0 (1- (length pp)))))
54
55 (if (and (not (string-match-p "\n" pp))
56 (<= (length pp) (- (window-width) (current-column))))
57 (insert pp)
58 (insert-text-button
59 "[Show]" 'action `(lambda (&rest ignore)
60 (with-output-to-temp-buffer
61 "*Pp Eval Output*"
62 (princ ',pp)))
63 'help-echo "mouse-2, RET: pretty print value in another buffer"))))
64
65(defun describe-property-list (properties)
66 "Insert a description of PROPERTIES in the current buffer.
67PROPERTIES should be a list of overlay or text properties.
68The `category', `face' and `font-lock-face' properties are made
69into help buttons that call `describe-text-category' or
70`describe-face' when pushed."
71 ;; Sort the properties by the size of their value.
72 (dolist (elt (sort (let (ret)
73 (while properties
74 (push (list (pop properties) (pop properties)) ret))
75 ret)
76 (lambda (a b) (string< (prin1-to-string (nth 0 a) t)
77 (prin1-to-string (nth 0 b) t)))))
78 (let ((key (nth 0 elt))
79 (value (nth 1 elt)))
80 (insert (propertize (format " %-20s " key)
81 'face 'help-argument-name))
82 (cond ((eq key 'category)
83 (insert-text-button
84 (symbol-name value)
85 'action `(lambda (&rest ignore)
86 (describe-text-category ',value))
87 'follow-link t
88 'help-echo "mouse-2, RET: describe this category"))
89 ((memq key '(face font-lock-face mouse-face))
90 (insert-text-button
91 (format "%S" value)
92 'type 'help-face 'help-args (list value)))
93 ((widgetp value)
94 (describe-text-widget value))
95 (t
96 (describe-text-sexp value))))
97 (insert "\n")))
98\f
99;;; Describe-Text Commands.
100
101(defun describe-text-category (category)
102 "Describe a text property category."
103 (interactive "SCategory: ")
104 (help-setup-xref (list #'describe-text-category category) (interactive-p))
105 (save-excursion
106 (with-output-to-temp-buffer "*Help*"
107 (set-buffer standard-output)
108 (insert "Category " (format "%S" category) ":\n\n")
109 (describe-property-list (symbol-plist category))
110 (goto-char (point-min)))))
111
112;;;###autoload
113(defun describe-text-properties (pos &optional output-buffer)
114 "Describe widgets, buttons, overlays and text properties at POS.
115Interactively, describe them for the character after point.
116If optional second argument OUTPUT-BUFFER is non-nil,
117insert the output into that buffer, and don't initialize or clear it
118otherwise."
119 (interactive "d")
120 (if (>= pos (point-max))
121 (error "No character follows specified position"))
122 (if output-buffer
123 (describe-text-properties-1 pos output-buffer)
124 (if (not (or (text-properties-at pos) (overlays-at pos)))
125 (message "This is plain text.")
126 (let ((buffer (current-buffer))
127 (target-buffer "*Help*"))
128 (when (eq buffer (get-buffer target-buffer))
129 (setq target-buffer "*Help*<2>"))
130 (save-excursion
131 (with-output-to-temp-buffer target-buffer
132 (set-buffer standard-output)
133 (setq output-buffer (current-buffer))
134 (insert "Text content at position " (format "%d" pos) ":\n\n")
135 (with-current-buffer buffer
136 (describe-text-properties-1 pos output-buffer))
137 (goto-char (point-min))))))))
138
139(defun describe-text-properties-1 (pos output-buffer)
140 (let* ((properties (text-properties-at pos))
141 (overlays (overlays-at pos))
142 (wid-field (get-char-property pos 'field))
143 (wid-button (get-char-property pos 'button))
144 (wid-doc (get-char-property pos 'widget-doc))
145 ;; If button.el is not loaded, we have no buttons in the text.
146 (button (and (fboundp 'button-at) (button-at pos)))
147 (button-type (and button (button-type button)))
148 (button-label (and button (button-label button)))
149 (widget (or wid-field wid-button wid-doc)))
150 (with-current-buffer output-buffer
151 ;; Widgets
152 (when (widgetp widget)
153 (newline)
154 (insert (cond (wid-field "This is an editable text area")
155 (wid-button "This is an active area")
156 (wid-doc "This is documentation text")))
157 (insert " of a ")
158 (describe-text-widget widget)
159 (insert ".\n\n"))
160 ;; Buttons
161 (when (and button (not (widgetp wid-button)))
162 (newline)
163 (insert "Here is a `" (format "%S" button-type)
164 "' button labeled `" button-label "'.\n\n"))
165 ;; Overlays
166 (when overlays
167 (newline)
168 (if (eq (length overlays) 1)
169 (insert "There is an overlay here:\n")
170 (insert "There are " (format "%d" (length overlays))
171 " overlays here:\n"))
172 (dolist (overlay overlays)
173 (insert " From " (format "%d" (overlay-start overlay))
174 " to " (format "%d" (overlay-end overlay)) "\n")
175 (describe-property-list (overlay-properties overlay)))
176 (insert "\n"))
177 ;; Text properties
178 (when properties
179 (newline)
180 (insert "There are text properties here:\n")
181 (describe-property-list properties)))))
182\f
183(defcustom describe-char-unidata-list
184 '(name old-name general-category decomposition)
185 "List of Unicode-based character property names shown by `describe-char'."
186 :group 'mule
187 :version "23.1"
188 :type '(choice (const :tag "All properties" t)
189 (set
190 (const :tag "Unicode Name" name)
191 (const :tag "Unicode old name" old-name)
192 (const :tag "Unicode general category " general-category)
193 (const :tag "Unicode canonical combining class"
194 canonical-combining-class)
195 (const :tag "Unicode bidi class" bidi-class)
196 (const :tag "Unicode decomposition mapping" decomposition)
197 (const :tag "Unicode decimal digit value" decimal-digit-value)
198 (const :tag "Unicode digit value" digit-value)
199 (const :tag "Unicode numeric value" numeric-value)
200 (const :tag "Unicode mirrored" mirrored)
201 (const :tag "Unicode ISO 10646 comment" iso-10646-comment)
202 (const :tag "Unicode simple uppercase mapping" uppercase)
203 (const :tag "Unicode simple lowercase mapping" lowercase)
204 (const :tag "Unicode simple titlecase mapping" titlecase))))
205
206(defcustom describe-char-unicodedata-file nil
207 "Location of Unicode data file.
208This is the UnicodeData.txt file from the Unicode Consortium, used for
209diagnostics. If it is non-nil `describe-char' will print data
210looked up from it. This facility is mostly of use to people doing
211multilingual development.
212
213This is a fairly large file, not typically present on GNU systems.
214At the time of writing it is at the URL
215`http://www.unicode.org/Public/UNIDATA/UnicodeData.txt'."
216 :group 'mule
217 :version "22.1"
218 :type '(choice (const :tag "None" nil)
219 file))
220
221(defun describe-char-unicode-data (char)
222 "Return a list of Unicode data for unicode CHAR.
223Each element is a list of a property description and the property value.
224The list is null if CHAR isn't found in `describe-char-unicodedata-file'.
225This function is semi-obsolete. Use `get-char-code-property'."
226 (when describe-char-unicodedata-file
227 (unless (file-exists-p describe-char-unicodedata-file)
228 (error "`unicodedata-file' %s not found" describe-char-unicodedata-file))
229 (with-current-buffer (get-buffer-create " *Unicode Data*")
230 (when (zerop (buffer-size))
231 ;; Don't use -literally in case of DOS line endings.
232 (insert-file-contents describe-char-unicodedata-file))
233 (goto-char (point-min))
234 (let ((hex (format "%04X" char))
235 found first last)
236 (if (re-search-forward (concat "^" hex) nil t)
237 (setq found t)
238 ;; It's not listed explicitly. Look for ranges, e.g. CJK
239 ;; ideographs, and check whether it's in one of them.
240 (while (and (re-search-forward "^\\([^;]+\\);[^;]+First>;" nil t)
241 (>= char (setq first
242 (string-to-number (match-string 1) 16)))
243 (progn
244 (forward-line 1)
245 (looking-at "^\\([^;]+\\);[^;]+Last>;")
246 (> char
247 (setq last
248 (string-to-number (match-string 1) 16))))))
249 (if (and (>= char first)
250 (<= char last))
251 (setq found t)))
252 (if found
253 (let ((fields (mapcar (lambda (elt)
254 (if (> (length elt) 0)
255 elt))
256 (cdr (split-string
257 (buffer-substring
258 (line-beginning-position)
259 (line-end-position))
260 ";")))))
261 ;; The length depends on whether the last field was empty.
262 (unless (or (= 13 (length fields))
263 (= 14 (length fields)))
264 (error "Invalid contents in %s" describe-char-unicodedata-file))
265 ;; The field names and values lists are slightly
266 ;; modified from Mule-UCS unidata.el.
267 (list
268 (list "Name" (let ((name (nth 0 fields)))
269 ;; Check for <..., First>, <..., Last>
270 (if (string-match "\\`\\(<[^,]+\\)," name)
271 (concat (match-string 1 name) ">")
272 name)))
273 (list "Category"
274 (let ((val (nth 1 fields)))
275 (or (char-code-property-description
276 'general-category (intern val))
277 val)))
278 (list "Combining class"
279 (let ((val (nth 1 fields)))
280 (or (char-code-property-description
281 'canonical-combining-class (intern val))
282 val)))
283 (list "Bidi category"
284 (let ((val (nth 1 fields)))
285 (or (char-code-property-description
286 'bidi-class (intern val))
287 val)))
288 (list
289 "Decomposition"
290 (if (nth 4 fields)
291 (let* ((parts (split-string (nth 4 fields)))
292 (info (car parts)))
293 (if (string-match "\\`<\\(.+\\)>\\'" info)
294 (setq info (match-string 1 info))
295 (setq info nil))
296 (if info (setq parts (cdr parts)))
297 (setq parts (mapconcat
298 (lambda (arg)
299 (string (string-to-number arg 16)))
300 parts " "))
301 (concat info parts))))
302 (list "Decimal digit value"
303 (nth 5 fields))
304 (list "Digit value"
305 (nth 6 fields))
306 (list "Numeric value"
307 (nth 7 fields))
308 (list "Mirrored"
309 (if (equal "Y" (nth 8 fields))
310 "yes"))
311 (list "Old name" (nth 9 fields))
312 (list "ISO 10646 comment" (nth 10 fields))
313 (list "Uppercase" (and (nth 11 fields)
314 (string (string-to-number
315 (nth 11 fields) 16))))
316 (list "Lowercase" (and (nth 12 fields)
317 (string (string-to-number
318 (nth 12 fields) 16))))
319 (list "Titlecase" (and (nth 13 fields)
320 (string (string-to-number
321 (nth 13 fields) 16)))))))))))
322
323;; Not defined on builds without X, but behind display-graphic-p.
324(declare-function internal-char-font "fontset.c" (position &optional ch))
325
326;; Return information about how CHAR is displayed at the buffer
327;; position POS. If the selected frame is on a graphic display,
328;; return a string "FONT-DRIVER:FONT-NAME (GLYPH-CODE)" where:
329;; FONT-DRIVER is the font-driver name,
330;; FONT-NAME is the font name,
331;; GLYPH-CODE is a hexadigit string representing the glyph-ID.
332;; Otherwise, return a string describing the terminal codes for the
333;; character.
334(defun describe-char-display (pos char)
335 (if (display-graphic-p (selected-frame))
336 (let ((char-font-info (internal-char-font pos char)))
337 (if char-font-info
338 (let ((type (font-get (car char-font-info) :type))
339 (name (font-xlfd-name (car char-font-info)))
340 (code (cdr char-font-info)))
341 (if (integerp code)
342 (format "%s:%s (#x%02X)" type name code)
343 (format "%s:%s (#x%04X%04X)"
344 type name (car code) (cdr code))))))
345 (let* ((charset (get-text-property pos 'charset))
346 (coding (or (terminal-coding-system) 'us-ascii))
347 (encoded (encode-coding-char char coding charset)))
348 (if encoded
349 (encoded-string-description encoded coding)))))
350
351\f
352;; Return a string of CH with composition for padding on both sides.
353;; It is displayed without overlapping with the left/right columns.
354(defsubst describe-char-padded-string (ch)
355 (compose-string (string ch) 0 1 (format "\t%c\t" ch)))
356
357;; Return a nicely formated list of categories; extended category
358;; description is added to the category name as a tooltip
359(defsubst describe-char-categories (category-set)
360 (let ((mnemonics (category-set-mnemonics category-set)))
361 (unless (eq mnemonics "")
362 (list (mapconcat
363 #'(lambda (x)
364 (let* ((c (category-docstring x))
365 (doc (if (string-match "\\`\\(.*?\\)\n\\(.*\\)\\'" c)
366 (propertize (match-string 1 c)
367 'help-echo (match-string 2 c))
368 c)))
369 (format "%c:%s" x doc)))
370 mnemonics ", ")))))
371
372;;;###autoload
373(defun describe-char (pos)
374 "Describe the character after POS (interactively, the character after point).
375The information includes character code, charset and code points in it,
376syntax, category, how the character is encoded in a file,
377character composition information (if relevant),
378as well as widgets, buttons, overlays, and text properties."
379 (interactive "d")
380 (if (>= pos (point-max))
381 (error "No character follows specified position"))
382 (let* ((char (char-after pos))
383 (eight-bit-p (and (not enable-multibyte-characters) (>= char 128)))
384 (charset (if eight-bit-p 'eight-bit
385 (or (get-text-property pos 'charset) (char-charset char))))
386 (composition (find-composition pos nil nil t))
387 (component-chars nil)
388 (display-table (or (window-display-table)
389 buffer-display-table
390 standard-display-table))
391 (disp-vector (and display-table (aref display-table char)))
392 (multibyte-p enable-multibyte-characters)
393 (overlays (mapcar #'(lambda (o) (overlay-properties o))
394 (overlays-at pos)))
395 (char-description (if (not multibyte-p)
396 (single-key-description char)
397 (if (< char 128)
398 (single-key-description char)
399 (string-to-multibyte
400 (char-to-string char)))))
401 (text-props-desc
402 (let ((tmp-buf (generate-new-buffer " *text-props*")))
403 (unwind-protect
404 (progn
405 (describe-text-properties pos tmp-buf)
406 (with-current-buffer tmp-buf (buffer-string)))
407 (kill-buffer tmp-buf))))
408 item-list max-width code)
409
410 (if multibyte-p
411 (or (setq code (encode-char char charset))
412 (setq charset (char-charset char)
413 code (encode-char char charset)))
414 (setq code char))
415 (when composition
416 ;; When the composition is trivial (i.e. composed only with the
417 ;; current character itself without any alternate characters),
418 ;; we don't show the composition information. Otherwise, store
419 ;; two descriptive strings in the first two elments of
420 ;; COMPOSITION.
421 (or (catch 'tag
422 (let ((from (car composition))
423 (to (nth 1 composition))
424 (next (1+ pos))
425 (components (nth 2 composition))
426 ch)
427 (if (and (vectorp components) (vectorp (aref components 0)))
428 (let ((idx (- pos from))
429 (nglyphs (lgstring-glyph-len components))
430 (i 0) j glyph glyph-from)
431 ;; COMPONENTS is a gstring. Find a grapheme
432 ;; cluster containing the current character.
433 (while (and (< i nglyphs)
434 (setq glyph (lgstring-glyph components i))
435 (< (lglyph-to glyph) idx))
436 (setq i (1+ i)))
437 (if (or (not glyph) (= i nglyphs))
438 ;; The composition is broken.
439 (throw 'tag nil))
440 (setq glyph-from (lglyph-from glyph)
441 to (+ from (lglyph-to glyph) 1)
442 from (+ from glyph-from)
443 j i)
444 (while (and (< j nglyphs)
445 (setq glyph (lgstring-glyph components j))
446 (= (lglyph-from glyph) glyph-from))
447 (setq j (1+ j)))
448 (if (and (= i (1- j))
449 (setq glyph (lgstring-glyph components i))
450 (= char (lglyph-char glyph)))
451 ;; The composition is trivial.
452 (throw 'tag nil))
453 (nconc composition (list i (1- j))))
454 (dotimes (i (length components))
455 (if (integerp (setq ch (aref components i)))
456 (push (cons ch (describe-char-display pos ch))
457 component-chars)))
458 (setq component-chars (nreverse component-chars)))
459 (if (< from pos)
460 (if (< (1+ pos) to)
461 (setcar composition
462 (concat
463 " with the surrounding characters \""
464 (mapconcat 'describe-char-padded-string
465 (buffer-substring from pos) "")
466 "\" and \""
467 (mapconcat 'describe-char-padded-string
468 (buffer-substring (1+ pos) to) "")
469 "\""))
470 (setcar composition
471 (concat
472 " with the preceding character(s) \""
473 (mapconcat 'describe-char-padded-string
474 (buffer-substring from pos) "")
475 "\"")))
476 (if (< (1+ pos) to)
477 (setcar composition
478 (concat
479 " with the following character(s) \""
480 (mapconcat 'describe-char-padded-string
481 (buffer-substring (1+ pos) to) "")
482 "\""))
483 (setcar composition nil)))
484 (setcar (cdr composition)
485 (format "composed to form \"%s\" (see below)"
486 (buffer-substring from to)))))
487 (setq composition nil)))
488
489 (setq item-list
490 `(("character"
491 ,(format "%s (%d, #o%o, #x%x)"
492 (apply 'propertize char-description
493 (text-properties-at pos))
494 char char char))
495 ("preferred charset"
496 ,`(insert-text-button
497 ,(symbol-name charset)
498 'type 'help-character-set 'help-args '(,charset))
499 ,(format "(%s)" (charset-description charset)))
500 ("code point"
501 ,(let ((str (if (integerp code)
502 (format (if (< code 256) "0x%02X" "0x%04X") code)
503 (format "0x%04X%04X" (car code) (cdr code)))))
504 (if (<= (charset-dimension charset) 2)
505 `(insert-text-button
506 ,str
507 'action (lambda (&rest ignore)
508 (list-charset-chars ',charset)
509 (with-selected-window
510 (get-buffer-window "*Character List*" 0)
511 (goto-char (point-min))
512 (forward-line 2) ;Skip the header.
513 (let ((case-fold-search nil))
514 (if (search-forward ,(char-to-string char)
515 nil t)
516 (goto-char (match-beginning 0))))))
517 'follow-link t
518 'help-echo
519 "mouse-2, RET: show this character in its character set")
520 str)))
521 ("syntax"
522 ,(let ((syntax (syntax-after pos)))
523 (with-temp-buffer
524 (internal-describe-syntax-value syntax)
525 (buffer-string))))
526 ("category"
527 ,@(if (not eight-bit-p)
528 (let ((category-set (char-category-set char)))
529 (if category-set
530 (describe-char-categories category-set)
531 '("-- none --")))))
532 ("to input"
533 ,@(if (not eight-bit-p)
534 (let ((key-list (and (eq input-method-function
535 'quail-input-method)
536 (quail-find-key char))))
537 (if (consp key-list)
538 (list "type"
539 (mapconcat #'(lambda (x) (concat "\"" x "\""))
540 key-list " or ")
541 "with"
542 `(insert-text-button
543 ,current-input-method
544 'type 'help-input-method
545 'help-args '(,current-input-method)))))))
546 ("buffer code"
547 ,(if multibyte-p
548 (encoded-string-description
549 (string-as-unibyte (char-to-string char)) nil)
550 (format "#x%02X" char)))
551 ("file code"
552 ,@(if multibyte-p
553 (let* ((coding buffer-file-coding-system)
554 (encoded (encode-coding-char char coding charset)))
555 (if encoded
556 (list (encoded-string-description encoded coding)
557 (format "(encoded by coding system %S)" coding))
558 (list "not encodable by coding system"
559 (symbol-name coding))))
560 (list (format "#x%02X" char))))
561 ("display"
562 ,(cond
563 (disp-vector
564 (setq disp-vector (copy-sequence disp-vector))
565 (dotimes (i (length disp-vector))
566 (aset disp-vector i
567 (cons (aref disp-vector i)
568 (describe-char-display
569 pos (glyph-char (aref disp-vector i))))))
570 (format "by display table entry [%s] (see below)"
571 (mapconcat
572 #'(lambda (x)
573 (format "?%c" (glyph-char (car x))))
574 disp-vector " ")))
575 (composition
576 (cadr composition))
577 (t
578 (let ((display (describe-char-display pos char)))
579 (if (display-graphic-p (selected-frame))
580 (if display
581 (concat "by this font (glyph code)\n " display)
582 "no font available")
583 (if display
584 (format "terminal code %s" display)
585 "not encodable for terminal"))))))
586 ,@(let ((face
587 (if (not (or disp-vector composition))
588 (cond
589 ((and show-trailing-whitespace
590 (save-excursion (goto-char pos)
591 (looking-at-p "[ \t]+$")))
592 'trailing-whitespace)
593 ((and nobreak-char-display char (eq char '#xa0))
594 'nobreak-space)
595 ((and nobreak-char-display char (eq char '#xad))
596 'escape-glyph)
597 ((and (< char 32) (not (memq char '(9 10))))
598 'escape-glyph)))))
599 (if face (list (list "hardcoded face"
600 `(insert-text-button
601 ,(symbol-name face)
602 'type 'help-face 'help-args '(,face))))))
603 ,@(if (not eight-bit-p)
604 (let ((unicodedata (describe-char-unicode-data char)))
605 (if unicodedata
606 (cons (list "Unicode data" " ") unicodedata))))))
607 (setq max-width (apply #'max (mapcar #'(lambda (x)
608 (if (cadr x) (length (car x)) 0))
609 item-list)))
610 (help-setup-xref nil (interactive-p))
611 (with-help-window (help-buffer)
612 (with-current-buffer standard-output
613 (set-buffer-multibyte multibyte-p)
614 (let ((formatter (format "%%%ds:" max-width)))
615 (dolist (elt item-list)
616 (when (cadr elt)
617 (insert (format formatter (car elt)))
618 (dolist (clm (cdr elt))
619 (if (eq (car-safe clm) 'insert-text-button)
620 (progn (insert " ") (eval clm))
621 (when (>= (+ (current-column)
622 (or (string-match-p "\n" clm)
623 (string-width clm))
624 1)
625 (window-width))
626 (insert "\n")
627 (indent-to (1+ max-width)))
628 (insert " " clm)))
629 (insert "\n"))))
630
631 (when overlays
632 (save-excursion
633 (goto-char (point-min))
634 (re-search-forward "character:[ \t\n]+")
635 (let ((end (+ (point) (length char-description))))
636 (mapc #'(lambda (props)
637 (let ((o (make-overlay (point) end)))
638 (while props
639 (overlay-put o (car props) (nth 1 props))
640 (setq props (cddr props)))))
641 overlays))))
642
643 (when disp-vector
644 (insert
645 "\nThe display table entry is displayed by ")
646 (if (display-graphic-p (selected-frame))
647 (progn
648 (insert "these fonts (glyph codes):\n")
649 (dotimes (i (length disp-vector))
650 (insert (glyph-char (car (aref disp-vector i))) ?:
651 (propertize " " 'display '(space :align-to 5))
652 (or (cdr (aref disp-vector i)) "-- no font --")
653 "\n")
654 (let ((face (glyph-face (car (aref disp-vector i)))))
655 (when face
656 (insert (propertize " " 'display '(space :align-to 5))
657 "face: ")
658 (insert (concat "`" (symbol-name face) "'"))
659 (insert "\n")))))
660 (insert "these terminal codes:\n")
661 (dotimes (i (length disp-vector))
662 (insert (car (aref disp-vector i))
663 (propertize " " 'display '(space :align-to 5))
664 (or (cdr (aref disp-vector i)) "-- not encodable --")
665 "\n"))))
666
667 (when composition
668 (insert "\nComposed")
669 (if (car composition)
670 (insert (car composition)))
671 (if (and (vectorp (nth 2 composition))
672 (vectorp (aref (nth 2 composition) 0)))
673 (let* ((gstring (nth 2 composition))
674 (font (lgstring-font gstring))
675 (from (nth 3 composition))
676 (to (nth 4 composition))
677 glyph)
678 (if (fontp font)
679 (progn
680 (insert " using this font:\n "
681 (symbol-name (font-get font :type))
682 ?:
683 (aref (query-font font) 0)
684 "\nby these glyphs:\n")
685 (while (and (<= from to)
686 (setq glyph (lgstring-glyph gstring from)))
687 (insert (format " %S\n" glyph))
688 (setq from (1+ from))))
689 (insert " by these characters:\n")
690 (while (and (<= from to)
691 (setq glyph (lgstring-glyph gstring from)))
692 (insert (format " %c (#x%d)\n"
693 (lglyph-char glyph) (lglyph-char glyph)))
694 (setq from (1+ from)))))
695 (insert " by the rule:\n\t(")
696 (let ((first t))
697 (mapc (lambda (x)
698 (if first (setq first nil)
699 (insert " "))
700 (if (consp x) (insert (format "%S" x))
701 (if (= x ?\t) (insert (single-key-description x))
702 (insert ??)
703 (insert (describe-char-padded-string x)))))
704 (nth 2 composition)))
705 (insert ")\nThe component character(s) are displayed by ")
706 (if (display-graphic-p (selected-frame))
707 (progn
708 (insert "these fonts (glyph codes):")
709 (dolist (elt component-chars)
710 (if (/= (car elt) ?\t)
711 (insert "\n "
712 (describe-char-padded-string (car elt))
713 ?:
714 (propertize " " 'display '(space :align-to 5))
715 (or (cdr elt) "-- no font --")))))
716 (insert "these terminal codes:")
717 (dolist (elt component-chars)
718 (insert "\n " (car elt) ":"
719 (propertize " " 'display '(space :align-to 4))
720 (or (cdr elt) "-- not encodable --"))))
721 (insert "\nSee the variable `reference-point-alist' for "
722 "the meaning of the rule.\n")))
723
724 (unless eight-bit-p
725 (insert (if (not describe-char-unidata-list)
726 "\nCharacter code properties are not shown: "
727 "\nCharacter code properties: "))
728 (insert-text-button
729 "customize what to show"
730 'action (lambda (&rest ignore)
731 (customize-variable
732 'describe-char-unidata-list))
733 'follow-link t)
734 (insert "\n")
735 (dolist (elt (if (eq describe-char-unidata-list t)
736 (nreverse (mapcar 'car char-code-property-alist))
737 describe-char-unidata-list))
738 (let ((val (get-char-code-property char elt))
739 description)
740 (when val
741 (setq description (char-code-property-description elt val))
742 (insert (if description
743 (format " %s: %s (%s)\n" elt val description)
744 (format " %s: %s\n" elt val)))))))
745
746 (if text-props-desc (insert text-props-desc))
747 (setq help-xref-stack-item (list 'help-insert-string (buffer-string)))
748 (toggle-read-only 1)))))
749
750(define-obsolete-function-alias 'describe-char-after 'describe-char "22.1")
751
752(provide 'descr-text)
753
754;; arch-tag: fc55a498-f3e9-4312-b5bd-98cc02480af1
755;;; descr-text.el ends here