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