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