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