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