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