Commit | Line | Data |
---|---|---|
dcb90b5f | 1 | ;;; descr-text.el --- describe text mode |
2a1e884e | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1994, 1995, 1996, 2001, 2002, 2003, 2004, |
409cc4a3 | 4 | ;; 2005, 2006, 2007, 2008 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 NR |
31 | (eval-when-compile (require 'quail)) |
32 | (require 'help-fns) | |
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. |
67 | PROPERTIES should be a list of overlay or text properties. | |
7fb0741b | 68 | The `category', `face' and `font-lock-face' properties are made |
57d79b99 | 69 | into 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)) | |
87 | 'help-echo "mouse-2, RET: describe this category")) | |
8b18fb8f | 88 | ((memq key '(face font-lock-face mouse-face)) |
2fd54bf8 JL |
89 | (insert-text-button |
90 | (format "%S" value) | |
91 | 'type 'help-face 'help-args (list value))) | |
f13cc97d | 92 | ((widgetp value) |
2a1e884e RS |
93 | (describe-text-widget value)) |
94 | (t | |
8b18fb8f | 95 | (describe-text-sexp value)))) |
57d79b99 | 96 | (insert "\n"))) |
2a1e884e RS |
97 | \f |
98 | ;;; Describe-Text Commands. | |
99 | ||
100 | (defun describe-text-category (category) | |
101 | "Describe a text property category." | |
e5a5c80c NR |
102 | (interactive "SCategory: ") |
103 | (help-setup-xref (list #'describe-text-category category) (interactive-p)) | |
2a1e884e | 104 | (save-excursion |
ca9088e7 SM |
105 | (with-output-to-temp-buffer "*Help*" |
106 | (set-buffer standard-output) | |
57d79b99 | 107 | (insert "Category " (format "%S" category) ":\n\n") |
4adb7c09 | 108 | (describe-property-list (symbol-plist category)) |
2a1e884e RS |
109 | (goto-char (point-min))))) |
110 | ||
111 | ;;;###autoload | |
4adb7c09 RS |
112 | (defun describe-text-properties (pos &optional output-buffer) |
113 | "Describe widgets, buttons, overlays and text properties at POS. | |
114 | Interactively, describe them for the character after point. | |
115 | If optional second argument OUTPUT-BUFFER is non-nil, | |
116 | insert the output into that buffer, and don't initialize or clear it | |
117 | otherwise." | |
2a1e884e | 118 | (interactive "d") |
4adb7c09 RS |
119 | (if (>= pos (point-max)) |
120 | (error "No character follows specified position")) | |
121 | (if output-buffer | |
122 | (describe-text-properties-1 pos output-buffer) | |
123 | (if (not (or (text-properties-at pos) (overlays-at pos))) | |
124 | (message "This is plain text.") | |
0911ac26 KS |
125 | (let ((buffer (current-buffer)) |
126 | (target-buffer "*Help*")) | |
127 | (when (eq buffer (get-buffer target-buffer)) | |
e217c04e | 128 | (setq target-buffer "*Help*<2>")) |
4adb7c09 | 129 | (save-excursion |
0911ac26 | 130 | (with-output-to-temp-buffer target-buffer |
ca9088e7 | 131 | (set-buffer standard-output) |
4adb7c09 | 132 | (setq output-buffer (current-buffer)) |
57d79b99 | 133 | (insert "Text content at position " (format "%d" pos) ":\n\n") |
4adb7c09 RS |
134 | (with-current-buffer buffer |
135 | (describe-text-properties-1 pos output-buffer)) | |
4adb7c09 RS |
136 | (goto-char (point-min)))))))) |
137 | ||
138 | (defun describe-text-properties-1 (pos output-buffer) | |
2a1e884e RS |
139 | (let* ((properties (text-properties-at pos)) |
140 | (overlays (overlays-at pos)) | |
2a1e884e RS |
141 | (wid-field (get-char-property pos 'field)) |
142 | (wid-button (get-char-property pos 'button)) | |
143 | (wid-doc (get-char-property pos 'widget-doc)) | |
144 | ;; If button.el is not loaded, we have no buttons in the text. | |
145 | (button (and (fboundp 'button-at) (button-at pos))) | |
146 | (button-type (and button (button-type button))) | |
147 | (button-label (and button (button-label button))) | |
148 | (widget (or wid-field wid-button wid-doc))) | |
4adb7c09 RS |
149 | (with-current-buffer output-buffer |
150 | ;; Widgets | |
151 | (when (widgetp widget) | |
152 | (newline) | |
57d79b99 NR |
153 | (insert (cond (wid-field "This is an editable text area") |
154 | (wid-button "This is an active area") | |
155 | (wid-doc "This is documentation text"))) | |
156 | (insert " of a ") | |
4adb7c09 | 157 | (describe-text-widget widget) |
57d79b99 | 158 | (insert ".\n\n")) |
4adb7c09 RS |
159 | ;; Buttons |
160 | (when (and button (not (widgetp wid-button))) | |
161 | (newline) | |
2fd54bf8 JL |
162 | (insert "Here is a `" (format "%S" button-type) |
163 | "' button labeled `" button-label "'.\n\n")) | |
4adb7c09 RS |
164 | ;; Overlays |
165 | (when overlays | |
166 | (newline) | |
167 | (if (eq (length overlays) 1) | |
57d79b99 NR |
168 | (insert "There is an overlay here:\n") |
169 | (insert "There are " (format "%d" (length overlays)) | |
4adb7c09 RS |
170 | " overlays here:\n")) |
171 | (dolist (overlay overlays) | |
57d79b99 | 172 | (insert " From " (format "%d" (overlay-start overlay)) |
4adb7c09 RS |
173 | " to " (format "%d" (overlay-end overlay)) "\n") |
174 | (describe-property-list (overlay-properties overlay))) | |
57d79b99 | 175 | (insert "\n")) |
4adb7c09 RS |
176 | ;; Text properties |
177 | (when properties | |
178 | (newline) | |
57d79b99 | 179 | (insert "There are text properties here:\n") |
4adb7c09 | 180 | (describe-property-list properties))))) |
d6c135fb | 181 | \f |
f1f194de KH |
182 | (defcustom describe-char-unidata-list nil |
183 | "List of Unicode-based character property names shown by `describe-char'." | |
184 | :group 'mule | |
8589dc17 | 185 | :version "23.1" |
3253c7c6 SM |
186 | :type '(choice (const :tag "All properties" t) |
187 | (set | |
188 | (const :tag "Unicode Name" name) | |
189 | (const :tag "Unicode general category " general-category) | |
190 | (const :tag "Unicode canonical combining class" | |
191 | canonical-combining-class) | |
192 | (const :tag "Unicode bidi class" bidi-class) | |
193 | (const :tag "Unicode decomposition mapping" decomposition) | |
194 | (const :tag "Unicode decimal digit value" decimal-digit-value) | |
195 | (const :tag "Unicode digit value" digit-value) | |
196 | (const :tag "Unicode numeric value" numeric-value) | |
197 | (const :tag "Unicode mirrored" mirrored) | |
198 | (const :tag "Unicode old name" old-name) | |
199 | (const :tag "Unicode ISO 10646 comment" iso-10646-comment) | |
200 | (const :tag "Unicode simple uppercase mapping" uppercase) | |
201 | (const :tag "Unicode simple lowercase mapping" lowercase) | |
202 | (const :tag "Unicode simple titlecase mapping" titlecase)))) | |
f1f194de | 203 | |
49c2a2dc SM |
204 | (defcustom describe-char-unicodedata-file nil |
205 | "Location of Unicode data file. | |
2acb13b1 | 206 | This is the UnicodeData.txt file from the Unicode Consortium, used for |
2a4960f9 | 207 | diagnostics. If it is non-nil `describe-char' will print data |
49c2a2dc SM |
208 | looked up from it. This facility is mostly of use to people doing |
209 | multilingual development. | |
4adb7c09 | 210 | |
2acb13b1 JB |
211 | This is a fairly large file, not typically present on GNU systems. |
212 | At the time of writing it is at the URL | |
57d79b99 | 213 | `http://www.unicode.org/Public/UNIDATA/UnicodeData.txt'." |
49c2a2dc | 214 | :group 'mule |
bf247b6e | 215 | :version "22.1" |
49c2a2dc SM |
216 | :type '(choice (const :tag "None" nil) |
217 | file)) | |
831ccfa6 | 218 | |
49c2a2dc SM |
219 | (defun describe-char-unicode-data (char) |
220 | "Return a list of Unicode data for unicode CHAR. | |
221 | Each element is a list of a property description and the property value. | |
f1f194de KH |
222 | The list is null if CHAR isn't found in `describe-char-unicodedata-file'. |
223 | This function is semi-obsolete. Use `get-char-code-property'." | |
49c2a2dc SM |
224 | (when describe-char-unicodedata-file |
225 | (unless (file-exists-p describe-char-unicodedata-file) | |
226 | (error "`unicodedata-file' %s not found" describe-char-unicodedata-file)) | |
def7167b JB |
227 | (with-current-buffer (get-buffer-create " *Unicode Data*") |
228 | (when (zerop (buffer-size)) | |
229 | ;; Don't use -literally in case of DOS line endings. | |
230 | (insert-file-contents describe-char-unicodedata-file)) | |
49c2a2dc SM |
231 | (goto-char (point-min)) |
232 | (let ((hex (format "%04X" char)) | |
233 | found first last) | |
234 | (if (re-search-forward (concat "^" hex) nil t) | |
235 | (setq found t) | |
236 | ;; It's not listed explicitly. Look for ranges, e.g. CJK | |
237 | ;; ideographs, and check whether it's in one of them. | |
238 | (while (and (re-search-forward "^\\([^;]+\\);[^;]+First>;" nil t) | |
239 | (>= char (setq first | |
240 | (string-to-number (match-string 1) 16))) | |
241 | (progn | |
242 | (forward-line 1) | |
243 | (looking-at "^\\([^;]+\\);[^;]+Last>;") | |
244 | (> char | |
245 | (setq last | |
246 | (string-to-number (match-string 1) 16)))))) | |
247 | (if (and (>= char first) | |
248 | (<= char last)) | |
249 | (setq found t))) | |
250 | (if found | |
251 | (let ((fields (mapcar (lambda (elt) | |
252 | (if (> (length elt) 0) | |
253 | elt)) | |
254 | (cdr (split-string | |
255 | (buffer-substring | |
256 | (line-beginning-position) | |
257 | (line-end-position)) | |
258 | ";"))))) | |
259 | ;; The length depends on whether the last field was empty. | |
260 | (unless (or (= 13 (length fields)) | |
261 | (= 14 (length fields))) | |
262 | (error "Invalid contents in %s" describe-char-unicodedata-file)) | |
263 | ;; The field names and values lists are slightly | |
264 | ;; modified from Mule-UCS unidata.el. | |
265 | (list | |
266 | (list "Name" (let ((name (nth 0 fields))) | |
267 | ;; Check for <..., First>, <..., Last> | |
268 | (if (string-match "\\`\\(<[^,]+\\)," name) | |
269 | (concat (match-string 1 name) ">") | |
270 | name))) | |
271 | (list "Category" | |
f1f194de KH |
272 | (let ((val (nth 1 fields))) |
273 | (or (char-code-property-description | |
274 | 'general-category (intern val)) | |
275 | val))) | |
49c2a2dc | 276 | (list "Combining class" |
f1f194de KH |
277 | (let ((val (nth 1 fields))) |
278 | (or (char-code-property-description | |
279 | 'canonical-combining-class (intern val)) | |
280 | val))) | |
49c2a2dc | 281 | (list "Bidi category" |
f1f194de KH |
282 | (let ((val (nth 1 fields))) |
283 | (or (char-code-property-description | |
284 | 'bidi-class (intern val)) | |
285 | val))) | |
49c2a2dc SM |
286 | (list |
287 | "Decomposition" | |
288 | (if (nth 4 fields) | |
289 | (let* ((parts (split-string (nth 4 fields))) | |
290 | (info (car parts))) | |
291 | (if (string-match "\\`<\\(.+\\)>\\'" info) | |
292 | (setq info (match-string 1 info)) | |
293 | (setq info nil)) | |
294 | (if info (setq parts (cdr parts))) | |
49c2a2dc SM |
295 | (setq parts (mapconcat |
296 | (lambda (arg) | |
f1f194de | 297 | (string (string-to-number arg 16))) |
49c2a2dc SM |
298 | parts " ")) |
299 | (concat info parts)))) | |
300 | (list "Decimal digit value" | |
301 | (nth 5 fields)) | |
302 | (list "Digit value" | |
303 | (nth 6 fields)) | |
304 | (list "Numeric value" | |
305 | (nth 7 fields)) | |
306 | (list "Mirrored" | |
307 | (if (equal "Y" (nth 8 fields)) | |
308 | "yes")) | |
309 | (list "Old name" (nth 9 fields)) | |
310 | (list "ISO 10646 comment" (nth 10 fields)) | |
311 | (list "Uppercase" (and (nth 11 fields) | |
f1f194de KH |
312 | (string (string-to-number |
313 | (nth 11 fields) 16)))) | |
49c2a2dc | 314 | (list "Lowercase" (and (nth 12 fields) |
f1f194de KH |
315 | (string (string-to-number |
316 | (nth 12 fields) 16)))) | |
49c2a2dc | 317 | (list "Titlecase" (and (nth 13 fields) |
f1f194de KH |
318 | (string (string-to-number |
319 | (nth 13 fields) 16))))))))))) | |
7fb0741b KH |
320 | |
321 | ;; Return information about how CHAR is displayed at the buffer | |
322 | ;; position POS. If the selected frame is on a graphic display, | |
e463f071 KH |
323 | ;; return a cons (FONTNAME . GLYPH-CODE) where GLYPH-CODE is a |
324 | ;; hexadigit string representing the glyph-ID. Otherwise, return a | |
325 | ;; string describing the terminal codes for the character. | |
7fb0741b KH |
326 | (defun describe-char-display (pos char) |
327 | (if (display-graphic-p (selected-frame)) | |
e463f071 | 328 | (let ((char-font-info (internal-char-font pos char))) |
a6bbf9f4 KH |
329 | (if char-font-info |
330 | (if (integerp (cdr char-font-info)) | |
331 | (setcdr char-font-info (format "%02X" (cdr char-font-info))) | |
332 | (setcdr char-font-info | |
333 | (format "%04X%04X" | |
334 | (cadr char-font-info) (cddr char-font-info))))) | |
e463f071 | 335 | char-font-info) |
7fb0741b KH |
336 | (let* ((coding (terminal-coding-system)) |
337 | (encoded (encode-coding-char char coding))) | |
338 | (if encoded | |
339 | (encoded-string-description encoded coding))))) | |
340 | ||
d6c135fb | 341 | \f |
4adb7c09 RS |
342 | ;;;###autoload |
343 | (defun describe-char (pos) | |
344 | "Describe the character after POS (interactively, the character after point). | |
345 | The information includes character code, charset and code points in it, | |
346 | syntax, category, how the character is encoded in a file, | |
347 | character composition information (if relevant), | |
348 | as well as widgets, buttons, overlays, and text properties." | |
349 | (interactive "d") | |
4adb7c09 RS |
350 | (if (>= pos (point-max)) |
351 | (error "No character follows specified position")) | |
352 | (let* ((char (char-after pos)) | |
353 | (charset (char-charset char)) | |
ca9088e7 | 354 | (composition (find-composition pos nil nil t)) |
7fb0741b KH |
355 | (component-chars nil) |
356 | (display-table (or (window-display-table) | |
357 | buffer-display-table | |
358 | standard-display-table)) | |
359 | (disp-vector (and display-table (aref display-table char))) | |
4adb7c09 | 360 | (multibyte-p enable-multibyte-characters) |
6482d093 KH |
361 | (overlays (mapcar #'(lambda (o) (overlay-properties o)) |
362 | (overlays-at pos))) | |
6398b88f AS |
363 | (char-description (if (not multibyte-p) |
364 | (single-key-description char) | |
365 | (if (< char 128) | |
366 | (single-key-description char) | |
367 | (string-to-multibyte | |
368 | (char-to-string char))))) | |
e5a5c80c NR |
369 | (text-props-desc |
370 | (let ((tmp-buf (generate-new-buffer " *text-props*"))) | |
371 | (unwind-protect | |
372 | (progn | |
373 | (describe-text-properties pos tmp-buf) | |
374 | (with-current-buffer tmp-buf (buffer-string))) | |
375 | (kill-buffer tmp-buf)))) | |
327719ee | 376 | item-list max-width code) |
831ccfa6 | 377 | |
327719ee | 378 | (setq code (encode-char char charset)) |
ed441285 KH |
379 | (setq item-list |
380 | `(("character" | |
41882805 | 381 | ,(format "%s (%d, #o%o, #x%x)" |
e5a5c80c NR |
382 | (apply 'propertize char-description |
383 | (text-properties-at pos)) | |
41882805 | 384 | char char char)) |
327719ee | 385 | ("preferred charset" |
57d79b99 | 386 | ,`(insert-text-button |
e5a5c80c NR |
387 | ,(symbol-name charset) |
388 | 'type 'help-character-set 'help-args '(,charset)) | |
ed441285 KH |
389 | ,(format "(%s)" (charset-description charset))) |
390 | ("code point" | |
879dfc97 KH |
391 | ,(let ((str (if (integerp code) |
392 | (format (if (< code 256) "0x%02X" "0x%04X") code) | |
393 | (format "0x%04X%04X" (car code) (cdr code))))) | |
394 | (if (<= (charset-dimension charset) 2) | |
41882805 MB |
395 | `(insert-text-button |
396 | ,str | |
397 | 'action (lambda (&rest ignore) | |
879dfc97 KH |
398 | (list-charset-chars ',charset) |
399 | (with-selected-window | |
400 | (get-buffer-window "*Character List*" 0) | |
401 | (goto-char (point-min)) | |
402 | (forward-line 2) ;Skip the header. | |
403 | (let ((case-fold-search nil)) | |
404 | (if (search-forward ,(char-to-string char) | |
405 | nil t) | |
406 | (goto-char (match-beginning 0)))))) | |
41882805 MB |
407 | 'help-echo |
408 | "mouse-2, RET: show this character in its character set") | |
879dfc97 | 409 | str))) |
ed441285 | 410 | ("syntax" |
d8ac3d27 | 411 | ,(let ((syntax (syntax-after pos))) |
ed441285 KH |
412 | (with-temp-buffer |
413 | (internal-describe-syntax-value syntax) | |
414 | (buffer-string)))) | |
415 | ("category" | |
416 | ,@(let ((category-set (char-category-set char))) | |
417 | (if (not category-set) | |
418 | '("-- none --") | |
9f40939d | 419 | (mapcar #'(lambda (x) (format "%c:%s" |
ed441285 KH |
420 | x (category-docstring x))) |
421 | (category-set-mnemonics category-set))))) | |
309473d0 | 422 | ("to input" |
22259c93 KH |
423 | ,@(let ((key-list (and (eq input-method-function |
424 | 'quail-input-method) | |
309473d0 KH |
425 | (quail-find-key char)))) |
426 | (if (consp key-list) | |
427 | (list "type" | |
428 | (mapconcat #'(lambda (x) (concat "\"" x "\"")) | |
fedbc8e5 JL |
429 | key-list " or ") |
430 | "with" | |
57d79b99 | 431 | `(insert-text-button |
2fd54bf8 | 432 | ,current-input-method |
e5a5c80c NR |
433 | 'type 'help-input-method |
434 | 'help-args '(,current-input-method)))))) | |
ed441285 KH |
435 | ("buffer code" |
436 | ,(encoded-string-description | |
437 | (string-as-unibyte (char-to-string char)) nil)) | |
438 | ("file code" | |
439 | ,@(let* ((coding buffer-file-coding-system) | |
440 | (encoded (encode-coding-char char coding))) | |
441 | (if encoded | |
442 | (list (encoded-string-description encoded coding) | |
443 | (format "(encoded by coding system %S)" coding)) | |
444 | (list "not encodable by coding system" | |
445 | (symbol-name coding))))) | |
446 | ("display" | |
447 | ,(cond | |
448 | (disp-vector | |
449 | (setq disp-vector (copy-sequence disp-vector)) | |
450 | (dotimes (i (length disp-vector)) | |
451 | (setq char (aref disp-vector i)) | |
452 | (aset disp-vector i | |
8b18fb8f | 453 | (cons char (describe-char-display |
da55bb96 | 454 | pos (glyph-char char))))) |
ed441285 | 455 | (format "by display table entry [%s] (see below)" |
8b18fb8f JL |
456 | (mapconcat |
457 | #'(lambda (x) | |
da55bb96 | 458 | (format "?%c" (glyph-char (car x)))) |
8b18fb8f | 459 | disp-vector " "))) |
ed441285 KH |
460 | (composition |
461 | (let ((from (car composition)) | |
462 | (to (nth 1 composition)) | |
463 | (next (1+ pos)) | |
464 | (components (nth 2 composition)) | |
465 | ch) | |
466 | (setcar composition | |
467 | (and (< from pos) (buffer-substring from pos))) | |
468 | (setcar (cdr composition) | |
469 | (and (< next to) (buffer-substring next to))) | |
470 | (dotimes (i (length components)) | |
471 | (if (integerp (setq ch (aref components i))) | |
472 | (push (cons ch (describe-char-display pos ch)) | |
473 | component-chars))) | |
474 | (setq component-chars (nreverse component-chars)) | |
475 | (format "composed to form \"%s\" (see below)" | |
476 | (buffer-substring from to)))) | |
477 | (t | |
478 | (let ((display (describe-char-display pos char))) | |
479 | (if (display-graphic-p (selected-frame)) | |
7fb0741b | 480 | (if display |
ed441285 KH |
481 | (concat |
482 | "by this font (glyph code)\n" | |
e463f071 | 483 | (format " %s (#x%s)" |
ed441285 KH |
484 | (car display) (cdr display))) |
485 | "no font available") | |
486 | (if display | |
487 | (format "terminal code %s" display) | |
488 | "not encodable for terminal")))))) | |
879dfc97 KH |
489 | ,@(let ((face |
490 | (if (not (or disp-vector composition)) | |
491 | (cond | |
492 | ((and show-trailing-whitespace | |
493 | (save-excursion (goto-char pos) | |
70583cb5 | 494 | (looking-at-p "[ \t]+$"))) |
879dfc97 KH |
495 | 'trailing-whitespace) |
496 | ((and nobreak-char-display char (eq char '#xa0)) | |
497 | 'nobreak-space) | |
498 | ((and nobreak-char-display char (eq char '#xad)) | |
499 | 'escape-glyph) | |
500 | ((and (< char 32) (not (memq char '(9 10)))) | |
501 | 'escape-glyph))))) | |
502 | (if face (list (list "hardcoded face" | |
2fd54bf8 JL |
503 | `(insert-text-button |
504 | ,(symbol-name face) | |
505 | 'type 'help-face 'help-args '(,face)))))) | |
180505d5 | 506 | ,@(let ((unicodedata (describe-char-unicode-data char))) |
ed441285 KH |
507 | (if unicodedata |
508 | (cons (list "Unicode data" " ") unicodedata))))) | |
95eede5c | 509 | (setq max-width (apply #'max (mapcar #'(lambda (x) |
879dfc97 | 510 | (if (cadr x) (length (car x)) 0)) |
4adb7c09 | 511 | item-list))) |
bfd94110 | 512 | (help-setup-xref nil (interactive-p)) |
3db0e8bf | 513 | (with-help-window (help-buffer) |
ca9088e7 | 514 | (with-current-buffer standard-output |
4adb7c09 RS |
515 | (set-buffer-multibyte multibyte-p) |
516 | (let ((formatter (format "%%%ds:" max-width))) | |
517 | (dolist (elt item-list) | |
831ccfa6 DL |
518 | (when (cadr elt) |
519 | (insert (format formatter (car elt))) | |
520 | (dolist (clm (cdr elt)) | |
57d79b99 | 521 | (if (eq (car-safe clm) 'insert-text-button) |
fedbc8e5 JL |
522 | (progn (insert " ") (eval clm)) |
523 | (when (>= (+ (current-column) | |
70583cb5 | 524 | (or (string-match-p "\n" clm) |
fedbc8e5 JL |
525 | (string-width clm)) |
526 | 1) | |
527 | (window-width)) | |
528 | (insert "\n") | |
529 | (indent-to (1+ max-width))) | |
530 | (insert " " clm))) | |
831ccfa6 | 531 | (insert "\n")))) |
7fb0741b | 532 | |
086c5b2b KH |
533 | (when overlays |
534 | (save-excursion | |
535 | (goto-char (point-min)) | |
536 | (re-search-forward "character:[ \t\n]+") | |
537 | (let* ((end (+ (point) (length char-description)))) | |
6398b88f | 538 | (mapc #'(lambda (props) |
086c5b2b | 539 | (let ((o (make-overlay (point) end))) |
6398b88f AS |
540 | (while props |
541 | (overlay-put o (car props) (nth 1 props)) | |
542 | (setq props (cddr props))))) | |
086c5b2b | 543 | overlays)))) |
ed441285 | 544 | |
7fb0741b KH |
545 | (when disp-vector |
546 | (insert | |
547 | "\nThe display table entry is displayed by ") | |
548 | (if (display-graphic-p (selected-frame)) | |
549 | (progn | |
550 | (insert "these fonts (glyph codes):\n") | |
551 | (dotimes (i (length disp-vector)) | |
da55bb96 | 552 | (insert (glyph-char (car (aref disp-vector i))) ?: |
7fb0741b KH |
553 | (propertize " " 'display '(space :align-to 5)) |
554 | (if (cdr (aref disp-vector i)) | |
e463f071 | 555 | (format "%s (#x%s)" (cadr (aref disp-vector i)) |
7fb0741b KH |
556 | (cddr (aref disp-vector i))) |
557 | "-- no font --") | |
fedbc8e5 | 558 | "\n") |
da55bb96 KS |
559 | (let ((face (glyph-face (car (aref disp-vector i))))) |
560 | (when face | |
561 | (insert (propertize " " 'display '(space :align-to 5)) | |
562 | "face: ") | |
563 | (insert (concat "`" (symbol-name face) "'")) | |
564 | (insert "\n"))))) | |
7fb0741b KH |
565 | (insert "these terminal codes:\n") |
566 | (dotimes (i (length disp-vector)) | |
567 | (insert (car (aref disp-vector i)) | |
568 | (propertize " " 'display '(space :align-to 5)) | |
569 | (or (cdr (aref disp-vector i)) "-- not encodable --") | |
570 | "\n")))) | |
571 | ||
4adb7c09 | 572 | (when composition |
7fb0741b KH |
573 | (insert "\nComposed") |
574 | (if (car composition) | |
575 | (if (cadr composition) | |
576 | (insert " with the surrounding characters \"" | |
577 | (car composition) "\" and \"" | |
578 | (cadr composition) "\"") | |
579 | (insert " with the preceding character(s) \"" | |
580 | (car composition) "\"")) | |
581 | (if (cadr composition) | |
582 | (insert " with the following character(s) \"" | |
583 | (cadr composition) "\""))) | |
3f8b1daa KH |
584 | (if (and (vectorp (nth 2 composition)) |
585 | (vectorp (aref (nth 2 composition) 0))) | |
7fb0741b | 586 | (progn |
b2c6a479 KH |
587 | (insert " using this font:\n " |
588 | (aref (query-font (aref (aref (nth 2 composition) 0) 0)) | |
589 | 0) | |
590 | "\nby these glyphs:\n") | |
3f8b1daa KH |
591 | (mapc (lambda (x) (insert (format " %S\n" x))) |
592 | (nth 2 composition))) | |
593 | (insert " by the rule:\n\t(" | |
594 | (mapconcat (lambda (x) | |
595 | (if (consp x) (format "%S" x) | |
596 | (if (= x ?\t) | |
597 | (single-key-description x) | |
598 | (string ?? x)))) | |
599 | (nth 2 composition) | |
600 | " ") | |
601 | ")") | |
602 | (insert "\nThe component character(s) are displayed by ") | |
603 | (if (display-graphic-p (selected-frame)) | |
604 | (progn | |
605 | (insert "these fonts (glyph codes):") | |
606 | (dolist (elt component-chars) | |
607 | (if (/= (car elt) ?\t) | |
608 | (insert "\n " (car elt) ?: | |
609 | (propertize " " 'display '(space :align-to 5)) | |
610 | (if (cdr elt) | |
e463f071 | 611 | (format "%s (#x%s)" (cadr elt) (cddr elt)) |
3f8b1daa KH |
612 | "-- no font --"))))) |
613 | (insert "these terminal codes:") | |
614 | (dolist (elt component-chars) | |
615 | (insert "\n " (car elt) ":" | |
616 | (propertize " " 'display '(space :align-to 4)) | |
617 | (or (cdr elt) "-- not encodable --")))) | |
618 | (insert "\nSee the variable `reference-point-alist' for " | |
619 | "the meaning of the rule.\n"))) | |
3a73f428 | 620 | |
3253c7c6 SM |
621 | (insert (if (not describe-char-unidata-list) |
622 | "\nCharacter code properties are not shown: " | |
623 | "\nCharacter code properties: ")) | |
3424774b KH |
624 | (insert-text-button |
625 | "customize what to show" | |
626 | 'action (lambda (&rest ignore) | |
627 | (customize-variable | |
628 | 'describe-char-unidata-list))) | |
f1f194de | 629 | (insert "\n") |
3253c7c6 | 630 | (dolist (elt (if (eq describe-char-unidata-list t) |
95eede5c | 631 | (nreverse (mapcar 'car char-code-property-alist)) |
3253c7c6 | 632 | describe-char-unidata-list)) |
f1f194de KH |
633 | (let ((val (get-char-code-property char elt)) |
634 | description) | |
635 | (when val | |
636 | (setq description (char-code-property-description elt val)) | |
3253c7c6 SM |
637 | (insert (if description |
638 | (format " %s: %s (%s)\n" elt val description) | |
639 | (format " %s: %s\n" elt val)))))) | |
f1f194de | 640 | |
25a3c9d1 | 641 | (if text-props-desc (insert text-props-desc)) |
2fd54bf8 | 642 | (setq help-xref-stack-item (list 'help-insert-string (buffer-string))) |
3db0e8bf | 643 | (toggle-read-only 1))))) |
4adb7c09 | 644 | |
781424c2 | 645 | (define-obsolete-function-alias 'describe-char-after 'describe-char "22.1") |
831ccfa6 | 646 | |
288395a7 CW |
647 | (provide 'descr-text) |
648 | ||
d8ac3d27 | 649 | ;; arch-tag: fc55a498-f3e9-4312-b5bd-98cc02480af1 |
2a1e884e | 650 | ;;; descr-text.el ends here |