Commit | Line | Data |
---|---|---|
dcb90b5f | 1 | ;;; descr-text.el --- describe text mode |
2a1e884e | 2 | |
72354910 | 3 | ;; Copyright (c) 1994, 95, 96, 2001, 02, 03, 04 Free Software Foundation, Inc. |
2a1e884e RS |
4 | |
5 | ;; Author: Boris Goldowsky <boris@gnu.org> | |
6 | ;; Keywords: faces | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
12 | ;; the Free Software Foundation; either version 2, or (at your option) | |
13 | ;; any later version. | |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;;; Describe-Text Mode. | |
28 | ||
29 | ;;; Code: | |
30 | ||
831ccfa6 DL |
31 | (eval-when-compile (require 'button)) |
32 | ||
2a1e884e RS |
33 | (defun describe-text-done () |
34 | "Delete the current window or bury the current buffer." | |
35 | (interactive) | |
36 | (if (> (count-windows) 1) | |
37 | (delete-window) | |
38 | (bury-buffer))) | |
39 | ||
71296446 | 40 | (defvar describe-text-mode-map |
2a1e884e RS |
41 | (let ((map (make-sparse-keymap))) |
42 | (set-keymap-parent map widget-keymap) | |
43 | map) | |
44 | "Keymap for `describe-text-mode'.") | |
71296446 | 45 | |
2a1e884e RS |
46 | (defcustom describe-text-mode-hook nil |
47 | "List of hook functions ran by `describe-text-mode'." | |
d77a0b9b MR |
48 | :type 'hook |
49 | :group 'facemenu) | |
2a1e884e RS |
50 | |
51 | (defun describe-text-mode () | |
4adb7c09 | 52 | "Major mode for buffers created by `describe-char'. |
2a1e884e RS |
53 | |
54 | \\{describe-text-mode-map} | |
55 | Entry to this mode calls the value of `describe-text-mode-hook' | |
56 | if that value is non-nil." | |
57 | (kill-all-local-variables) | |
58 | (setq major-mode 'describe-text-mode | |
59 | mode-name "Describe-Text") | |
60 | (use-local-map describe-text-mode-map) | |
61 | (widget-setup) | |
f0397cde | 62 | (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) |
2a1e884e RS |
63 | (run-hooks 'describe-text-mode-hook)) |
64 | ||
65 | ;;; Describe-Text Utilities. | |
66 | ||
67 | (defun describe-text-widget (widget) | |
68 | "Insert text to describe WIDGET in the current buffer." | |
69 | (widget-create 'link | |
70 | :notify `(lambda (&rest ignore) | |
71 | (widget-browse ',widget)) | |
71296446 | 72 | (format "%S" (if (symbolp widget) |
2a1e884e RS |
73 | widget |
74 | (car widget)))) | |
75 | (widget-insert " ") | |
76 | (widget-create 'info-link :tag "widget" "(widget)Top")) | |
77 | ||
78 | (defun describe-text-sexp (sexp) | |
79 | "Insert a short description of SEXP in the current buffer." | |
80 | (let ((pp (condition-case signal | |
81 | (pp-to-string sexp) | |
82 | (error (prin1-to-string signal))))) | |
83 | (when (string-match "\n\\'" pp) | |
84 | (setq pp (substring pp 0 (1- (length pp))))) | |
85 | (if (cond ((string-match "\n" pp) | |
86 | nil) | |
87 | ((> (length pp) (- (window-width) (current-column))) | |
88 | nil) | |
89 | (t t)) | |
90 | (widget-insert pp) | |
91 | (widget-create 'push-button | |
92 | :tag "show" | |
93 | :action (lambda (widget &optional event) | |
94 | (with-output-to-temp-buffer | |
95 | "*Pp Eval Output*" | |
96 | (princ (widget-get widget :value)))) | |
97 | pp)))) | |
2a1e884e | 98 | |
4adb7c09 | 99 | (defun describe-property-list (properties) |
2a1e884e RS |
100 | "Insert a description of PROPERTIES in the current buffer. |
101 | PROPERTIES should be a list of overlay or text properties. | |
4eb59450 JL |
102 | The `category', `face' and `font-lock-face' properties are made |
103 | into widget buttons that call `describe-text-category' or | |
104 | `describe-face' when pushed." | |
e2fa2f6e CW |
105 | ;; Sort the properties by the size of their value. |
106 | (dolist (elt (sort (let ((ret nil) | |
107 | (key nil) | |
108 | (val nil) | |
109 | (len nil)) | |
110 | (while properties | |
111 | (setq key (pop properties) | |
112 | val (pop properties) | |
113 | len 0) | |
4eb59450 | 114 | (unless (or (memq key '(category face font-lock-face)) |
e2fa2f6e CW |
115 | (widgetp val)) |
116 | (setq val (pp-to-string val) | |
117 | len (length val))) | |
118 | (push (list key val len) ret)) | |
119 | ret) | |
120 | (lambda (a b) | |
121 | (< (nth 2 a) | |
122 | (nth 2 b))))) | |
123 | (let ((key (nth 0 elt)) | |
124 | (value (nth 1 elt))) | |
c1a1535a | 125 | (widget-insert (propertize (format " %-20s " key) |
e2fa2f6e | 126 | 'font-lock-face 'italic)) |
2a1e884e | 127 | (cond ((eq key 'category) |
c1a1535a | 128 | (widget-create 'link |
2a1e884e RS |
129 | :notify `(lambda (&rest ignore) |
130 | (describe-text-category ',value)) | |
131 | (format "%S" value))) | |
4eb59450 | 132 | ((memq key '(face font-lock-face)) |
72354910 JL |
133 | (widget-create 'link |
134 | :notify `(lambda (&rest ignore) | |
135 | (describe-face ',value)) | |
136 | (format "%S" value))) | |
2a1e884e RS |
137 | ((widgetp value) |
138 | (describe-text-widget value)) | |
139 | (t | |
e2fa2f6e CW |
140 | (widget-insert value)))) |
141 | (widget-insert "\n"))) | |
2a1e884e RS |
142 | \f |
143 | ;;; Describe-Text Commands. | |
144 | ||
145 | (defun describe-text-category (category) | |
146 | "Describe a text property category." | |
147 | (interactive "S") | |
2a1e884e | 148 | (save-excursion |
ca9088e7 SM |
149 | (with-output-to-temp-buffer "*Help*" |
150 | (set-buffer standard-output) | |
2a1e884e | 151 | (widget-insert "Category " (format "%S" category) ":\n\n") |
4adb7c09 | 152 | (describe-property-list (symbol-plist category)) |
2a1e884e RS |
153 | (describe-text-mode) |
154 | (goto-char (point-min))))) | |
155 | ||
156 | ;;;###autoload | |
4adb7c09 RS |
157 | (defun describe-text-properties (pos &optional output-buffer) |
158 | "Describe widgets, buttons, overlays and text properties at POS. | |
159 | Interactively, describe them for the character after point. | |
160 | If optional second argument OUTPUT-BUFFER is non-nil, | |
161 | insert the output into that buffer, and don't initialize or clear it | |
162 | otherwise." | |
2a1e884e | 163 | (interactive "d") |
4adb7c09 RS |
164 | (if (>= pos (point-max)) |
165 | (error "No character follows specified position")) | |
166 | (if output-buffer | |
167 | (describe-text-properties-1 pos output-buffer) | |
168 | (if (not (or (text-properties-at pos) (overlays-at pos))) | |
169 | (message "This is plain text.") | |
4adb7c09 | 170 | (let ((buffer (current-buffer))) |
ca9088e7 SM |
171 | (when (eq buffer (get-buffer "*Help*")) |
172 | (error "Can't do self inspection")) | |
4adb7c09 | 173 | (save-excursion |
ca9088e7 SM |
174 | (with-output-to-temp-buffer "*Help*" |
175 | (set-buffer standard-output) | |
4adb7c09 RS |
176 | (setq output-buffer (current-buffer)) |
177 | (widget-insert "Text content at position " (format "%d" pos) ":\n\n") | |
178 | (with-current-buffer buffer | |
179 | (describe-text-properties-1 pos output-buffer)) | |
180 | (describe-text-mode) | |
181 | (goto-char (point-min)))))))) | |
182 | ||
183 | (defun describe-text-properties-1 (pos output-buffer) | |
2a1e884e RS |
184 | (let* ((properties (text-properties-at pos)) |
185 | (overlays (overlays-at pos)) | |
186 | overlay | |
187 | (wid-field (get-char-property pos 'field)) | |
188 | (wid-button (get-char-property pos 'button)) | |
189 | (wid-doc (get-char-property pos 'widget-doc)) | |
190 | ;; If button.el is not loaded, we have no buttons in the text. | |
191 | (button (and (fboundp 'button-at) (button-at pos))) | |
192 | (button-type (and button (button-type button))) | |
193 | (button-label (and button (button-label button))) | |
194 | (widget (or wid-field wid-button wid-doc))) | |
4adb7c09 RS |
195 | (with-current-buffer output-buffer |
196 | ;; Widgets | |
197 | (when (widgetp widget) | |
198 | (newline) | |
199 | (widget-insert (cond (wid-field "This is an editable text area") | |
200 | (wid-button "This is an active area") | |
201 | (wid-doc "This is documentation text"))) | |
202 | (widget-insert " of a ") | |
203 | (describe-text-widget widget) | |
204 | (widget-insert ".\n\n")) | |
205 | ;; Buttons | |
206 | (when (and button (not (widgetp wid-button))) | |
207 | (newline) | |
71296446 | 208 | (widget-insert "Here is a " (format "%S" button-type) |
4adb7c09 RS |
209 | " button labeled `" button-label "'.\n\n")) |
210 | ;; Overlays | |
211 | (when overlays | |
212 | (newline) | |
213 | (if (eq (length overlays) 1) | |
214 | (widget-insert "There is an overlay here:\n") | |
215 | (widget-insert "There are " (format "%d" (length overlays)) | |
216 | " overlays here:\n")) | |
217 | (dolist (overlay overlays) | |
71296446 | 218 | (widget-insert " From " (format "%d" (overlay-start overlay)) |
4adb7c09 RS |
219 | " to " (format "%d" (overlay-end overlay)) "\n") |
220 | (describe-property-list (overlay-properties overlay))) | |
221 | (widget-insert "\n")) | |
222 | ;; Text properties | |
223 | (when properties | |
224 | (newline) | |
225 | (widget-insert "There are text properties here:\n") | |
226 | (describe-property-list properties))))) | |
d6c135fb RS |
227 | \f |
228 | ;;; We cannot use the UnicodeData.txt file as such; it is not free. | |
229 | ;;; We can turn that info a different format and release the result | |
230 | ;;; as free data. When that is done, we could reinstate the code below. | |
231 | ;;; For the mean time, here is a dummy placeholder. | |
232 | ;;; -- rms | |
233 | (defun describe-char-unicode-data (char) nil) | |
4adb7c09 | 234 | |
d6c135fb RS |
235 | ;;; (defcustom describe-char-unicodedata-file nil |
236 | ;;; "Location of Unicode data file. | |
237 | ;;; This is the UnicodeData.txt file from the Unicode consortium, used for | |
238 | ;;; diagnostics. If it is non-nil `describe-char-after' will print data | |
239 | ;;; looked up from it. This facility is mostly of use to people doing | |
240 | ;;; multilingual development. | |
831ccfa6 | 241 | |
d6c135fb RS |
242 | ;;; This is a fairly large file, not typically present on GNU systems. At |
243 | ;;; the time of writing it is at | |
244 | ;;; <URL:ftp://www.unicode.org/Public/UNIDATA/UnicodeData.txt>." | |
245 | ;;; :group 'mule | |
246 | ;;; :version "21.5" | |
247 | ;;; :type '(choice (const :tag "None" nil) | |
248 | ;;; file)) | |
831ccfa6 | 249 | |
d6c135fb RS |
250 | ;;; ;; We could convert the unidata file into a Lispy form once-for-all |
251 | ;;; ;; and distribute it for loading on demand. It might be made more | |
252 | ;;; ;; space-efficient by splitting strings word-wise and replacing them | |
253 | ;;; ;; with lists of symbols interned in a private obarray, e.g. | |
254 | ;;; ;; "LATIN SMALL LETTER A" => '(LATIN SMALL LETTER A). | |
831ccfa6 | 255 | |
d6c135fb RS |
256 | ;;; ;; Fixme: Check whether this needs updating for Unicode 4. |
257 | ;;; (defun describe-char-unicode-data (char) | |
258 | ;;; "Return a list of Unicode data for unicode CHAR. | |
259 | ;;; Each element is a list of a property description and the property value. | |
260 | ;;; The list is null if CHAR isn't found in `describe-char-unicodedata-file'." | |
261 | ;;; (when describe-char-unicodedata-file | |
262 | ;;; (unless (file-exists-p describe-char-unicodedata-file) | |
263 | ;;; (error "`unicodedata-file' %s not found" describe-char-unicodedata-file)) | |
264 | ;;; (save-excursion | |
265 | ;;; ;; Find file in fundamental mode to avoid, e.g. flyspell turned | |
266 | ;;; ;; on for .txt. Don't use RAWFILE arg in case of DOS line endings. | |
267 | ;;; (set-buffer (let ((auto-mode-alist)) | |
268 | ;;; (find-file-noselect describe-char-unicodedata-file))) | |
269 | ;;; (goto-char (point-min)) | |
270 | ;;; (let ((hex (format "%04X" char)) | |
271 | ;;; found first last) | |
272 | ;;; (if (re-search-forward (concat "^" hex) nil t) | |
273 | ;;; (setq found t) | |
274 | ;;; ;; It's not listed explicitly. Look for ranges, e.g. CJK | |
275 | ;;; ;; ideographs, and check whether it's in one of them. | |
276 | ;;; (while (and (re-search-forward "^\\([^;]+\\);[^;]+First>;" nil t) | |
277 | ;;; (>= char (setq first | |
278 | ;;; (string-to-number (match-string 1) 16))) | |
279 | ;;; (progn | |
280 | ;;; (forward-line 1) | |
281 | ;;; (looking-at "^\\([^;]+\\);[^;]+Last>;") | |
282 | ;;; (> char | |
283 | ;;; (setq last | |
284 | ;;; (string-to-number (match-string 1) 16)))))) | |
285 | ;;; (if (and (>= char first) | |
286 | ;;; (<= char last)) | |
287 | ;;; (setq found t))) | |
288 | ;;; (if found | |
289 | ;;; (let ((fields (mapcar (lambda (elt) | |
290 | ;;; (if (> (length elt) 0) | |
291 | ;;; elt)) | |
292 | ;;; (cdr (split-string | |
293 | ;;; (buffer-substring | |
294 | ;;; (line-beginning-position) | |
295 | ;;; (line-end-position)) | |
296 | ;;; ";"))))) | |
297 | ;;; ;; The length depends on whether the last field was empty. | |
298 | ;;; (unless (or (= 13 (length fields)) | |
299 | ;;; (= 14 (length fields))) | |
300 | ;;; (error "Invalid contents in %s" describe-char-unicodedata-file)) | |
301 | ;;; ;; The field names and values lists are slightly | |
302 | ;;; ;; modified from Mule-UCS unidata.el. | |
303 | ;;; (list | |
304 | ;;; (list "Name" (let ((name (nth 0 fields))) | |
305 | ;;; ;; Check for <..., First>, <..., Last> | |
306 | ;;; (if (string-match "\\`\\(<[^,]+\\)," name) | |
307 | ;;; (concat (match-string 1 name) ">") | |
308 | ;;; name))) | |
309 | ;;; (list "Category" | |
310 | ;;; (cdr (assoc | |
311 | ;;; (nth 1 fields) | |
312 | ;;; '(("Lu" . "uppercase letter") | |
313 | ;;; ("Ll" . "lowercase letter") | |
314 | ;;; ("Lt" . "titlecase letter") | |
315 | ;;; ("Mn" . "non-spacing mark") | |
316 | ;;; ("Mc" . "spacing-combining mark") | |
317 | ;;; ("Me" . "enclosing mark") | |
318 | ;;; ("Nd" . "decimal digit") | |
319 | ;;; ("Nl" . "letter number") | |
320 | ;;; ("No" . "other number") | |
321 | ;;; ("Zs" . "space separator") | |
322 | ;;; ("Zl" . "line separator") | |
323 | ;;; ("Zp" . "paragraph separator") | |
324 | ;;; ("Cc" . "other control") | |
325 | ;;; ("Cf" . "other format") | |
326 | ;;; ("Cs" . "surrogate") | |
327 | ;;; ("Co" . "private use") | |
328 | ;;; ("Cn" . "not assigned") | |
329 | ;;; ("Lm" . "modifier letter") | |
330 | ;;; ("Lo" . "other letter") | |
331 | ;;; ("Pc" . "connector punctuation") | |
332 | ;;; ("Pd" . "dash punctuation") | |
333 | ;;; ("Ps" . "open punctuation") | |
334 | ;;; ("Pe" . "close punctuation") | |
335 | ;;; ("Pi" . "initial-quotation punctuation") | |
336 | ;;; ("Pf" . "final-quotation punctuation") | |
337 | ;;; ("Po" . "other punctuation") | |
338 | ;;; ("Sm" . "math symbol") | |
339 | ;;; ("Sc" . "currency symbol") | |
340 | ;;; ("Sk" . "modifier symbol") | |
341 | ;;; ("So" . "other symbol"))))) | |
342 | ;;; (list "Combining class" | |
343 | ;;; (cdr (assoc | |
344 | ;;; (string-to-number (nth 2 fields)) | |
345 | ;;; '((0 . "Spacing") | |
346 | ;;; (1 . "Overlays and interior") | |
544cb6b0 | 347 | ;;; (7 . "Nuktas") |
d6c135fb RS |
348 | ;;; (8 . "Hiragana/Katakana voicing marks") |
349 | ;;; (9 . "Viramas") | |
350 | ;;; (10 . "Start of fixed position classes") | |
351 | ;;; (199 . "End of fixed position classes") | |
352 | ;;; (200 . "Below left attached") | |
353 | ;;; (202 . "Below attached") | |
354 | ;;; (204 . "Below right attached") | |
355 | ;;; (208 . "Left attached (reordrant around \ | |
356 | ;;; single base character)") | |
357 | ;;; (210 . "Right attached") | |
358 | ;;; (212 . "Above left attached") | |
359 | ;;; (214 . "Above attached") | |
360 | ;;; (216 . "Above right attached") | |
361 | ;;; (218 . "Below left") | |
362 | ;;; (220 . "Below") | |
363 | ;;; (222 . "Below right") | |
364 | ;;; (224 . "Left (reordrant around single base \ | |
365 | ;;; character)") | |
366 | ;;; (226 . "Right") | |
367 | ;;; (228 . "Above left") | |
368 | ;;; (230 . "Above") | |
369 | ;;; (232 . "Above right") | |
370 | ;;; (233 . "Double below") | |
371 | ;;; (234 . "Double above") | |
372 | ;;; (240 . "Below (iota subscript)"))))) | |
373 | ;;; (list "Bidi category" | |
374 | ;;; (cdr (assoc | |
375 | ;;; (nth 3 fields) | |
376 | ;;; '(("L" . "Left-to-Right") | |
377 | ;;; ("LRE" . "Left-to-Right Embedding") | |
378 | ;;; ("LRO" . "Left-to-Right Override") | |
379 | ;;; ("R" . "Right-to-Left") | |
380 | ;;; ("AL" . "Right-to-Left Arabic") | |
381 | ;;; ("RLE" . "Right-to-Left Embedding") | |
382 | ;;; ("RLO" . "Right-to-Left Override") | |
383 | ;;; ("PDF" . "Pop Directional Format") | |
384 | ;;; ("EN" . "European Number") | |
385 | ;;; ("ES" . "European Number Separator") | |
386 | ;;; ("ET" . "European Number Terminator") | |
387 | ;;; ("AN" . "Arabic Number") | |
388 | ;;; ("CS" . "Common Number Separator") | |
389 | ;;; ("NSM" . "Non-Spacing Mark") | |
390 | ;;; ("BN" . "Boundary Neutral") | |
391 | ;;; ("B" . "Paragraph Separator") | |
392 | ;;; ("S" . "Segment Separator") | |
393 | ;;; ("WS" . "Whitespace") | |
394 | ;;; ("ON" . "Other Neutrals"))))) | |
395 | ;;; (list | |
396 | ;;; "Decomposition" | |
397 | ;;; (if (nth 4 fields) | |
398 | ;;; (let* ((parts (split-string (nth 4 fields))) | |
399 | ;;; (info (car parts))) | |
400 | ;;; (if (string-match "\\`<\\(.+\\)>\\'" info) | |
401 | ;;; (setq info (match-string 1 info)) | |
402 | ;;; (setq info nil)) | |
403 | ;;; (if info (setq parts (cdr parts))) | |
404 | ;;; ;; Maybe printing ? for unrepresentable unicodes | |
405 | ;;; ;; here and below should be changed? | |
406 | ;;; (setq parts (mapconcat | |
407 | ;;; (lambda (arg) | |
408 | ;;; (string (or (decode-char | |
409 | ;;; 'ucs | |
410 | ;;; (string-to-number arg 16)) | |
411 | ;;; ??))) | |
412 | ;;; parts " ")) | |
413 | ;;; (concat info parts)))) | |
414 | ;;; (list "Decimal digit value" | |
415 | ;;; (nth 5 fields)) | |
416 | ;;; (list "Digit value" | |
417 | ;;; (nth 6 fields)) | |
418 | ;;; (list "Numeric value" | |
419 | ;;; (nth 7 fields)) | |
420 | ;;; (list "Mirrored" | |
421 | ;;; (if (equal "Y" (nth 8 fields)) | |
422 | ;;; "yes")) | |
423 | ;;; (list "Old name" (nth 9 fields)) | |
424 | ;;; (list "ISO 10646 comment" (nth 10 fields)) | |
425 | ;;; (list "Uppercase" (and (nth 11 fields) | |
426 | ;;; (string (or (decode-char | |
427 | ;;; 'ucs | |
428 | ;;; (string-to-number | |
429 | ;;; (nth 11 fields) 16)) | |
430 | ;;; ??)))) | |
431 | ;;; (list "Lowercase" (and (nth 12 fields) | |
432 | ;;; (string (or (decode-char | |
433 | ;;; 'ucs | |
434 | ;;; (string-to-number | |
435 | ;;; (nth 12 fields) 16)) | |
436 | ;;; ??)))) | |
437 | ;;; (list "Titlecase" (and (nth 13 fields) | |
438 | ;;; (string (or (decode-char | |
439 | ;;; 'ucs | |
440 | ;;; (string-to-number | |
441 | ;;; (nth 13 fields) 16)) | |
442 | ;;; ??))))))))))) | |
f15078e2 KH |
443 | |
444 | ;; Return information about how CHAR is displayed at the buffer | |
445 | ;; position POS. If the selected frame is on a graphic display, | |
446 | ;; return a cons (FONTNAME . GLYPH-CODE). Otherwise, return a string | |
447 | ;; describing the terminal codes for the character. | |
448 | (defun describe-char-display (pos char) | |
449 | (if (display-graphic-p (selected-frame)) | |
450 | (internal-char-font pos char) | |
451 | (let* ((coding (terminal-coding-system)) | |
452 | (encoded (encode-coding-char char coding))) | |
453 | (if encoded | |
454 | (encoded-string-description encoded coding))))) | |
455 | ||
d6c135fb | 456 | \f |
4adb7c09 RS |
457 | ;;;###autoload |
458 | (defun describe-char (pos) | |
459 | "Describe the character after POS (interactively, the character after point). | |
460 | The information includes character code, charset and code points in it, | |
461 | syntax, category, how the character is encoded in a file, | |
462 | character composition information (if relevant), | |
463 | as well as widgets, buttons, overlays, and text properties." | |
464 | (interactive "d") | |
4adb7c09 RS |
465 | (if (>= pos (point-max)) |
466 | (error "No character follows specified position")) | |
467 | (let* ((char (char-after pos)) | |
468 | (charset (char-charset char)) | |
469 | (buffer (current-buffer)) | |
ca9088e7 | 470 | (composition (find-composition pos nil nil t)) |
f15078e2 KH |
471 | (component-chars nil) |
472 | (display-table (or (window-display-table) | |
473 | buffer-display-table | |
474 | standard-display-table)) | |
475 | (disp-vector (and display-table (aref display-table char))) | |
4adb7c09 | 476 | (multibyte-p enable-multibyte-characters) |
831ccfa6 | 477 | item-list max-width unicode) |
4adb7c09 RS |
478 | (if (eq charset 'unknown) |
479 | (setq item-list | |
480 | `(("character" | |
481 | ,(format "%s (0%o, %d, 0x%x) -- invalid character code" | |
482 | (if (< char 256) | |
483 | (single-key-description char) | |
484 | (char-to-string char)) | |
485 | char char char)))) | |
831ccfa6 | 486 | |
9b5e7a5c | 487 | (if (or (< char 256) |
831ccfa6 DL |
488 | (memq 'mule-utf-8 (find-coding-systems-region pos (1+ pos))) |
489 | (get-char-property pos 'untranslated-utf-8)) | |
490 | (setq unicode (or (get-char-property pos 'untranslated-utf-8) | |
491 | (encode-char char 'ucs)))) | |
4adb7c09 RS |
492 | (setq item-list |
493 | `(("character" | |
831ccfa6 | 494 | ,(format "%s (0%o, %d, 0x%x%s)" (if (< char 256) |
4adb7c09 RS |
495 | (single-key-description char) |
496 | (char-to-string char)) | |
831ccfa6 DL |
497 | char char char |
498 | (if unicode | |
9b5e7a5c | 499 | (format ", U+%04X" unicode) |
831ccfa6 | 500 | ""))) |
4adb7c09 RS |
501 | ("charset" |
502 | ,(symbol-name charset) | |
503 | ,(format "(%s)" (charset-description charset))) | |
504 | ("code point" | |
505 | ,(let ((split (split-char char))) | |
506 | (if (= (charset-dimension charset) 1) | |
507 | (format "%d" (nth 1 split)) | |
508 | (format "%d %d" (nth 1 split) (nth 2 split))))) | |
509 | ("syntax" | |
ca9088e7 | 510 | ,(let ((syntax (syntax-after pos))) |
4adb7c09 | 511 | (with-temp-buffer |
ca9088e7 | 512 | (internal-describe-syntax-value syntax) |
4adb7c09 RS |
513 | (buffer-string)))) |
514 | ("category" | |
515 | ,@(let ((category-set (char-category-set char))) | |
516 | (if (not category-set) | |
517 | '("-- none --") | |
518 | (mapcar #'(lambda (x) (format "%c:%s " | |
519 | x (category-docstring x))) | |
520 | (category-set-mnemonics category-set))))) | |
521 | ,@(let ((props (aref char-code-property-table char)) | |
522 | ps) | |
523 | (when props | |
524 | (while props | |
525 | (push (format "%s:" (pop props)) ps) | |
526 | (push (format "%s;" (pop props)) ps)) | |
527 | (list (cons "Properties" (nreverse ps))))) | |
528 | ("buffer code" | |
529 | ,(encoded-string-description | |
530 | (string-as-unibyte (char-to-string char)) nil)) | |
531 | ("file code" | |
532 | ,@(let* ((coding buffer-file-coding-system) | |
533 | (encoded (encode-coding-char char coding))) | |
534 | (if encoded | |
535 | (list (encoded-string-description encoded coding) | |
536 | (format "(encoded by coding system %S)" coding)) | |
537 | (list "not encodable by coding system" | |
538 | (symbol-name coding))))) | |
f15078e2 KH |
539 | ("display" |
540 | ,(cond | |
541 | (disp-vector | |
542 | (setq disp-vector (copy-sequence disp-vector)) | |
543 | (dotimes (i (length disp-vector)) | |
544 | (setq char (aref disp-vector i)) | |
545 | (aset disp-vector i | |
546 | (cons char (describe-char-display pos char)))) | |
547 | (format "by display table entry [%s] (see below)" | |
548 | (mapconcat #'(lambda (x) (format "?%c" (car x))) | |
549 | disp-vector " "))) | |
550 | (composition | |
551 | (let ((from (car composition)) | |
552 | (to (nth 1 composition)) | |
553 | (next (1+ pos)) | |
554 | (components (nth 2 composition)) | |
555 | ch) | |
556 | (setcar composition | |
557 | (and (< from pos) (buffer-substring from pos))) | |
558 | (setcar (cdr composition) | |
559 | (and (< next to) (buffer-substring next to))) | |
560 | (dotimes (i (length components)) | |
561 | (if (integerp (setq ch (aref components i))) | |
562 | (push (cons ch (describe-char-display pos ch)) | |
563 | component-chars))) | |
564 | (setq component-chars (nreverse component-chars)) | |
565 | (format "composed to form \"%s\" (see below)" | |
566 | (buffer-substring from to)))) | |
567 | (t | |
568 | (let ((display (describe-char-display pos char))) | |
569 | (if (display-graphic-p (selected-frame)) | |
570 | (if display | |
571 | (concat | |
572 | "by this font (glyph code)\n" | |
573 | (format " %s (0x%02X)" | |
574 | (car display) (cdr display))) | |
3ed9ee82 | 575 | "no font available") |
f15078e2 KH |
576 | (if display |
577 | (format "terminal code %s" display) | |
578 | "not encodable for terminal")))))) | |
831ccfa6 | 579 | ,@(let ((unicodedata (and unicode |
d6c135fb | 580 | (describe-char-unicode-data unicode)))) |
831ccfa6 DL |
581 | (if unicodedata |
582 | (cons (list "Unicode data" " ") unicodedata)))))) | |
4adb7c09 RS |
583 | (setq max-width (apply #'max (mapcar #'(lambda (x) (length (car x))) |
584 | item-list))) | |
ca9088e7 | 585 | (when (eq (current-buffer) (get-buffer "*Help*")) |
831ccfa6 | 586 | (error "Can't describe char in Help buffer")) |
4adb7c09 | 587 | (with-output-to-temp-buffer "*Help*" |
ca9088e7 | 588 | (with-current-buffer standard-output |
4adb7c09 RS |
589 | (set-buffer-multibyte multibyte-p) |
590 | (let ((formatter (format "%%%ds:" max-width))) | |
591 | (dolist (elt item-list) | |
831ccfa6 DL |
592 | (when (cadr elt) |
593 | (insert (format formatter (car elt))) | |
594 | (dolist (clm (cdr elt)) | |
595 | (when (>= (+ (current-column) | |
596 | (or (string-match "\n" clm) | |
597 | (string-width clm)) 1) | |
544cb6b0 | 598 | (window-width)) |
831ccfa6 DL |
599 | (insert "\n") |
600 | (indent-to (1+ max-width))) | |
601 | (insert " " clm)) | |
602 | (insert "\n")))) | |
f15078e2 KH |
603 | |
604 | (when disp-vector | |
605 | (insert | |
606 | "\nThe display table entry is displayed by ") | |
607 | (if (display-graphic-p (selected-frame)) | |
608 | (progn | |
609 | (insert "these fonts (glyph codes):\n") | |
610 | (dotimes (i (length disp-vector)) | |
611 | (insert (car (aref disp-vector i)) ?: | |
612 | (propertize " " 'display '(space :align-to 5)) | |
613 | (if (cdr (aref disp-vector i)) | |
614 | (format "%s (0x%02X)" (cadr (aref disp-vector i)) | |
615 | (cddr (aref disp-vector i))) | |
616 | "-- no font --") | |
617 | "\n "))) | |
618 | (insert "these terminal codes:\n") | |
619 | (dotimes (i (length disp-vector)) | |
544cb6b0 | 620 | (insert (car (aref disp-vector i)) |
f15078e2 KH |
621 | (propertize " " 'display '(space :align-to 5)) |
622 | (or (cdr (aref disp-vector i)) "-- not encodable --") | |
623 | "\n")))) | |
624 | ||
4adb7c09 | 625 | (when composition |
f15078e2 KH |
626 | (insert "\nComposed") |
627 | (if (car composition) | |
628 | (if (cadr composition) | |
629 | (insert " with the surrounding characters \"" | |
630 | (car composition) "\" and \"" | |
631 | (cadr composition) "\"") | |
632 | (insert " with the preceding character(s) \"" | |
633 | (car composition) "\"")) | |
634 | (if (cadr composition) | |
635 | (insert " with the following character(s) \"" | |
636 | (cadr composition) "\""))) | |
637 | (insert " by the rule:\n\t(" | |
638 | (mapconcat (lambda (x) | |
639 | (format (if (consp x) "%S" "?%c") x)) | |
640 | (nth 2 composition) | |
641 | " ") | |
642 | ")") | |
643 | (insert "\nThe component character(s) are displayed by ") | |
644 | (if (display-graphic-p (selected-frame)) | |
645 | (progn | |
646 | (insert "these fonts (glyph codes):") | |
647 | (dolist (elt component-chars) | |
648 | (insert "\n " (car elt) ?: | |
649 | (propertize " " 'display '(space :align-to 5)) | |
650 | (if (cdr elt) | |
651 | (format "%s (0x%02X)" (cadr elt) (cddr elt)) | |
652 | "-- no font --")))) | |
653 | (insert "these terminal codes:") | |
654 | (dolist (elt component-chars) | |
655 | (insert "\n " (car elt) ":" | |
656 | (propertize " " 'display '(space :align-to 5)) | |
657 | (or (cdr elt) "-- not encodable --")))) | |
658 | (insert "\nSee the variable `reference-point-alist' for " | |
659 | "the meaning of the rule.\n")) | |
4adb7c09 RS |
660 | |
661 | (let ((output (current-buffer))) | |
662 | (with-current-buffer buffer | |
663 | (describe-text-properties pos output)) | |
664 | (describe-text-mode)))))) | |
2a1e884e | 665 | |
831ccfa6 DL |
666 | (defalias 'describe-char-after 'describe-char) |
667 | (make-obsolete 'describe-char-after 'describe-char "21.5") | |
668 | ||
288395a7 CW |
669 | (provide 'descr-text) |
670 | ||
ab5796a9 | 671 | ;;; arch-tag: fc55a498-f3e9-4312-b5bd-98cc02480af1 |
2a1e884e | 672 | ;;; descr-text.el ends here |