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