]> code.delx.au - gnu-emacs/blob - lisp/international/mule-diag.el
(describe-character-set): Pay attention to charsets that don't have
[gnu-emacs] / lisp / international / mule-diag.el
1 ;;; mule-diag.el --- Show diagnosis of multilingual environment (Mule)
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5
6 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
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 ;;; General utility function
26
27 ;; Print all arguments with single space separator in one line.
28 (defun print-list (&rest args)
29 (while (cdr args)
30 (when (car args)
31 (princ (car args))
32 (princ " "))
33 (setq args (cdr args)))
34 (princ (car args))
35 (princ "\n"))
36
37 ;; Re-order the elements of charset-list.
38 (defun sort-charset-list ()
39 (setq charset-list
40 (sort charset-list
41 (function (lambda (x y) (< (charset-id x) (charset-id y)))))))
42
43 ;;; CHARSET
44
45 ;;;###autoload
46 (defun list-character-sets (arg)
47 "Display a list of all character sets.
48
49 The ID-NUM column contains a charset identification number
50 for internal Emacs use.
51
52 The MULTIBYTE-FORM column contains a format of multibyte sequence
53 of characters in the charset for buffer and string
54 by one to four hexadecimal digits.
55 `xx' stands for any byte in the range 0..127.
56 `XX' stands for any byte in the range 160..255.
57
58 The D column contains a dimension of this character set.
59 The CH column contains a number of characters in a block of this character set.
60 The FINAL-CHAR column contains an ISO-2022's <final-char> to use for
61 designating this character set in ISO-2022-based coding systems.
62
63 With prefix arg, the output format gets more cryptic,
64 but still shows the full information."
65 (interactive "P")
66 (with-output-to-temp-buffer "*Help*"
67 (with-current-buffer standard-output
68 (if arg
69 (list-character-sets-2)
70 ;; Insert header.
71 (insert
72 (substitute-command-keys
73 (concat "Use "
74 (if (display-mouse-p) "\\[help-follow-mouse] or ")
75 "\\[help-follow]:\n")))
76 (insert " on a column title to sort by that title,")
77 (indent-to 56)
78 (insert "+----DIMENSION\n")
79 (insert " on a charset name to list characters.")
80 (indent-to 56)
81 (insert "| +--CHARS\n")
82 (let ((columns '(("ID-NUM" . id) "\t"
83 ("CHARSET-NAME" . name) "\t\t\t"
84 ("MULTIBYTE-FORM" . id) "\t"
85 ("D CH FINAL-CHAR" . iso-spec)))
86 (help-highlight-face 'region)
87 (help-echo
88 (substitute-command-keys
89 (concat (if (display-mouse-p) "\\[help-follow-mouse], ")
90 "\\[help-follow]: sort on this column")))
91 pos)
92 (while columns
93 (if (stringp (car columns))
94 (insert (car columns))
95 (insert (car (car columns)))
96 (search-backward (car (car columns)))
97 (help-xref-button 0 'sort-listed-character-sets
98 (cdr (car columns))
99 help-echo)
100 (goto-char (point-max)))
101 (setq columns (cdr columns)))
102 (insert "\n"))
103 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
104
105 ;; Insert body sorted by charset IDs.
106 (list-character-sets-1 'id)
107 (help-setup-xref (list #'list-character-sets arg) (interactive-p))))))
108
109
110 ;; Sort character set list by SORT-KEY.
111
112 (defun sort-listed-character-sets (sort-key)
113 (if sort-key
114 (save-excursion
115 (let ((buffer-read-only nil))
116 (goto-char (point-min))
117 (re-search-forward "[0-9][0-9][0-9]")
118 (beginning-of-line)
119 (delete-region (point) (point-max))
120 (list-character-sets-1 sort-key)
121 (help-setup-xref (list #'list-character-sets nil) t)))))
122
123 (defun charset-multibyte-form-string (charset)
124 (let ((info (charset-info charset)))
125 (cond ((eq charset 'ascii)
126 "xx")
127 ((eq charset 'eight-bit-control)
128 (format "%2X Xx" (aref info 6)))
129 ((eq charset 'eight-bit-graphic)
130 "XX")
131 (t
132 (let ((str (format "%2X" (aref info 6))))
133 (if (> (aref info 7) 0)
134 (setq str (format "%s %2X"
135 str (aref info 7))))
136 (setq str (concat str " XX"))
137 (if (> (aref info 2) 1)
138 (setq str (concat str " XX")))
139 str)))))
140
141 ;; Insert a list of character sets sorted by SORT-KEY. SORT-KEY
142 ;; should be one of `id', `name', and `iso-spec'. If SORT-KEY is nil,
143 ;; it defaults to `id'.
144
145 (defun list-character-sets-1 (sort-key)
146 (or sort-key
147 (setq sort-key 'id))
148 (let ((tail (charset-list))
149 (help-echo
150 (substitute-command-keys
151 (concat (if (display-mouse-p) "\\[help-follow-mouse], ")
152 "\\[help-follow]: show table of this character set")))
153 charset-info-list elt charset info sort-func)
154 (while tail
155 (setq charset (car tail) tail (cdr tail)
156 info (charset-info charset))
157
158 ;; Generate a list that contains all information to display.
159 (setq charset-info-list
160 (cons (list (charset-id charset) ; ID-NUM
161 charset ; CHARSET-NAME
162 (charset-multibyte-form-string charset); MULTIBYTE-FORM
163 (aref info 2) ; DIMENSION
164 (aref info 3) ; CHARS
165 (aref info 8) ; FINAL-CHAR
166 )
167 charset-info-list)))
168
169 ;; Determine a predicate for `sort' by SORT-KEY.
170 (setq sort-func
171 (cond ((eq sort-key 'id)
172 (function (lambda (x y) (< (car x) (car y)))))
173
174 ((eq sort-key 'name)
175 (function (lambda (x y) (string< (nth 1 x) (nth 1 y)))))
176
177 ((eq sort-key 'iso-spec)
178 ;; Sort by DIMENSION CHARS FINAL-CHAR
179 (function
180 (lambda (x y)
181 (or (< (nth 3 x) (nth 3 y))
182 (and (= (nth 3 x) (nth 3 y))
183 (or (< (nth 4 x) (nth 4 y))
184 (and (= (nth 4 x) (nth 4 y))
185 (< (nth 5 x) (nth 5 y)))))))))
186 (t
187 (error "Invalid charset sort key: %s" sort-key))))
188
189 (setq charset-info-list (sort charset-info-list sort-func))
190
191 ;; Insert information of character sets.
192 (while charset-info-list
193 (setq elt (car charset-info-list)
194 charset-info-list (cdr charset-info-list))
195 (insert (format "%03d(%02X)" (car elt) (car elt))) ; ID-NUM
196 (indent-to 8)
197 (insert (symbol-name (nth 1 elt))) ; CHARSET-NAME
198 (search-backward (symbol-name (nth 1 elt)))
199 (help-xref-button 0 'list-charset-chars (nth 1 elt) help-echo)
200 (goto-char (point-max))
201 (insert "\t")
202 (indent-to 40)
203 (insert (nth 2 elt)) ; MULTIBYTE-FORM
204 (indent-to 56)
205 (insert (format "%d %2d " (nth 3 elt) (nth 4 elt)) ; DIMENSION and CHARS
206 (if (< (nth 5 elt) 0) "none" (nth 5 elt))) ; FINAL-CHAR
207 (insert "\n"))))
208
209
210 ;; List all character sets in a form that a program can easily parse.
211
212 (defun list-character-sets-2 ()
213 (insert "#########################
214 ## LIST OF CHARSETS
215 ## Each line corresponds to one charset.
216 ## The following attributes are listed in this order
217 ## separated by a colon `:' in one line.
218 ## CHARSET-ID,
219 ## CHARSET-SYMBOL-NAME,
220 ## DIMENSION (1 or 2)
221 ## CHARS (94 or 96)
222 ## BYTES (of multibyte form: 1, 2, 3, or 4),
223 ## WIDTH (occupied column numbers: 1 or 2),
224 ## DIRECTION (0:left-to-right, 1:right-to-left),
225 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
226 ## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
227 ## DESCRIPTION (describing string of the charset)
228 ")
229 (let ((l charset-list)
230 charset)
231 (while l
232 (setq charset (car l) l (cdr l))
233 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
234 (charset-id charset)
235 charset
236 (charset-dimension charset)
237 (charset-chars charset)
238 (charset-bytes charset)
239 (charset-width charset)
240 (charset-direction charset)
241 (charset-iso-final-char charset)
242 (charset-iso-graphic-plane charset)
243 (charset-description charset))))))
244
245 (defvar non-iso-charset-alist
246 `((viscii
247 (ascii vietnamese-viscii-lower vietnamese-viscii-upper)
248 viet-viscii-nonascii-translation-table
249 ((0 255)))
250 (koi8-r
251 (ascii cyrillic-iso8859-5)
252 cyrillic-koi8-r-nonascii-translation-table
253 ((32 255)))
254 (alternativnyj
255 (ascii cyrillic-iso8859-5)
256 cyrillic-alternativnyj-nonascii-translation-table
257 ((32 255)))
258 (big5
259 (ascii chinese-big5-1 chinese-big5-2)
260 decode-big5-char
261 ((32 127)
262 ((?\xA1 ?\xFE) . (?\x40 ?\x7E ?\xA1 ?\xFE))))
263 (sjis
264 (ascii katakana-jisx0201 japanese-jisx0208)
265 decode-sjis-char
266 ((32 127 ?\xA1 ?\xDF)
267 ((?\x81 ?\x9F ?\xE0 ?\xEF) . (?\x40 ?\x7E ?\x80 ?\xFC)))))
268 "Alist of non-ISO charset names vs the corresponding information.
269
270 Non-ISO charsets are what Emacs can read (or write) by mapping to (or
271 from) some Emacs' charsets that correspond to ISO charsets.
272
273 Each element has the following format:
274 (NON-ISO-CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
275
276 NON-ISO-CHARSET is a name (symbol) of the non-ISO charset.
277
278 CHARSET-LIST is a list of Emacs' charsets into which characters of
279 NON-ISO-CHARSET are mapped.
280
281 TRANSLATION-METHOD is a translation table (symbol) to translate a
282 character code of NON-ISO-CHARSET to the corresponding Emacs character
283 code. It can also be a function to call with one argument, a
284 character code in NON-ISO-CHARSET.
285
286 CODE-RANGE specifies the valid code ranges of NON-ISO-CHARSET.
287 It is a list of RANGEs, where each RANGE is of the form:
288 (FROM1 TO1 FROM2 TO2 ...)
289 or
290 ((FROM1-1 TO1-1 FROM1-2 TO1-2 ...) . (FROM2-1 TO2-1 FROM2-2 TO2-2 ...))
291 In the first form, valid codes are between FROM1 and TO1, or FROM2 and
292 TO2, or...
293 The second form is used for 2-byte codes. The car part is the ranges
294 of the first byte, and the cdr part is the ranges of the second byte.")
295
296
297 ;; Decode a character that has code CODE in CODEPAGE. Value is a
298 ;; string of decoded character.
299
300 (defun decode-codepage-char (codepage code)
301 ;; Each CODEPAGE corresponds to a coding system cpCODEPAGE.
302 (let ((coding-system (intern (format "cp%d" codepage))))
303 (or (coding-system-p coding-system)
304 (codepage-setup codepage))
305 (string-to-char
306 (decode-coding-string (char-to-string code) coding-system))))
307
308
309 ;; Add DOS codepages to `non-iso-charset-alist'.
310
311 (let ((tail (cp-supported-codepages))
312 elt)
313 (while tail
314 (setq elt (car tail) tail (cdr tail))
315 ;; Now ELT is (CODEPAGE . CHARSET), where CODEPAGE is a string
316 ;; (e.g. "850"), CHARSET is a charset that characters in CODEPAGE
317 ;; are mapped to.
318 (setq non-iso-charset-alist
319 (cons (list (intern (concat "cp" (car elt)))
320 (list 'ascii (cdr elt))
321 `(lambda (code)
322 (decode-codepage-char ,(string-to-int (car elt))
323 code))
324 (list (list 0 255)))
325 non-iso-charset-alist))))
326
327
328 ;; A variable to hold charset input history.
329 (defvar charset-history nil)
330
331
332 ;;;###autoload
333 (defun read-charset (prompt &optional default-value initial-input)
334 "Read a character set from the minibuffer, prompting with string PROMPT.
335 It reads an Emacs' character set listed in the variable `charset-list'
336 or a non-ISO character set listed in the variable
337 `non-iso-charset-alist'.
338
339 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
340 DEFAULT-VALUE, if non-nil, is the default value.
341 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
342 See the documentation of the function `completing-read' for the
343 detailed meanings of these arguments."
344 (let* ((table (append (mapcar (function (lambda (x) (list (symbol-name x))))
345 charset-list)
346 (mapcar (function (lambda (x)
347 (list (symbol-name (car x)))))
348 non-iso-charset-alist)))
349 (charset (completing-read prompt table
350 nil t initial-input 'charset-history
351 default-value)))
352 (if (> (length charset) 0)
353 (intern charset))))
354
355
356 ;; List characters of the range MIN and MAX of CHARSET. If dimension
357 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
358 ;; (block index) of the characters, and MIN and MAX are the second
359 ;; bytes of the characters. If the dimension is one, ROW should be 0.
360 ;; For a non-ISO charset, CHARSET is a translation table (symbol) or a
361 ;; function to get Emacs' character codes that corresponds to the
362 ;; characters to list.
363
364 (defun list-block-of-chars (charset row min max)
365 (let (i ch)
366 (insert-char ?- (+ 4 (* 3 16)))
367 (insert "\n ")
368 (setq i 0)
369 (while (< i 16)
370 (insert (format "%3X" i))
371 (setq i (1+ i)))
372 (setq i (* (/ min 16) 16))
373 (while (<= i max)
374 (if (= (% i 16) 0)
375 (insert (format "\n%3Xx" (/ (+ (* row 256) i) 16))))
376 (setq ch (cond ((< i min)
377 32)
378 ((charsetp charset)
379 (if (= row 0)
380 (make-char charset i)
381 (make-char charset row i)))
382 ((and (symbolp charset) (get charset 'translation-table))
383 (aref (get charset 'translation-table) i))
384 (t (funcall charset (+ (* row 256) i)))))
385 (if (and (char-table-p charset)
386 (or (< ch 32) (and (>= ch 127) (<= ch 255))))
387 ;; Don't insert a control code.
388 (setq ch 32))
389 (indent-to (+ (* (% i 16) 3) 6))
390 (insert ch)
391 (setq i (1+ i))))
392 (insert "\n"))
393
394
395 ;; List all characters in ISO charset CHARSET.
396
397 (defun list-iso-charset-chars (charset)
398 (let ((dim (charset-dimension charset))
399 (chars (charset-chars charset))
400 (plane (charset-iso-graphic-plane charset))
401 min max)
402 (insert (format "Characters in the charset %s.\n" charset))
403
404 (cond ((eq charset 'eight-bit-control)
405 (setq min 128 max 159))
406 ((eq charset 'eight-bit-graphic)
407 (setq min 160 max 255))
408 (t
409 (if (= chars 94)
410 (setq min 33 max 126)
411 (setq min 32 max 127))
412 (or (= plane 0)
413 (setq min (+ min 128) max (+ max 128)))))
414
415 (if (= dim 1)
416 (list-block-of-chars charset 0 min max)
417 (let ((i min))
418 (while (<= i max)
419 (list-block-of-chars charset i min max)
420 (setq i (1+ i)))))))
421
422
423 ;; List all characters in non-ISO charset CHARSET.
424
425 (defun list-non-iso-charset-chars (charset)
426 (let* ((slot (assq charset non-iso-charset-alist))
427 (charsets (nth 1 slot))
428 (translate-method (nth 2 slot))
429 (ranges (nth 3 slot))
430 range)
431 (or slot
432 (error "Unknown external charset: %s" charset))
433 (insert (format "Characters in non-ISO charset %s.\n" charset))
434 (insert "They are mapped to: "
435 (mapconcat #'symbol-name charsets ", ")
436 "\n")
437 (while ranges
438 (setq range (car ranges) ranges (cdr ranges))
439 (if (integerp (car range))
440 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
441 (while range
442 (list-block-of-chars translate-method
443 0 (car range) (nth 1 range))
444 (setq range (nthcdr 2 range)))
445 ;; The form of RANGES is ((FROM1-1 TO1-1 ...) . (FROM2-1 TO2-1 ...)).
446 (let ((row-range (car range))
447 row row-max
448 col-range col col-max)
449 (while row-range
450 (setq row (car row-range) row-max (nth 1 row-range)
451 row-range (nthcdr 2 row-range))
452 (while (<= row row-max)
453 (setq col-range (cdr range))
454 (while col-range
455 (setq col (car col-range) col-max (nth 1 col-range)
456 col-range (nthcdr 2 col-range))
457 (list-block-of-chars translate-method row col col-max))
458 (setq row (1+ row)))))))))
459
460
461 ;;;###autoload
462 (defun list-charset-chars (charset)
463 "Display a list of characters in the specified character set."
464 (interactive (list (read-charset "Character set: ")))
465 (with-output-to-temp-buffer "*Help*"
466 (with-current-buffer standard-output
467 (set-buffer-multibyte t)
468 (cond ((charsetp charset)
469 (list-iso-charset-chars charset))
470 ((assq charset non-iso-charset-alist)
471 (list-non-iso-charset-chars charset))
472 (t
473 (error "Invalid charset %s" charset))))))
474
475
476 ;;;###autoload
477 (defun describe-character-set (charset)
478 "Display information about character set CHARSET."
479 (interactive (list (let ((non-iso-charset-alist nil))
480 (read-charset "Charset: "))))
481 (or (charsetp charset)
482 (error "Invalid charset: %S" charset))
483 (let ((info (charset-info charset)))
484 (with-output-to-temp-buffer "*Help*"
485 (save-excursion
486 (set-buffer standard-output)
487 (insert "Character set: " (symbol-name charset)
488 (format " (ID:%d)\n\n" (aref info 0)))
489 (insert (aref info 13) "\n\n") ; description
490 (insert "number of contained characters: "
491 (if (= (aref info 2) 1)
492 (format "%d\n" (aref info 3))
493 (format "%dx%d\n" (aref info 3) (aref info 3))))
494 (insert "the final char of ISO2022's designation sequence: ")
495 (if (>= (aref info 8) 0)
496 (insert (format "`%c'\n" (aref info 8)))
497 (insert "not assigned\n"))
498 (insert (format "width (how many columns on screen): %d\n"
499 (aref info 4)))
500 (insert (format "internal multibyte sequence: %s\n"
501 (charset-multibyte-form-string charset)))
502 (let ((coding (plist-get (aref info 14) 'preferred-coding-system)))
503 (when coding
504 (insert (format "preferred coding system: %s\n" coding))
505 (search-backward (symbol-name coding))
506 (help-xref-button 0 #'describe-coding-system coding
507 "mouse-2, RET: describe this coding system")))
508 (help-setup-xref (list #'describe-character-set charset)
509 (interactive-p))
510 ))))
511
512 ;;;###autoload
513 (defun describe-char-after (&optional pos)
514 "Display information about the character at POS in the current buffer.
515 POS defaults to point.
516 The information includes character code, charset and code points in it,
517 syntax, category, how the character is encoded in a file,
518 which font is being used for displaying the character."
519 (interactive)
520 (or pos
521 (setq pos (point)))
522 (if (>= pos (point-max))
523 (error "No character at point"))
524 (let* ((char (char-after pos))
525 (charset (char-charset char))
526 (composition (find-composition (point) nil nil t))
527 (composed (if composition (buffer-substring (car composition)
528 (nth 1 composition))))
529 (multibyte-p enable-multibyte-characters)
530 item-list max-width)
531 (if (eq charset 'unknown)
532 (setq item-list
533 `(("character"
534 ,(format "%s (0%o, %d, 0x%x) -- invalid character code"
535 (if (< char 256)
536 (single-key-description char)
537 (char-to-string char))
538 char char char))))
539 (setq item-list
540 `(("character"
541 ,(format "%s (0%o, %d, 0x%x)" (if (< char 256)
542 (single-key-description char)
543 (char-to-string char))
544 char char char))
545 ("charset"
546 ,(symbol-name charset)
547 ,(format "(%s)" (charset-description charset)))
548 ("code point"
549 ,(let ((split (split-char char)))
550 (if (= (charset-dimension charset) 1)
551 (format "%d" (nth 1 split))
552 (format "%d %d" (nth 1 split) (nth 2 split)))))
553 ("syntax"
554 ,(nth 2 (assq (char-syntax char) syntax-code-table)))
555 ("category"
556 ,@(let ((category-set (char-category-set char)))
557 (if (not category-set)
558 '("-- none --")
559 (mapcar #'(lambda (x) (format "%c:%s "
560 x (category-docstring x)))
561 (category-set-mnemonics category-set)))))
562 ("buffer code"
563 ,(encoded-string-description
564 (string-as-unibyte (char-to-string char)) nil))
565 ("file code"
566 ,@(let* ((coding buffer-file-coding-system)
567 (encoded (encode-coding-char char coding)))
568 (if encoded
569 (list (encoded-string-description encoded coding)
570 (format "(encoded by coding system %S)" coding))
571 (list "not encodable by coding system"
572 (symbol-name coding)))))
573 ,(if (display-graphic-p (selected-frame))
574 (list "font" (or (internal-char-font (point))
575 "-- none --"))
576 (list "terminal code"
577 (let* ((coding (terminal-coding-system))
578 (encoded (encode-coding-char char coding)))
579 (if encoded
580 (encoded-string-description encoded coding)
581 "not encodable")))))))
582 (setq max-width (apply #'max (mapcar #'(lambda (x) (length (car x)))
583 item-list)))
584 (with-output-to-temp-buffer "*Help*"
585 (save-excursion
586 (set-buffer standard-output)
587 (set-buffer-multibyte multibyte-p)
588 (let ((formatter (format "%%%ds:" max-width)))
589 (dolist (elt item-list)
590 (insert (format formatter (car elt)))
591 (dolist (clm (cdr elt))
592 (when (>= (+ (current-column) (string-width clm) 1)
593 (frame-width))
594 (insert "\n")
595 (indent-to (1+ max-width)))
596 (insert " " clm))
597 (insert "\n")))
598 (when composition
599 (insert "\nComposed with the following character(s) "
600 (mapconcat (lambda (x) (format "`%c'" x))
601 (substring composed 1)
602 ", ")
603 " to form `" composed "'")
604 (if (nth 3 composition)
605 (insert ".\n")
606 (insert "\nby the rule ("
607 (mapconcat (lambda (x)
608 (format (if (consp x) "%S" "?%c") x))
609 (nth 2 composition)
610 " ")
611 ").\n"
612 "See the variable `reference-point-alist' for the meaning of the rule.\n")))
613 ))))
614
615 \f
616 ;;; CODING-SYSTEM
617
618 ;; Print information of designation of each graphic register in FLAGS
619 ;; in human readable format. See the documentation of
620 ;; `make-coding-system' for the meaning of FLAGS.
621 (defun print-designation (flags)
622 (let ((graphic-register 0)
623 charset)
624 (while (< graphic-register 4)
625 (setq charset (aref flags graphic-register))
626 (princ (format
627 " G%d -- %s\n"
628 graphic-register
629 (cond ((null charset)
630 "never used")
631 ((eq charset t)
632 "no initial designation, and used by any charsets")
633 ((symbolp charset)
634 (format "%s:%s"
635 charset (charset-description charset)))
636 ((listp charset)
637 (if (charsetp (car charset))
638 (format "%s:%s, and also used by the followings:"
639 (car charset)
640 (charset-description (car charset)))
641 "no initial designation, and used by the followings:"))
642 (t
643 "invalid designation information"))))
644 (when (listp charset)
645 (setq charset (cdr charset))
646 (while charset
647 (cond ((eq (car charset) t)
648 (princ "\tany other charsets\n"))
649 ((charsetp (car charset))
650 (princ (format "\t%s:%s\n"
651 (car charset)
652 (charset-description (car charset)))))
653 (t
654 "invalid designation information"))
655 (setq charset (cdr charset))))
656 (setq graphic-register (1+ graphic-register)))))
657
658 ;;;###autoload
659 (defun describe-coding-system (coding-system)
660 "Display information about CODING-SYSTEM."
661 (interactive "zDescribe coding system (default, current choices): ")
662 (if (null coding-system)
663 (describe-current-coding-system)
664 (with-output-to-temp-buffer "*Help*"
665 (print-coding-system-briefly coding-system 'doc-string)
666 (let ((coding-spec (coding-system-spec coding-system)))
667 (princ "Type: ")
668 (let ((type (coding-system-type coding-system))
669 (flags (coding-system-flags coding-system)))
670 (princ type)
671 (cond ((eq type nil)
672 (princ " (do no conversion)"))
673 ((eq type t)
674 (princ " (do automatic conversion)"))
675 ((eq type 0)
676 (princ " (Emacs internal multibyte form)"))
677 ((eq type 1)
678 (princ " (Shift-JIS, MS-KANJI)"))
679 ((eq type 2)
680 (princ " (variant of ISO-2022)\n")
681 (princ "Initial designations:\n")
682 (print-designation flags)
683 (princ "Other Form: \n ")
684 (princ (if (aref flags 4) "short-form" "long-form"))
685 (if (aref flags 5) (princ ", ASCII@EOL"))
686 (if (aref flags 6) (princ ", ASCII@CNTL"))
687 (princ (if (aref flags 7) ", 7-bit" ", 8-bit"))
688 (if (aref flags 8) (princ ", use-locking-shift"))
689 (if (aref flags 9) (princ ", use-single-shift"))
690 (if (aref flags 10) (princ ", use-roman"))
691 (if (aref flags 11) (princ ", use-old-jis"))
692 (if (aref flags 12) (princ ", no-ISO6429"))
693 (if (aref flags 13) (princ ", init-bol"))
694 (if (aref flags 14) (princ ", designation-bol"))
695 (if (aref flags 15) (princ ", convert-unsafe"))
696 (if (aref flags 16) (princ ", accept-latin-extra-code"))
697 (princ "."))
698 ((eq type 3)
699 (princ " (Big5)"))
700 ((eq type 4)
701 (princ " (do conversion by CCL program)"))
702 ((eq type 5)
703 (princ " (text with random binary characters)"))
704 (t (princ ": invalid coding-system."))))
705 (princ "\nEOL type: ")
706 (let ((eol-type (coding-system-eol-type coding-system)))
707 (cond ((vectorp eol-type)
708 (princ "Automatic selection from:\n\t")
709 (princ eol-type)
710 (princ "\n"))
711 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n"))
712 ((eq eol-type 1) (princ "CRLF\n"))
713 ((eq eol-type 2) (princ "CR\n"))
714 (t (princ "invalid\n")))))
715 (let ((postread (coding-system-get coding-system 'post-read-conversion)))
716 (when postread
717 (princ "After decoding text normally,")
718 (princ " perform post-conversion using the function: ")
719 (princ "\n ")
720 (princ postread)
721 (princ "\n")))
722 (let ((prewrite (coding-system-get coding-system 'pre-write-conversion)))
723 (when prewrite
724 (princ "Before encoding text normally,")
725 (princ " perform pre-conversion using the function: ")
726 (princ "\n ")
727 (princ prewrite)
728 (princ "\n")))
729 (save-excursion
730 (set-buffer standard-output)
731 (let ((charsets (coding-system-get coding-system 'safe-charsets)))
732 (when charsets
733 (if (eq charsets t)
734 (insert "This coding system can encode all charsets.\n")
735 (insert "This coding system encodes the following charsets:\n ")
736 (while charsets
737 (insert " " (symbol-name (car charsets)))
738 (search-backward (symbol-name (car charsets)))
739 (help-xref-button 0 #'describe-character-set (car charsets))
740 (goto-char (point-max))
741 (setq charsets (cdr charsets))))))
742 (help-setup-xref (list #'describe-coding-system coding-system)
743 (interactive-p))))))
744
745
746 ;;;###autoload
747 (defun describe-current-coding-system-briefly ()
748 "Display coding systems currently used in a brief format in echo area.
749
750 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
751 where mnemonics of the following coding systems come in this order
752 at the place of `..':
753 `buffer-file-coding-system' (of the current buffer)
754 eol-type of `buffer-file-coding-system' (of the current buffer)
755 Value returned by `keyboard-coding-system'
756 eol-type of `keyboard-coding-system'
757 Value returned by `terminal-coding-system'.
758 eol-type of `terminal-coding-system'
759 `process-coding-system' for read (of the current buffer, if any)
760 eol-type of `process-coding-system' for read (of the current buffer, if any)
761 `process-coding-system' for write (of the current buffer, if any)
762 eol-type of `process-coding-system' for write (of the current buffer, if any)
763 `default-buffer-file-coding-system'
764 eol-type of `default-buffer-file-coding-system'
765 `default-process-coding-system' for read
766 eol-type of `default-process-coding-system' for read
767 `default-process-coding-system' for write
768 eol-type of `default-process-coding-system'"
769 (interactive)
770 (let* ((proc (get-buffer-process (current-buffer)))
771 (process-coding-systems (if proc (process-coding-system proc))))
772 (message
773 "F[%c%s],K[%c%s],T[%c%s],P>[%c%s],P<[%c%s], default F[%c%s],P>[%c%s],P<[%c%s]"
774 (coding-system-mnemonic buffer-file-coding-system)
775 (coding-system-eol-type-mnemonic buffer-file-coding-system)
776 (coding-system-mnemonic (keyboard-coding-system))
777 (coding-system-eol-type-mnemonic (keyboard-coding-system))
778 (coding-system-mnemonic (terminal-coding-system))
779 (coding-system-eol-type-mnemonic (terminal-coding-system))
780 (coding-system-mnemonic (car process-coding-systems))
781 (coding-system-eol-type-mnemonic (car process-coding-systems))
782 (coding-system-mnemonic (cdr process-coding-systems))
783 (coding-system-eol-type-mnemonic (cdr process-coding-systems))
784 (coding-system-mnemonic default-buffer-file-coding-system)
785 (coding-system-eol-type-mnemonic default-buffer-file-coding-system)
786 (coding-system-mnemonic (car default-process-coding-system))
787 (coding-system-eol-type-mnemonic (car default-process-coding-system))
788 (coding-system-mnemonic (cdr default-process-coding-system))
789 (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
790 )))
791
792 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
793 (defun print-coding-system-briefly (coding-system &optional doc-string)
794 (if (not coding-system)
795 (princ "nil\n")
796 (princ (format "%c -- %s"
797 (coding-system-mnemonic coding-system)
798 coding-system))
799 (let ((aliases (coding-system-get coding-system 'alias-coding-systems)))
800 (if (eq coding-system (car aliases))
801 (if (cdr aliases)
802 (princ (format " %S" (cons 'alias: (cdr aliases)))))
803 (if (memq coding-system aliases)
804 (princ (format " (alias of %s)" (car aliases))))))
805 (princ "\n")
806 (if (and doc-string
807 (setq doc-string (coding-system-doc-string coding-system)))
808 (princ (format " %s\n" doc-string)))))
809
810 ;;;###autoload
811 (defun describe-current-coding-system ()
812 "Display coding systems currently used, in detail."
813 (interactive)
814 (with-output-to-temp-buffer "*Help*"
815 (let* ((proc (get-buffer-process (current-buffer)))
816 (process-coding-systems (if proc (process-coding-system proc))))
817 (princ "Coding system for saving this buffer:\n ")
818 (if (local-variable-p 'buffer-file-coding-system)
819 (print-coding-system-briefly buffer-file-coding-system)
820 (princ "Not set locally, use the default.\n"))
821 (princ "Default coding system (for new files):\n ")
822 (print-coding-system-briefly default-buffer-file-coding-system)
823 (princ "Coding system for keyboard input:\n ")
824 (print-coding-system-briefly (keyboard-coding-system))
825 (princ "Coding system for terminal output:\n ")
826 (print-coding-system-briefly (terminal-coding-system))
827 (when (get-buffer-process (current-buffer))
828 (princ "Coding systems for process I/O:\n")
829 (princ " encoding input to the process: ")
830 (print-coding-system-briefly (cdr process-coding-systems))
831 (princ " decoding output from the process: ")
832 (print-coding-system-briefly (car process-coding-systems)))
833 (princ "Defaults for subprocess I/O:\n")
834 (princ " decoding: ")
835 (print-coding-system-briefly (car default-process-coding-system))
836 (princ " encoding: ")
837 (print-coding-system-briefly (cdr default-process-coding-system)))
838
839 (save-excursion
840 (set-buffer standard-output)
841
842 (princ "\nPriority order for recognizing coding systems when reading files:\n")
843 (let ((l coding-category-list)
844 (i 1)
845 (coding-list nil)
846 coding aliases)
847 (while l
848 (setq coding (symbol-value (car l)))
849 ;; Do not list up the same coding system twice.
850 (when (and coding (not (memq coding coding-list)))
851 (setq coding-list (cons coding coding-list))
852 (princ (format " %d. %s " i coding))
853 (setq aliases (coding-system-get coding 'alias-coding-systems))
854 (if (eq coding (car aliases))
855 (if (cdr aliases)
856 (princ (cons 'alias: (cdr aliases))))
857 (if (memq coding aliases)
858 (princ (list 'alias 'of (car aliases)))))
859 (terpri)
860 (setq i (1+ i)))
861 (setq l (cdr l))))
862
863 (princ "\n Other coding systems cannot be distinguished automatically
864 from these, and therefore cannot be recognized automatically
865 with the present coding system priorities.\n\n")
866
867 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else))
868 coding-system codings)
869 (while categories
870 (setq coding-system (symbol-value (car categories)))
871 (mapcar
872 (function
873 (lambda (x)
874 (if (and (not (eq x coding-system))
875 (coding-system-get x 'no-initial-designation)
876 (let ((flags (coding-system-flags x)))
877 (not (or (aref flags 10) (aref flags 11)))))
878 (setq codings (cons x codings)))))
879 (get (car categories) 'coding-systems))
880 (if codings
881 (let ((max-col (frame-width))
882 pos)
883 (princ (format " The followings are decoded correctly but recognized as %s:\n " coding-system))
884 (while codings
885 (setq pos (point))
886 (insert (format " %s" (car codings)))
887 (when (> (current-column) max-col)
888 (goto-char pos)
889 (insert "\n ")
890 (goto-char (point-max)))
891 (setq codings (cdr codings)))
892 (insert "\n\n")))
893 (setq categories (cdr categories))))
894
895 (princ "Particular coding systems specified for certain file names:\n")
896 (terpri)
897 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
898 (princ " ---------\t--------------\t\t----------------\n")
899 (let ((func (lambda (operation alist)
900 (princ " ")
901 (princ operation)
902 (if (not alist)
903 (princ "\tnothing specified\n")
904 (while alist
905 (indent-to 16)
906 (prin1 (car (car alist)))
907 (if (>= (current-column) 40)
908 (newline))
909 (indent-to 40)
910 (princ (cdr (car alist)))
911 (princ "\n")
912 (setq alist (cdr alist)))))))
913 (funcall func "File I/O" file-coding-system-alist)
914 (funcall func "Process I/O" process-coding-system-alist)
915 (funcall func "Network I/O" network-coding-system-alist))
916 (help-mode))))
917
918 ;; Print detailed information on CODING-SYSTEM.
919 (defun print-coding-system (coding-system)
920 (let ((type (coding-system-type coding-system))
921 (eol-type (coding-system-eol-type coding-system))
922 (flags (coding-system-flags coding-system))
923 (aliases (coding-system-get coding-system 'alias-coding-systems)))
924 (if (not (eq (car aliases) coding-system))
925 (princ (format "%s (alias of %s)\n" coding-system (car aliases)))
926 (princ coding-system)
927 (setq aliases (cdr aliases))
928 (while aliases
929 (princ ",")
930 (princ (car aliases))
931 (setq aliases (cdr aliases)))
932 (princ (format ":%s:%c:%d:"
933 type
934 (coding-system-mnemonic coding-system)
935 (if (integerp eol-type) eol-type 3)))
936 (cond ((eq type 2) ; ISO-2022
937 (let ((idx 0)
938 charset)
939 (while (< idx 4)
940 (setq charset (aref flags idx))
941 (cond ((null charset)
942 (princ -1))
943 ((eq charset t)
944 (princ -2))
945 ((charsetp charset)
946 (princ charset))
947 ((listp charset)
948 (princ "(")
949 (princ (car charset))
950 (setq charset (cdr charset))
951 (while charset
952 (princ ",")
953 (princ (car charset))
954 (setq charset (cdr charset)))
955 (princ ")")))
956 (princ ",")
957 (setq idx (1+ idx)))
958 (while (< idx 12)
959 (princ (if (aref flags idx) 1 0))
960 (princ ",")
961 (setq idx (1+ idx)))
962 (princ (if (aref flags idx) 1 0))))
963 ((eq type 4) ; CCL
964 (let (i len)
965 (if (symbolp (car flags))
966 (princ (format " %s" (car flags)))
967 (setq i 0 len (length (car flags)))
968 (while (< i len)
969 (princ (format " %x" (aref (car flags) i)))
970 (setq i (1+ i))))
971 (princ ",")
972 (if (symbolp (cdr flags))
973 (princ (format "%s" (cdr flags)))
974 (setq i 0 len (length (cdr flags)))
975 (while (< i len)
976 (princ (format " %x" (aref (cdr flags) i)))
977 (setq i (1+ i))))))
978 (t (princ 0)))
979 (princ ":")
980 (princ (coding-system-doc-string coding-system))
981 (princ "\n"))))
982
983 ;;;###autoload
984 (defun list-coding-systems (&optional arg)
985 "Display a list of all coding systems.
986 This shows the mnemonic letter, name, and description of each coding system.
987
988 With prefix arg, the output format gets more cryptic,
989 but still contains full information about each coding system."
990 (interactive "P")
991 (with-output-to-temp-buffer "*Help*"
992 (list-coding-systems-1 arg)))
993
994 (defun list-coding-systems-1 (arg)
995 (if (null arg)
996 (princ "\
997 ###############################################
998 # List of coding systems in the following format:
999 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
1000 # DOC-STRING
1001 ")
1002 (princ "\
1003 #########################
1004 ## LIST OF CODING SYSTEMS
1005 ## Each line corresponds to one coding system
1006 ## Format of a line is:
1007 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
1008 ## :PRE-WRITE-CONVERSION:DOC-STRING,
1009 ## where
1010 ## NAME = coding system name
1011 ## ALIAS = alias of the coding system
1012 ## TYPE = nil (no conversion), t (undecided or automatic detection),
1013 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
1014 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
1015 ## FLAGS =
1016 ## if TYPE = 2 then
1017 ## comma (`,') separated data of the followings:
1018 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
1019 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
1020 ## else if TYPE = 4 then
1021 ## comma (`,') separated CCL programs for read and write
1022 ## else
1023 ## 0
1024 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
1025 ##
1026 "))
1027 (let ((bases (coding-system-list 'base-only))
1028 coding-system)
1029 (while bases
1030 (setq coding-system (car bases))
1031 (if (null arg)
1032 (print-coding-system-briefly coding-system 'doc-string)
1033 (print-coding-system coding-system))
1034 (setq bases (cdr bases)))))
1035
1036 ;;;###autoload
1037 (defun list-coding-categories ()
1038 "Display a list of all coding categories."
1039 (with-output-to-temp-buffer "*Help*"
1040 (princ "\
1041 ############################
1042 ## LIST OF CODING CATEGORIES (ordered by priority)
1043 ## CATEGORY:CODING-SYSTEM
1044 ##
1045 ")
1046 (let ((l coding-category-list))
1047 (while l
1048 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
1049 (setq l (cdr l))))))
1050 \f
1051 ;;; FONT
1052
1053 ;; Print information of a font in FONTINFO.
1054 (defun describe-font-internal (font-info &optional verbose)
1055 (print-list "name (opened by):" (aref font-info 0))
1056 (print-list " full name:" (aref font-info 1))
1057 (print-list " size:" (format "%2d" (aref font-info 2)))
1058 (print-list " height:" (format "%2d" (aref font-info 3)))
1059 (print-list " baseline-offset:" (format "%2d" (aref font-info 4)))
1060 (print-list "relative-compose:" (format "%2d" (aref font-info 5))))
1061
1062 ;;;###autoload
1063 (defun describe-font (fontname)
1064 "Display information about fonts which partially match FONTNAME."
1065 (interactive "sFontname (default, current choice for ASCII chars): ")
1066 (or (and window-system (fboundp 'fontset-list))
1067 (error "No fontsets being used"))
1068 (when (or (not fontname) (= (length fontname) 0))
1069 (setq fontname (cdr (assq 'font (frame-parameters))))
1070 (if (query-fontset fontname)
1071 (setq fontname
1072 (nth 1 (assq 'ascii (aref (fontset-info fontname) 2))))))
1073 (let ((font-info (font-info fontname)))
1074 (if (null font-info)
1075 (message "No matching font")
1076 (with-output-to-temp-buffer "*Help*"
1077 (describe-font-internal font-info 'verbose)))))
1078
1079 ;; Print information of FONTSET. If optional arg PRINT-FONTS is
1080 ;; non-nil, print also names of all opened fonts for FONTSET. This
1081 ;; function actually INSERT such information in the current buffer.
1082 (defun print-fontset (fontset &optional print-fonts)
1083 (let ((tail (aref (fontset-info fontset) 2))
1084 elt chars font-spec opened prev-charset charset from to)
1085 (beginning-of-line)
1086 (insert "Fontset: " fontset "\n")
1087 (insert "CHARSET or CHAR RANGE")
1088 (indent-to 24)
1089 (insert "FONT NAME\n")
1090 (insert "---------------------")
1091 (indent-to 24)
1092 (insert "---------")
1093 (insert "\n")
1094 (while tail
1095 (setq elt (car tail) tail (cdr tail))
1096 (setq chars (car elt) font-spec (car (cdr elt)) opened (cdr (cdr elt)))
1097 (if (symbolp chars)
1098 (setq charset chars from nil to nil)
1099 (if (integerp chars)
1100 (setq charset (char-charset chars) from chars to chars)
1101 (setq charset (char-charset (car chars))
1102 from (car chars) to (cdr chars))))
1103 (unless (eq charset prev-charset)
1104 (insert (symbol-name charset))
1105 (if from
1106 (insert "\n")))
1107 (when from
1108 (let ((split (split-char from)))
1109 (if (and (= (charset-dimension charset) 2)
1110 (= (nth 2 split) 0))
1111 (setq from
1112 (make-char charset (nth 1 split)
1113 (if (= (charset-chars charset) 94) 33 32))))
1114 (insert " " from))
1115 (when (/= from to)
1116 (insert "-")
1117 (let ((split (split-char to)))
1118 (if (and (= (charset-dimension charset) 2)
1119 (= (nth 2 split) 0))
1120 (setq to
1121 (make-char charset (nth 1 split)
1122 (if (= (charset-chars charset) 94) 126 127))))
1123 (insert to))))
1124 (indent-to 24)
1125 (if (stringp font-spec)
1126 (insert font-spec)
1127 (if (car font-spec)
1128 (if (string-match "-" (car font-spec))
1129 (insert "-" (car font-spec) "-*-")
1130 (insert "-*-" (car font-spec) "-*-"))
1131 (insert "-*-"))
1132 (if (cdr font-spec)
1133 (if (string-match "-" (cdr font-spec))
1134 (insert (cdr font-spec))
1135 (insert (cdr font-spec) "-*"))
1136 (insert "*")))
1137 (insert "\n")
1138 (when print-fonts
1139 (while opened
1140 (indent-to 5)
1141 (insert "[" (car opened) "]\n")
1142 (setq opened (cdr opened))))
1143 (setq prev-charset charset)
1144 )))
1145
1146 ;;;###autoload
1147 (defun describe-fontset (fontset)
1148 "Display information of FONTSET.
1149 This shows which font is used for which character(s)."
1150 (interactive
1151 (if (not (and window-system (fboundp 'fontset-list)))
1152 (error "No fontsets being used")
1153 (let ((fontset-list (nconc
1154 (mapcar 'list (fontset-list))
1155 (mapcar (lambda (x) (list (cdr x)))
1156 fontset-alias-alist)))
1157 (completion-ignore-case t))
1158 (list (completing-read
1159 "Fontset (default, used by the current frame): "
1160 fontset-list nil t)))))
1161 (if (= (length fontset) 0)
1162 (setq fontset (cdr (assq 'font (frame-parameters)))))
1163 (if (not (setq fontset (query-fontset fontset)))
1164 (error "Current frame is using font, not fontset"))
1165 (with-output-to-temp-buffer "*Help*"
1166 (save-excursion
1167 (set-buffer standard-output)
1168 (print-fontset fontset t))))
1169
1170 ;;;###autoload
1171 (defun list-fontsets (arg)
1172 "Display a list of all fontsets.
1173 This shows the name, size, and style of each fontset.
1174 With prefix arg, it also list the fonts contained in each fontset;
1175 see the function `describe-fontset' for the format of the list."
1176 (interactive "P")
1177 (if (not (and window-system (fboundp 'fontset-list)))
1178 (error "No fontsets being used")
1179 (with-output-to-temp-buffer "*Help*"
1180 (save-excursion
1181 ;; This code is duplicated near the end of mule-diag.
1182 (set-buffer standard-output)
1183 (let ((fontsets
1184 (sort (fontset-list)
1185 (function (lambda (x y)
1186 (string< (fontset-plain-name x)
1187 (fontset-plain-name y)))))))
1188 (while fontsets
1189 (if arg
1190 (print-fontset (car fontsets) nil)
1191 (insert "Fontset: " (car fontsets) "\n"))
1192 (setq fontsets (cdr fontsets))))))))
1193 \f
1194 ;;;###autoload
1195 (defun list-input-methods ()
1196 "Display information about all input methods."
1197 (interactive)
1198 (with-output-to-temp-buffer "*Help*"
1199 (list-input-methods-1)))
1200
1201 (defun list-input-methods-1 ()
1202 (if (not input-method-alist)
1203 (progn
1204 (princ "
1205 No input method is available, perhaps because you have not yet
1206 installed LEIM (Libraries of Emacs Input Method).
1207
1208 LEIM is available from the same ftp directory as Emacs. For instance,
1209 if there exists an archive file `emacs-20.N.tar.gz', there should also
1210 be a file `leim-20.N.tar.gz'. When you extract this file, LEIM files
1211 are put under the subdirectory `emacs-20.N/leim'. When you install
1212 Emacs again, you should be able to use various input methods."))
1213 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1214 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1215 (setq input-method-alist
1216 (sort input-method-alist
1217 (function (lambda (x y) (string< (nth 1 x) (nth 1 y))))))
1218 (let ((l input-method-alist)
1219 language elt)
1220 (while l
1221 (setq elt (car l) l (cdr l))
1222 (when (not (equal language (nth 1 elt)))
1223 (setq language (nth 1 elt))
1224 (princ language)
1225 (terpri))
1226 (princ (format " %s (`%s' in mode line)\n %s\n"
1227 (car elt)
1228 (let ((title (nth 3 elt)))
1229 (if (and (consp title) (stringp (car title)))
1230 (car title)
1231 title))
1232 (let ((description (nth 4 elt)))
1233 (string-match ".*" description)
1234 (match-string 0 description))))))))
1235 \f
1236 ;;; DIAGNOSIS
1237
1238 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1239 (defun insert-section (section-number title)
1240 (insert "########################################\n"
1241 "# Section " (format "%d" section-number) ". " title "\n"
1242 "########################################\n\n"))
1243
1244 ;;;###autoload
1245 (defun mule-diag ()
1246 "Display diagnosis of the multilingual environment (Mule).
1247
1248 This shows various information related to the current multilingual
1249 environment, including lists of input methods, coding systems,
1250 character sets, and fontsets (if Emacs is running under a window
1251 system which uses fontsets)."
1252 (interactive)
1253 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1254 (save-excursion
1255 (set-buffer standard-output)
1256 (insert "###############################################\n"
1257 "### Current Status of Multilingual Features ###\n"
1258 "###############################################\n\n"
1259 "CONTENTS: Section 1. General Information\n"
1260 " Section 2. Display\n"
1261 " Section 3. Input methods\n"
1262 " Section 4. Coding systems\n"
1263 " Section 5. Character sets\n")
1264 (if (and window-system (fboundp 'fontset-list))
1265 (insert " Section 6. Fontsets\n"))
1266 (insert "\n")
1267
1268 (insert-section 1 "General Information")
1269 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1270 (insert "Configuration options:\n " system-configuration-options "\n\n")
1271 (insert "Multibyte characters awareness:\n"
1272 (format " default: %S\n" default-enable-multibyte-characters)
1273 (format " current-buffer: %S\n\n" enable-multibyte-characters))
1274 (insert "Current language environment: " current-language-environment
1275 "\n\n")
1276
1277 (insert-section 2 "Display")
1278 (if window-system
1279 (insert "Window-system: "
1280 (symbol-name window-system)
1281 (format "%s" window-system-version))
1282 (insert "Terminal: " (getenv "TERM")))
1283 (insert "\n\n")
1284
1285 (if (eq window-system 'x)
1286 (let ((font (cdr (assq 'font (frame-parameters)))))
1287 (insert "The selected frame is using the "
1288 (if (query-fontset font) "fontset" "font")
1289 ":\n\t" font))
1290 (insert "Coding system of the terminal: "
1291 (symbol-name (terminal-coding-system))))
1292 (insert "\n\n")
1293
1294 (insert-section 3 "Input methods")
1295 (list-input-methods-1)
1296 (insert "\n")
1297 (if default-input-method
1298 (insert (format "Default input method: %s\n" default-input-method))
1299 (insert "No default input method is specified\n"))
1300
1301 (insert-section 4 "Coding systems")
1302 (list-coding-systems-1 t)
1303 (princ "\
1304 ############################
1305 ## LIST OF CODING CATEGORIES (ordered by priority)
1306 ## CATEGORY:CODING-SYSTEM
1307 ##
1308 ")
1309 (let ((l coding-category-list))
1310 (while l
1311 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
1312 (setq l (cdr l))))
1313 (insert "\n")
1314
1315 (insert-section 5 "Character sets")
1316 (list-character-sets-2)
1317 (insert "\n")
1318
1319 (when (and window-system (fboundp 'fontset-list))
1320 ;; This code duplicates most of list-fontsets.
1321 (insert-section 6 "Fontsets")
1322 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1323 (insert "------------\t\t\t\t\t\t ----- -----\n")
1324 (let ((fontsets (fontset-list)))
1325 (while fontsets
1326 (print-fontset (car fontsets) t)
1327 (setq fontsets (cdr fontsets)))))
1328 (print-help-return-message))))
1329
1330 \f
1331 ;;; DUMP DATA FILE
1332
1333 ;;;###autoload
1334 (defun dump-charsets ()
1335 "Dump information about all charsets into the file `CHARSETS'.
1336 The file is saved in the directory `data-directory'."
1337 (let ((file (expand-file-name "CHARSETS" data-directory))
1338 buf)
1339 (or (file-writable-p file)
1340 (error "Can't write to file %s" file))
1341 (setq buf (find-file-noselect file))
1342 (save-window-excursion
1343 (save-excursion
1344 (set-buffer buf)
1345 (setq buffer-read-only nil)
1346 (erase-buffer)
1347 (list-character-sets-2)
1348 (insert-buffer-substring "*Help*")
1349 (let (make-backup-files
1350 coding-system-for-write)
1351 (save-buffer))))
1352 (kill-buffer buf))
1353 (if noninteractive
1354 (kill-emacs)))
1355
1356 ;;;###autoload
1357 (defun dump-codings ()
1358 "Dump information about all coding systems into the file `CODINGS'.
1359 The file is saved in the directory `data-directory'."
1360 (let ((file (expand-file-name "CODINGS" data-directory))
1361 buf)
1362 (or (file-writable-p file)
1363 (error "Can't write to file %s" file))
1364 (setq buf (find-file-noselect file))
1365 (save-window-excursion
1366 (save-excursion
1367 (set-buffer buf)
1368 (setq buffer-read-only nil)
1369 (erase-buffer)
1370 (list-coding-systems t)
1371 (insert-buffer-substring "*Help*")
1372 (list-coding-categories)
1373 (insert-buffer-substring "*Help*")
1374 (let (make-backup-files
1375 coding-system-for-write)
1376 (save-buffer))))
1377 (kill-buffer buf))
1378 (if noninteractive
1379 (kill-emacs)))
1380
1381 ;;; mule-diag.el ends here