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 "*Character Set List*"
88 (with-current-buffer standard-output
90 (list-character-sets-2)
92 (insert "Indirectly supported character sets are shown below.\n")
94 (substitute-command-keys
96 (if (display-mouse-p) "\\[help-follow-mouse] or ")
97 "\\[help-follow]:\n")))
98 (insert " on a column title to sort by that title,")
100 (insert "+----DIMENSION\n")
101 (insert " on a charset name to list characters.")
103 (insert "| +--CHARS\n")
104 (let ((columns '(("ID-NUM" . id
) "\t"
105 ("CHARSET-NAME" . name
) "\t\t\t"
106 ("MULTIBYTE-FORM" . id
) "\t"
107 ("D CH FINAL-CHAR" . iso-spec
)))
110 (if (stringp (car columns
))
111 (insert (car columns
))
112 (insert-text-button (car (car columns
))
113 :type
'sort-listed-character-sets
114 'sort-key
(cdr (car columns
)))
115 (goto-char (point-max)))
116 (setq columns
(cdr columns
)))
118 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
120 ;; Insert body sorted by charset IDs.
121 (list-character-sets-1 'id
)
123 ;; Insert non-directly-supported charsets.
125 (insert "\n\nINDIRECTLY SUPPORTED CHARSETS SETS:\n\n"
126 (propertize "CHARSET NAME\tMAPPED TO" 'face
'bold
)
127 "\n------------\t---------\n")
128 (dolist (elt non-iso-charset-alist
)
129 (insert-text-button (symbol-name (car elt
))
130 :type
'list-charset-chars
131 'help-args
(list (car elt
)))
133 (dolist (e (nth 1 elt
))
134 (when (>= (+ (current-column) 1 (string-width (symbol-name e
)))
135 ;; This is an approximate value. We don't know
136 ;; the correct window width of this buffer yet.
141 (insert (format "%s " e
)))
144 (defun sort-listed-character-sets (sort-key)
147 (help-setup-xref (list #'list-character-sets nil
) t
)
148 (let ((buffer-read-only nil
))
149 (goto-char (point-min))
150 (re-search-forward "[0-9][0-9][0-9]")
153 (search-forward "----------")
156 (narrow-to-region pos
(point))
157 (delete-region (point-min) (point-max))
158 (list-character-sets-1 sort-key
)))))))
160 (defun charset-multibyte-form-string (charset)
161 (let ((info (charset-info charset
)))
162 (cond ((eq charset
'ascii
)
164 ((eq charset
'eight-bit-control
)
165 (format "%2X Xx" (aref info
6)))
166 ((eq charset
'eight-bit-graphic
)
169 (let ((str (format "%2X" (aref info
6))))
170 (if (> (aref info
7) 0)
171 (setq str
(format "%s %2X"
173 (setq str
(concat str
" XX"))
174 (if (> (aref info
2) 1)
175 (setq str
(concat str
" XX")))
178 ;; Insert a list of character sets sorted by SORT-KEY. SORT-KEY
179 ;; should be one of `id', `name', and `iso-spec'. If SORT-KEY is nil,
180 ;; it defaults to `id'.
182 (defun list-character-sets-1 (sort-key)
185 (let ((tail (charset-list))
186 charset-info-list elt charset info sort-func
)
188 (setq charset
(car tail
) tail
(cdr tail
)
189 info
(charset-info charset
))
191 ;; Generate a list that contains all information to display.
192 (setq charset-info-list
193 (cons (list (charset-id charset
) ; ID-NUM
194 charset
; CHARSET-NAME
195 (charset-multibyte-form-string charset
); MULTIBYTE-FORM
196 (aref info
2) ; DIMENSION
197 (aref info
3) ; CHARS
198 (aref info
8) ; FINAL-CHAR
202 ;; Determine a predicate for `sort' by SORT-KEY.
204 (cond ((eq sort-key
'id
)
205 (lambda (x y
) (< (car x
) (car y
))))
208 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
))))
210 ((eq sort-key
'iso-spec
)
211 ;; Sort by DIMENSION CHARS FINAL-CHAR
213 (or (< (nth 3 x
) (nth 3 y
))
214 (and (= (nth 3 x
) (nth 3 y
))
215 (or (< (nth 4 x
) (nth 4 y
))
216 (and (= (nth 4 x
) (nth 4 y
))
217 (< (nth 5 x
) (nth 5 y
))))))))
219 (error "Invalid charset sort key: %s" sort-key
))))
221 (setq charset-info-list
(sort charset-info-list sort-func
))
223 ;; Insert information of character sets.
224 (while charset-info-list
225 (setq elt
(car charset-info-list
)
226 charset-info-list
(cdr charset-info-list
))
227 (insert (format "%03d(%02X)" (car elt
) (car elt
))) ; ID-NUM
229 (insert-text-button (symbol-name (nth 1 elt
))
230 :type
'list-charset-chars
231 'help-args
(list (nth 1 elt
)))
232 (goto-char (point-max))
235 (insert (nth 2 elt
)) ; MULTIBYTE-FORM
237 (insert (format "%d %2d " (nth 3 elt
) (nth 4 elt
)) ; DIMENSION and CHARS
238 (if (< (nth 5 elt
) 0) "none" (nth 5 elt
))) ; FINAL-CHAR
242 ;; List all character sets in a form that a program can easily parse.
244 (defun list-character-sets-2 ()
245 (insert "#########################
247 ## Each line corresponds to one charset.
248 ## The following attributes are listed in this order
249 ## separated by a colon `:' in one line.
251 ## CHARSET-SYMBOL-NAME,
252 ## DIMENSION (1 or 2)
254 ## BYTES (of multibyte form: 1, 2, 3, or 4),
255 ## WIDTH (occupied column numbers: 1 or 2),
256 ## DIRECTION (0:left-to-right, 1:right-to-left),
257 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
258 ## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
259 ## DESCRIPTION (describing string of the charset)
261 (let ((l charset-list
)
264 (setq charset
(car l
) l
(cdr l
))
265 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
268 (charset-dimension charset
)
269 (charset-chars charset
)
270 (charset-bytes charset
)
271 (charset-width charset
)
272 (charset-direction charset
)
273 (charset-iso-final-char charset
)
274 (charset-iso-graphic-plane charset
)
275 (charset-description charset
))))))
277 (defvar non-iso-charset-alist
279 (ascii latin-iso8859-1 mule-unicode-2500-33ff
280 mule-unicode-0100-24ff mule-unicode-e000-ffff
)
284 (ascii vietnamese-viscii-lower vietnamese-viscii-upper
)
285 viet-viscii-nonascii-translation-table
288 (ascii cyrillic-iso8859-5
)
289 cyrillic-koi8-r-nonascii-translation-table
292 (ascii cyrillic-iso8859-5
)
293 cyrillic-alternativnyj-nonascii-translation-table
296 (ascii chinese-big5-1 chinese-big5-2
)
299 ((?
\xA1 ?
\xFE) .
(?
\x40 ?
\x7E ?
\xA1 ?
\xFE))))
301 (ascii katakana-jisx0201 japanese-jisx0208
)
303 ((32 127 ?
\xA1 ?
\xDF)
304 ((?
\x81 ?
\x9F ?
\xE0 ?
\xEF) .
(?
\x40 ?
\x7E ?
\x80 ?
\xFC)))))
305 "Alist of charset names vs the corresponding information.
306 This is mis-named for historical reasons. The charsets are actually
307 non-built-in ones. They correspond to Emacs coding systems, not Emacs
308 charsets, i.e. what Emacs can read (or write) by mapping to (or
309 from) Emacs internal charsets that typically correspond to a limited
312 Each element has the following format:
313 (CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
315 CHARSET is the name (symbol) of the charset.
317 CHARSET-LIST is a list of Emacs charsets into which characters of
320 TRANSLATION-METHOD is a translation table (symbol) to translate a
321 character code of CHARSET to the corresponding Emacs character
322 code. It can also be a function to call with one argument, a
323 character code in CHARSET.
325 CODE-RANGE specifies the valid code ranges of CHARSET.
326 It is a list of RANGEs, where each RANGE is of the form:
327 (FROM1 TO1 FROM2 TO2 ...)
329 ((FROM1-1 TO1-1 FROM1-2 TO1-2 ...) . (FROM2-1 TO2-1 FROM2-2 TO2-2 ...))
330 In the first form, valid codes are between FROM1 and TO1, or FROM2 and
332 The second form is used for 2-byte codes. The car part is the ranges
333 of the first byte, and the cdr part is the ranges of the second byte.")
336 (defun decode-codepage-char (codepage code
)
337 "Decode a character that has code CODE in CODEPAGE.
338 Return a decoded character string. Each CODEPAGE corresponds to a
339 coding system cpCODEPAGE."
340 (let ((coding-system (intern (format "cp%d" codepage
))))
341 (or (coding-system-p coding-system
)
342 (codepage-setup codepage
))
344 (decode-coding-string (char-to-string code
) coding-system
))))
347 ;; Add DOS codepages to `non-iso-charset-alist'.
349 (let ((tail (cp-supported-codepages))
352 (setq elt
(car tail
) tail
(cdr tail
))
353 ;; Now ELT is (CODEPAGE . CHARSET), where CODEPAGE is a string
354 ;; (e.g. "850"), CHARSET is a charset that characters in CODEPAGE
356 (unless (assq (intern (concat "cp" (car elt
))) non-iso-charset-alist
)
357 (setq non-iso-charset-alist
358 (cons (list (intern (concat "cp" (car elt
)))
359 (list 'ascii
(cdr elt
))
361 (decode-codepage-char ,(string-to-int (car elt
))
364 non-iso-charset-alist
)))))
367 ;; A variable to hold charset input history.
368 (defvar charset-history nil
)
372 (defun read-charset (prompt &optional default-value initial-input
)
373 "Read a character set from the minibuffer, prompting with string PROMPT.
374 It must be an Emacs character set listed in the variable `charset-list'
375 or a non-ISO character set listed in the variable
376 `non-iso-charset-alist'.
378 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
379 DEFAULT-VALUE, if non-nil, is the default value.
380 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
381 See the documentation of the function `completing-read' for the
382 detailed meanings of these arguments."
383 (let* ((table (append (mapcar (lambda (x) (list (symbol-name x
)))
385 (mapcar (lambda (x) (list (symbol-name (car x
))))
386 non-iso-charset-alist
)))
387 (charset (completing-read prompt table
388 nil t initial-input
'charset-history
390 (if (> (length charset
) 0)
394 ;; List characters of the range MIN and MAX of CHARSET. If dimension
395 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
396 ;; (block index) of the characters, and MIN and MAX are the second
397 ;; bytes of the characters. If the dimension is one, ROW should be 0.
398 ;; For a non-ISO charset, CHARSET is a translation table (symbol) or a
399 ;; function to get Emacs' character codes that corresponds to the
400 ;; characters to list.
402 (defun list-block-of-chars (charset row min max
)
404 (insert-char ?-
(+ 4 (* 3 16)))
408 (insert (format "%3X" i
))
410 (setq i
(* (/ min
16) 16))
413 (insert (format "\n%3Xx" (/ (+ (* row
256) i
) 16))))
414 (setq ch
(cond ((< i min
)
418 (make-char charset i
)
419 (make-char charset row i
)))
420 ((and (symbolp charset
) (get charset
'translation-table
))
421 (aref (get charset
'translation-table
) i
))
422 (t (funcall charset
(+ (* row
256) i
)))))
423 (if (and (char-table-p charset
)
424 (or (< ch
32) (and (>= ch
127) (<= ch
255))))
425 ;; Don't insert a control code.
427 (unless ch
(setq ch
32))
430 (setq ch
(propertize "\t" 'display
"^I")))
431 ;; This doesn't DTRT. Maybe it's better to insert "^J" and not
432 ;; worry about the buffer contents not being correct.
434 ;;; (setq ch (propertize "\n" 'display "^J")))
435 (indent-to (+ (* (% i
16) 3) 6))
440 (defun list-iso-charset-chars (charset)
441 (let ((dim (charset-dimension charset
))
442 (chars (charset-chars charset
))
443 (plane (charset-iso-graphic-plane charset
))
445 (insert (format "Characters in the coded character set %s.\n" charset
))
447 (cond ((eq charset
'eight-bit-control
)
448 (setq min
128 max
159))
449 ((eq charset
'eight-bit-graphic
)
450 (setq min
160 max
255))
453 (setq min
33 max
126)
454 (setq min
32 max
127))
456 (setq min
(+ min
128) max
(+ max
128)))))
459 (list-block-of-chars charset
0 min max
)
462 (list-block-of-chars charset i min max
)
465 (defun list-non-iso-charset-chars (charset)
466 "List all characters in non-built-in coded character set CHARSET."
467 (let* ((slot (assq charset non-iso-charset-alist
))
468 (charsets (nth 1 slot
))
469 (translate-method (nth 2 slot
))
470 (ranges (nth 3 slot
))
473 (error "Unknown character set: %s" charset
))
474 (insert (format "Characters in the coded character set %s.\n" charset
))
476 (insert "They are mapped to: "
477 (mapconcat #'symbol-name charsets
", ")
480 (setq range
(pop ranges
))
481 (if (integerp (car range
))
482 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
483 (if (and (not (functionp translate-method
))
484 (< (car (last range
)) 256))
485 ;; Do it all in one block to avoid the listing being
486 ;; broken up at gaps in the range. Don't do that for
487 ;; function translate-method, since not all codes in
488 ;; that range may be valid.
489 (list-block-of-chars translate-method
490 0 (car range
) (car (last range
)))
492 (list-block-of-chars translate-method
493 0 (car range
) (nth 1 range
))
494 (setq range
(nthcdr 2 range
))))
495 ;; The form of RANGES is ((FROM1-1 TO1-1 ...) . (FROM2-1 TO2-1 ...)).
496 (let ((row-range (car range
))
498 col-range col col-max
)
500 (setq row
(car row-range
) row-max
(nth 1 row-range
)
501 row-range
(nthcdr 2 row-range
))
502 (while (<= row row-max
)
503 (setq col-range
(cdr range
))
505 (setq col
(car col-range
) col-max
(nth 1 col-range
)
506 col-range
(nthcdr 2 col-range
))
507 (list-block-of-chars translate-method row col col-max
))
508 (setq row
(1+ row
)))))))))
512 (defun list-charset-chars (charset)
513 "Display a list of characters in the specified character set.
514 This can list both Emacs `official' (ISO standard) charsets and the
515 characters encoded by various Emacs coding systems which correspond to
516 PC `codepages' and other coded character sets. See `non-iso-charset-alist'."
517 (interactive (list (read-charset "Character set: ")))
518 (with-output-to-temp-buffer "*Character List*"
519 (with-current-buffer standard-output
520 (setq mode-line-format
(copy-sequence mode-line-format
))
521 (let ((slot (memq 'mode-line-buffer-identification mode-line-format
)))
524 (cons (format " (%s)" charset
)
526 (setq indent-tabs-mode nil
)
527 (set-buffer-multibyte t
)
528 (cond ((charsetp charset
)
529 (list-iso-charset-chars charset
))
530 ((assq charset non-iso-charset-alist
)
531 (list-non-iso-charset-chars charset
))
533 (error "Invalid character set %s" charset
))))))
537 (defun describe-character-set (charset)
538 "Display information about built-in character set CHARSET."
539 (interactive (list (let ((non-iso-charset-alist nil
))
540 (read-charset "Charset: "))))
541 (or (charsetp charset
)
542 (error "Invalid charset: %S" charset
))
543 (let ((info (charset-info charset
)))
544 (help-setup-xref (list #'describe-character-set charset
) (interactive-p))
545 (with-output-to-temp-buffer (help-buffer)
546 (with-current-buffer standard-output
547 (insert "Character set: " (symbol-name charset
)
548 (format " (ID:%d)\n\n" (aref info
0)))
549 (insert (aref info
13) "\n\n") ; description
550 (insert "Number of contained characters: "
551 (if (= (aref info
2) 1)
552 (format "%d\n" (aref info
3))
553 (format "%dx%d\n" (aref info
3) (aref info
3))))
554 (insert "Final char of ISO2022 designation sequence: ")
555 (if (>= (aref info
8) 0)
556 (insert (format "`%c'\n" (aref info
8)))
557 (insert "not assigned\n"))
558 (insert (format "Width (how many columns on screen): %d\n"
560 (insert (format "Internal multibyte sequence: %s\n"
561 (charset-multibyte-form-string charset
)))
562 (let ((coding (plist-get (aref info
14) 'preferred-coding-system
)))
564 (insert (format "Preferred coding system: %s\n" coding
))
565 (search-backward (symbol-name coding
))
566 (help-xref-button 0 'help-coding-system coding
)))))))
570 ;; Print information of designation of each graphic register in FLAGS
571 ;; in human readable format. See the documentation of
572 ;; `make-coding-system' for the meaning of FLAGS.
573 (defun print-designation (flags)
574 (let ((graphic-register 0)
576 (while (< graphic-register
4)
577 (setq charset
(aref flags graphic-register
))
581 (cond ((null charset
)
584 "no initial designation, and used by any charsets")
587 charset
(charset-description charset
)))
589 (if (charsetp (car charset
))
590 (format "%s:%s, and also used by the followings:"
592 (charset-description (car charset
)))
593 "no initial designation, and used by the followings:"))
595 "invalid designation information"))))
596 (when (listp charset
)
597 (setq charset
(cdr charset
))
599 (cond ((eq (car charset
) t
)
600 (princ "\tany other charsets\n"))
601 ((charsetp (car charset
))
602 (princ (format "\t%s:%s\n"
604 (charset-description (car charset
)))))
606 "invalid designation information"))
607 (setq charset
(cdr charset
))))
608 (setq graphic-register
(1+ graphic-register
)))))
611 (defun describe-coding-system (coding-system)
612 "Display information about CODING-SYSTEM."
613 (interactive "zDescribe coding system (default, current choices): ")
614 (if (null coding-system
)
615 (describe-current-coding-system)
616 (help-setup-xref (list #'describe-coding-system coding-system
)
618 (with-output-to-temp-buffer (help-buffer)
619 (print-coding-system-briefly coding-system
'doc-string
)
621 (let ((vars (coding-system-get coding-system
'dependency
)))
623 (princ "See also the documentation of these customizable variables
624 which alter the behaviour of this coding system.\n")
632 (let ((type (coding-system-type coding-system
))
633 (flags (coding-system-flags coding-system
)))
636 (princ " (do no conversion)"))
638 (princ " (do automatic conversion)"))
640 (princ " (Emacs internal multibyte form)"))
642 (princ " (Shift-JIS, MS-KANJI)"))
644 (princ " (variant of ISO-2022)\n")
645 (princ "Initial designations:\n")
646 (print-designation flags
)
647 (princ "Other Form: \n ")
648 (princ (if (aref flags
4) "short-form" "long-form"))
649 (if (aref flags
5) (princ ", ASCII@EOL"))
650 (if (aref flags
6) (princ ", ASCII@CNTL"))
651 (princ (if (aref flags
7) ", 7-bit" ", 8-bit"))
652 (if (aref flags
8) (princ ", use-locking-shift"))
653 (if (aref flags
9) (princ ", use-single-shift"))
654 (if (aref flags
10) (princ ", use-roman"))
655 (if (aref flags
11) (princ ", use-old-jis"))
656 (if (aref flags
12) (princ ", no-ISO6429"))
657 (if (aref flags
13) (princ ", init-bol"))
658 (if (aref flags
14) (princ ", designation-bol"))
659 (if (aref flags
15) (princ ", convert-unsafe"))
660 (if (aref flags
16) (princ ", accept-latin-extra-code"))
665 (princ " (do conversion by CCL program)"))
667 (princ " (text with random binary characters)"))
668 (t (princ ": invalid coding-system."))))
669 (princ "\nEOL type: ")
670 (let ((eol-type (coding-system-eol-type coding-system
)))
671 (cond ((vectorp eol-type
)
672 (princ "Automatic selection from:\n\t")
675 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
676 ((eq eol-type
1) (princ "CRLF\n"))
677 ((eq eol-type
2) (princ "CR\n"))
678 (t (princ "invalid\n"))))
679 (let ((postread (coding-system-get coding-system
'post-read-conversion
)))
681 (princ "After decoding text normally,")
682 (princ " perform post-conversion using the function: ")
686 (let ((prewrite (coding-system-get coding-system
'pre-write-conversion
)))
688 (princ "Before encoding text normally,")
689 (princ " perform pre-conversion using the function: ")
693 (with-current-buffer standard-output
694 (let ((charsets (coding-system-get coding-system
'safe-charsets
)))
695 (when (and (not (memq (coding-system-base coding-system
)
696 '(raw-text emacs-mule
)))
699 (insert "This coding system can encode all charsets except for
700 eight-bit-control and eight-bit-graphic.\n")
701 (insert "This coding system encodes the following charsets:\n ")
703 (insert " " (symbol-name (car charsets
)))
704 (search-backward (symbol-name (car charsets
)))
705 (help-xref-button 0 'help-character-set
(car charsets
))
706 (goto-char (point-max))
707 (setq charsets
(cdr charsets
))))))))))
711 (defun describe-current-coding-system-briefly ()
712 "Display coding systems currently used in a brief format in echo area.
714 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
715 where mnemonics of the following coding systems come in this order
717 `buffer-file-coding-system' (of the current buffer)
718 eol-type of `buffer-file-coding-system' (of the current buffer)
719 Value returned by `keyboard-coding-system'
720 eol-type of `keyboard-coding-system'
721 Value returned by `terminal-coding-system'.
722 eol-type of `terminal-coding-system'
723 `process-coding-system' for read (of the current buffer, if any)
724 eol-type of `process-coding-system' for read (of the current buffer, if any)
725 `process-coding-system' for write (of the current buffer, if any)
726 eol-type of `process-coding-system' for write (of the current buffer, if any)
727 `default-buffer-file-coding-system'
728 eol-type of `default-buffer-file-coding-system'
729 `default-process-coding-system' for read
730 eol-type of `default-process-coding-system' for read
731 `default-process-coding-system' for write
732 eol-type of `default-process-coding-system'"
734 (let* ((proc (get-buffer-process (current-buffer)))
735 (process-coding-systems (if proc
(process-coding-system proc
))))
737 "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]"
738 (coding-system-mnemonic buffer-file-coding-system
)
739 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
740 (coding-system-mnemonic (keyboard-coding-system))
741 (coding-system-eol-type-mnemonic (keyboard-coding-system))
742 (coding-system-mnemonic (terminal-coding-system))
743 (coding-system-eol-type-mnemonic (terminal-coding-system))
744 (coding-system-mnemonic (car process-coding-systems
))
745 (coding-system-eol-type-mnemonic (car process-coding-systems
))
746 (coding-system-mnemonic (cdr process-coding-systems
))
747 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
748 (coding-system-mnemonic default-buffer-file-coding-system
)
749 (coding-system-eol-type-mnemonic default-buffer-file-coding-system
)
750 (coding-system-mnemonic (car default-process-coding-system
))
751 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
752 (coding-system-mnemonic (cdr default-process-coding-system
))
753 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
756 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
757 (defun print-coding-system-briefly (coding-system &optional doc-string
)
758 (if (not coding-system
)
760 (princ (format "%c -- %s"
761 (coding-system-mnemonic coding-system
)
763 (let ((aliases (coding-system-get coding-system
'alias-coding-systems
)))
764 (cond ((eq coding-system
(car aliases
))
766 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
767 ((memq coding-system aliases
)
768 (princ (format " (alias of %s)" (car aliases
))))
770 (let ((eol-type (coding-system-eol-type coding-system
))
771 (base-eol-type (coding-system-eol-type (car aliases
))))
772 (if (and (integerp eol-type
)
773 (vectorp base-eol-type
)
774 (not (eq coding-system
(aref base-eol-type eol-type
))))
775 (princ (format " (alias of %s)"
776 (aref base-eol-type eol-type
))))))))
779 (setq doc-string
(coding-system-doc-string coding-system
)))
780 (princ (format "%s\n" doc-string
)))))
783 (defun describe-current-coding-system ()
784 "Display coding systems currently used, in detail."
786 (with-output-to-temp-buffer "*Help*"
787 (let* ((proc (get-buffer-process (current-buffer)))
788 (process-coding-systems (if proc
(process-coding-system proc
))))
789 (princ "Coding system for saving this buffer:\n ")
790 (if (local-variable-p 'buffer-file-coding-system
)
791 (print-coding-system-briefly buffer-file-coding-system
)
792 (princ "Not set locally, use the default.\n"))
793 (princ "Default coding system (for new files):\n ")
794 (print-coding-system-briefly default-buffer-file-coding-system
)
795 (princ "Coding system for keyboard input:\n ")
796 (print-coding-system-briefly (keyboard-coding-system))
797 (princ "Coding system for terminal output:\n ")
798 (print-coding-system-briefly (terminal-coding-system))
799 (when (get-buffer-process (current-buffer))
800 (princ "Coding systems for process I/O:\n")
801 (princ " encoding input to the process: ")
802 (print-coding-system-briefly (cdr process-coding-systems
))
803 (princ " decoding output from the process: ")
804 (print-coding-system-briefly (car process-coding-systems
)))
805 (princ "Defaults for subprocess I/O:\n")
806 (princ " decoding: ")
807 (print-coding-system-briefly (car default-process-coding-system
))
808 (princ " encoding: ")
809 (print-coding-system-briefly (cdr default-process-coding-system
)))
811 (with-current-buffer standard-output
814 Priority order for recognizing coding systems when reading files:\n")
815 (let ((l coding-category-list
)
820 (setq coding
(symbol-value (car l
)))
821 ;; Do not list up the same coding system twice.
822 (when (and coding
(not (memq coding coding-list
)))
823 (setq coding-list
(cons coding coding-list
))
824 (princ (format " %d. %s " i coding
))
825 (setq aliases
(coding-system-get coding
'alias-coding-systems
))
826 (if (eq coding
(car aliases
))
828 (princ (cons 'alias
: (cdr aliases
))))
829 (if (memq coding aliases
)
830 (princ (list 'alias
'of
(car aliases
)))))
835 (princ "\n Other coding systems cannot be distinguished automatically
836 from these, and therefore cannot be recognized automatically
837 with the present coding system priorities.\n\n")
839 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
840 coding-system codings
)
842 (setq coding-system
(symbol-value (car categories
)))
845 (if (and (not (eq x coding-system
))
846 (coding-system-get x
'no-initial-designation
)
847 (let ((flags (coding-system-flags x
)))
848 (not (or (aref flags
10) (aref flags
11)))))
849 (setq codings
(cons x codings
))))
850 (get (car categories
) 'coding-systems
))
852 (let ((max-col (frame-width))
855 The following are decoded correctly but recognized as %s:\n "
859 (insert (format " %s" (car codings
)))
860 (when (> (current-column) max-col
)
863 (goto-char (point-max)))
864 (setq codings
(cdr codings
)))
866 (setq categories
(cdr categories
))))
868 (princ "Particular coding systems specified for certain file names:\n")
870 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
871 (princ " ---------\t--------------\t\t----------------\n")
872 (let ((func (lambda (operation alist
)
876 (princ "\tnothing specified\n")
879 (prin1 (car (car alist
)))
880 (if (>= (current-column) 40)
883 (princ (cdr (car alist
)))
885 (setq alist
(cdr alist
)))))))
886 (funcall func
"File I/O" file-coding-system-alist
)
887 (funcall func
"Process I/O" process-coding-system-alist
)
888 (funcall func
"Network I/O" network-coding-system-alist
))
891 ;; Print detailed information on CODING-SYSTEM.
892 (defun print-coding-system (coding-system)
893 (let ((type (coding-system-type coding-system
))
894 (eol-type (coding-system-eol-type coding-system
))
895 (flags (coding-system-flags coding-system
))
896 (aliases (coding-system-get coding-system
'alias-coding-systems
)))
897 (if (not (eq (car aliases
) coding-system
))
898 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
899 (princ coding-system
)
900 (setq aliases
(cdr aliases
))
903 (princ (car aliases
))
904 (setq aliases
(cdr aliases
)))
905 (princ (format ":%s:%c:%d:"
907 (coding-system-mnemonic coding-system
)
908 (if (integerp eol-type
) eol-type
3)))
909 (cond ((eq type
2) ; ISO-2022
913 (setq charset
(aref flags idx
))
914 (cond ((null charset
)
922 (princ (car charset
))
923 (setq charset
(cdr charset
))
926 (princ (car charset
))
927 (setq charset
(cdr charset
)))
932 (princ (if (aref flags idx
) 1 0))
935 (princ (if (aref flags idx
) 1 0))))
938 (if (symbolp (car flags
))
939 (princ (format " %s" (car flags
)))
940 (setq i
0 len
(length (car flags
)))
942 (princ (format " %x" (aref (car flags
) i
)))
945 (if (symbolp (cdr flags
))
946 (princ (format "%s" (cdr flags
)))
947 (setq i
0 len
(length (cdr flags
)))
949 (princ (format " %x" (aref (cdr flags
) i
)))
953 (princ (coding-system-doc-string coding-system
))
957 (defun list-coding-systems (&optional arg
)
958 "Display a list of all coding systems.
959 This shows the mnemonic letter, name, and description of each coding system.
961 With prefix arg, the output format gets more cryptic,
962 but still contains full information about each coding system."
964 (with-output-to-temp-buffer "*Help*"
965 (list-coding-systems-1 arg
)))
967 (defun list-coding-systems-1 (arg)
970 ###############################################
971 # List of coding systems in the following format:
972 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
976 #########################
977 ## LIST OF CODING SYSTEMS
978 ## Each line corresponds to one coding system
979 ## Format of a line is:
980 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
981 ## :PRE-WRITE-CONVERSION:DOC-STRING,
983 ## NAME = coding system name
984 ## ALIAS = alias of the coding system
985 ## TYPE = nil (no conversion), t (undecided or automatic detection),
986 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
987 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
990 ## comma (`,') separated data of the followings:
991 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
992 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
993 ## else if TYPE = 4 then
994 ## comma (`,') separated CCL programs for read and write
997 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
1000 (let ((bases (coding-system-list 'base-only
))
1003 (setq coding-system
(car bases
))
1005 (print-coding-system-briefly coding-system
'doc-string
)
1006 (print-coding-system coding-system
))
1007 (setq bases
(cdr bases
)))))
1010 (defun list-coding-categories ()
1011 "Display a list of all coding categories."
1012 (with-output-to-temp-buffer "*Help*"
1014 ############################
1015 ## LIST OF CODING CATEGORIES (ordered by priority)
1016 ## CATEGORY:CODING-SYSTEM
1019 (let ((l coding-category-list
))
1021 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1022 (setq l
(cdr l
))))))
1026 ;; Print information of a font in FONTINFO.
1027 (defun describe-font-internal (font-info &optional verbose
)
1028 (print-list "name (opened by):" (aref font-info
0))
1029 (print-list " full name:" (aref font-info
1))
1030 (print-list " size:" (format "%2d" (aref font-info
2)))
1031 (print-list " height:" (format "%2d" (aref font-info
3)))
1032 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
1033 (print-list "relative-compose:" (format "%2d" (aref font-info
5))))
1036 (defun describe-font (fontname)
1037 "Display information about fonts which partially match FONTNAME."
1038 (interactive "sFontname (default, current choice for ASCII chars): ")
1039 (or (and window-system
(fboundp 'fontset-list
))
1040 (error "No fontsets being used"))
1041 (when (or (not fontname
) (= (length fontname
) 0))
1042 (setq fontname
(cdr (assq 'font
(frame-parameters))))
1043 (if (query-fontset fontname
)
1045 (nth 1 (assq 'ascii
(aref (fontset-info fontname
) 2))))))
1046 (let ((font-info (font-info fontname
)))
1047 (if (null font-info
)
1048 (message "No matching font")
1049 (with-output-to-temp-buffer "*Help*"
1050 (describe-font-internal font-info
'verbose
)))))
1052 (defun print-fontset (fontset &optional print-fonts
)
1053 "Print information about FONTSET.
1054 If optional arg PRINT-FONTS is non-nil, also print names of all opened
1055 fonts for FONTSET. This function actually inserts the information in
1056 the current buffer."
1057 (let ((tail (aref (fontset-info fontset
) 2))
1058 elt chars font-spec opened prev-charset charset from to
)
1060 (insert "Fontset: " fontset
"\n")
1061 (insert "CHARSET or CHAR RANGE")
1063 (insert "FONT NAME\n")
1064 (insert "---------------------")
1066 (insert "---------")
1069 (setq elt
(car tail
) tail
(cdr tail
))
1070 (setq chars
(car elt
) font-spec
(car (cdr elt
)) opened
(cdr (cdr elt
)))
1072 (setq charset chars from nil to nil
)
1073 (if (integerp chars
)
1074 (setq charset
(char-charset chars
) from chars to chars
)
1075 (setq charset
(char-charset (car chars
))
1076 from
(car chars
) to
(cdr chars
))))
1077 (unless (eq charset prev-charset
)
1078 (insert (symbol-name charset
))
1082 (let ((split (split-char from
)))
1083 (if (and (= (charset-dimension charset
) 2)
1084 (= (nth 2 split
) 0))
1086 (make-char charset
(nth 1 split
)
1087 (if (= (charset-chars charset
) 94) 33 32))))
1091 (let ((split (split-char to
)))
1092 (if (and (= (charset-dimension charset
) 2)
1093 (= (nth 2 split
) 0))
1095 (make-char charset
(nth 1 split
)
1096 (if (= (charset-chars charset
) 94) 126 127))))
1099 (if (stringp font-spec
)
1102 (if (string-match "-" (car font-spec
))
1103 (insert "-" (car font-spec
) "-*-")
1104 (insert "-*-" (car font-spec
) "-*-"))
1107 (if (string-match "-" (cdr font-spec
))
1108 (insert (cdr font-spec
))
1109 (insert (cdr font-spec
) "-*"))
1115 (insert "[" (car opened
) "]\n")
1116 (setq opened
(cdr opened
))))
1117 (setq prev-charset charset
)
1121 (defun describe-fontset (fontset)
1122 "Display information about FONTSET.
1123 This shows which font is used for which character(s)."
1125 (if (not (and window-system
(fboundp 'fontset-list
)))
1126 (error "No fontsets being used")
1127 (let ((fontset-list (nconc
1129 (mapcar 'cdr fontset-alias-alist
)))
1130 (completion-ignore-case t
))
1131 (list (completing-read
1132 "Fontset (default, used by the current frame): "
1133 fontset-list nil t
)))))
1134 (if (= (length fontset
) 0)
1135 (setq fontset
(cdr (assq 'font
(frame-parameters)))))
1136 (if (not (setq fontset
(query-fontset fontset
)))
1137 (error "Current frame is using font, not fontset"))
1138 (help-setup-xref (list #'describe-fontset fontset
) (interactive-p))
1139 (with-output-to-temp-buffer (help-buffer)
1140 (with-current-buffer standard-output
1141 (print-fontset fontset t
))))
1144 (defun list-fontsets (arg)
1145 "Display a list of all fontsets.
1146 This shows the name, size, and style of each fontset.
1147 With prefix arg, also list the fonts contained in each fontset;
1148 see the function `describe-fontset' for the format of the list."
1150 (if (not (and window-system
(fboundp 'fontset-list
)))
1151 (error "No fontsets being used")
1152 (help-setup-xref (list #'list-fontsets arg
) (interactive-p))
1153 (with-output-to-temp-buffer (help-buffer)
1154 (with-current-buffer standard-output
1155 ;; This code is duplicated near the end of mule-diag.
1157 (sort (fontset-list)
1159 (string< (fontset-plain-name x
)
1160 (fontset-plain-name y
))))))
1163 (print-fontset (car fontsets
) nil
)
1164 (insert "Fontset: " (car fontsets
) "\n"))
1165 (setq fontsets
(cdr fontsets
))))))))
1168 (defun list-input-methods ()
1169 "Display information about all input methods."
1171 (help-setup-xref '(list-input-methods) (interactive-p))
1172 (with-output-to-temp-buffer (help-buffer)
1173 (list-input-methods-1)
1174 (with-current-buffer standard-output
1176 (goto-char (point-min))
1177 (while (re-search-forward
1178 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t
)
1179 (help-xref-button 1 #'help-input-method
1181 "mouse-2: describe this method"))))))
1183 (defun list-input-methods-1 ()
1184 (if (not input-method-alist
)
1187 No input method is available, perhaps because you have not
1188 installed LEIM (Libraries of Emacs Input Methods)."))
1189 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1190 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1191 (setq input-method-alist
1192 (sort input-method-alist
1193 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
1194 (let ((l input-method-alist
)
1197 (setq elt
(car l
) l
(cdr l
))
1198 (when (not (equal language
(nth 1 elt
)))
1199 (setq language
(nth 1 elt
))
1202 (princ (format " %s (`%s' in mode line)\n %s\n"
1204 (let ((title (nth 3 elt
)))
1205 (if (and (consp title
) (stringp (car title
)))
1208 (let ((description (nth 4 elt
)))
1209 (string-match ".*" description
)
1210 (match-string 0 description
))))))))
1214 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1215 (defun insert-section (section-number title
)
1216 (insert "########################################\n"
1217 "# Section " (format "%d" section-number
) ". " title
"\n"
1218 "########################################\n\n"))
1222 "Display diagnosis of the multilingual environment (Mule).
1224 This shows various information related to the current multilingual
1225 environment, including lists of input methods, coding systems,
1226 character sets, and fontsets (if Emacs is running under a window
1227 system which uses fontsets)."
1229 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1230 (with-current-buffer standard-output
1231 (insert "###############################################\n"
1232 "### Current Status of Multilingual Features ###\n"
1233 "###############################################\n\n"
1234 "CONTENTS: Section 1. General Information\n"
1235 " Section 2. Display\n"
1236 " Section 3. Input methods\n"
1237 " Section 4. Coding systems\n"
1238 " Section 5. Character sets\n")
1239 (if (and window-system
(fboundp 'fontset-list
))
1240 (insert " Section 6. Fontsets\n"))
1243 (insert-section 1 "General Information")
1244 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1245 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1246 (insert "Multibyte characters awareness:\n"
1247 (format " default: %S\n" default-enable-multibyte-characters
)
1248 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1249 (insert "Current language environment: " current-language-environment
1252 (insert-section 2 "Display")
1254 (insert "Window-system: "
1255 (symbol-name window-system
)
1256 (format "%s" window-system-version
))
1257 (insert "Terminal: " (getenv "TERM")))
1260 (if (eq window-system
'x
)
1261 (let ((font (cdr (assq 'font
(frame-parameters)))))
1262 (insert "The selected frame is using the "
1263 (if (query-fontset font
) "fontset" "font")
1265 (insert "Coding system of the terminal: "
1266 (symbol-name (terminal-coding-system))))
1269 (insert-section 3 "Input methods")
1270 (list-input-methods-1)
1272 (if default-input-method
1273 (insert (format "Default input method: %s\n" default-input-method
))
1274 (insert "No default input method is specified\n"))
1276 (insert-section 4 "Coding systems")
1277 (list-coding-systems-1 t
)
1279 ############################
1280 ## LIST OF CODING CATEGORIES (ordered by priority)
1281 ## CATEGORY:CODING-SYSTEM
1284 (let ((l coding-category-list
))
1286 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1290 (insert-section 5 "Character sets")
1291 (list-character-sets-2)
1294 (when (and window-system
(fboundp 'fontset-list
))
1295 ;; This code duplicates most of list-fontsets.
1296 (insert-section 6 "Fontsets")
1297 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1298 (insert "------------\t\t\t\t\t\t ----- -----\n")
1299 (let ((fontsets (fontset-list)))
1301 (print-fontset (car fontsets
) t
)
1302 (setq fontsets
(cdr fontsets
)))))
1303 (print-help-return-message))))
1305 ;;; mule-diag.el ends here