1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 2001, 2002 Free Software Foundation, Inc.
7 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
9 ;; This file is part of GNU Emacs.
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)
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.
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.
30 ;; Make sure the help-xref button type is defined.
33 ;;; General utility function
35 ;; Print all arguments with single space separator in one line.
36 (defun print-list (&rest args)
41 (setq args (cdr args)))
45 ;; Re-order the elements of charset-list.
46 (defun sort-charset-list ()
49 (lambda (x y) (< (charset-id x) (charset-id y))))))
53 (define-button-type 'sort-listed-character-sets
54 'help-echo (purecopy "mouse-2, RET: sort on this column")
56 'action #'(lambda (button)
57 (sort-listed-character-sets (button-get button 'sort-key))))
59 (define-button-type 'list-charset-chars
61 'help-function #'list-charset-chars
62 'help-echo "mouse-2, RET: show table of characters for this character set")
66 (defun list-character-sets (arg)
67 "Display a list of all character sets.
69 The ID-NUM column contains a charset identification number for
72 The MULTIBYTE-FORM column contains the format of the buffer and string
73 multibyte sequence of characters in the charset using one to four
75 `xx' stands for any byte in the range 0..127.
76 `XX' stands for any byte in the range 160..255.
78 The D column contains the dimension of this character set. The CH
79 column contains the number of characters in a block of this character
80 set. The FINAL-CHAR column contains an ISO-2022 <final-char> to use
81 for designating this character set in ISO-2022-based coding systems.
83 With prefix arg, the output format gets more cryptic,
84 but still shows the full information."
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
90 (list-character-sets-2)
93 (substitute-command-keys
95 (if (display-mouse-p) "\\[help-follow-mouse] or ")
96 "\\[help-follow]:\n")))
97 (insert " on a column title to sort by that title,")
99 (insert "+----DIMENSION\n")
100 (insert " on a charset name to list characters.")
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)))
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)))
117 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
119 ;; Insert body sorted by charset IDs.
120 (list-character-sets-1 'id)))))
122 (defun sort-listed-character-sets (sort-key)
125 (help-setup-xref (list #'list-character-sets nil) t)
126 (let ((buffer-read-only nil))
127 (goto-char (point-min))
128 (re-search-forward "[0-9][0-9][0-9]")
130 (delete-region (point) (point-max))
131 (list-character-sets-1 sort-key)))))
133 (defun charset-multibyte-form-string (charset)
134 (let ((info (charset-info charset)))
135 (cond ((eq charset 'ascii)
137 ((eq charset 'eight-bit-control)
138 (format "%2X Xx" (aref info 6)))
139 ((eq charset 'eight-bit-graphic)
142 (let ((str (format "%2X" (aref info 6))))
143 (if (> (aref info 7) 0)
144 (setq str (format "%s %2X"
146 (setq str (concat str " XX"))
147 (if (> (aref info 2) 1)
148 (setq str (concat str " XX")))
151 ;; Insert a list of character sets sorted by SORT-KEY. SORT-KEY
152 ;; should be one of `id', `name', and `iso-spec'. If SORT-KEY is nil,
153 ;; it defaults to `id'.
155 (defun list-character-sets-1 (sort-key)
158 (let ((tail (charset-list))
159 charset-info-list elt charset info sort-func)
161 (setq charset (car tail) tail (cdr tail)
162 info (charset-info charset))
164 ;; Generate a list that contains all information to display.
165 (setq charset-info-list
166 (cons (list (charset-id charset) ; ID-NUM
167 charset ; CHARSET-NAME
168 (charset-multibyte-form-string charset); MULTIBYTE-FORM
169 (aref info 2) ; DIMENSION
170 (aref info 3) ; CHARS
171 (aref info 8) ; FINAL-CHAR
175 ;; Determine a predicate for `sort' by SORT-KEY.
177 (cond ((eq sort-key 'id)
178 (lambda (x y) (< (car x) (car y))))
181 (lambda (x y) (string< (nth 1 x) (nth 1 y))))
183 ((eq sort-key 'iso-spec)
184 ;; Sort by DIMENSION CHARS FINAL-CHAR
186 (or (< (nth 3 x) (nth 3 y))
187 (and (= (nth 3 x) (nth 3 y))
188 (or (< (nth 4 x) (nth 4 y))
189 (and (= (nth 4 x) (nth 4 y))
190 (< (nth 5 x) (nth 5 y))))))))
192 (error "Invalid charset sort key: %s" sort-key))))
194 (setq charset-info-list (sort charset-info-list sort-func))
196 ;; Insert information of character sets.
197 (while charset-info-list
198 (setq elt (car charset-info-list)
199 charset-info-list (cdr charset-info-list))
200 (insert (format "%03d(%02X)" (car elt) (car elt))) ; ID-NUM
202 (insert-text-button (symbol-name (nth 1 elt))
203 :type 'list-charset-chars
204 'help-args (list (nth 1 elt)))
205 (goto-char (point-max))
208 (insert (nth 2 elt)) ; MULTIBYTE-FORM
210 (insert (format "%d %2d " (nth 3 elt) (nth 4 elt)) ; DIMENSION and CHARS
211 (if (< (nth 5 elt) 0) "none" (nth 5 elt))) ; FINAL-CHAR
215 ;; List all character sets in a form that a program can easily parse.
217 (defun list-character-sets-2 ()
218 (insert "#########################
220 ## Each line corresponds to one charset.
221 ## The following attributes are listed in this order
222 ## separated by a colon `:' in one line.
224 ## CHARSET-SYMBOL-NAME,
225 ## DIMENSION (1 or 2)
227 ## BYTES (of multibyte form: 1, 2, 3, or 4),
228 ## WIDTH (occupied column numbers: 1 or 2),
229 ## DIRECTION (0:left-to-right, 1:right-to-left),
230 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
231 ## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
232 ## DESCRIPTION (describing string of the charset)
234 (let ((l charset-list)
237 (setq charset (car l) l (cdr l))
238 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
241 (charset-dimension charset)
242 (charset-chars charset)
243 (charset-bytes charset)
244 (charset-width charset)
245 (charset-direction charset)
246 (charset-iso-final-char charset)
247 (charset-iso-graphic-plane charset)
248 (charset-description charset))))))
250 (defvar non-iso-charset-alist
256 (ascii vietnamese-viscii-lower vietnamese-viscii-upper)
257 viet-viscii-nonascii-translation-table
260 (ascii cyrillic-iso8859-5)
261 cyrillic-koi8-r-nonascii-translation-table
264 (ascii cyrillic-iso8859-5)
265 cyrillic-alternativnyj-nonascii-translation-table
268 (ascii chinese-big5-1 chinese-big5-2)
271 ((?\xA1 ?\xFE) . (?\x40 ?\x7E ?\xA1 ?\xFE))))
273 (ascii katakana-jisx0201 japanese-jisx0208)
275 ((32 127 ?\xA1 ?\xDF)
276 ((?\x81 ?\x9F ?\xE0 ?\xEF) . (?\x40 ?\x7E ?\x80 ?\xFC)))))
277 "Alist of charset names vs the corresponding information.
278 This is mis-named for historical reasons. The charsets are actually
279 non-built-in ones. They correspond to Emacs coding systems, not Emacs
280 charsets, i.e. what Emacs can read (or write) by mapping to (or
281 from) Emacs internal charsets that typically correspond to a limited
284 Each element has the following format:
285 (CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
287 CHARSET is the name (symbol) of the charset.
289 CHARSET-LIST is a list of Emacs charsets into which characters of
292 TRANSLATION-METHOD is a translation table (symbol) to translate a
293 character code of CHARSET to the corresponding Emacs character
294 code. It can also be a function to call with one argument, a
295 character code in CHARSET.
297 CODE-RANGE specifies the valid code ranges of CHARSET.
298 It is a list of RANGEs, where each RANGE is of the form:
299 (FROM1 TO1 FROM2 TO2 ...)
301 ((FROM1-1 TO1-1 FROM1-2 TO1-2 ...) . (FROM2-1 TO2-1 FROM2-2 TO2-2 ...))
302 In the first form, valid codes are between FROM1 and TO1, or FROM2 and
304 The second form is used for 2-byte codes. The car part is the ranges
305 of the first byte, and the cdr part is the ranges of the second byte.")
308 (defun decode-codepage-char (codepage code)
309 "Decode a character that has code CODE in CODEPAGE.
310 Return a decoded character string. Each CODEPAGE corresponds to a
311 coding system cpCODEPAGE."
312 (let ((coding-system (intern (format "cp%d" codepage))))
313 (or (coding-system-p coding-system)
314 (codepage-setup codepage))
316 (decode-coding-string (char-to-string code) coding-system))))
319 ;; Add DOS codepages to `non-iso-charset-alist'.
321 (let ((tail (cp-supported-codepages))
324 (setq elt (car tail) tail (cdr tail))
325 ;; Now ELT is (CODEPAGE . CHARSET), where CODEPAGE is a string
326 ;; (e.g. "850"), CHARSET is a charset that characters in CODEPAGE
328 (unless (assq (intern (concat "cp" (car elt))) non-iso-charset-alist)
329 (setq non-iso-charset-alist
330 (cons (list (intern (concat "cp" (car elt)))
331 (list 'ascii (cdr elt))
333 (decode-codepage-char ,(string-to-int (car elt))
336 non-iso-charset-alist)))))
339 ;; A variable to hold charset input history.
340 (defvar charset-history nil)
344 (defun read-charset (prompt &optional default-value initial-input)
345 "Read a character set from the minibuffer, prompting with string PROMPT.
346 It must be an Emacs character set listed in the variable `charset-list'
347 or a non-ISO character set listed in the variable
348 `non-iso-charset-alist'.
350 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
351 DEFAULT-VALUE, if non-nil, is the default value.
352 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
353 See the documentation of the function `completing-read' for the
354 detailed meanings of these arguments."
355 (let* ((table (append (mapcar (lambda (x) (list (symbol-name x)))
357 (mapcar (lambda (x) (list (symbol-name (car x))))
358 non-iso-charset-alist)))
359 (charset (completing-read prompt table
360 nil t initial-input 'charset-history
362 (if (> (length charset) 0)
366 ;; List characters of the range MIN and MAX of CHARSET. If dimension
367 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
368 ;; (block index) of the characters, and MIN and MAX are the second
369 ;; bytes of the characters. If the dimension is one, ROW should be 0.
370 ;; For a non-ISO charset, CHARSET is a translation table (symbol) or a
371 ;; function to get Emacs' character codes that corresponds to the
372 ;; characters to list.
374 (defun list-block-of-chars (charset row min max)
376 (insert-char ?- (+ 4 (* 3 16)))
380 (insert (format "%3X" i))
382 (setq i (* (/ min 16) 16))
385 (insert (format "\n%3Xx" (/ (+ (* row 256) i) 16))))
386 (setq ch (cond ((< i min)
390 (make-char charset i)
391 (make-char charset row i)))
392 ((and (symbolp charset) (get charset 'translation-table))
393 (aref (get charset 'translation-table) i))
394 (t (funcall charset (+ (* row 256) i)))))
395 (if (and (char-table-p charset)
396 (or (< ch 32) (and (>= ch 127) (<= ch 255))))
397 ;; Don't insert a control code.
399 (unless ch (setq ch 32))
402 (setq ch (propertize "\t" 'display "^I")))
403 ;; This doesn't DTRT. Maybe it's better to insert "^J" and not
404 ;; worry about the buffer contents not being correct.
406 ;;; (setq ch (propertize "\n" 'display "^J")))
407 (indent-to (+ (* (% i 16) 3) 6))
412 (defun list-iso-charset-chars (charset)
413 (let ((dim (charset-dimension charset))
414 (chars (charset-chars charset))
415 (plane (charset-iso-graphic-plane charset))
417 (insert (format "Characters in the coded character set %s.\n" charset))
419 (cond ((eq charset 'eight-bit-control)
420 (setq min 128 max 159))
421 ((eq charset 'eight-bit-graphic)
422 (setq min 160 max 255))
425 (setq min 33 max 126)
426 (setq min 32 max 127))
428 (setq min (+ min 128) max (+ max 128)))))
431 (list-block-of-chars charset 0 min max)
434 (list-block-of-chars charset i min max)
437 (defun list-non-iso-charset-chars (charset)
438 "List all characters in non-built-in coded character set CHARSET."
439 (let* ((slot (assq charset non-iso-charset-alist))
440 (charsets (nth 1 slot))
441 (translate-method (nth 2 slot))
442 (ranges (nth 3 slot))
445 (error "Unknown character set: %s" charset))
446 (insert (format "Characters in the coded character set %s.\n" charset))
448 (insert "They are mapped to: "
449 (mapconcat #'symbol-name charsets ", ")
452 (setq range (pop ranges))
453 (if (integerp (car range))
454 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
455 (if (and (not (functionp translate-method))
456 (< (car (last range)) 256))
457 ;; Do it all in one block to avoid the listing being
458 ;; broken up at gaps in the range. Don't do that for
459 ;; function translate-method, since not all codes in
460 ;; that range may be valid.
461 (list-block-of-chars translate-method
462 0 (car range) (car (last range)))
464 (list-block-of-chars translate-method
465 0 (car range) (nth 1 range))
466 (setq range (nthcdr 2 range))))
467 ;; The form of RANGES is ((FROM1-1 TO1-1 ...) . (FROM2-1 TO2-1 ...)).
468 (let ((row-range (car range))
470 col-range col col-max)
472 (setq row (car row-range) row-max (nth 1 row-range)
473 row-range (nthcdr 2 row-range))
474 (while (<= row row-max)
475 (setq col-range (cdr range))
477 (setq col (car col-range) col-max (nth 1 col-range)
478 col-range (nthcdr 2 col-range))
479 (list-block-of-chars translate-method row col col-max))
480 (setq row (1+ row)))))))))
484 (defun list-charset-chars (charset)
485 "Display a list of characters in the specified character set.
486 This can list both Emacs `official' (ISO standard) charsets and the
487 characters encoded by various Emacs coding systems which correspond to
488 PC `codepages' and other coded character sets. See `non-iso-charset-alist'."
489 (interactive (list (read-charset "Character set: ")))
490 (with-output-to-temp-buffer "*Help*"
491 (with-current-buffer standard-output
492 (setq indent-tabs-mode nil)
493 (set-buffer-multibyte t)
494 (cond ((charsetp charset)
495 (list-iso-charset-chars charset))
496 ((assq charset non-iso-charset-alist)
497 (list-non-iso-charset-chars charset))
499 (error "Invalid character set %s" charset))))))
503 (defun describe-character-set (charset)
504 "Display information about built-in character set CHARSET."
505 (interactive (list (let ((non-iso-charset-alist nil))
506 (read-charset "Charset: "))))
507 (or (charsetp charset)
508 (error "Invalid charset: %S" charset))
509 (let ((info (charset-info charset)))
510 (help-setup-xref (list #'describe-character-set charset) (interactive-p))
511 (with-output-to-temp-buffer (help-buffer)
512 (with-current-buffer standard-output
513 (insert "Character set: " (symbol-name charset)
514 (format " (ID:%d)\n\n" (aref info 0)))
515 (insert (aref info 13) "\n\n") ; description
516 (insert "Number of contained characters: "
517 (if (= (aref info 2) 1)
518 (format "%d\n" (aref info 3))
519 (format "%dx%d\n" (aref info 3) (aref info 3))))
520 (insert "Final char of ISO2022 designation sequence: ")
521 (if (>= (aref info 8) 0)
522 (insert (format "`%c'\n" (aref info 8)))
523 (insert "not assigned\n"))
524 (insert (format "Width (how many columns on screen): %d\n"
526 (insert (format "Internal multibyte sequence: %s\n"
527 (charset-multibyte-form-string charset)))
528 (let ((coding (plist-get (aref info 14) 'preferred-coding-system)))
530 (insert (format "Preferred coding system: %s\n" coding))
531 (search-backward (symbol-name coding))
532 (help-xref-button 0 'help-coding-system coding)))))))
536 ;; Print information of designation of each graphic register in FLAGS
537 ;; in human readable format. See the documentation of
538 ;; `make-coding-system' for the meaning of FLAGS.
539 (defun print-designation (flags)
540 (let ((graphic-register 0)
542 (while (< graphic-register 4)
543 (setq charset (aref flags graphic-register))
547 (cond ((null charset)
550 "no initial designation, and used by any charsets")
553 charset (charset-description charset)))
555 (if (charsetp (car charset))
556 (format "%s:%s, and also used by the followings:"
558 (charset-description (car charset)))
559 "no initial designation, and used by the followings:"))
561 "invalid designation information"))))
562 (when (listp charset)
563 (setq charset (cdr charset))
565 (cond ((eq (car charset) t)
566 (princ "\tany other charsets\n"))
567 ((charsetp (car charset))
568 (princ (format "\t%s:%s\n"
570 (charset-description (car charset)))))
572 "invalid designation information"))
573 (setq charset (cdr charset))))
574 (setq graphic-register (1+ graphic-register)))))
577 (defun describe-coding-system (coding-system)
578 "Display information about CODING-SYSTEM."
579 (interactive "zDescribe coding system (default, current choices): ")
580 (if (null coding-system)
581 (describe-current-coding-system)
582 (help-setup-xref (list #'describe-coding-system coding-system)
584 (with-output-to-temp-buffer (help-buffer)
585 (print-coding-system-briefly coding-system 'doc-string)
588 (let ((type (coding-system-type coding-system))
589 (flags (coding-system-flags coding-system)))
592 (princ " (do no conversion)"))
594 (princ " (do automatic conversion)"))
596 (princ " (Emacs internal multibyte form)"))
598 (princ " (Shift-JIS, MS-KANJI)"))
600 (princ " (variant of ISO-2022)\n")
601 (princ "Initial designations:\n")
602 (print-designation flags)
603 (princ "Other Form: \n ")
604 (princ (if (aref flags 4) "short-form" "long-form"))
605 (if (aref flags 5) (princ ", ASCII@EOL"))
606 (if (aref flags 6) (princ ", ASCII@CNTL"))
607 (princ (if (aref flags 7) ", 7-bit" ", 8-bit"))
608 (if (aref flags 8) (princ ", use-locking-shift"))
609 (if (aref flags 9) (princ ", use-single-shift"))
610 (if (aref flags 10) (princ ", use-roman"))
611 (if (aref flags 11) (princ ", use-old-jis"))
612 (if (aref flags 12) (princ ", no-ISO6429"))
613 (if (aref flags 13) (princ ", init-bol"))
614 (if (aref flags 14) (princ ", designation-bol"))
615 (if (aref flags 15) (princ ", convert-unsafe"))
616 (if (aref flags 16) (princ ", accept-latin-extra-code"))
621 (princ " (do conversion by CCL program)"))
623 (princ " (text with random binary characters)"))
624 (t (princ ": invalid coding-system."))))
625 (princ "\nEOL type: ")
626 (let ((eol-type (coding-system-eol-type coding-system)))
627 (cond ((vectorp eol-type)
628 (princ "Automatic selection from:\n\t")
631 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n"))
632 ((eq eol-type 1) (princ "CRLF\n"))
633 ((eq eol-type 2) (princ "CR\n"))
634 (t (princ "invalid\n"))))
635 (let ((postread (coding-system-get coding-system 'post-read-conversion)))
637 (princ "After decoding text normally,")
638 (princ " perform post-conversion using the function: ")
642 (let ((prewrite (coding-system-get coding-system 'pre-write-conversion)))
644 (princ "Before encoding text normally,")
645 (princ " perform pre-conversion using the function: ")
649 (with-current-buffer standard-output
650 (let ((charsets (coding-system-get coding-system 'safe-charsets)))
651 (when (and (not (memq (coding-system-base coding-system)
652 '(raw-text emacs-mule)))
655 (insert "This coding system can encode all charsets except for
656 eight-bit-control and eight-bit-graphic.\n")
657 (insert "This coding system encodes the following charsets:\n ")
659 (insert " " (symbol-name (car charsets)))
660 (search-backward (symbol-name (car charsets)))
661 (help-xref-button 0 'help-character-set (car charsets))
662 (goto-char (point-max))
663 (setq charsets (cdr charsets))))))))))
667 (defun describe-current-coding-system-briefly ()
668 "Display coding systems currently used in a brief format in echo area.
670 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
671 where mnemonics of the following coding systems come in this order
673 `buffer-file-coding-system' (of the current buffer)
674 eol-type of `buffer-file-coding-system' (of the current buffer)
675 Value returned by `keyboard-coding-system'
676 eol-type of `keyboard-coding-system'
677 Value returned by `terminal-coding-system'.
678 eol-type of `terminal-coding-system'
679 `process-coding-system' for read (of the current buffer, if any)
680 eol-type of `process-coding-system' for read (of the current buffer, if any)
681 `process-coding-system' for write (of the current buffer, if any)
682 eol-type of `process-coding-system' for write (of the current buffer, if any)
683 `default-buffer-file-coding-system'
684 eol-type of `default-buffer-file-coding-system'
685 `default-process-coding-system' for read
686 eol-type of `default-process-coding-system' for read
687 `default-process-coding-system' for write
688 eol-type of `default-process-coding-system'"
690 (let* ((proc (get-buffer-process (current-buffer)))
691 (process-coding-systems (if proc (process-coding-system proc))))
693 "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]"
694 (coding-system-mnemonic buffer-file-coding-system)
695 (coding-system-eol-type-mnemonic buffer-file-coding-system)
696 (coding-system-mnemonic (keyboard-coding-system))
697 (coding-system-eol-type-mnemonic (keyboard-coding-system))
698 (coding-system-mnemonic (terminal-coding-system))
699 (coding-system-eol-type-mnemonic (terminal-coding-system))
700 (coding-system-mnemonic (car process-coding-systems))
701 (coding-system-eol-type-mnemonic (car process-coding-systems))
702 (coding-system-mnemonic (cdr process-coding-systems))
703 (coding-system-eol-type-mnemonic (cdr process-coding-systems))
704 (coding-system-mnemonic default-buffer-file-coding-system)
705 (coding-system-eol-type-mnemonic default-buffer-file-coding-system)
706 (coding-system-mnemonic (car default-process-coding-system))
707 (coding-system-eol-type-mnemonic (car default-process-coding-system))
708 (coding-system-mnemonic (cdr default-process-coding-system))
709 (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
712 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
713 (defun print-coding-system-briefly (coding-system &optional doc-string)
714 (if (not coding-system)
716 (princ (format "%c -- %s"
717 (coding-system-mnemonic coding-system)
719 (let ((aliases (coding-system-get coding-system 'alias-coding-systems)))
720 (cond ((eq coding-system (car aliases))
722 (princ (format " %S" (cons 'alias: (cdr aliases))))))
723 ((memq coding-system aliases)
724 (princ (format " (alias of %s)" (car aliases))))
726 (let ((eol-type (coding-system-eol-type coding-system))
727 (base-eol-type (coding-system-eol-type (car aliases))))
728 (if (and (integerp eol-type)
729 (vectorp base-eol-type)
730 (not (eq coding-system (aref base-eol-type eol-type))))
731 (princ (format " (alias of %s)"
732 (aref base-eol-type eol-type))))))))
735 (setq doc-string (coding-system-doc-string coding-system)))
736 (princ (format "%s\n" doc-string)))))
739 (defun describe-current-coding-system ()
740 "Display coding systems currently used, in detail."
742 (with-output-to-temp-buffer "*Help*"
743 (let* ((proc (get-buffer-process (current-buffer)))
744 (process-coding-systems (if proc (process-coding-system proc))))
745 (princ "Coding system for saving this buffer:\n ")
746 (if (local-variable-p 'buffer-file-coding-system)
747 (print-coding-system-briefly buffer-file-coding-system)
748 (princ "Not set locally, use the default.\n"))
749 (princ "Default coding system (for new files):\n ")
750 (print-coding-system-briefly default-buffer-file-coding-system)
751 (princ "Coding system for keyboard input:\n ")
752 (print-coding-system-briefly (keyboard-coding-system))
753 (princ "Coding system for terminal output:\n ")
754 (print-coding-system-briefly (terminal-coding-system))
755 (when (get-buffer-process (current-buffer))
756 (princ "Coding systems for process I/O:\n")
757 (princ " encoding input to the process: ")
758 (print-coding-system-briefly (cdr process-coding-systems))
759 (princ " decoding output from the process: ")
760 (print-coding-system-briefly (car process-coding-systems)))
761 (princ "Defaults for subprocess I/O:\n")
762 (princ " decoding: ")
763 (print-coding-system-briefly (car default-process-coding-system))
764 (princ " encoding: ")
765 (print-coding-system-briefly (cdr default-process-coding-system)))
767 (with-current-buffer standard-output
770 Priority order for recognizing coding systems when reading files:\n")
771 (let ((l coding-category-list)
776 (setq coding (symbol-value (car l)))
777 ;; Do not list up the same coding system twice.
778 (when (and coding (not (memq coding coding-list)))
779 (setq coding-list (cons coding coding-list))
780 (princ (format " %d. %s " i coding))
781 (setq aliases (coding-system-get coding 'alias-coding-systems))
782 (if (eq coding (car aliases))
784 (princ (cons 'alias: (cdr aliases))))
785 (if (memq coding aliases)
786 (princ (list 'alias 'of (car aliases)))))
791 (princ "\n Other coding systems cannot be distinguished automatically
792 from these, and therefore cannot be recognized automatically
793 with the present coding system priorities.\n\n")
795 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else))
796 coding-system codings)
798 (setq coding-system (symbol-value (car categories)))
801 (if (and (not (eq x coding-system))
802 (coding-system-get x 'no-initial-designation)
803 (let ((flags (coding-system-flags x)))
804 (not (or (aref flags 10) (aref flags 11)))))
805 (setq codings (cons x codings))))
806 (get (car categories) 'coding-systems))
808 (let ((max-col (frame-width))
811 The following are decoded correctly but recognized as %s:\n "
815 (insert (format " %s" (car codings)))
816 (when (> (current-column) max-col)
819 (goto-char (point-max)))
820 (setq codings (cdr codings)))
822 (setq categories (cdr categories))))
824 (princ "Particular coding systems specified for certain file names:\n")
826 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
827 (princ " ---------\t--------------\t\t----------------\n")
828 (let ((func (lambda (operation alist)
832 (princ "\tnothing specified\n")
835 (prin1 (car (car alist)))
836 (if (>= (current-column) 40)
839 (princ (cdr (car alist)))
841 (setq alist (cdr alist)))))))
842 (funcall func "File I/O" file-coding-system-alist)
843 (funcall func "Process I/O" process-coding-system-alist)
844 (funcall func "Network I/O" network-coding-system-alist))
847 ;; Print detailed information on CODING-SYSTEM.
848 (defun print-coding-system (coding-system)
849 (let ((type (coding-system-type coding-system))
850 (eol-type (coding-system-eol-type coding-system))
851 (flags (coding-system-flags coding-system))
852 (aliases (coding-system-get coding-system 'alias-coding-systems)))
853 (if (not (eq (car aliases) coding-system))
854 (princ (format "%s (alias of %s)\n" coding-system (car aliases)))
855 (princ coding-system)
856 (setq aliases (cdr aliases))
859 (princ (car aliases))
860 (setq aliases (cdr aliases)))
861 (princ (format ":%s:%c:%d:"
863 (coding-system-mnemonic coding-system)
864 (if (integerp eol-type) eol-type 3)))
865 (cond ((eq type 2) ; ISO-2022
869 (setq charset (aref flags idx))
870 (cond ((null charset)
878 (princ (car charset))
879 (setq charset (cdr charset))
882 (princ (car charset))
883 (setq charset (cdr charset)))
888 (princ (if (aref flags idx) 1 0))
891 (princ (if (aref flags idx) 1 0))))
894 (if (symbolp (car flags))
895 (princ (format " %s" (car flags)))
896 (setq i 0 len (length (car flags)))
898 (princ (format " %x" (aref (car flags) i)))
901 (if (symbolp (cdr flags))
902 (princ (format "%s" (cdr flags)))
903 (setq i 0 len (length (cdr flags)))
905 (princ (format " %x" (aref (cdr flags) i)))
909 (princ (coding-system-doc-string coding-system))
913 (defun list-coding-systems (&optional arg)
914 "Display a list of all coding systems.
915 This shows the mnemonic letter, name, and description of each coding system.
917 With prefix arg, the output format gets more cryptic,
918 but still contains full information about each coding system."
920 (with-output-to-temp-buffer "*Help*"
921 (list-coding-systems-1 arg)))
923 (defun list-coding-systems-1 (arg)
926 ###############################################
927 # List of coding systems in the following format:
928 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
932 #########################
933 ## LIST OF CODING SYSTEMS
934 ## Each line corresponds to one coding system
935 ## Format of a line is:
936 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
937 ## :PRE-WRITE-CONVERSION:DOC-STRING,
939 ## NAME = coding system name
940 ## ALIAS = alias of the coding system
941 ## TYPE = nil (no conversion), t (undecided or automatic detection),
942 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
943 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
946 ## comma (`,') separated data of the followings:
947 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
948 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
949 ## else if TYPE = 4 then
950 ## comma (`,') separated CCL programs for read and write
953 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
956 (let ((bases (coding-system-list 'base-only))
959 (setq coding-system (car bases))
961 (print-coding-system-briefly coding-system 'doc-string)
962 (print-coding-system coding-system))
963 (setq bases (cdr bases)))))
966 (defun list-coding-categories ()
967 "Display a list of all coding categories."
968 (with-output-to-temp-buffer "*Help*"
970 ############################
971 ## LIST OF CODING CATEGORIES (ordered by priority)
972 ## CATEGORY:CODING-SYSTEM
975 (let ((l coding-category-list))
977 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
982 ;; Print information of a font in FONTINFO.
983 (defun describe-font-internal (font-info &optional verbose)
984 (print-list "name (opened by):" (aref font-info 0))
985 (print-list " full name:" (aref font-info 1))
986 (print-list " size:" (format "%2d" (aref font-info 2)))
987 (print-list " height:" (format "%2d" (aref font-info 3)))
988 (print-list " baseline-offset:" (format "%2d" (aref font-info 4)))
989 (print-list "relative-compose:" (format "%2d" (aref font-info 5))))
992 (defun describe-font (fontname)
993 "Display information about fonts which partially match FONTNAME."
994 (interactive "sFontname (default, current choice for ASCII chars): ")
995 (or (and window-system (fboundp 'fontset-list))
996 (error "No fontsets being used"))
997 (when (or (not fontname) (= (length fontname) 0))
998 (setq fontname (cdr (assq 'font (frame-parameters))))
999 (if (query-fontset fontname)
1001 (nth 1 (assq 'ascii (aref (fontset-info fontname) 2))))))
1002 (let ((font-info (font-info fontname)))
1003 (if (null font-info)
1004 (message "No matching font")
1005 (with-output-to-temp-buffer "*Help*"
1006 (describe-font-internal font-info 'verbose)))))
1008 (defun print-fontset (fontset &optional print-fonts)
1009 "Print information about FONTSET.
1010 If optional arg PRINT-FONTS is non-nil, also print names of all opened
1011 fonts for FONTSET. This function actually inserts the information in
1012 the current buffer."
1013 (let ((tail (aref (fontset-info fontset) 2))
1014 elt chars font-spec opened prev-charset charset from to)
1016 (insert "Fontset: " fontset "\n")
1017 (insert "CHARSET or CHAR RANGE")
1019 (insert "FONT NAME\n")
1020 (insert "---------------------")
1022 (insert "---------")
1025 (setq elt (car tail) tail (cdr tail))
1026 (setq chars (car elt) font-spec (car (cdr elt)) opened (cdr (cdr elt)))
1028 (setq charset chars from nil to nil)
1029 (if (integerp chars)
1030 (setq charset (char-charset chars) from chars to chars)
1031 (setq charset (char-charset (car chars))
1032 from (car chars) to (cdr chars))))
1033 (unless (eq charset prev-charset)
1034 (insert (symbol-name charset))
1038 (let ((split (split-char from)))
1039 (if (and (= (charset-dimension charset) 2)
1040 (= (nth 2 split) 0))
1042 (make-char charset (nth 1 split)
1043 (if (= (charset-chars charset) 94) 33 32))))
1047 (let ((split (split-char to)))
1048 (if (and (= (charset-dimension charset) 2)
1049 (= (nth 2 split) 0))
1051 (make-char charset (nth 1 split)
1052 (if (= (charset-chars charset) 94) 126 127))))
1055 (if (stringp font-spec)
1058 (if (string-match "-" (car font-spec))
1059 (insert "-" (car font-spec) "-*-")
1060 (insert "-*-" (car font-spec) "-*-"))
1063 (if (string-match "-" (cdr font-spec))
1064 (insert (cdr font-spec))
1065 (insert (cdr font-spec) "-*"))
1071 (insert "[" (car opened) "]\n")
1072 (setq opened (cdr opened))))
1073 (setq prev-charset charset)
1077 (defun describe-fontset (fontset)
1078 "Display information about FONTSET.
1079 This shows which font is used for which character(s)."
1081 (if (not (and window-system (fboundp 'fontset-list)))
1082 (error "No fontsets being used")
1083 (let ((fontset-list (nconc
1085 (mapcar 'cdr fontset-alias-alist)))
1086 (completion-ignore-case t))
1087 (list (completing-read
1088 "Fontset (default, used by the current frame): "
1089 fontset-list nil t)))))
1090 (if (= (length fontset) 0)
1091 (setq fontset (cdr (assq 'font (frame-parameters)))))
1092 (if (not (setq fontset (query-fontset fontset)))
1093 (error "Current frame is using font, not fontset"))
1094 (help-setup-xref (list #'describe-fontset fontset) (interactive-p))
1095 (with-output-to-temp-buffer (help-buffer)
1096 (with-current-buffer standard-output
1097 (print-fontset fontset t))))
1100 (defun list-fontsets (arg)
1101 "Display a list of all fontsets.
1102 This shows the name, size, and style of each fontset.
1103 With prefix arg, also list the fonts contained in each fontset;
1104 see the function `describe-fontset' for the format of the list."
1106 (if (not (and window-system (fboundp 'fontset-list)))
1107 (error "No fontsets being used")
1108 (help-setup-xref (list #'list-fontsets arg) (interactive-p))
1109 (with-output-to-temp-buffer (help-buffer)
1110 (with-current-buffer standard-output
1111 ;; This code is duplicated near the end of mule-diag.
1113 (sort (fontset-list)
1115 (string< (fontset-plain-name x)
1116 (fontset-plain-name y))))))
1119 (print-fontset (car fontsets) nil)
1120 (insert "Fontset: " (car fontsets) "\n"))
1121 (setq fontsets (cdr fontsets))))))))
1124 (defun list-input-methods ()
1125 "Display information about all input methods."
1127 (help-setup-xref '(list-input-methods) (interactive-p))
1128 (with-output-to-temp-buffer (help-buffer)
1129 (list-input-methods-1)
1130 (with-current-buffer standard-output
1132 (goto-char (point-min))
1133 (while (re-search-forward
1134 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t)
1135 (help-xref-button 1 #'help-input-method
1137 "mouse-2: describe this method"))))))
1139 (defun list-input-methods-1 ()
1140 (if (not input-method-alist)
1143 No input method is available, perhaps because you have not
1144 installed LEIM (Libraries of Emacs Input Methods)."))
1145 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1146 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1147 (setq input-method-alist
1148 (sort input-method-alist
1149 (lambda (x y) (string< (nth 1 x) (nth 1 y)))))
1150 (let ((l input-method-alist)
1153 (setq elt (car l) l (cdr l))
1154 (when (not (equal language (nth 1 elt)))
1155 (setq language (nth 1 elt))
1158 (princ (format " %s (`%s' in mode line)\n %s\n"
1160 (let ((title (nth 3 elt)))
1161 (if (and (consp title) (stringp (car title)))
1164 (let ((description (nth 4 elt)))
1165 (string-match ".*" description)
1166 (match-string 0 description))))))))
1170 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1171 (defun insert-section (section-number title)
1172 (insert "########################################\n"
1173 "# Section " (format "%d" section-number) ". " title "\n"
1174 "########################################\n\n"))
1178 "Display diagnosis of the multilingual environment (Mule).
1180 This shows various information related to the current multilingual
1181 environment, including lists of input methods, coding systems,
1182 character sets, and fontsets (if Emacs is running under a window
1183 system which uses fontsets)."
1185 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1186 (with-current-buffer standard-output
1187 (insert "###############################################\n"
1188 "### Current Status of Multilingual Features ###\n"
1189 "###############################################\n\n"
1190 "CONTENTS: Section 1. General Information\n"
1191 " Section 2. Display\n"
1192 " Section 3. Input methods\n"
1193 " Section 4. Coding systems\n"
1194 " Section 5. Character sets\n")
1195 (if (and window-system (fboundp 'fontset-list))
1196 (insert " Section 6. Fontsets\n"))
1199 (insert-section 1 "General Information")
1200 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1201 (insert "Configuration options:\n " system-configuration-options "\n\n")
1202 (insert "Multibyte characters awareness:\n"
1203 (format " default: %S\n" default-enable-multibyte-characters)
1204 (format " current-buffer: %S\n\n" enable-multibyte-characters))
1205 (insert "Current language environment: " current-language-environment
1208 (insert-section 2 "Display")
1210 (insert "Window-system: "
1211 (symbol-name window-system)
1212 (format "%s" window-system-version))
1213 (insert "Terminal: " (getenv "TERM")))
1216 (if (eq window-system 'x)
1217 (let ((font (cdr (assq 'font (frame-parameters)))))
1218 (insert "The selected frame is using the "
1219 (if (query-fontset font) "fontset" "font")
1221 (insert "Coding system of the terminal: "
1222 (symbol-name (terminal-coding-system))))
1225 (insert-section 3 "Input methods")
1226 (list-input-methods-1)
1228 (if default-input-method
1229 (insert (format "Default input method: %s\n" default-input-method))
1230 (insert "No default input method is specified\n"))
1232 (insert-section 4 "Coding systems")
1233 (list-coding-systems-1 t)
1235 ############################
1236 ## LIST OF CODING CATEGORIES (ordered by priority)
1237 ## CATEGORY:CODING-SYSTEM
1240 (let ((l coding-category-list))
1242 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
1246 (insert-section 5 "Character sets")
1247 (list-character-sets-2)
1250 (when (and window-system (fboundp 'fontset-list))
1251 ;; This code duplicates most of list-fontsets.
1252 (insert-section 6 "Fontsets")
1253 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1254 (insert "------------\t\t\t\t\t\t ----- -----\n")
1255 (let ((fontsets (fontset-list)))
1257 (print-fontset (car fontsets) t)
1258 (setq fontsets (cdr fontsets)))))
1259 (print-help-return-message))))
1261 ;;; mule-diag.el ends here