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