1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
6 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
8 ;; This file is part of GNU Emacs.
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)
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.
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.
29 ;;; General utility function
31 ;; Print all arguments with single space separator in one line.
32 (defun print-list (&rest args
)
37 (setq args
(cdr args
)))
41 ;; Re-order the elements of charset-list.
42 (defun sort-charset-list ()
45 (function (lambda (x y
) (< (charset-id x
) (charset-id y
)))))))
50 (defun list-character-sets (arg)
51 "Display a list of all character sets.
53 The ID-NUM column contains a charset identification number
54 for internal Emacs use.
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.
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.
67 With prefix arg, the output format gets more cryptic,
68 but still shows the full information."
70 (with-output-to-temp-buffer "*Help*"
71 (with-current-buffer standard-output
73 (list-character-sets-2)
76 (substitute-command-keys
78 (if (display-mouse-p) "\\[help-follow-mouse] or ")
79 "\\[help-follow]:\n")))
80 (insert " on a column title to sort by that title,")
82 (insert "+----DIMENSION\n")
83 (insert " on a charset name to list characters.")
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
)
92 (substitute-command-keys
93 (concat (if (display-mouse-p) "\\[help-follow-mouse], ")
94 "\\[help-follow]: sort on this column")))
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
104 (goto-char (point-max)))
105 (setq columns
(cdr columns
)))
107 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
109 ;; Insert body sorted by charset IDs.
110 (list-character-sets-1 'id
)
111 (help-setup-xref (list #'list-character-sets arg
) (interactive-p))))))
114 ;; Sort character set list by SORT-KEY.
116 (defun sort-listed-character-sets (sort-key)
119 (let ((buffer-read-only nil
))
120 (goto-char (point-min))
121 (re-search-forward "[0-9][0-9][0-9]")
123 (delete-region (point) (point-max))
124 (list-character-sets-1 sort-key
)
125 (help-setup-xref (list #'list-character-sets nil
) t
)))))
127 (defun charset-multibyte-form-string (charset)
128 (let ((info (charset-info charset
)))
129 (cond ((eq charset
'ascii
)
131 ((eq charset
'eight-bit-control
)
132 (format "%2X Xx" (aref info
6)))
133 ((eq charset
'eight-bit-graphic
)
136 (let ((str (format "%2X" (aref info
6))))
137 (if (> (aref info
7) 0)
138 (setq str
(format "%s %2X"
140 (setq str
(concat str
" XX"))
141 (if (> (aref info
2) 1)
142 (setq str
(concat str
" XX")))
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'.
149 (defun list-character-sets-1 (sort-key)
152 (let ((tail (charset-list))
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
)
159 (setq charset
(car tail
) tail
(cdr tail
)
160 info
(charset-info charset
))
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
173 ;; Determine a predicate for `sort' by SORT-KEY.
175 (cond ((eq sort-key
'id
)
176 (function (lambda (x y
) (< (car x
) (car y
)))))
179 (function (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
181 ((eq sort-key
'iso-spec
)
182 ;; Sort by DIMENSION CHARS FINAL-CHAR
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
)))))))))
191 (error "Invalid charset sort key: %s" sort-key
))))
193 (setq charset-info-list
(sort charset-info-list sort-func
))
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
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))
207 (insert (nth 2 elt
)) ; MULTIBYTE-FORM
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
214 ;; List all character sets in a form that a program can easily parse.
216 (defun list-character-sets-2 ()
217 (insert "#########################
219 ## Each line corresponds to one charset.
220 ## The following attributes are listed in this order
221 ## separated by a colon `:' in one line.
223 ## CHARSET-SYMBOL-NAME,
224 ## DIMENSION (1 or 2)
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)
233 (let ((l charset-list
)
236 (setq charset
(car l
) l
(cdr l
))
237 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
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
))))))
249 (defvar non-iso-charset-alist
251 (ascii vietnamese-viscii-lower vietnamese-viscii-upper
)
252 viet-viscii-nonascii-translation-table
255 (ascii cyrillic-iso8859-5
)
256 cyrillic-koi8-r-nonascii-translation-table
259 (ascii cyrillic-iso8859-5
)
260 cyrillic-alternativnyj-nonascii-translation-table
263 (ascii chinese-big5-1 chinese-big5-2
)
266 ((?
\xA1 ?
\xFE) .
(?
\x40 ?
\x7E ?
\xA1 ?
\xFE))))
268 (ascii katakana-jisx0201 japanese-jisx0208
)
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.
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.
277 Each element has the following format:
278 (NON-ISO-CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
280 NON-ISO-CHARSET is a name (symbol) of the non-ISO charset.
282 CHARSET-LIST is a list of Emacs' charsets into which characters of
283 NON-ISO-CHARSET are mapped.
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.
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 ...)
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
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.")
301 ;; Decode a character that has code CODE in CODEPAGE. Value is a
302 ;; string of decoded character.
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
))
310 (decode-coding-string (char-to-string code
) coding-system
))))
313 ;; Add DOS codepages to `non-iso-charset-alist'.
315 (let ((tail (cp-supported-codepages))
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
322 (setq non-iso-charset-alist
323 (cons (list (intern (concat "cp" (car elt
)))
324 (list 'ascii
(cdr elt
))
326 (decode-codepage-char ,(string-to-int (car elt
))
329 non-iso-charset-alist
))))
332 ;; A variable to hold charset input history.
333 (defvar charset-history nil
)
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'.
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
))))
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
356 (if (> (length charset
) 0)
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.
368 (defun list-block-of-chars (charset row min max
)
370 (insert-char ?-
(+ 4 (* 3 16)))
374 (insert (format "%3X" i
))
376 (setq i
(* (/ min
16) 16))
379 (insert (format "\n%3Xx" (/ (+ (* row
256) i
) 16))))
380 (setq ch
(cond ((< i min
)
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.
393 (indent-to (+ (* (% i
16) 3) 6))
399 ;; List all characters in ISO charset CHARSET.
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
))
406 (insert (format "Characters in the charset %s.\n" charset
))
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))
414 (setq min
33 max
126)
415 (setq min
32 max
127))
417 (setq min
(+ min
128) max
(+ max
128)))))
420 (list-block-of-chars charset
0 min max
)
423 (list-block-of-chars charset i min max
)
427 ;; List all characters in non-ISO charset CHARSET.
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
))
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
", ")
442 (setq range
(car ranges
) ranges
(cdr ranges
))
443 (if (integerp (car range
))
444 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
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
))
452 col-range col col-max
)
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
))
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
)))))))))
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
))
477 (error "Invalid charset %s" charset
))))))
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*"
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"
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
)))
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
)
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."
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
)
535 (if (eq charset
'unknown
)
538 ,(format "%s (0%o, %d, 0x%x) -- invalid character code"
540 (single-key-description char
)
541 (char-to-string char
))
545 ,(format "%s (0%o, %d, 0x%x)" (if (< char
256)
546 (single-key-description char
)
547 (char-to-string char
))
550 ,(symbol-name charset
)
551 ,(format "(%s)" (charset-description charset
)))
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
)))))
558 ,(nth 2 (assq (char-syntax char
) syntax-code-table
)))
560 ,@(let ((category-set (char-category-set char
)))
561 (if (not category-set
)
563 (mapcar #'(lambda (x) (format "%c:%s "
564 x
(category-docstring x
)))
565 (category-set-mnemonics category-set
)))))
567 ,(encoded-string-description
568 (string-as-unibyte (char-to-string char
)) nil
))
570 ,@(let* ((coding buffer-file-coding-system
)
571 (encoded (encode-coding-char char coding
)))
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))
580 (list "terminal code"
581 (let* ((coding (terminal-coding-system))
582 (encoded (encode-coding-char char coding
)))
584 (encoded-string-description encoded coding
)
585 "not encodable")))))))
586 (setq max-width
(apply #'max
(mapcar #'(lambda (x) (length (car x
)))
588 (with-output-to-temp-buffer "*Help*"
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)
599 (indent-to (1+ max-width
)))
603 (insert "\nComposed with the following character(s) "
604 (mapconcat (lambda (x) (format "`%c'" x
))
605 (substring composed
1)
607 " to form `" composed
"'")
608 (if (nth 3 composition
)
610 (insert "\nby the rule ("
611 (mapconcat (lambda (x)
612 (format (if (consp x
) "%S" "?%c") x
))
616 "See the variable `reference-point-alist' for the meaning of the rule.\n")))
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)
628 (while (< graphic-register
4)
629 (setq charset
(aref flags graphic-register
))
633 (cond ((null charset
)
636 "no initial designation, and used by any charsets")
639 charset
(charset-description charset
)))
641 (if (charsetp (car charset
))
642 (format "%s:%s, and also used by the followings:"
644 (charset-description (car charset
)))
645 "no initial designation, and used by the followings:"))
647 "invalid designation information"))))
648 (when (listp charset
)
649 (setq charset
(cdr charset
))
651 (cond ((eq (car charset
) t
)
652 (princ "\tany other charsets\n"))
653 ((charsetp (car charset
))
654 (princ (format "\t%s:%s\n"
656 (charset-description (car charset
)))))
658 "invalid designation information"))
659 (setq charset
(cdr charset
))))
660 (setq graphic-register
(1+ graphic-register
)))))
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
)))
672 (let ((type (coding-system-type coding-system
))
673 (flags (coding-system-flags coding-system
)))
676 (princ " (do no conversion)"))
678 (princ " (do automatic conversion)"))
680 (princ " (Emacs internal multibyte form)"))
682 (princ " (Shift-JIS, MS-KANJI)"))
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"))
705 (princ " (do conversion by CCL program)"))
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")
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
)))
721 (princ "After decoding text normally,")
722 (princ " perform post-conversion using the function: ")
726 (let ((prewrite (coding-system-get coding-system
'pre-write-conversion
)))
728 (princ "Before encoding text normally,")
729 (princ " perform pre-conversion using the function: ")
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
)))
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 ")
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
)
754 (defun describe-current-coding-system-briefly ()
755 "Display coding systems currently used in a brief format in echo area.
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'"
777 (let* ((proc (get-buffer-process (current-buffer)))
778 (process-coding-systems (if proc
(process-coding-system proc
))))
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
))
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
)
803 (princ (format "%c -- %s"
804 (coding-system-mnemonic coding-system
)
806 (let ((aliases (coding-system-get coding-system
'alias-coding-systems
)))
807 (if (eq coding-system
(car aliases
))
809 (princ (format " %S" (cons 'alias
: (cdr aliases
)))))
810 (if (memq coding-system aliases
)
811 (princ (format " (alias of %s)" (car aliases
))))))
814 (setq doc-string
(coding-system-doc-string coding-system
)))
815 (princ (format " %s\n" doc-string
)))))
818 (defun describe-current-coding-system ()
819 "Display coding systems currently used, in detail."
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
)))
847 (set-buffer standard-output
)
849 (princ "\nPriority order for recognizing coding systems when reading files:\n")
850 (let ((l coding-category-list
)
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
))
863 (princ (cons 'alias
: (cdr aliases
))))
864 (if (memq coding aliases
)
865 (princ (list 'alias
'of
(car aliases
)))))
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")
874 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
875 coding-system codings
)
877 (setq coding-system
(symbol-value (car categories
)))
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
))
888 (let ((max-col (frame-width))
890 (princ (format " The followings are decoded correctly but recognized as %s:\n " coding-system
))
893 (insert (format " %s" (car codings
)))
894 (when (> (current-column) max-col
)
897 (goto-char (point-max)))
898 (setq codings
(cdr codings
)))
900 (setq categories
(cdr categories
))))
902 (princ "Particular coding systems specified for certain file names:\n")
904 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
905 (princ " ---------\t--------------\t\t----------------\n")
906 (let ((func (lambda (operation alist
)
910 (princ "\tnothing specified\n")
913 (prin1 (car (car alist
)))
914 (if (>= (current-column) 40)
917 (princ (cdr (car alist
)))
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
))
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
))
937 (princ (car aliases
))
938 (setq aliases
(cdr aliases
)))
939 (princ (format ":%s:%c:%d:"
941 (coding-system-mnemonic coding-system
)
942 (if (integerp eol-type
) eol-type
3)))
943 (cond ((eq type
2) ; ISO-2022
947 (setq charset
(aref flags idx
))
948 (cond ((null charset
)
956 (princ (car charset
))
957 (setq charset
(cdr charset
))
960 (princ (car charset
))
961 (setq charset
(cdr charset
)))
966 (princ (if (aref flags idx
) 1 0))
969 (princ (if (aref flags idx
) 1 0))))
972 (if (symbolp (car flags
))
973 (princ (format " %s" (car flags
)))
974 (setq i
0 len
(length (car flags
)))
976 (princ (format " %x" (aref (car flags
) i
)))
979 (if (symbolp (cdr flags
))
980 (princ (format "%s" (cdr flags
)))
981 (setq i
0 len
(length (cdr flags
)))
983 (princ (format " %x" (aref (cdr flags
) i
)))
987 (princ (coding-system-doc-string coding-system
))
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.
995 With prefix arg, the output format gets more cryptic,
996 but still contains full information about each coding system."
998 (with-output-to-temp-buffer "*Help*"
999 (list-coding-systems-1 arg
)))
1001 (defun list-coding-systems-1 (arg)
1004 ###############################################
1005 # List of coding systems in the following format:
1006 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
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,
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)
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
1031 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
1034 (let ((bases (coding-system-list 'base-only
))
1037 (setq coding-system
(car bases
))
1039 (print-coding-system-briefly coding-system
'doc-string
)
1040 (print-coding-system coding-system
))
1041 (setq bases
(cdr bases
)))))
1044 (defun list-coding-categories ()
1045 "Display a list of all coding categories."
1046 (with-output-to-temp-buffer "*Help*"
1048 ############################
1049 ## LIST OF CODING CATEGORIES (ordered by priority)
1050 ## CATEGORY:CODING-SYSTEM
1053 (let ((l coding-category-list
))
1055 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1056 (setq l
(cdr l
))))))
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))))
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
)
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
)))))
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
)
1093 (insert "Fontset: " fontset
"\n")
1094 (insert "CHARSET or CHAR RANGE")
1096 (insert "FONT NAME\n")
1097 (insert "---------------------")
1099 (insert "---------")
1102 (setq elt
(car tail
) tail
(cdr tail
))
1103 (setq chars
(car elt
) font-spec
(car (cdr elt
)) opened
(cdr (cdr elt
)))
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
))
1115 (let ((split (split-char from
)))
1116 (if (and (= (charset-dimension charset
) 2)
1117 (= (nth 2 split
) 0))
1119 (make-char charset
(nth 1 split
)
1120 (if (= (charset-chars charset
) 94) 33 32))))
1124 (let ((split (split-char to
)))
1125 (if (and (= (charset-dimension charset
) 2)
1126 (= (nth 2 split
) 0))
1128 (make-char charset
(nth 1 split
)
1129 (if (= (charset-chars charset
) 94) 126 127))))
1132 (if (stringp font-spec
)
1135 (if (string-match "-" (car font-spec
))
1136 (insert "-" (car font-spec
) "-*-")
1137 (insert "-*-" (car font-spec
) "-*-"))
1140 (if (string-match "-" (cdr font-spec
))
1141 (insert (cdr font-spec
))
1142 (insert (cdr font-spec
) "-*"))
1148 (insert "[" (car opened
) "]\n")
1149 (setq opened
(cdr opened
))))
1150 (setq prev-charset charset
)
1154 (defun describe-fontset (fontset)
1155 "Display information of FONTSET.
1156 This shows which font is used for which character(s)."
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*"
1174 (set-buffer standard-output
)
1175 (print-fontset fontset t
))))
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."
1184 (if (not (and window-system
(fboundp 'fontset-list
)))
1185 (error "No fontsets being used")
1186 (with-output-to-temp-buffer "*Help*"
1188 ;; This code is duplicated near the end of mule-diag.
1189 (set-buffer standard-output
)
1191 (sort (fontset-list)
1192 (function (lambda (x y
)
1193 (string< (fontset-plain-name x
)
1194 (fontset-plain-name y
)))))))
1197 (print-fontset (car fontsets
) nil
)
1198 (insert "Fontset: " (car fontsets
) "\n"))
1199 (setq fontsets
(cdr fontsets
))))))))
1202 (defun list-input-methods ()
1203 "Display information about all input methods."
1205 (with-output-to-temp-buffer "*Help*"
1206 (list-input-methods-1)))
1208 (defun list-input-methods-1 ()
1209 (if (not input-method-alist
)
1212 No input method is available, perhaps because you have not yet
1213 installed LEIM (Libraries of Emacs Input Method).
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
)
1228 (setq elt
(car l
) l
(cdr l
))
1229 (when (not (equal language
(nth 1 elt
)))
1230 (setq language
(nth 1 elt
))
1233 (princ (format " %s (`%s' in mode line)\n %s\n"
1235 (let ((title (nth 3 elt
)))
1236 (if (and (consp title
) (stringp (car title
)))
1239 (let ((description (nth 4 elt
)))
1240 (string-match ".*" description
)
1241 (match-string 0 description
))))))))
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"))
1253 "Display diagnosis of the multilingual environment (Mule).
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)."
1260 (with-output-to-temp-buffer "*Mule-Diagnosis*"
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"))
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
1284 (insert-section 2 "Display")
1286 (insert "Window-system: "
1287 (symbol-name window-system
)
1288 (format "%s" window-system-version
))
1289 (insert "Terminal: " (getenv "TERM")))
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")
1297 (insert "Coding system of the terminal: "
1298 (symbol-name (terminal-coding-system))))
1301 (insert-section 3 "Input methods")
1302 (list-input-methods-1)
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"))
1308 (insert-section 4 "Coding systems")
1309 (list-coding-systems-1 t
)
1311 ############################
1312 ## LIST OF CODING CATEGORIES (ordered by priority)
1313 ## CATEGORY:CODING-SYSTEM
1316 (let ((l coding-category-list
))
1318 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1322 (insert-section 5 "Character sets")
1323 (list-character-sets-2)
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)))
1333 (print-fontset (car fontsets
) t
)
1334 (setq fontsets
(cdr fontsets
)))))
1335 (print-help-return-message))))
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
))
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
1352 (setq buffer-read-only nil
)
1354 (list-character-sets-2)
1355 (insert-buffer-substring "*Help*")
1356 (let (make-backup-files
1357 coding-system-for-write
)
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
))
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
1375 (setq buffer-read-only nil
)
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
)
1388 ;;; mule-diag.el ends here